Skip to content

Commit

Permalink
Update src from PHP Codesniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 6, 2024
1 parent b9e11ee commit d09ab7c
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 144 deletions.
10 changes: 5 additions & 5 deletions src/store/modules/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
},
Expand Down
10 changes: 5 additions & 5 deletions src/store/modules/configuration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
12 changes: 6 additions & 6 deletions src/store/modules/configuration.specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -38,7 +38,7 @@ describe(

it(
'sets configuration list correctly', () => {
const store = useConfigurationStore()
const store = useConfigurationStore()

store.setConfigurationItem(testData)

Expand Down
114 changes: 61 additions & 53 deletions src/store/modules/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},
}
)
16 changes: 8 additions & 8 deletions src/store/modules/metadata.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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]
Expand All @@ -44,7 +44,7 @@ describe(

it(
'sets metadata list correctly', () => {
const store = useMetadataStore()
const store = useMetadataStore()

store.setMetaDataList(mockMetadata())

Expand All @@ -57,7 +57,7 @@ describe(

it(
'get metadata property from key', () => {
const store = useMetadataStore()
const store = useMetadataStore()

store.setMetaDataItem(mockMetadata()[0])
store.setMetadataDataKey('test')
Expand Down
10 changes: 5 additions & 5 deletions src/store/modules/organisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
},
Expand Down
12 changes: 6 additions & 6 deletions src/store/modules/organisation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -38,7 +38,7 @@ describe(

it(
'sets organisation list correctly', () => {
const store = useOrganisationStore()
const store = useOrganisationStore()

store.setOrganisationList(mockOrganisation())

Expand Down
98 changes: 53 additions & 45 deletions src/store/modules/search.js
Original file line number Diff line number Diff line change
@@ -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 = ''
},
},
}
)
Loading

0 comments on commit d09ab7c

Please sign in to comment.