Bug 38201: Migrate UserRoles and Documents to RelationshipWidget
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
b3c69e142d
commit
b6e48dc73a
|
|
@ -259,7 +259,6 @@ export default {
|
|||
},
|
||||
],
|
||||
},
|
||||
label: __("Periods"),
|
||||
group: __("Periods"),
|
||||
props: {
|
||||
resourceRelationships: {
|
||||
|
|
@ -346,9 +345,8 @@ export default {
|
|||
},
|
||||
{
|
||||
name: "user_roles",
|
||||
type: "component",
|
||||
type: "relationshipWidget",
|
||||
group: __("Users"),
|
||||
componentPath: "./ERM/UserRoles.vue",
|
||||
showElement: {
|
||||
type: "table",
|
||||
columnData: "user_roles",
|
||||
|
|
@ -367,17 +365,25 @@ export default {
|
|||
],
|
||||
},
|
||||
props: {
|
||||
user_roles: {
|
||||
resourceRelationships: {
|
||||
type: "resourceProperty",
|
||||
resourceProperty: "user_roles",
|
||||
},
|
||||
av_user_roles: {
|
||||
type: "av",
|
||||
av: null,
|
||||
resourceStrings: {
|
||||
type: "object",
|
||||
value: {
|
||||
nameLC: __("user"),
|
||||
nameUC: __("Agreement user"),
|
||||
namePL: __("users"),
|
||||
},
|
||||
},
|
||||
user_type: {
|
||||
type: "string",
|
||||
value: __("Agreement user %s"),
|
||||
newRelationship: {
|
||||
type: "object",
|
||||
value: {
|
||||
user_id: null,
|
||||
role: null,
|
||||
patron_str: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
subFields: [
|
||||
|
|
@ -423,7 +429,6 @@ export default {
|
|||
{
|
||||
name: "licenses",
|
||||
type: "relationshipWidget",
|
||||
label: __("Licenses"),
|
||||
group: __("Licenses"),
|
||||
showElement: {
|
||||
type: "table",
|
||||
|
|
@ -551,7 +556,6 @@ export default {
|
|||
{
|
||||
name: "relationships",
|
||||
type: "relationshipWidget",
|
||||
label: __("Relationships"),
|
||||
group: __("Relationships"),
|
||||
showElement: {
|
||||
type: "component",
|
||||
|
|
@ -645,11 +649,11 @@ export default {
|
|||
},
|
||||
{
|
||||
name: "documents",
|
||||
type: "component",
|
||||
componentPath: "./ERM/Documents.vue",
|
||||
group: "Documents",
|
||||
type: "relationshipWidget",
|
||||
group: __("Documents"),
|
||||
showElement: {
|
||||
type: "component",
|
||||
label: __("Agreement users"),
|
||||
hidden: agreement => !!agreement.documents?.length,
|
||||
componentPath: "./DocumentDisplay.vue",
|
||||
props: {
|
||||
|
|
@ -660,10 +664,30 @@ export default {
|
|||
},
|
||||
},
|
||||
props: {
|
||||
documents: {
|
||||
resourceRelationships: {
|
||||
type: "resourceProperty",
|
||||
resourceProperty: "documents",
|
||||
},
|
||||
resourceStrings: {
|
||||
type: "object",
|
||||
value: {
|
||||
nameLC: __("document"),
|
||||
nameUC: __("Document"),
|
||||
namePL: __("documents"),
|
||||
},
|
||||
},
|
||||
newRelationship: {
|
||||
type: "object",
|
||||
value: {
|
||||
file_name: null,
|
||||
file_type: null,
|
||||
file_description: null,
|
||||
file_content: null,
|
||||
physical_location: null,
|
||||
uri: null,
|
||||
notes: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
subFields: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,74 +0,0 @@
|
|||
<template>
|
||||
<fieldset class="rows" id="documents">
|
||||
<fieldset
|
||||
:id="`document_${counter}`"
|
||||
class="rows"
|
||||
v-for="(document, counter) in documents"
|
||||
v-bind:key="counter"
|
||||
>
|
||||
<legend>
|
||||
{{ $__("Document %s").format(counter + 1) }}
|
||||
<a href="#" @click.prevent="deleteDocument(counter)"
|
||||
><i class="fa fa-trash"></i>
|
||||
{{ $__("Remove this document") }}</a
|
||||
>
|
||||
</legend>
|
||||
<ol>
|
||||
<li v-for="(attr, index) in subFields" v-bind:key="index">
|
||||
<FormElement
|
||||
:resource="document"
|
||||
:attr="attr"
|
||||
:index="counter"
|
||||
/>
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
<a class="btn btn-default" @click="addDocument"
|
||||
><font-awesome-icon icon="plus" /> {{ $__("Add new document") }}</a
|
||||
>
|
||||
</fieldset>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import FormElement from "../FormElement.vue";
|
||||
export default {
|
||||
components: { FormElement },
|
||||
setup() {
|
||||
const format_date = $date;
|
||||
return { format_date };
|
||||
},
|
||||
methods: {
|
||||
selectFile(e, i) {
|
||||
let files = e.target.files;
|
||||
if (!files) return;
|
||||
let file = files[0];
|
||||
const reader = new FileReader();
|
||||
reader.onload = e => this.loadFile(file.name, e.target.result, i);
|
||||
reader.readAsBinaryString(file);
|
||||
},
|
||||
loadFile(filename, content, i) {
|
||||
this.documents[i].file_name = filename;
|
||||
this.documents[i].file_content = btoa(content);
|
||||
},
|
||||
addDocument() {
|
||||
this.documents.push({
|
||||
file_name: null,
|
||||
file_type: null,
|
||||
file_description: null,
|
||||
file_content: null,
|
||||
physical_location: null,
|
||||
uri: null,
|
||||
notes: null,
|
||||
});
|
||||
},
|
||||
deleteDocument(counter) {
|
||||
this.documents.splice(counter, 1);
|
||||
},
|
||||
},
|
||||
name: "Documents",
|
||||
props: {
|
||||
documents: Array,
|
||||
subFields: Array,
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
@ -244,13 +244,13 @@ export default {
|
|||
},
|
||||
{
|
||||
name: "user_roles",
|
||||
type: "relationship",
|
||||
label: __("Users"),
|
||||
componentPath: "./ERM/UserRoles.vue",
|
||||
type: "relationshipWidget",
|
||||
group: __("Users"),
|
||||
showElement: {
|
||||
type: "table",
|
||||
columnData: "user_roles",
|
||||
hidden: license => !!license.user_roles?.length,
|
||||
label: __("License users"),
|
||||
columns: [
|
||||
{
|
||||
name: __("Name"),
|
||||
|
|
@ -265,17 +265,25 @@ export default {
|
|||
],
|
||||
},
|
||||
props: {
|
||||
user_roles: {
|
||||
resourceRelationships: {
|
||||
type: "resourceProperty",
|
||||
resourceProperty: "user_roles",
|
||||
},
|
||||
av_user_roles: {
|
||||
type: "av",
|
||||
av: null,
|
||||
resourceStrings: {
|
||||
type: "object",
|
||||
value: {
|
||||
nameLC: __("user"),
|
||||
nameUC: __("License user"),
|
||||
namePL: __("users"),
|
||||
},
|
||||
},
|
||||
user_type: {
|
||||
type: "string",
|
||||
value: __("License user %s"),
|
||||
newRelationship: {
|
||||
type: "object",
|
||||
value: {
|
||||
user_id: null,
|
||||
role: null,
|
||||
patron_str: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
subFields: [
|
||||
|
|
@ -320,8 +328,8 @@ export default {
|
|||
},
|
||||
{
|
||||
name: "documents",
|
||||
type: "relationship",
|
||||
componentPath: "./ERM/Documents.vue",
|
||||
type: "relationshipWidget",
|
||||
group: __("Documents"),
|
||||
showElement: {
|
||||
type: "component",
|
||||
hidden: license => !!license.documents?.length,
|
||||
|
|
@ -334,10 +342,30 @@ export default {
|
|||
},
|
||||
},
|
||||
props: {
|
||||
documents: {
|
||||
resourceRelationships: {
|
||||
type: "resourceProperty",
|
||||
resourceProperty: "documents",
|
||||
},
|
||||
resourceStrings: {
|
||||
type: "object",
|
||||
value: {
|
||||
nameLC: __("document"),
|
||||
nameUC: __("Document"),
|
||||
namePL: __("documents"),
|
||||
},
|
||||
},
|
||||
newRelationship: {
|
||||
type: "object",
|
||||
value: {
|
||||
file_name: null,
|
||||
file_type: null,
|
||||
file_description: null,
|
||||
file_content: null,
|
||||
physical_location: null,
|
||||
uri: null,
|
||||
notes: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
subFields: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,91 +0,0 @@
|
|||
<template>
|
||||
<fieldset class="rows" id="user_roles">
|
||||
<fieldset
|
||||
class="rows"
|
||||
v-for="(user_role, counter) in user_roles"
|
||||
v-bind:key="counter"
|
||||
>
|
||||
<legend>
|
||||
{{ user_type.format(counter + 1) }}
|
||||
<a href="#" @click.prevent="deleteUser(counter)"
|
||||
><i class="fa fa-trash"></i>
|
||||
{{ $__("Remove this user") }}</a
|
||||
>
|
||||
</legend>
|
||||
<ol>
|
||||
<li v-for="(attr, index) in subFields" v-bind:key="index">
|
||||
<FormElement
|
||||
:resource="user_role"
|
||||
:attr="attr"
|
||||
:index="counter"
|
||||
/>
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
<input
|
||||
type="hidden"
|
||||
name="selected_patron_id"
|
||||
id="selected_patron_id"
|
||||
/>
|
||||
<a class="btn btn-default" @click="addUser"
|
||||
><font-awesome-icon icon="plus" /> {{ $__("Add new user") }}</a
|
||||
>
|
||||
</fieldset>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { APIClient } from "../../fetch/api-client.js";
|
||||
import FormElement from "../FormElement.vue";
|
||||
|
||||
export default {
|
||||
components: { FormElement },
|
||||
name: "UserRoles",
|
||||
props: {
|
||||
user_type: String,
|
||||
av_user_roles: Array,
|
||||
user_roles: Array,
|
||||
subFields: Array,
|
||||
},
|
||||
beforeCreate() {
|
||||
this.user_roles.forEach(u => {
|
||||
u.patron_str = $patron_to_html(u.patron);
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
addUser() {
|
||||
this.user_roles.push({
|
||||
user_id: null,
|
||||
role: null,
|
||||
patron_str: "",
|
||||
});
|
||||
},
|
||||
deleteUser(counter) {
|
||||
this.user_roles.splice(counter, 1);
|
||||
},
|
||||
selectUser(counter) {
|
||||
// This is a bit dirty, the "select user" window should be rewritten and be a Vue component
|
||||
// but that's not for now...
|
||||
$(document).on(
|
||||
"hidden.bs.modal",
|
||||
"#patron_search_modal",
|
||||
this.newUserSelected
|
||||
);
|
||||
this.selected_user_counter = counter;
|
||||
},
|
||||
newUserSelected(e) {
|
||||
let c = this.selected_user_counter;
|
||||
let selected_patron_id =
|
||||
document.getElementById("selected_patron_id").value;
|
||||
let patron;
|
||||
const client = APIClient.patron;
|
||||
// FIXME We are missing a "loading..."
|
||||
client.patrons.get(selected_patron_id).then(p => {
|
||||
patron = p;
|
||||
this.user_roles[c].patron = patron;
|
||||
this.user_roles[c].patron_str = $patron_to_html(patron);
|
||||
this.user_roles[c].user_id = patron.patron_id;
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
data-bs-toggle="modal"
|
||||
><i class="fa fa-plus"></i> {{ $__("Select user") }}</a
|
||||
>
|
||||
<input type="hidden" name="selected_patron_id" id="selected_patron_id" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
|
@ -35,10 +36,8 @@ export default {
|
|||
"#patron_search_modal",
|
||||
this.newUserSelected
|
||||
);
|
||||
// this.selected_user_counter = counter
|
||||
},
|
||||
newUserSelected(e) {
|
||||
// let c = this.selected_user_counter
|
||||
let selected_patron_id =
|
||||
document.getElementById("selected_patron_id").value;
|
||||
let patron;
|
||||
|
|
|
|||
Loading…
Reference in New Issue