diff --git a/src/store/modules/catalogi.js b/src/store/modules/catalogi.js index 67d9bacc..7e290976 100644 --- a/src/store/modules/catalogi.js +++ b/src/store/modules/catalogi.js @@ -3,6 +3,7 @@ import { defineStore } from 'pinia' import { Catalogi } from '../../entities/index.js' export const useCatalogiStore = defineStore( +<<<<<<< HEAD 'catalogi', { state: () => ({ catalogiItem: false, @@ -49,4 +50,52 @@ export const useCatalogiStore = defineStore( }, }, }, +======= + 'catalogi', { + state: () => ({ + catalogiItem: false, + catalogiList: [], + }), + actions: { + setCatalogiItem(catalogiItem) { + this.catalogiItem = catalogiItem && new Catalogi(catalogiItem) + console.log('Active catalog item set to ' + catalogiItem && catalogiItem?.id) + }, + setCatalogiList(catalogiList) { + this.catalogiList = catalogiList.map( + (catalogiItem) => new Catalogi(catalogiItem), + ) + console.log('Catalogi list set to ' + catalogiList.length + ' item') + }, + async refreshCatalogiList(search = null) { + // @todo this might belong in a service? + let endpoint = '/index.php/apps/opencatalogi/api/catalogi' + if (search !== null && search !== '') { + endpoint = endpoint + '?_search=' + search + } + return fetch( + endpoint, { + method: 'GET', + } + ) + .then( + (response) => { + response.json().then( + (data) => { + this.catalogiList = data.results.map( + (catalogiItem) => new Catalogi(catalogiItem), + ) + } + ) + } + ) + .catch( + (err) => { + console.error(err) + } + ) + }, + }, + } +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 ) diff --git a/src/store/modules/catalogi.spec.js b/src/store/modules/catalogi.spec.js index ea313261..cc03f6c7 100644 --- a/src/store/modules/catalogi.spec.js +++ b/src/store/modules/catalogi.spec.js @@ -5,6 +5,7 @@ import { useCatalogiStore } from './catalogi.js' import { Catalogi } from '../../entities/index.js' describe( +<<<<<<< HEAD 'Catalogi Store', () => { beforeEach( () => { @@ -15,6 +16,18 @@ describe( it( 'sets catalogi item correctly', () => { const store = useCatalogiStore() +======= + 'Catalogi Store', () => { + beforeEach( + () => { + setActivePinia(createPinia()) + } + ) + + it( + 'sets catalogi item correctly', () => { + const store = useCatalogiStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setCatalogiItem(testData[0]) @@ -25,9 +38,15 @@ describe( }, ) +<<<<<<< HEAD it( 'sets catalogi list correctly', () => { const store = useCatalogiStore() +======= + it( + 'sets catalogi list correctly', () => { + const store = useCatalogiStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setCatalogiList(testData) diff --git a/src/store/modules/directory.js b/src/store/modules/directory.js index eb2a32bd..7ea6b82c 100644 --- a/src/store/modules/directory.js +++ b/src/store/modules/directory.js @@ -3,6 +3,7 @@ import { defineStore } from 'pinia' import { Listing } from '../../entities/index.js' export const useDirectoryStore = defineStore( +<<<<<<< HEAD 'directory', { state: () => ({ listingItem: false, @@ -49,4 +50,52 @@ export const useDirectoryStore = defineStore( }, }, }, +======= + 'directory', { + state: () => ({ + listingItem: false, + listingList: [], + }), + actions: { + setListingItem(listingItem) { + this.listingItem = listingItem && new Listing(listingItem) + console.log('Active directory item set to ' + listingItem && listingItem.id) + }, + setListingList(listingList) { + this.listingList = listingList.map( + (listingItem) => new Listing(listingItem), + ) + console.log('Active directory item set to ' + listingList.length) + }, + async refreshListingList(search = null) { + // @todo this might belong in a service? + let endpoint = '/index.php/apps/opencatalogi/api/directory' + if (search !== null && search !== '') { + endpoint = endpoint + '?_search=' + search + } + return fetch( + endpoint, { + method: 'GET', + } + ) + .then( + (response) => { + response.json().then( + (data) => { + this.listingList = data.results.map( + (listingItem) => new Listing(listingItem), + ) + } + ) + } + ) + .catch( + (err) => { + console.error(err) + } + ) + }, + }, + } +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 ) diff --git a/src/store/modules/directory.spec.js b/src/store/modules/directory.spec.js index a3ca566e..b67094ff 100644 --- a/src/store/modules/directory.spec.js +++ b/src/store/modules/directory.spec.js @@ -5,6 +5,7 @@ import { useDirectoryStore } from './directory.js' import { Listing } from '../../entities/index.js' describe( +<<<<<<< HEAD 'Directory Store', () => { beforeEach( () => { @@ -15,6 +16,18 @@ describe( it( 'sets listing item correctly', () => { const store = useDirectoryStore() +======= + 'Directory Store', () => { + beforeEach( + () => { + setActivePinia(createPinia()) + } + ) + + it( + 'sets listing item correctly', () => { + const store = useDirectoryStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setListingItem(testData[0]) @@ -23,9 +36,15 @@ describe( }, ) +<<<<<<< HEAD it( 'sets listings list correctly', () => { const store = useDirectoryStore() +======= + it( + 'sets listings list correctly', () => { + const store = useDirectoryStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setListingList(testData) diff --git a/src/store/modules/metadata.spec.js b/src/store/modules/metadata.spec.js index 0f26eb79..cd8d1035 100644 --- a/src/store/modules/metadata.spec.js +++ b/src/store/modules/metadata.spec.js @@ -4,6 +4,7 @@ import { setActivePinia, createPinia } from 'pinia' import { useMetadataStore } from './metadata.js' describe( +<<<<<<< HEAD 'Metadata Store', () => { beforeEach( () => { @@ -34,9 +35,42 @@ describe( }, }, } +======= + 'Metadata Store', () => { + beforeEach( + () => { + setActivePinia(createPinia()) + } + ) + + it( + 'sets metadata item correctly', () => { + const store = useMetadataStore() + const metadataItem = { + id: '1', + name: 'Test metadata name', + title: 'Test metadata', + summary: 'This is a test listing', + description: 'this is a very long description for test listing', + version: '0.0.1', + properties: { + sasds: { + type: 'string', + description: 'property description', + format: 'a format', + maxDate: '2025-07-13', + required: false, + default: false, + cascadeDelete: false, + exclusiveMinimum: '2', + }, + }, + } +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setMetaDataItem(metadataItem) +<<<<<<< HEAD expect(store.metaDataItem).toEqual(metadataItem) }, ) @@ -53,6 +87,24 @@ describe( version: '0.0.1', properties: '{"sasds":{"type":"string","description":"property description","format":"a format","maxDate":"2025-07-13","required":false,"default":false,"cascadeDelete":false,"exclusiveMinimum":"2"}}', } +======= + expect(store.metaDataItem).toEqual(metadataItem) + } + ) + + it( + 'sets metadata item with string "properties" property', () => { + const store = useMetadataStore() + const metadataItem = { + id: '1', + name: 'Test metadata name', + title: 'Test metadata', + summary: 'This is a test listing', + description: 'this is a very long description for test listing', + version: '0.0.1', + properties: '{"sasds":{"type":"string","description":"property description","format":"a format","maxDate":"2025-07-13","required":false,"default":false,"cascadeDelete":false,"exclusiveMinimum":"2"}}', + } +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setMetaDataItem(metadataItem) @@ -74,6 +126,7 @@ describe( }, ) +<<<<<<< HEAD it( 'sets metadata list correctly', () => { const store = useMetadataStore() @@ -118,9 +171,56 @@ describe( properties: {}, }, ] +======= + it( + 'sets metadata list correctly', () => { + const store = useMetadataStore() + const metadataList = [ + { + id: '1', + name: 'Test metadata name', + title: 'Test metadata', + summary: 'This is a test metadata', + description: 'this is a very long description for test metadata', + version: '0.0.1', + properties: { + sasds: { + type: 'string', + description: 'property description', + format: 'a format', + maxDate: '2025-07-13', + required: false, + default: false, + cascadeDelete: false, + exclusiveMinimum: '2', + }, + gfdgds: { + type: 'string', + description: 'property description', + format: 'a format', + maxDate: '2025-07-13', + required: false, + default: false, + cascadeDelete: false, + exclusiveMinimum: '2', + }, + }, + }, + { + id: '2', + name: 'Test metadata naming', + title: 'Test metadata aaaa', + summary: 'This is a test metadata baaa da daaa', + description: 'this is a very long descriptio-', + version: '0.0.1', + properties: {}, + }, + ] +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setMetaDataList(metadataList) +<<<<<<< HEAD expect(store.metaDataList).toHaveLength(metadataList.length) store.metaDataList.forEach( (item, index) => { @@ -164,6 +264,51 @@ describe( }, }, } +======= + expect(store.metaDataList).toHaveLength(metadataList.length) + store.metaDataList.forEach( + (item, index) => { + expect(item).toEqual(metadataList[index]) + } + ) + } + ) + + it( + 'get metadata property from key', () => { + const store = useMetadataStore() + const metadataItem = { + id: '1', + name: 'Test metadata name', + title: 'Test metadata', + summary: 'This is a test metadata', + description: 'this is a very long description for test metadata', + version: '0.0.1', + properties: { + sasds: { + type: 'string', + description: 'property description', + format: 'a format', + maxDate: '2025-07-13', + $ref: '', + required: false, + default: false, + cascadeDelete: false, + exclusiveMinimum: '2', + }, + gfdgds: { + type: 'string', + description: 'property description', + format: 'a format', + maxDate: '2025-07-13', + required: false, + default: false, + cascadeDelete: false, + exclusiveMinimum: '2', + }, + }, + } +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setMetaDataItem(metadataItem) store.setMetadataDataKey('sasds') @@ -173,8 +318,15 @@ describe( const properties = store.getMetadataPropertyKeys('sasds') +<<<<<<< HEAD expect(properties).toEqual(metadataItem.properties.sasds) }, ) }, +======= + expect(properties).toEqual(metadataItem.properties.sasds) + } + ) + } +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 ) diff --git a/src/store/modules/navigation.spec.js b/src/store/modules/navigation.spec.js index 73f2e8ff..b9ad0fbf 100644 --- a/src/store/modules/navigation.spec.js +++ b/src/store/modules/navigation.spec.js @@ -4,6 +4,7 @@ import { setActivePinia, createPinia } from 'pinia' import { useNavigationStore } from './navigation.js' describe( +<<<<<<< HEAD 'Navigation Store', () => { beforeEach( () => { @@ -14,6 +15,18 @@ describe( it( 'set current selected view correctly', () => { const store = useNavigationStore() +======= + 'Navigation Store', () => { + beforeEach( + () => { + setActivePinia(createPinia()) + } + ) + + it( + 'set current selected view correctly', () => { + const store = useNavigationStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setSelected('publication') expect(store.selected).toBe('publication') @@ -26,9 +39,15 @@ describe( }, ) +<<<<<<< HEAD it( 'set current selected publication catalogi correctly', () => { const store = useNavigationStore() +======= + it( + 'set current selected publication catalogi correctly', () => { + const store = useNavigationStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setSelectedCatalogus('7a048bfd-210f-4e93-a1e8-5aa9261740b7') expect(store.selectedCatalogus).toBe('7a048bfd-210f-4e93-a1e8-5aa9261740b7') @@ -41,9 +60,15 @@ describe( }, ) +<<<<<<< HEAD it( 'set modal correctly', () => { const store = useNavigationStore() +======= + it( + 'set modal correctly', () => { + const store = useNavigationStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setModal('editPublication') expect(store.modal).toBe('editPublication') @@ -56,9 +81,15 @@ describe( }, ) +<<<<<<< HEAD it( 'set modal correctly', () => { const store = useNavigationStore() +======= + it( + 'set modal correctly', () => { + const store = useNavigationStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setDialog('deletePublication') expect(store.dialog).toBe('deletePublication') diff --git a/src/store/modules/publication.js b/src/store/modules/publication.js index 53b0d490..4e07e550 100644 --- a/src/store/modules/publication.js +++ b/src/store/modules/publication.js @@ -3,6 +3,7 @@ import { Attachment, Publication } from '../../entities/index.js' import { defineStore } from 'pinia' export const usePublicationStore = defineStore( +<<<<<<< HEAD 'publication', { state: () => ({ publicationItem: false, @@ -137,4 +138,140 @@ export const usePublicationStore = defineStore( }, }, }, +======= + 'publication', { + state: () => ({ + publicationItem: false, + publicationList: [], + publicationDataKey: false, + attachmentItem: false, + publicationAttachments: [], + conceptPublications: [], + conceptAttachments: [], + }), + actions: { + setPublicationItem(publicationItem) { + // To prevent forms etc from braking we alway use a default/skeleton object + this.publicationItem = publicationItem && new Publication(publicationItem) + console.log('Active publication item set to ' + publicationItem && publicationItem.id) + }, + setPublicationList(publicationList) { + this.publicationList = publicationList.map((publicationItem) => new Publication(publicationItem)) + console.log('Active publication item set to ' + publicationList.length) + }, + async refreshPublicationList(search = null) { + // @todo this might belong in a service? + let endpoint = '/index.php/apps/opencatalogi/api/publications' + if (search !== null && search !== '') { + endpoint = endpoint + '?_search=' + search + } + return fetch( + endpoint, + { + method: 'GET', + }, + ) + .then( + (response) => { + response.json().then( + (data) => { + this.setPublicationList(data?.results) + return data + } + ) + } + ) + .catch( + (err) => { + console.error(err) + return err + } + ) + }, + getPublicationAttachments(publication) { // @todo this might belong in a service? + fetch( + '/index.php/apps/opencatalogi/api/attachments', + { + method: 'GET', + }, + ) + .then( + (response) => { + response.json().then( + (data) => { + this.publicationAttachments = data.results.map( + (attachmentItem) => new Attachment(attachmentItem), + ) + return data + } + ) + } + ) + .catch( + (err) => { + console.error(err) + return err + } + ) + }, + getConceptPublications() { // @todo this might belong in a service? + fetch( + '/index.php/apps/opencatalogi/api/publications?status=concept', + { + method: 'GET', + }, + ) + .then( + (response) => { + response.json().then( + (data) => { + this.conceptPublications = data + return data + } + ) + } + ) + .catch( + (err) => { + console.error(err) + return err + } + ) + }, + getConceptAttachments() { // @todo this might belong in a service? + fetch( + '/index.php/apps/opencatalogi/api/attachments?status=concept', + { + method: 'GET', + }, + ) + .then( + (response) => { + response.json().then( + (data) => { + this.conceptAttachments = data + return data + } + ) + } + ) + .catch( + (err) => { + console.error(err) + return err + } + ) + }, + // @todo why does the following run through the store? -- because its impossible with props, and its vital information for the modal. + setPublicationDataKey(publicationDataKey) { + this.publicationDataKey = publicationDataKey + console.log('Active publication data key set to ' + publicationDataKey) + }, + setAttachmentItem(attachmentItem) { + this.attachmentItem = attachmentItem && new Attachment(attachmentItem) + console.log('Active attachment item set to ' + attachmentItem) + }, + }, + } +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 ) diff --git a/src/store/modules/publication.spec.js b/src/store/modules/publication.spec.js index c96c1372..d4564e94 100644 --- a/src/store/modules/publication.spec.js +++ b/src/store/modules/publication.spec.js @@ -5,6 +5,7 @@ import { usePublicationStore } from './publication.js' import { Attachment, Publication } from '../../entities/index.js' describe( +<<<<<<< HEAD 'Metadata Store', () => { beforeEach( () => { @@ -15,6 +16,18 @@ describe( it( 'sets publication item correctly', () => { const store = usePublicationStore() +======= + 'Metadata Store', () => { + beforeEach( + () => { + setActivePinia(createPinia()) + } + ) + + it( + 'sets publication item correctly', () => { + const store = usePublicationStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setPublicationItem(testData[0]) @@ -36,9 +49,15 @@ describe( }, ) +<<<<<<< HEAD it( 'sets publication list correctly', () => { const store = usePublicationStore() +======= + it( + 'sets publication list correctly', () => { + const store = usePublicationStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setPublicationList(testData) @@ -58,10 +77,17 @@ describe( }, ) +<<<<<<< HEAD // TODO: fix this it( 'set publication data.data property key correctly', () => { const store = usePublicationStore() +======= + // TODO: fix this + it( + 'set publication data.data property key correctly', () => { + const store = usePublicationStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setPublicationDataKey('contactPoint') @@ -69,9 +95,15 @@ describe( }, ) +<<<<<<< HEAD it( 'set attachment item correctly', () => { const store = usePublicationStore() +======= + it( + 'set attachment item correctly', () => { + const store = usePublicationStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setAttachmentItem(attachmentTestData[0]) diff --git a/src/store/modules/search.js b/src/store/modules/search.js index 0ad14f75..15ed0dd5 100644 --- a/src/store/modules/search.js +++ b/src/store/modules/search.js @@ -2,6 +2,7 @@ import { defineStore } from 'pinia' export const useSearchStore = defineStore( +<<<<<<< HEAD 'search', { state: () => ({ search: '', @@ -43,4 +44,47 @@ export const useSearchStore = defineStore( }, }, }, +======= + 'search', { + state: () => ({ + search: '', + searchResults: '', + }), + 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) + }, + getSearchResults() { + fetch( + '/index.php/apps/opencatalogi/api/search?_search=' + this.search, + { + method: 'GET', + }, + ) + .then( + (response) => { + response.json().then( + (data) => { + this.searchResults = data + } + ) + } + ) + .catch( + (err) => { + console.error(err) + } + ) + }, + clearSearch() { + this.search = '' + }, + }, + } +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 ) diff --git a/src/store/modules/search.spec.js b/src/store/modules/search.spec.js index 6fcf6305..c0e434de 100644 --- a/src/store/modules/search.spec.js +++ b/src/store/modules/search.spec.js @@ -4,6 +4,7 @@ import { setActivePinia, createPinia } from 'pinia' import { useSearchStore } from './search.js' describe( +<<<<<<< HEAD 'Search Store', () => { beforeEach( () => { @@ -14,6 +15,18 @@ describe( it( 'set search correctly', () => { const store = useSearchStore() +======= + 'Search Store', () => { + beforeEach( + () => { + setActivePinia(createPinia()) + } + ) + + it( + 'set search correctly', () => { + const store = useSearchStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setSearch('cata') expect(store.search).toBe('cata') @@ -26,18 +39,30 @@ describe( }, ) +<<<<<<< HEAD it( 'set search result correctly', () => { const store = useSearchStore() +======= + it( + 'set search result correctly', () => { + const store = useSearchStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setSearchResults(['foo', 'bar', 'bux']) expect(store.searchResults).toEqual(['foo', 'bar', 'bux']) }, ) +<<<<<<< HEAD it( 'clear search correctly', () => { const store = useSearchStore() +======= + it( + 'clear search correctly', () => { + const store = useSearchStore() +>>>>>>> b9967e2fa96c9c05d7a70f54b75412883822a595 store.setSearch('Lorem ipsum dolor sit amet') expect(store.search).toBe('Lorem ipsum dolor sit amet')