Skip to content

Commit

Permalink
added organisation to edit modal
Browse files Browse the repository at this point in the history
  • Loading branch information
RalkeyOfficial committed Aug 8, 2024
1 parent 3b4b6a9 commit 4990020
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 49 deletions.
93 changes: 91 additions & 2 deletions src/modals/catalog/EditCatalogModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ import { catalogiStore, navigationStore } from '../../store/store.js'
:checked.sync="catalogiStore.catalogiItem.listed">
Publiek vindbaar
</NcCheckboxRadioSwitch>
<NcSelect v-bind="organisations"
v-model="organisations.value"
input-label="Organisatie"
:loading="organisationsLoading" />
</div>
<NcButton v-if="success === null"
:disabled="loading"
type="primary"
class="ecm-submit-button"
@click="editCatalog()">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
Expand All @@ -55,7 +60,7 @@ import { catalogiStore, navigationStore } from '../../store/store.js'
</template>

<script>
import { NcButton, NcModal, NcTextField, NcNoteCard, NcLoadingIcon, NcCheckboxRadioSwitch } from '@nextcloud/vue'
import { NcButton, NcModal, NcTextField, NcNoteCard, NcLoadingIcon, NcCheckboxRadioSwitch, NcSelect } from '@nextcloud/vue'
import ContentSaveOutline from 'vue-material-design-icons/ContentSaveOutline.vue'
export default {
Expand All @@ -67,20 +72,97 @@ export default {
NcNoteCard,
NcLoadingIcon,
NcCheckboxRadioSwitch,
NcSelect,
// Icons
ContentSaveOutline,
},
data() {
return {
catalogiItem: {
title: '',
summary: '',
description: '',
image: '',
listed: false,
organisation: '',
},
loading: false,
success: null,
error: false,
organisations: {},
organisationsLoading: false,
hasUpdated: false,
}
},
mounted() {
// catalogiStore.catalogiItem can be false, so only assign catalogiStore.catalogiItem to catalogiItem if its NOT false
catalogiStore.catalogiItem && (this.catalogiItem = catalogiStore.catalogiItem)
},
updated() {
if (navigationStore.modal === 'editCatalog' && this.hasUpdated) {
if (this.catalogiItem.id === catalogiStore.catalogiItem.id) return
this.hasUpdated = false
}
if (navigationStore.modal === 'editCatalog' && !this.hasUpdated) {
catalogiStore.catalogiItem && (this.catalogiItem = catalogiStore.catalogiItem)
this.fetchData(catalogiStore.catalogiItem.id)
this.fetchOrganisations()
this.hasUpdated = true
}
},
methods: {
closeModal() {
navigationStore.modal = false
},
fetchData(id) {
this.loading = true
fetch(
`/index.php/apps/opencatalogi/api/catalogi/${id}`,
{
method: 'GET',
},
)
.then((response) => {
response.json().then((data) => {
catalogiStore.setCatalogiItem(data)
this.catalogiItem = catalogiStore.catalogiItem
})
this.loading = false
})
.catch((err) => {
console.error(err)
this.loading = false
})
},
fetchOrganisations() {
this.organisationsLoading = true
fetch('/index.php/apps/opencatalogi/api/organisations', {
method: 'GET',
})
.then((response) => {
response.json().then((data) => {
const selectedOrganisation = data.results.filter((org) => org?.id === catalogiStore.catalogiItem?.organisation?.id) || null
this.organisations = {
options: data.results.map((organisation) => ({
id: organisation.id,
label: organisation.title,
})),
value: selectedOrganisation[0]
? {
id: selectedOrganisation?.id,
label: selectedOrganisation?.title,
}
: null,
}
})
this.organisationsLoading = false
})
.catch((err) => {
console.error(err)
this.organisationsLoading = false
})
},
editCatalog() {
this.loading = true
this.error = false
Expand All @@ -91,7 +173,10 @@ export default {
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(catalogiStore.catalogiItem),
body: JSON.stringify({
...catalogiStore.catalogiItem,
organisation: this.organisations?.value?.id,
}),
},
)
.then((response) => {
Expand Down Expand Up @@ -133,4 +218,8 @@ export default {
.success {
color: green;
}
.ecm-submit-button {
margin-block-start: 1rem;
}
</style>
60 changes: 13 additions & 47 deletions src/store/modules/catalogi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,27 @@ export const useCatalogiStore = defineStore(
)
console.log('Catalogi list set to ' + catalogiList.length + ' item')
},
/* istanbul ignore next */ // ignore this for Jest until moved into a service
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),
)
},
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)
},
)
},
},
setCatalogiList(catalogiList) {
this.catalogiList = catalogiList.map(
(catalogiItem) => new Catalogi(catalogiItem),
)
console.log('Catalogi list set to ' + catalogiList.length + ' item')
},
/* istanbul ignore next */ // ignore this for Jest until moved into a service
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)
})
.catch((err) => {
console.error(err)
})
},
},
},
)

0 comments on commit 4990020

Please sign in to comment.