diff --git a/src/store/modules/configuration.js b/src/store/modules/configuration.js index d4561a4b..a1cb0449 100644 --- a/src/store/modules/configuration.js +++ b/src/store/modules/configuration.js @@ -27,16 +27,16 @@ export const useConfigurationStore = defineStore( ) .then( (response) => { - response.json().then( - (data) => { - this.setConfigurationItem(data) + response.json().then( + (data) => { + this.setConfigurationItem(data) } - ) + ) } ) .catch( (err) => { - console.error(err) + console.error(err) } ) }, diff --git a/src/store/modules/configuration.spec.js b/src/store/modules/configuration.spec.js index 814184e0..674586b6 100644 --- a/src/store/modules/configuration.spec.js +++ b/src/store/modules/configuration.spec.js @@ -5,15 +5,15 @@ import { useConfigurationStore } from './configuration.js' describe( 'Configuration Store', () => { - beforeEach( - () => { - setActivePinia(createPinia()) + beforeEach( + () => { + setActivePinia(createPinia()) } - ) + ) it( 'sets configuration item correctly', () => { - const store = useConfigurationStore() + const store = useConfigurationStore() store.setConfigurationItem(mockConfiguration()[0]) diff --git a/src/store/modules/configuration.specs.js b/src/store/modules/configuration.specs.js index 62920f59..aeb143d3 100644 --- a/src/store/modules/configuration.specs.js +++ b/src/store/modules/configuration.specs.js @@ -6,15 +6,15 @@ import { useConfigurationStore } from './configuration.js'; describe( 'Metadata Store', () => { - beforeEach( - () => { - setActivePinia(createPinia()) + beforeEach( + () => { + setActivePinia(createPinia()) } - ) + ) it( 'sets configuration item correctly', () => { - const store = useConfigurationStore() + const store = useConfigurationStore() store.setConfigurationItem(testData[0]) @@ -38,7 +38,7 @@ describe( it( 'sets configuration list correctly', () => { - const store = useConfigurationStore() + const store = useConfigurationStore() store.setConfigurationItem(testData) diff --git a/src/store/modules/metadata.js b/src/store/modules/metadata.js index cea9fe47..cb8c0ffd 100644 --- a/src/store/modules/metadata.js +++ b/src/store/modules/metadata.js @@ -2,58 +2,66 @@ import { defineStore } from 'pinia' import { Metadata } from '../../entities/index.js' -export const useMetadataStore = defineStore('metadata', { - state: () => ({ - metaDataItem: false, - metaDataList: [], - metadataDataKey: false, - }), - actions: { - setMetaDataItem(metaDataItem) { - // for backward compatibility - if (!!metaDataItem && typeof metaDataItem?.properties === 'string') { - metaDataItem.properties = JSON.parse(metaDataItem.properties) - } +export const useMetadataStore = defineStore( + 'metadata', { + state: () => ({ + metaDataItem: false, + metaDataList: [], + metadataDataKey: false, + }), + actions: { + setMetaDataItem(metaDataItem) { + // for backward compatibility + if (!!metaDataItem && typeof metaDataItem?.properties === 'string') { + metaDataItem.properties = JSON.parse(metaDataItem.properties) + } - this.metaDataItem = metaDataItem && new Metadata(metaDataItem) + this.metaDataItem = metaDataItem && new Metadata(metaDataItem) - console.log('Active metadata object set to ' + metaDataItem && metaDataItem.id) - }, - setMetaDataList(metaDataList) { - this.metaDataList = metaDataList.map( - (metadataItem) => new Metadata(metadataItem), - ) - console.log('Active metadata lest set') - }, - /* istanbul ignore next */ // ignore this for Jest until moved into a service - async refreshMetaDataList(search = null) { - // @todo this might belong in a service? - let endpoint = '/index.php/apps/opencatalogi/api/metadata' - if (search !== null && search !== '') { - endpoint = endpoint + '?_search=' + search - } - return fetch( - endpoint, - { - method: 'GET', - }, - ) - .then((response) => { - response.json().then((data) => { - this.metaDataList = data.results.map( - (metadataItem) => new Metadata(metadataItem), - ) - return data - }) - }) - .catch((err) => { - console.error(err) - return err - }) - }, - setMetadataDataKey(metadataDataKey) { - this.metadataDataKey = metadataDataKey - console.log('Active metadata data key set to ' + metadataDataKey) - }, - }, -}) + console.log('Active metadata object set to ' + metaDataItem && metaDataItem.id) + }, + setMetaDataList(metaDataList) { + this.metaDataList = metaDataList.map( + (metadataItem) => new Metadata(metadataItem), + ) + console.log('Active metadata lest set') + }, + /* istanbul ignore next */ // ignore this for Jest until moved into a service + async refreshMetaDataList(search = null) { + // @todo this might belong in a service? + let endpoint = '/index.php/apps/opencatalogi/api/metadata' + if (search !== null && search !== '') { + endpoint = endpoint + '?_search=' + search + } + return fetch( + endpoint, + { + method: 'GET', + }, + ) + .then( + (response) => { + response.json().then( + (data) => { + this.metaDataList = data.results.map( + (metadataItem) => new Metadata(metadataItem), + ) + return data + } + ) + } + ) + .catch( + (err) => { + console.error(err) + return err + } + ) + }, + setMetadataDataKey(metadataDataKey) { + this.metadataDataKey = metadataDataKey + console.log('Active metadata data key set to ' + metadataDataKey) + }, + }, + } +) diff --git a/src/store/modules/metadata.spec.js b/src/store/modules/metadata.spec.js index 38b1a8ab..514b5062 100644 --- a/src/store/modules/metadata.spec.js +++ b/src/store/modules/metadata.spec.js @@ -6,15 +6,15 @@ import { Metadata, mockMetadata } from '../../entities/index.js' describe( 'Metadata Store', () => { - beforeEach( - () => { - setActivePinia(createPinia()) + beforeEach( + () => { + setActivePinia(createPinia()) } - ) + ) it( 'sets metadata item correctly', () => { - const store = useMetadataStore() + const store = useMetadataStore() store.setMetaDataItem(mockMetadata()[0]) @@ -27,7 +27,7 @@ describe( it( 'sets metadata item with string "properties" property', () => { - const store = useMetadataStore() + const store = useMetadataStore() // stringify json data const mockData = mockMetadata()[0] @@ -44,7 +44,7 @@ describe( it( 'sets metadata list correctly', () => { - const store = useMetadataStore() + const store = useMetadataStore() store.setMetaDataList(mockMetadata()) @@ -57,7 +57,7 @@ describe( it( 'get metadata property from key', () => { - const store = useMetadataStore() + const store = useMetadataStore() store.setMetaDataItem(mockMetadata()[0]) store.setMetadataDataKey('test') diff --git a/src/store/modules/organisation.js b/src/store/modules/organisation.js index 3844677c..61b952b7 100644 --- a/src/store/modules/organisation.js +++ b/src/store/modules/organisation.js @@ -33,16 +33,16 @@ export const useOrganisationStore = defineStore( ) .then( (response) => { - response.json().then( - (data) => { - this.setOrganisationList(data.results) + response.json().then( + (data) => { + this.setOrganisationList(data.results) } - ) + ) } ) .catch( (err) => { - console.error(err) + console.error(err) } ) }, diff --git a/src/store/modules/organisation.spec.js b/src/store/modules/organisation.spec.js index b14a260b..27385c8e 100644 --- a/src/store/modules/organisation.spec.js +++ b/src/store/modules/organisation.spec.js @@ -6,15 +6,15 @@ import { useOrganisationStore } from './organisation.js'; describe( 'Organisation Store', () => { - beforeEach( - () => { - setActivePinia(createPinia()) + beforeEach( + () => { + setActivePinia(createPinia()) } - ) + ) it( 'sets organisation item correctly', () => { - const store = useOrganisationStore() + const store = useOrganisationStore() store.setOrganisationItem(mockOrganisation()[0]) @@ -38,7 +38,7 @@ describe( it( 'sets organisation list correctly', () => { - const store = useOrganisationStore() + const store = useOrganisationStore() store.setOrganisationList(mockOrganisation()) diff --git a/src/store/modules/search.js b/src/store/modules/search.js index 155e46bc..db326f1e 100644 --- a/src/store/modules/search.js +++ b/src/store/modules/search.js @@ -1,48 +1,56 @@ /* eslint-disable no-console */ import { defineStore } from 'pinia' -export const useSearchStore = defineStore('search', { - state: () => ({ - search: '', - searchResults: '', - searchError: '', - }), - actions: { - setSearch(search) { - this.search = search - console.log('Active search set to ' + search) - }, - setSearchResults(searchResults) { - this.searchResults = searchResults - console.log('Active search set to ' + searchResults) - }, - /* istanbul ignore next */ // ignore this for Jest until moved into a service - getSearchResults() { - fetch( - '/index.php/apps/opencatalogi/api/search?_search=' + this.search, - { - method: 'GET', - }, - ) - .then((response) => { - response.json().then((data) => { - if (data?.code === 403 && data?.message) { - this.searchError = data.message - console.log(this.searchError) - } else { - this.searchError = '' // Clear any previous errors - } - this.searchResults = data - }) - }) - .catch((err) => { - this.searchError = err.message || 'An error occurred' - console.error(err.message ?? err) - }) - }, - clearSearch() { - this.search = '' - this.searchError = '' - }, - }, -}) +export const useSearchStore = defineStore( + 'search', { + state: () => ({ + search: '', + searchResults: '', + searchError: '', + }), + actions: { + setSearch(search) { + this.search = search + console.log('Active search set to ' + search) + }, + setSearchResults(searchResults) { + this.searchResults = searchResults + console.log('Active search set to ' + searchResults) + }, + /* istanbul ignore next */ // ignore this for Jest until moved into a service + getSearchResults() { + fetch( + '/index.php/apps/opencatalogi/api/search?_search=' + this.search, + { + method: 'GET', + }, + ) + .then( + (response) => { + response.json().then( + (data) => { + if (data?.code === 403 && data?.message) { + this.searchError = data.message + console.log(this.searchError) + } else { + this.searchError = '' // Clear any previous errors + } + this.searchResults = data + } + ) + } + ) + .catch( + (err) => { + this.searchError = err.message || 'An error occurred' + console.error(err.message ?? err) + } + ) + }, + clearSearch() { + this.search = '' + this.searchError = '' + }, + }, + } +) diff --git a/src/store/modules/theme.js b/src/store/modules/theme.js index 0cecf1b0..e7fe9bd1 100644 --- a/src/store/modules/theme.js +++ b/src/store/modules/theme.js @@ -33,16 +33,16 @@ export const useThemeStore = defineStore( ) .then( (response) => { - response.json().then( - (data) => { - this.setThemeList(data.results) + response.json().then( + (data) => { + this.setThemeList(data.results) } - ) + ) } ) .catch( (err) => { - console.error(err) + console.error(err) } ) }, diff --git a/src/store/modules/theme.spec.js b/src/store/modules/theme.spec.js index cb7b85cc..34931d81 100644 --- a/src/store/modules/theme.spec.js +++ b/src/store/modules/theme.spec.js @@ -6,15 +6,15 @@ import { mockTheme, Theme } from '../../entities/index.js' describe( 'Theme Store', () => { - beforeEach( - () => { - setActivePinia(createPinia()) + beforeEach( + () => { + setActivePinia(createPinia()) } - ) + ) it( 'sets theme item correctly', () => { - const store = useThemeStore() + const store = useThemeStore() store.setThemeItem(mockTheme()[0]) @@ -38,7 +38,7 @@ describe( it( 'sets theme list correctly', () => { - const store = useThemeStore() + const store = useThemeStore() store.setThemeList(mockTheme())