From 5537c8131122aaf0d7a9de3191d6a19585b693bd Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 5 May 2022 14:59:49 +0200 Subject: [PATCH] Bug 32030: Store current_view and messages Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../vue/components/ERM/AgreementUserRoles.vue | 9 +- .../prog/js/vue/components/ERM/Agreements.vue | 82 ++++-------------- .../vue/components/ERM/AgreementsFormAdd.vue | 21 +++-- .../ERM/AgreementsFormConfirmDelete.vue | 23 +++-- .../js/vue/components/ERM/AgreementsList.vue | 20 +++-- .../js/vue/components/ERM/AgreementsShow.vue | 9 +- .../vue/components/ERM/AgreementsToolbar.vue | 16 +++- .../prog/js/vue/components/ERM/Dialog.vue | 16 ++++ .../prog/js/vue/components/ERM/ERMMain.vue | 7 ++ .../prog/js/vue/components/ERM/Licenses.vue | 83 ++++--------------- .../js/vue/components/ERM/LicensesFormAdd.vue | 28 ++++--- .../ERM/LicensesFormConfirmDelete.vue | 25 ++++-- .../js/vue/components/ERM/LicensesList.vue | 20 +++-- .../js/vue/components/ERM/LicensesShow.vue | 20 ++--- .../js/vue/components/ERM/LicensesToolbar.vue | 16 +++- .../intranet-tmpl/prog/js/vue/stores/main.js | 29 +++++++ 16 files changed, 227 insertions(+), 197 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Dialog.vue create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementUserRoles.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementUserRoles.vue index 7257eeba24..fe9cf75753 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementUserRoles.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementUserRoles.vue @@ -58,7 +58,13 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue index a8f0c73ed1..7bfdc6f37e 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue @@ -179,7 +179,7 @@ Cancel @@ -193,6 +193,7 @@ import AgreementUserRoles from './AgreementUserRoles.vue' import AgreementLicenses from './AgreementLicenses.vue' import { useVendorStore } from "../../stores/vendors" import { useAVStore } from "../../stores/authorised_values" +import { useMainStore } from "../../stores/main" import { storeToRefs } from "pinia" export default { @@ -209,6 +210,9 @@ export default { av_agreement_license_location, } = storeToRefs(AVStore) + const mainStore = useMainStore() + const { setMessage, setError, resetMessages, setCurrentView } = mainStore + return { vendors, av_agreement_statuses, @@ -217,6 +221,7 @@ export default { av_agreement_user_roles, av_agreement_license_statuses, av_agreement_license_location, + setMessage, setError, resetMessages, setCurrentView, } }, data() { @@ -250,6 +255,9 @@ export default { .then( (result) => { this.agreement = result + }, + (error) => { + this.setError(error) } ) }, @@ -292,15 +300,17 @@ export default { fetch(apiUrl, options) .then(response => { if (response.status == 200) { - this.$emit('agreement-updated') + this.setCurrentView('list') + this.setMessage('Agreement updated') } else if (response.status == 201) { - this.$emit('agreement-created') + this.setCurrentView('list') + this.setMessage('Agreement created') } else { - this.$emit('set-error', response.message || response.statusText) + this.setError(response.message || response.statusText) } }).catch( (error) => { - this.$emit('set-error', error) + this.setError(error) } ) }, @@ -310,7 +320,6 @@ export default { } } }, - emits: ['agreement-created', 'agreement-updated', 'set-error', 'switch-view'], props: { agreement_id: Number, }, diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormConfirmDelete.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormConfirmDelete.vue index 7baf782cb0..59806ba257 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormConfirmDelete.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormConfirmDelete.vue @@ -17,7 +17,10 @@
- No, do not delete
@@ -26,8 +29,16 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Dialog.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Dialog.vue new file mode 100644 index 0000000000..9e20c51eeb --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Dialog.vue @@ -0,0 +1,16 @@ + + + \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/ERMMain.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/ERMMain.vue index 4a8e3cf630..41712aa449 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/ERMMain.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/ERMMain.vue @@ -17,6 +17,7 @@
  • Agreements Licenses - -
    {{ message }}
    -
    {{ error }}
    + + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue index 1802f6e11e..5bd9a01c21 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue @@ -99,7 +99,7 @@ Cancel @@ -110,6 +110,7 @@ + \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormConfirmDelete.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormConfirmDelete.vue index e3f4a7b450..2b3c10cf4b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormConfirmDelete.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormConfirmDelete.vue @@ -16,7 +16,10 @@
    - No, do not delete
    @@ -25,8 +28,16 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js new file mode 100644 index 0000000000..a48f967cf7 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js @@ -0,0 +1,29 @@ +import { defineStore } from 'pinia' + +export const useMainStore = defineStore('main', { + state: () => ({ + current_view: 'list', + current_object_id: null, + message: null, + error: null, + }), + actions: { + setCurrentView(view) { + this.current_view = view; + this.error = null; + this.message = null; + }, + setMessage(message) { + this.error = null; + this.message = message; + }, + setError(error) { + this.error = "Something went wrong: " + error; + this.message = null; + }, + removeMessages() { + this.error = null; + this.message = null; + }, + }, +}); \ No newline at end of file -- 2.39.5