Bug 38201: Move additional fields logic to the element component tree
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
2955a17c10
commit
a507ea2d00
|
|
@ -114,6 +114,9 @@ export default {
|
|||
});
|
||||
return property;
|
||||
},
|
||||
additionalFieldsChanged(additionalFieldValues, resource) {
|
||||
resource.extended_attributes = additionalFieldValues;
|
||||
},
|
||||
},
|
||||
name: "BaseElement",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
tableUrl,
|
||||
embedded,
|
||||
hasAdditionalFields,
|
||||
resourceName,
|
||||
extendedAttributesResourceType,
|
||||
}"
|
||||
@select-resource="$emit('select-resource', $event)"
|
||||
/>
|
||||
|
|
@ -97,6 +97,7 @@ export default {
|
|||
displayNameLowerCase: __("agreement"),
|
||||
displayNamePlural: __("agreements"),
|
||||
},
|
||||
extendedAttributesResourceType: "agreement",
|
||||
av_agreement_statuses,
|
||||
av_agreement_closure_reasons,
|
||||
av_agreement_renewal_priorities,
|
||||
|
|
@ -191,44 +192,8 @@ export default {
|
|||
},
|
||||
{
|
||||
name: "additional_fields",
|
||||
type: "component",
|
||||
showElement: {
|
||||
type: "relationship",
|
||||
hidden: agreement =>
|
||||
agreement._strings?.additional_field_values
|
||||
?.length > 0,
|
||||
componentPath: "./AdditionalFieldsDisplay.vue",
|
||||
componentProps: {
|
||||
extended_attributes_resource_type: {
|
||||
type: "string",
|
||||
value: "agreement",
|
||||
},
|
||||
additional_field_values: {
|
||||
resourceProperty:
|
||||
"_strings.additional_field_values",
|
||||
},
|
||||
},
|
||||
},
|
||||
componentPath: "./AdditionalFieldsEntry.vue",
|
||||
componentProps: {
|
||||
extended_attributes_resource_type: {
|
||||
type: "string",
|
||||
value: "agreement",
|
||||
},
|
||||
additional_field_values: {
|
||||
resourceProperty: "extended_attributes",
|
||||
},
|
||||
resource: {
|
||||
type: "resource",
|
||||
value: "agreement",
|
||||
},
|
||||
},
|
||||
events: [
|
||||
{
|
||||
name: "additional-fields-changed",
|
||||
callback: this.additionalFieldsChanged,
|
||||
},
|
||||
],
|
||||
extended_attributes_resource_type:
|
||||
this.extendedAttributesResourceType,
|
||||
},
|
||||
{
|
||||
name: "periods",
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
tableUrl,
|
||||
embedded,
|
||||
hasAdditionalFields,
|
||||
resourceName,
|
||||
extendedAttributesResourceType,
|
||||
getToolbarButtons,
|
||||
}"
|
||||
@select-resource="$emit('select-resource', $event)"
|
||||
|
|
@ -79,7 +79,7 @@ export default {
|
|||
|
||||
return {
|
||||
...BaseResource.setup({
|
||||
resourceName: "erm_package",
|
||||
resourceName: "package",
|
||||
nameAttr: "name",
|
||||
idAttr: "package_id",
|
||||
showComponent: "EHoldingsLocalPackagesShow",
|
||||
|
|
@ -94,6 +94,7 @@ export default {
|
|||
displayNameLowerCase: __("package"),
|
||||
displayNamePlural: __("packages"),
|
||||
},
|
||||
extendedAttributesResourceType: "package",
|
||||
av_package_types,
|
||||
av_package_content_types,
|
||||
vendors,
|
||||
|
|
@ -151,6 +152,11 @@ export default {
|
|||
type: "text",
|
||||
label: __("Notes"),
|
||||
},
|
||||
{
|
||||
name: "additional_fields",
|
||||
extended_attributes_resource_type:
|
||||
this.extendedAttributesResourceType,
|
||||
},
|
||||
{
|
||||
name: "package_agreements",
|
||||
type: "relationshipWidget",
|
||||
|
|
@ -249,7 +255,7 @@ export default {
|
|||
},
|
||||
},
|
||||
],
|
||||
erm_package: {
|
||||
package: {
|
||||
package_id: null,
|
||||
vendor_id: null,
|
||||
name: "",
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
filterTable,
|
||||
tableUrl,
|
||||
hasAdditionalFields,
|
||||
resourceName,
|
||||
extendedAttributesResourceType,
|
||||
}"
|
||||
@select-resource="$emit('select-resource', $event)"
|
||||
/>
|
||||
|
|
@ -89,11 +89,12 @@ export default {
|
|||
displayNameLowerCase: __("license"),
|
||||
displayNamePlural: __("licenses"),
|
||||
},
|
||||
extendedAttributesResourceType: "license",
|
||||
av_license_types,
|
||||
av_license_statuses,
|
||||
av_user_roles,
|
||||
vendors,
|
||||
}),
|
||||
av_license_types,
|
||||
av_license_statuses,
|
||||
av_user_roles,
|
||||
vendors,
|
||||
};
|
||||
},
|
||||
data() {
|
||||
|
|
@ -204,43 +205,8 @@ export default {
|
|||
},
|
||||
{
|
||||
name: "additional_fields",
|
||||
type: "relationship",
|
||||
showElement: {
|
||||
type: "relationship",
|
||||
hidden: license =>
|
||||
!!license._strings?.additional_field_values?.length,
|
||||
componentPath: "./AdditionalFieldsDisplay.vue",
|
||||
componentProps: {
|
||||
extended_attributes_resource_type: {
|
||||
type: "string",
|
||||
value: "license",
|
||||
},
|
||||
additional_field_values: {
|
||||
resourceProperty:
|
||||
"_strings.additional_field_values",
|
||||
},
|
||||
},
|
||||
},
|
||||
componentPath: "./AdditionalFieldsEntry.vue",
|
||||
componentProps: {
|
||||
extended_attributes_resource_type: {
|
||||
type: "string",
|
||||
value: "license",
|
||||
},
|
||||
additional_field_values: {
|
||||
resourceProperty: "extended_attributes",
|
||||
},
|
||||
resource: {
|
||||
type: "resource",
|
||||
value: "license",
|
||||
},
|
||||
},
|
||||
events: [
|
||||
{
|
||||
name: "additional-fields-changed",
|
||||
callback: this.additionalFieldsChanged,
|
||||
},
|
||||
],
|
||||
extended_attributes_resource_type:
|
||||
this.extendedAttributesResourceType,
|
||||
},
|
||||
{
|
||||
name: "user_roles",
|
||||
|
|
|
|||
|
|
@ -140,11 +140,22 @@
|
|||
:resource="resource"
|
||||
></FormRelationshipSelect>
|
||||
</template>
|
||||
<template v-else-if="attr.name == 'additional_fields'">
|
||||
<AdditionalFieldsEntry
|
||||
:resource="resource"
|
||||
:additional_field_values="resource.extended_attributes"
|
||||
:extended_attributes_resource_type="
|
||||
attr.extended_attributes_resource_type
|
||||
"
|
||||
@additional-fields-changed="additionalFieldsChanged"
|
||||
></AdditionalFieldsEntry>
|
||||
</template>
|
||||
<ToolTip v-if="attr.toolTip" :toolTip="attr.toolTip"></ToolTip>
|
||||
<span v-if="attr.required" class="required">{{ $__("Required") }}</span>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import AdditionalFieldsEntry from "./AdditionalFieldsEntry.vue";
|
||||
import BaseElement from "./BaseElement.vue";
|
||||
import FormRelationshipSelect from "./FormRelationshipSelect.vue";
|
||||
import ToolTip from "./ToolTip.vue";
|
||||
|
|
@ -216,6 +227,6 @@ export default {
|
|||
},
|
||||
},
|
||||
name: "FormElement",
|
||||
components: { FormRelationshipSelect, ToolTip },
|
||||
components: { FormRelationshipSelect, ToolTip, AdditionalFieldsEntry },
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div v-if="!initialized">{{ $__("Loading") }}</div>
|
||||
<div v-else :id="`${resourceName}_list`">
|
||||
<div v-else :id="`${extendedAttributesResourceType}_list`">
|
||||
<Toolbar v-if="!embedded">
|
||||
<ToolbarButton
|
||||
action="add"
|
||||
|
|
@ -85,7 +85,7 @@ export default {
|
|||
filterTable: Function,
|
||||
tableUrl: Function,
|
||||
hasAdditionalFields: { type: Boolean, default: false },
|
||||
resourceName: String,
|
||||
extendedAttributesResourceType: String,
|
||||
getToolbarButtons: {
|
||||
type: Function,
|
||||
default: () => [],
|
||||
|
|
@ -128,15 +128,17 @@ export default {
|
|||
},
|
||||
async getSearchableAdditionalFields() {
|
||||
const client = APIClient.additional_fields;
|
||||
await client.additional_fields.getAll(this.resourceName).then(
|
||||
searchable_additional_fields => {
|
||||
this.searchable_additional_fields =
|
||||
searchable_additional_fields.filter(
|
||||
field => field.searchable
|
||||
);
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
await client.additional_fields
|
||||
.getAll(this.extendedAttributesResourceType)
|
||||
.then(
|
||||
searchable_additional_fields => {
|
||||
this.searchable_additional_fields =
|
||||
searchable_additional_fields.filter(
|
||||
field => field.searchable
|
||||
);
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
},
|
||||
async getSearchableAVOptions() {
|
||||
const client_av = APIClient.authorised_values;
|
||||
|
|
|
|||
|
|
@ -119,15 +119,29 @@
|
|||
></component>
|
||||
</template>
|
||||
</template>
|
||||
<template
|
||||
v-else-if="
|
||||
attr.name == 'additional_fields' &&
|
||||
resource._strings?.additional_field_values.length > 0
|
||||
"
|
||||
>
|
||||
<AdditionalFieldsDisplay
|
||||
:additional_field_values="resource._strings.additional_field_values"
|
||||
:extended_attributes_resource_type="
|
||||
attr.extended_attributes_resource_type
|
||||
"
|
||||
></AdditionalFieldsDisplay>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { inject } from "vue";
|
||||
import LinkWrapper from "./LinkWrapper.vue";
|
||||
import BaseElement from "./BaseElement.vue";
|
||||
import AdditionalFieldsDisplay from "./AdditionalFieldsDisplay.vue";
|
||||
|
||||
export default {
|
||||
components: { LinkWrapper },
|
||||
components: { LinkWrapper, AdditionalFieldsDisplay },
|
||||
extends: BaseElement,
|
||||
setup() {
|
||||
const AVStore = inject("AVStore");
|
||||
|
|
|
|||
Loading…
Reference in New Issue