@@ -124,28 +127,27 @@ import Breadcrumb from "../../components/Breadcrumb.vue"
import Dialog from "../../components/Dialog.vue"
import { APIClient } from "../../fetch/api-client.js"
import "vue-select/dist/vue-select.css"
+import { storeToRefs } from "pinia"
export default {
setup() {
- const AVStore = inject("AVStore")
- AVStore.av_agreement_statuses = agreement_statuses
- AVStore.av_agreement_closure_reasons = agreement_closure_reasons
- AVStore.av_agreement_renewal_priorities = agreement_renewal_priorities
- AVStore.av_user_roles = user_roles
- AVStore.av_license_types = license_types
- AVStore.av_license_statuses = license_statuses
- AVStore.av_agreement_license_statuses = agreement_license_statuses
- AVStore.av_agreement_license_location = agreement_license_location
- AVStore.av_package_types = package_types
- AVStore.av_package_content_types = package_content_types
- AVStore.av_title_publication_types = title_publication_types
-
const vendorStore = inject("vendorStore")
+ const AVStore = inject("AVStore")
+
+ const mainStore = inject("mainStore")
+
+ // Note that we cannot use loading and loaded from messages
+ // Pinia is not initiated yet there
+ const { is_loading } = storeToRefs(mainStore)
+
return {
vendorStore,
+ AVStore,
+ mainStore,
erm_providers,
ERMModule,
+ is_loading,
}
},
data() {
@@ -154,14 +156,40 @@ export default {
}
},
beforeCreate() {
- const client = APIClient.acquisition
- client.vendors.getAll().then(
+ this.mainStore.is_loading = true
+
+ const acq_client = APIClient.acquisition
+ acq_client.vendors.getAll().then(
vendors => {
this.vendorStore.vendors = vendors
this.initialized = true
},
error => {}
)
+
+ const av_client = APIClient.authorised_values
+ const authorised_values = {
+ av_agreement_statuses: "ERM_AGREEMENT_STATUS",
+ av_agreement_closure_reasons: "ERM_AGREEMENT_CLOSURE_REASON",
+ av_agreement_renewal_priorities: "ERM_AGREEMENT_RENEWAL_PRIORITY",
+ av_user_roles: "ERM_USER_ROLES",
+ av_license_types: "ERM_LICENSE_TYPE",
+ av_license_statuses: "ERM_LICENSE_STATUS",
+ av_agreement_license_statuses: "ERM_AGREEMENT_LICENSE_STATUS",
+ av_agreement_license_location: "ERM_AGREEMENT_LICENSE_LOCATION",
+ av_package_types: "ERM_PACKAGE_TYPE",
+ 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
+ })
+ )
+ })
+ Promise.all(promises).then(() => (this.mainStore.is_loading = false))
},
components: {
Breadcrumb,
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UserRoles.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UserRoles.vue
index 22237fb8e8..e7725768b9 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UserRoles.vue
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UserRoles.vue
@@ -35,8 +35,8 @@
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client.js
index 20ceaa2e40..5c3f8535e2 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client.js
@@ -1,9 +1,11 @@
import ERMAPIClient from "./erm-api-client";
import PatronAPIClient from "./patron-api-client";
import AcquisitionAPIClient from "./acquisition-api-client";
+import AVAPIClient from "./authorised-values";
export const APIClient = {
erm: new ERMAPIClient(),
patron: new PatronAPIClient(),
acquisition: new AcquisitionAPIClient(),
-};
\ No newline at end of file
+ authorised_values: new AVAPIClient(),
+};
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/authorised-values.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/authorised-values.js
new file mode 100644
index 0000000000..639d8cf99f
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/authorised-values.js
@@ -0,0 +1,20 @@
+import HttpClient from "./http-client";
+
+export class AVAPIClient extends HttpClient {
+ constructor() {
+ super({
+ baseURL: "/api/v1/authorised_value_categories/",
+ });
+ }
+
+ get values() {
+ return {
+ getAll: (category_name, query) =>
+ this.get({
+ endpoint: category_name + "/values?" + (query || "_per_page=-1"),
+ }),
+ };
+ }
+}
+
+export default AVAPIClient;
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/messages.js b/koha-tmpl/intranet-tmpl/prog/js/vue/messages.js
index 7b9d5f904e..7c94ff0103 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/vue/messages.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/messages.js
@@ -31,4 +31,14 @@ export const submitted = function () {
const mainStore = useMainStore();
const { submitted } = mainStore;
submitted();
+};
+export const loading = function () {
+ const mainStore = useMainStore();
+ const { loading } = mainStore;
+ loading();
+};
+export const loaded = function () {
+ const mainStore = useMainStore();
+ const { loaded } = mainStore;
+ loaded();
};
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts
index 142527ac6e..e4290931df 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts
@@ -27,7 +27,7 @@ const router = createRouter({
import { useMainStore } from "../stores/main";
import { useVendorStore } from "../stores/vendors";
-import { useAVStore } from "../stores/authorised_values";
+import { useAVStore } from "../stores/authorised-values";
const pinia = createPinia();
@@ -52,7 +52,8 @@ app.config.unwrapInjectedRef = true;
app.provide("vendorStore", useVendorStore(pinia));
const mainStore = useMainStore(pinia);
app.provide("mainStore", mainStore);
-app.provide("AVStore", useAVStore(pinia));
+const AVStore = useAVStore(pinia);
+app.provide("AVStore", AVStore);
app.mount("#erm");
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js
similarity index 51%
rename from koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js
rename to koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js
index 901384436d..fc4573344e 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js
@@ -11,27 +11,27 @@ export const useAVStore = defineStore("authorised_values", {
av_agreement_license_statuses: [],
av_agreement_license_location: [],
av_agreement_relationships: [
- { authorised_value: "supersedes", lib: __("supersedes") },
- { authorised_value: "is-superseded-by", lib: __("is superseded by") },
+ { value: "supersedes", description: __("supersedes") },
+ { value: "is-superseded-by", description: __("is superseded by") },
{
- authorised_value: "provides_post-cancellation_access_for",
- lib: __("provides post-cancellation access for"),
+ value: "provides_post-cancellation_access_for",
+ description: __("provides post-cancellation access for"),
},
{
- authorised_value: "has-post-cancellation-access-in",
- lib: __("has post-cancellation access in"),
+ value: "has-post-cancellation-access-in",
+ description: __("has post-cancellation access in"),
},
{
- authorised_value: "tracks_demand-driven_acquisitions_for",
- lib: __("tracks demand-driven acquisitions for"),
+ value: "tracks_demand-driven_acquisitions_for",
+ description: __("tracks demand-driven acquisitions for"),
},
{
- authorised_value: "has-demand-driven-acquisitions-in",
- lib: __("has demand-driven acquisitions in"),
+ value: "has-demand-driven-acquisitions-in",
+ description: __("has demand-driven acquisitions in"),
},
- { authorised_value: "has_backfile_in", lib: __("has backfile in") },
- { authorised_value: "has_frontfile_in", lib: __("has frontfile in") },
- { authorised_value: "related_to", lib: __("related to") },
+ { value: "has_backfile_in", description: __("has backfile in") },
+ { value: "has_frontfile_in", description: __("has frontfile in") },
+ { value: "related_to", description: __("related to") },
],
av_package_types: [],
av_package_content_types: [],
@@ -47,13 +47,13 @@ export const useAVStore = defineStore("authorised_values", {
);
return;
}
- let o = this[arr_name].find((e) => e.authorised_value == av);
- return o ? o.lib : av;
+ let o = this[arr_name].find((e) => e.value == av);
+ return o ? o.description : av;
},
map_av_dt_filter(arr_name) {
return this[arr_name].map((e) => {
- e["_id"] = e["authorised_value"];
- e["_str"] = e["lib"];
+ e["_id"] = e["value"];
+ e["_str"] = e["description"];
return e;
});
},
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js
index 58305dd4bb..b2b1b6ce30 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js
@@ -9,6 +9,7 @@ export const useMainStore = defineStore("main", {
previousError: null,
displayed_already: false,
is_submitting: false,
+ is_loading: false,
}),
actions: {
setMessage(message) {
@@ -41,5 +42,11 @@ export const useMainStore = defineStore("main", {
submitted(){
this.is_submitting = false;
},
+ loading(){
+ this.is_loading = true;
+ },
+ loaded(){
+ this.is_loading = false;
+ },
},
});