From aead1dd59818080c354f205b3b152b670e71a7ee Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 20 May 2022 12:51:37 +0200 Subject: [PATCH] Bug 32030: ERM - Packages - Vue Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- api/v1/swagger/definitions/vendor.yaml | 2 +- api/v1/swagger/paths/erm_packages.yaml | 20 +- cypress/integration/Packages_spec.ts | 216 ++++++++++++++++++ installer/data/mysql/atomicupdate/erm.pl | 23 ++ .../data/mysql/mandatory/auth_val_cat.sql | 18 +- .../intranet-tmpl/prog/en/modules/erm/erm.tt | 19 +- .../components/ERM/AgreementRelationships.vue | 2 +- .../vue/components/ERM/AgreementsFormAdd.vue | 3 - .../js/vue/components/ERM/AgreementsList.vue | 2 +- .../prog/js/vue/components/ERM/ERMMain.vue | 10 + .../js/vue/components/ERM/LicensesFormAdd.vue | 3 - .../js/vue/components/ERM/LicensesList.vue | 6 +- .../js/vue/components/ERM/PackagesFormAdd.vue | 206 +++++++++++++++++ .../ERM/PackagesFormConfirmDelete.vue | 86 +++++++ .../js/vue/components/ERM/PackagesList.vue | 216 ++++++++++++++++++ .../js/vue/components/ERM/PackagesShow.vue | 140 ++++++++++++ .../js/vue/components/ERM/PackagesToolbar.vue | 12 + koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js | 33 +++ koha-tmpl/intranet-tmpl/prog/js/vue/routes.js | 65 ++++++ .../prog/js/vue/stores/authorised_values.js | 10 + 20 files changed, 1066 insertions(+), 26 deletions(-) create mode 100644 cypress/integration/Packages_spec.ts create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesFormAdd.vue create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesFormConfirmDelete.vue create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesList.vue create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesShow.vue create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesToolbar.vue diff --git a/api/v1/swagger/definitions/vendor.yaml b/api/v1/swagger/definitions/vendor.yaml index f50dd710dc..90feafbd81 100644 --- a/api/v1/swagger/definitions/vendor.yaml +++ b/api/v1/swagger/definitions/vendor.yaml @@ -111,7 +111,7 @@ properties: description: Expected delivery time (in days) external_id: type: - - integer + - string - "null" description: External id additionalProperties: false diff --git a/api/v1/swagger/paths/erm_packages.yaml b/api/v1/swagger/paths/erm_packages.yaml index 61e0afe6ff..8ec0ef0135 100644 --- a/api/v1/swagger/paths/erm_packages.yaml +++ b/api/v1/swagger/paths/erm_packages.yaml @@ -1,8 +1,8 @@ --- /erm/packages: get: - x-mojo-to: ERM::packages#list - operationId: listErmpackages + x-mojo-to: ERM::Packages#list + operationId: listErmPackages tags: - package summary: List packages @@ -76,8 +76,8 @@ permissions: erm: 1 post: - x-mojo-to: ERM::packages#add - operationId: addErmpackages + x-mojo-to: ERM::Packages#add + operationId: addErmPackages tags: - package summary: Add package @@ -133,8 +133,8 @@ erm: 1 "/erm/packages/{package_id}": get: - x-mojo-to: ERM::packages#get - operationId: getErmpackages + x-mojo-to: ERM::Packages#get + operationId: getErmPackages tags: - package summary: Get package @@ -174,8 +174,8 @@ permissions: erm: 1 put: - x-mojo-to: ERM::packages#update - operationId: updateErmpackages + x-mojo-to: ERM::Packages#update + operationId: updateErmPackages tags: - package summary: Update package @@ -228,8 +228,8 @@ permissions: erm: 1 delete: - x-mojo-to: ERM::packages#delete - operationId: deleteErmpackages + x-mojo-to: ERM::Packages#delete + operationId: deleteErmPackages tags: - package summary: Delete package diff --git a/cypress/integration/Packages_spec.ts b/cypress/integration/Packages_spec.ts new file mode 100644 index 0000000000..5a21a5052b --- /dev/null +++ b/cypress/integration/Packages_spec.ts @@ -0,0 +1,216 @@ +import { mount } from "@cypress/vue"; +const dayjs = require("dayjs"); /* Cannot use our calendar JS code, it's in an include file (!) + Also note that moment.js is deprecated */ + +function get_package() { + return { + package_id: 1, + name: "package 1", + package_type: "complete", + content_type: "print", + package_agreements: [], + }; +} + +describe("Package CRUD operations", () => { + beforeEach(() => { + cy.login("koha", "koha"); + cy.title().should("eq", "Koha staff interface"); + }); + + it("List package", () => { + // GET package returns 500 + cy.intercept("GET", "/api/v1/erm/packages", { + statusCode: 500, + error: "Something went wrong", + }); + cy.visit("/cgi-bin/koha/erm/erm.pl"); + cy.get("#navmenulist").contains("Packages").click(); + cy.get("main div[class='dialog alert']").contains( + /Something went wrong/ + ); + + // GET packages returns empty list + cy.intercept("GET", "/api/v1/erm/packages*", []); + cy.visit("/cgi-bin/koha/erm/packages"); + cy.get("#packages_list").contains("There are no packages defined."); + + // GET packages returns something + let erm_package = get_package(); + let packages = [erm_package]; + + cy.intercept("GET", "/api/v1/erm/packages*", { + statusCode: 200, + body: packages, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + cy.intercept("GET", "/api/v1/erm/packages/*", erm_package); + cy.visit("/cgi-bin/koha/erm/packages"); + cy.get("#packages_list").contains("Showing 1 to 1 of 1 entries"); + }); + + it("Add package", () => { + // Click the button in the toolbar + cy.visit("/cgi-bin/koha/erm/packages"); + cy.contains("New package").click(); + cy.get("#packages_add h2").contains("New package"); + + // Fill in the form for normal attributes + let erm_package = get_package(); + + cy.get("#packages_add").contains("Submit").click(); + cy.get("input:invalid,textarea:invalid,select:invalid").should( + "have.length", + 1 + ); + cy.get("#package_name").type(erm_package.name); + cy.get("#package_type").select(erm_package.package_type); + cy.get("#package_content_type").select(erm_package.content_type); + + // Submit the form, get 500 + cy.intercept("POST", "/api/v1/erm/packages", { + statusCode: 500, + error: "Something went wrong", + }); + cy.get("#packages_add").contains("Submit").click(); + cy.get("main div[class='dialog alert']").contains( + "Something went wrong: Internal Server Error" + ); + + // Submit the form, success! + cy.intercept("POST", "/api/v1/erm/packages", { + statusCode: 201, + body: erm_package, + }); + cy.get("#packages_add").contains("Submit").click(); + cy.get("main div[class='dialog message']").contains( + "Package created" + ); + }); + + it("Edit package", () => { + let erm_package = get_package(); + let packages = [erm_package]; + // Click the 'Edit' button from the list + cy.intercept("GET", "/api/v1/erm/packages*", { + statusCode: 200, + body: packages, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + cy.intercept("GET", "/api/v1/erm/packages/*", erm_package).as( + "get-package" + ); + cy.visit("/cgi-bin/koha/erm/packages"); + cy.get("#packages_list table tbody tr:first") + .contains("Edit") + .click(); + cy.wait("@get-package"); + cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + cy.get("#packages_add h2").contains("Edit package"); + + // Form has been correctly filled in + cy.get("#package_name").should("have.value", erm_package.name); + cy.get("#package_type").should("have.value", erm_package.package_type); + cy.get("#package_content_type").should("have.value", erm_package.content_type); + + // Submit the form, get 500 + cy.intercept("PUT", "/api/v1/erm/packages/*", { + statusCode: 500, + error: "Something went wrong", + }); + cy.get("#packages_add").contains("Submit").click(); + cy.get("main div[class='dialog alert']").contains( + "Something went wrong: Internal Server Error" + ); + + // Submit the form, success! + cy.intercept("PUT", "/api/v1/erm/packages/*", { + statusCode: 200, + body: erm_package, + }); + cy.get("#packages_add").contains("Submit").click(); + cy.get("main div[class='dialog message']").contains( + "Package updated" + ); + }); + + it("Show package", () => { + let erm_package = get_package(); + let packages = [erm_package]; + // Click the "name" link from the list + cy.intercept("GET", "/api/v1/erm/packages*", { + statusCode: 200, + body: packages, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + cy.intercept("GET", "/api/v1/erm/packages/*", erm_package).as( + "get-package" + ); + cy.visit("/cgi-bin/koha/erm/packages"); + let name_link = cy.get( + "#packages_list table tbody tr:first td:first a" + ); + name_link.should( + "have.text", + erm_package.name + " (#" + erm_package.package_id + ")" + ); + name_link.click(); + cy.wait("@get-package"); + cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + cy.get("#packages_show h2").contains( + "Package #" + erm_package.package_id + ); + }); + + it("Delete package", () => { + let erm_package = get_package(); + let packages = [erm_package]; + + // Click the 'Delete' button from the list + cy.intercept("GET", "/api/v1/erm/packages*", { + statusCode: 200, + body: packages, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + cy.intercept("GET", "/api/v1/erm/packages/*", erm_package); + cy.visit("/cgi-bin/koha/erm/packages"); + + cy.get("#packages_list table tbody tr:first") + .contains("Delete") + .click(); + cy.get("#packages_confirm_delete h2").contains("Delete package"); + cy.contains("Package name: " + erm_package.name); + + // Submit the form, get 500 + cy.intercept("DELETE", "/api/v1/erm/packages/*", { + statusCode: 500, + error: "Something went wrong", + }); + cy.contains("Yes, delete").click(); + cy.get("main div[class='dialog alert']").contains( + "Something went wrong: Internal Server Error" + ); + + // Submit the form, success! + cy.intercept("DELETE", "/api/v1/erm/packages/*", { + statusCode: 204, + body: null, + }); + cy.contains("Yes, delete").click(); + cy.get("main div[class='dialog message']").contains( + "Package deleted" + ); + }); +}); diff --git a/installer/data/mysql/atomicupdate/erm.pl b/installer/data/mysql/atomicupdate/erm.pl index 0682cf84de..859b4ca2c6 100755 --- a/installer/data/mysql/atomicupdate/erm.pl +++ b/installer/data/mysql/atomicupdate/erm.pl @@ -265,5 +265,28 @@ return { AFTER `deliverytime` }); } + + $dbh->do(q{ + INSERT IGNORE INTO authorised_value_categories (category_name, is_system) + VALUES + ('ERM_PACKAGE_TYPE', 1), + ('ERM_PACKAGE_CONTENT_TYPE', 1) + }); + + $dbh->do(q{ + INSERT IGNORE INTO authorised_values (category, authorised_value, lib) + VALUES + ('ERM_PACKAGE_TYPE', 'local', 'Local'), + ('ERM_PACKAGE_TYPE', 'complete', 'Complete'), + ('ERM_PACKAGE_CONTENT_TYPE', 'mixed_content', 'Aggregated full'), + ('ERM_PACKAGE_CONTENT_TYPE', 'mixed_content', 'Abstract and index'), + ('ERM_PACKAGE_CONTENT_TYPE', 'e_book', 'E-book'), + ('ERM_PACKAGE_CONTENT_TYPE', 'mixed_content', 'Mixed content'), + ('ERM_PACKAGE_CONTENT_TYPE', 'e_journal', 'E-journal'), + ('ERM_PACKAGE_CONTENT_TYPE', 'online_reference', 'Online reference'), + ('ERM_PACKAGE_CONTENT_TYPE', 'print', 'Print'), + ('ERM_PACKAGE_CONTENT_TYPE', 'streaming_media', 'Streaming media'), + ('ERM_PACKAGE_CONTENT_TYPE', 'unknown', 'Unknown') + }); } }; diff --git a/installer/data/mysql/mandatory/auth_val_cat.sql b/installer/data/mysql/mandatory/auth_val_cat.sql index 8b9367055b..ddf21f9027 100644 --- a/installer/data/mysql/mandatory/auth_val_cat.sql +++ b/installer/data/mysql/mandatory/auth_val_cat.sql @@ -83,7 +83,9 @@ VALUES ('ERM_LICENSE_TYPE', 1), ('ERM_LICENSE_STATUS', 1), ('ERM_AGREEMENT_LICENSE_STATUS', 1), - ('ERM_AGREEMENT_LICENSE_LOCATION', 1); + ('ERM_AGREEMENT_LICENSE_LOCATION', 1), + ('ERM_PACKAGE_TYPE', 1), + ('ERM_PACKAGE_CONTENT_TYPE', 1); INSERT IGNORE INTO authorised_values (category, authorised_value, lib) VALUES @@ -110,4 +112,16 @@ VALUES ('ERM_AGREEMENT_LICENSE_STATUS', 'future', 'Future'), ('ERM_AGREEMENT_LICENSE_STATUS', 'history', 'Historic'), ('ERM_AGREEMENT_LICENSE_LOCATION', 'filing_cabinet', 'Filing cabinet'), - ('ERM_AGREEMENT_LICENSE_LOCATION', 'cupboard', 'Cupboard'); + ('ERM_AGREEMENT_LICENSE_LOCATION', 'cupboard', 'Cupboard'), + ('ERM_PACKAGE_TYPE', 'local', 'Local'), + ('ERM_PACKAGE_TYPE', 'complete', 'Complete'), + ('ERM_PACKAGE_CONTENT_TYPE', 'mixed_content', 'Aggregated full'), + ('ERM_PACKAGE_CONTENT_TYPE', 'mixed_content', 'Abstract and index'), + ('ERM_PACKAGE_CONTENT_TYPE', 'e_book', 'E-book'), + ('ERM_PACKAGE_CONTENT_TYPE', 'mixed_content', 'Mixed content'), + ('ERM_PACKAGE_CONTENT_TYPE', 'e_journal', 'E-journal'), + ('ERM_PACKAGE_CONTENT_TYPE', 'online_reference', 'Online reference'), + ('ERM_PACKAGE_CONTENT_TYPE', 'print', 'Print'), + ('ERM_PACKAGE_CONTENT_TYPE', 'streaming_media', 'Streaming media'), + ('ERM_PACKAGE_CONTENT_TYPE', 'unknown', 'Unknown'); + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/erm/erm.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/erm/erm.tt index 0ef7d28541..79ba61a18a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/erm/erm.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/erm/erm.tt @@ -33,7 +33,7 @@ const agreement_renewal_priorities = [% To.json(AuthorisedValues.Get('ERM_AGREEMENT_RENEWAL_PRIORITY')) | $raw %]; const agreement_user_roles = [% To.json(AuthorisedValues.Get('ERM_AGREEMENT_USER_ROLES')) | $raw %]; - var table_settings = [% TablesSettings.GetTableSettings( 'erm', 'agreements', 'agreements', 'json' ) | $raw %]; + var agreement_table_settings = [% TablesSettings.GetTableSettings( 'erm', 'agreements', 'agreements', 'json' ) | $raw %]; var agreements_table_url = '/api/v1/erm/agreements?'; [% IF agreement_name_filter %] @@ -48,7 +48,7 @@ const license_types = [% To.json(AuthorisedValues.Get('ERM_LICENSE_TYPE')) | $raw %]; const license_statuses = [% To.json(AuthorisedValues.Get('ERM_LICENSE_STATUS')) | $raw %]; - var table_settings = [% TablesSettings.GetTableSettings( 'erm', 'agreements', 'agreements', 'json' ) | $raw %]; + var license_table_settings = [% TablesSettings.GetTableSettings( 'erm', 'licenses', 'licenses', 'json' ) | $raw %]; var licenses_table_url = '/api/v1/erm/licenses?'; [% IF license_name_filter %] @@ -63,6 +63,21 @@ const agreement_license_statuses = [% To.json(AuthorisedValues.Get('ERM_AGREEMENT_LICENSE_STATUS')) | $raw %]; const agreement_license_location = [% To.json(AuthorisedValues.Get('ERM_AGREEMENT_LICENSE_LOCATION')) | $raw %]; + const package_types = [% To.json(AuthorisedValues.Get('ERM_PACKAGE_TYPE')) | $raw %]; + const package_content_types = [% To.json(AuthorisedValues.Get('ERM_PACKAGE_CONTENT_TYPE')) | $raw %]; + + var package_table_settings = [% TablesSettings.GetTableSettings( 'erm', 'packages', 'packages', 'json' ) | $raw %]; + + var packages_table_url = '/api/v1/erm/packages?'; + [% IF package_name_filter %] + var package_name_filter = { + 'name': { + "like": '%[%- package_name_filter | html -%]%' + } + }; + packages_table_url += 'q='+ encodeURIComponent(JSON.stringify(package_name_filter)); + [% END %] + [% Asset.js("js/vue/dist/main.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue index 61c08fb5a3..e4a191eaeb 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue @@ -121,4 +121,4 @@ export default { }, name: 'AgreementRelationships', } - \ No newline at end of file + 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 3de4440f24..cfad178f7d 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 @@ -343,9 +343,6 @@ export default { } } }, - props: { - agreement_id: Number, - }, components: { AgreementPeriods, AgreementUserRoles, diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue index 12765f8343..a46a529c0f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue @@ -231,7 +231,7 @@ export default { $("#" + table_id).find("thead th").eq(6).attr('data-filter', 'av_agreement_renewal_priorities') } - }, table_settings, 1) + }, agreement_table_settings, 1) }, beforeUnmount() { $('#agreement_list') 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 baa441b4fd..4001bd95eb 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 @@ -23,6 +23,14 @@ {{ $t("Agreements") }} +
  • + + + {{ $t("Packages") }} +
  • { console.log(e) }) }, }, - props: { - license_id: Number, - }, components: { flatPickr }, diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue index d3925207ac..edea2482fb 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue @@ -104,7 +104,7 @@ export default { "searchable": true, "orderable": true, "render": function (data, type, row, meta) { - return escape_str(row.started_on) + return $date(row.started_on) } }, { @@ -113,7 +113,7 @@ export default { "searchable": true, "orderable": true, "render": function (data, type, row, meta) { - return escape_str(row.ended_on) + return $date(row.ended_on) } }, { @@ -170,7 +170,7 @@ export default { $("#" + table_id).find("thead th").eq(3).attr('data-filter', 'av_license_statuses') } - }, table_settings, 1) + }, license_table_settings, 1) }, beforeUnmount() { $('#license_list') diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesFormAdd.vue new file mode 100644 index 0000000000..09a52c3f61 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesFormAdd.vue @@ -0,0 +1,206 @@ + + + \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesFormConfirmDelete.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesFormConfirmDelete.vue new file mode 100644 index 0000000000..32329975e7 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesFormConfirmDelete.vue @@ -0,0 +1,86 @@ + + + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesList.vue new file mode 100644 index 0000000000..a1c596e4c3 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesList.vue @@ -0,0 +1,216 @@ + + + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesShow.vue new file mode 100644 index 0000000000..6fd84c4196 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesShow.vue @@ -0,0 +1,140 @@ + + + + \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesToolbar.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesToolbar.vue new file mode 100644 index 0000000000..cb48be36e6 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/PackagesToolbar.vue @@ -0,0 +1,12 @@ + + + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js index 2c1c551ba2..a321c5b565 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js @@ -103,3 +103,36 @@ export const fetchVendors = async function () { ); return vendors; }; + +export const fetchPackage = async function (package_id) { + if (!package_id) return; + const apiUrl = "/api/v1/erm/packages/" + package_id; + let erm_package; + await fetch(apiUrl) + .then((res) => res.json()) + .then( + (result) => { + erm_package = result; + }, + (error) => { + setError(error); + } + ); + return erm_package; +}; + +export const fetchPackages = async function () { + const apiUrl = "/api/v1/erm/packages"; + let packages; + await fetch(apiUrl) + .then((res) => res.json()) + .then( + (result) => { + packages = result; + }, + (error) => { + setError(error); + } + ); + return packages; +}; diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/routes.js b/koha-tmpl/intranet-tmpl/prog/js/vue/routes.js index a43472021a..5c3c91063c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/routes.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/routes.js @@ -3,6 +3,10 @@ import AgreementsList from "./components/ERM/AgreementsList.vue"; import AgreementsShow from "./components/ERM/AgreementsShow.vue"; import AgreementsFormAdd from "./components/ERM/AgreementsFormAdd.vue"; import AgreementsFormConfirmDelete from "./components/ERM/AgreementsFormConfirmDelete.vue"; +import PackagesList from "./components/ERM/PackagesList.vue"; +import PackagesShow from "./components/ERM/PackagesShow.vue"; +import PackagesFormAdd from "./components/ERM/PackagesFormAdd.vue"; +import PackagesFormConfirmDelete from "./components/ERM/PackagesFormConfirmDelete.vue"; import LicensesList from "./components/ERM/LicensesList.vue"; import LicensesShow from "./components/ERM/LicensesShow.vue"; import LicensesFormAdd from "./components/ERM/LicensesFormAdd.vue"; @@ -16,6 +20,7 @@ const breadcrumbs = { }, agreements: { text: "Agreements", path: "/cgi-bin/koha/erm/agreements" }, licenses: { text: "Licenses", path: "/cgi-bin/koha/erm/licenses" }, + packages: { text: "Packages", path: "/cgi-bin/koha/erm/packages" }, }; export const routes = [ { path: "/cgi-bin/koha/mainpage.pl" }, @@ -86,6 +91,66 @@ export const routes = [ view: "edit", }, }, + { + path: "/cgi-bin/koha/erm/packages", + component: PackagesList, + meta: { + breadcrumb: [ + breadcrumbs.home, + breadcrumbs.erm_home, + breadcrumbs.packages, + ], + view: "list", + }, + }, + { + path: "/cgi-bin/koha/erm/packages/:package_id", + component: PackagesShow, + meta: { + breadcrumb: [ + breadcrumbs.home, + breadcrumbs.erm_home, + breadcrumbs.packages, + ], + view: "show", + }, + }, + { + path: "/cgi-bin/koha/erm/packages/delete/:package_id", + component: PackagesFormConfirmDelete, + meta: { + breadcrumb: [ + breadcrumbs.home, + breadcrumbs.erm_home, + breadcrumbs.packages, + ], + view: "confirm-delete-form", + }, + }, + { + path: "/cgi-bin/koha/erm/packages/add", + component: PackagesFormAdd, + meta: { + breadcrumb: [ + breadcrumbs.home, + breadcrumbs.erm_home, + breadcrumbs.packages, + ], + view: "add", + }, + }, + { + path: "/cgi-bin/koha/erm/packages/edit/:package_id", + component: PackagesFormAdd, + meta: { + breadcrumb: [ + breadcrumbs.home, + breadcrumbs.erm_home, + breadcrumbs.packages, + ], + view: "edit", + }, + }, { path: "/cgi-bin/koha/erm/licenses", component: LicensesList, 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 index 0a49a2baf9..d6e6693ba1 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 @@ -33,9 +33,19 @@ export const useAVStore = defineStore("authorised_values", { { authorised_value: "has_frontfile_in", lib: "has_frontfile_in" }, { authorised_value: "related_to", lib: "related_to" }, ], + av_package_types: [], + av_package_content_types: [], }), actions: { get_lib_from_av(arr_name, av) { + if (this[arr_name] === undefined) { + console.warn( + "The authorised value category for '%s' is not defined.".format( + arr_name + ) + ); + return; + } let o = this[arr_name].find((e) => e.authorised_value == av); return o ? o.lib : ""; }, -- 2.39.5