Bug 38201: Add a afterResourceFetch hook
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
c503d58197
commit
bd6caf88ca
|
|
@ -108,6 +108,9 @@ export default {
|
|||
appendToShow: this.appendToShow ? this.appendToShow() : [],
|
||||
nameAttr: this.nameAttr || null,
|
||||
idAttr: this.idAttr || null,
|
||||
afterResourceFetch:
|
||||
this.afterResourceFetch ||
|
||||
((component, resource, caller) => null),
|
||||
};
|
||||
return {
|
||||
resourceToBeGenerated: {},
|
||||
|
|
|
|||
|
|
@ -359,6 +359,77 @@ export default {
|
|||
].filter(b => Object.keys(b).length),
|
||||
};
|
||||
},
|
||||
afterResourceFetch(component, resource, caller) {
|
||||
if (caller === "show") {
|
||||
let display_table = component.resource.items.every(
|
||||
item =>
|
||||
item.processing_id ==
|
||||
component.resource.default_processing_id
|
||||
);
|
||||
if (display_table) {
|
||||
component.item_table = {
|
||||
display: false,
|
||||
data: [],
|
||||
columns: [],
|
||||
};
|
||||
component.item_table.data = [];
|
||||
component.resource.items.forEach(item => {
|
||||
let item_row = {};
|
||||
component.resource.default_processing.attributes.forEach(
|
||||
attribute => {
|
||||
item_row[attribute.processing_attribute_id] =
|
||||
item.attributes
|
||||
.filter(
|
||||
a =>
|
||||
a.processing_attribute_id ==
|
||||
attribute.processing_attribute_id
|
||||
)
|
||||
.map(a => a._strings.value.str);
|
||||
}
|
||||
);
|
||||
item_row.item = item;
|
||||
component.item_table.data.push(item_row);
|
||||
});
|
||||
component.item_table.columns = [];
|
||||
component.item_table.columns.push(
|
||||
{
|
||||
name: "checkboxes",
|
||||
className: "checkboxes",
|
||||
width: "5%",
|
||||
render: (data, type, row) => {
|
||||
return "";
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "",
|
||||
title: component.$__("ID"),
|
||||
data: "item.user_train_item_id",
|
||||
}
|
||||
);
|
||||
resource.default_processing.attributes.forEach(a =>
|
||||
component.item_table.columns.push({
|
||||
name: a.name,
|
||||
title: a.name,
|
||||
data: a.processing_attribute_id,
|
||||
render: (data, type, row) => {
|
||||
return data.join("<br/>");
|
||||
},
|
||||
})
|
||||
);
|
||||
component.item_table.columns.push({
|
||||
name: "actions",
|
||||
className: "actions noExport",
|
||||
title: component.$__("Actions"),
|
||||
searchable: false,
|
||||
orderable: false,
|
||||
render: (data, type, row) => {
|
||||
return "";
|
||||
},
|
||||
});
|
||||
}
|
||||
component.item_table.display = display_table;
|
||||
}
|
||||
},
|
||||
},
|
||||
name: "TrainResource",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ export default {
|
|||
resourceNamePlural: String,
|
||||
getFieldGroupings: Function,
|
||||
formGroupsDisplayMode: String,
|
||||
afterResourceFetch: Function,
|
||||
},
|
||||
created() {
|
||||
if (this.$route.params[this.idAttr]) {
|
||||
|
|
@ -185,6 +186,7 @@ export default {
|
|||
}
|
||||
});
|
||||
this.resourceToEdit = resource;
|
||||
this.afterResourceFetch(this, resource, "form");
|
||||
this.initialized = true;
|
||||
},
|
||||
error => {}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ export default {
|
|||
getFieldGroupings: Function,
|
||||
appendToShow: Array,
|
||||
getToolbarButtons: Function,
|
||||
afterResourceFetch: Function,
|
||||
},
|
||||
created() {
|
||||
this.getResource(this.$route.params[this.idAttr]);
|
||||
|
|
@ -74,6 +75,7 @@ export default {
|
|||
this.apiClient.get(resourceId).then(
|
||||
resource => {
|
||||
this.resource = resource;
|
||||
this.afterResourceFetch(this, resource, "show");
|
||||
this.initialized = true;
|
||||
},
|
||||
error => {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue