Bug 32983: Use REST API route to retrieve authorised values

Make one API call for all AV categories+values instead of one API call per AV category required

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Pedro Amorim 2023-02-23 12:28:18 +00:00 committed by Tomas Cohen Arazi
parent 5d8c6a36b8
commit 09dabdad95
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 27 additions and 12 deletions

View file

@ -181,15 +181,26 @@ export default {
av_package_content_types: "ERM_PACKAGE_CONTENT_TYPE",
av_title_publication_types: "ERM_TITLE_PUBLICATION_TYPE",
}
let promises = []
Object.entries(authorised_values).forEach(([av_var, av_cat]) => {
promises.push(
av_client.values.getAll(av_cat).then(av => {
this.AVStore[av_var] = av
})
)
let av_cat_array = Object.keys(authorised_values).map(function (
av_cat
) {
return '"' + authorised_values[av_cat] + '"'
})
Promise.all(promises).then(() => (this.mainStore.is_loading = false))
av_client.values
.getCategoriesWithValues(av_cat_array)
.then(av_categories => {
Object.entries(authorised_values).forEach(
([av_var, av_cat]) => {
const av_match = av_categories.find(
element => element.category_name == av_cat
)
this.AVStore[av_var] = av_match.authorised_values
}
)
})
.then(() => (this.mainStore.is_loading = false))
},
components: {
Breadcrumb,

View file

@ -3,16 +3,20 @@ import HttpClient from "./http-client";
export class AVAPIClient extends HttpClient {
constructor() {
super({
baseURL: "/api/v1/authorised_value_categories/",
baseURL: "/api/v1/authorised_value_categories",
});
}
get values() {
return {
getAll: (category_name, query) =>
getCategoriesWithValues: (cat_array) =>
this.get({
endpoint: category_name + "/values?" + (query || "_per_page=-1"),
}),
endpoint: "?q={\"me.category_name\":["+(cat_array.join(", "))+"]}",
headers: {
"x-koha-embed":
"authorised_values",
},
}),
};
}
}