Skip to content

Commit

Permalink
made edit modal partially
Browse files Browse the repository at this point in the history
  • Loading branch information
RalkeyOfficial committed Aug 8, 2024
1 parent 4eac87d commit 87c7eed
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 137 deletions.
3 changes: 3 additions & 0 deletions src/entities/catalogi/catalogi.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const mockCatalogiData = (): TCatalogi[] => [
rsin: '987654321',
pki: 'PKI-12345-67890',
},
metadata: ['1', '3'],
},
{
id: '2',
Expand All @@ -37,6 +38,7 @@ export const mockCatalogiData = (): TCatalogi[] => [
rsin: '987654321',
pki: 'PKI-12345-67890',
},
metadata: [],
},
{
id: '3',
Expand All @@ -56,6 +58,7 @@ export const mockCatalogiData = (): TCatalogi[] => [
rsin: '987654321',
pki: 'PKI-12345-67890',
},
metadata: ['1', '3'],
},
]

Expand Down
4 changes: 4 additions & 0 deletions src/entities/catalogi/catalogi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class Catalogi implements TCatalogi {
pki: string
}

public metadata: string[]

constructor(data: TCatalogi) {
this.hydrate(data)
}
Expand All @@ -42,6 +44,7 @@ export class Catalogi implements TCatalogi {
rsin: '',
pki: '',
}
this.metadata = data.metadata || []
}

/* istanbul ignore next */
Expand All @@ -62,6 +65,7 @@ export class Catalogi implements TCatalogi {
rsin: z.string(),
pki: z.string(),
}),
metadata: z.string().array(),
})

const result = schema.safeParse({
Expand Down
1 change: 1 addition & 0 deletions src/entities/catalogi/catalogi.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export type TCatalogi = {
rsin: string
pki: string
}
metadata: string[]
}
3 changes: 3 additions & 0 deletions src/modals/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<EditMetaDataPropertyModal />
<AddCatalogModal />
<EditCatalogModal />
<AddCatalogiMetadata />
<AddDirectoryModal />
<EditListingModal />
<AddPublicationDataModal />
Expand All @@ -37,6 +38,7 @@ import EditMetaDataPropertyModal from './metaData/EditMetaDataPropertyModal.vue'
import AddCatalogModal from './catalog/AddCatalogModal.vue'
import EditCatalogModal from './catalog/EditCatalogModal.vue'
import AddCatalogiMetadata from './catalogiMetadata/AddCatalogiMetadata.vue'
import AddDirectoryModal from './directory/AddDirectoryModal.vue'
import EditListingModal from './directory/EditListingModal.vue'
import AddOrganisationModal from './organisation/AddOrganisationModal.vue'
Expand All @@ -59,6 +61,7 @@ export default {
EditMetaDataPropertyModal,
AddCatalogModal,
EditCatalogModal,
AddCatalogiMetadata,
AddDirectoryModal,
EditListingModal,
AddPublicationDataModal,
Expand Down
179 changes: 179 additions & 0 deletions src/modals/catalogiMetadata/AddCatalogiMetadata.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<script setup>
import { catalogiStore, navigationStore } from '../../store/store.js'
</script>

<template>
<NcModal v-if="navigationStore.modal === 'addCatalogiMetadata'"
ref="modalRef"
label-id="addCatalogModal"
@close="closeModal">
<div class="modal__content">
<h2>Metadata toevoegen aan Catalogus</h2>
<div v-if="success !== null || error">
<NcNoteCard v-if="success" type="success">
<p>Catalogus succesvol toegevoegd</p>
</NcNoteCard>
<NcNoteCard v-if="!success" type="error">
<p>Er is iets fout gegaan bij het toevoegen van catalogus</p>
</NcNoteCard>
<NcNoteCard v-if="error" type="error">
<p>{{ error }}</p>
</NcNoteCard>
</div>
<div v-if="success === null" class="form-group">
<NcSelect v-bind="metaData"
v-model="metaData.value"
input-label="MetaData"
:loading="metaDataLoading"
required />
</div>
<NcButton v-if="success === null"
:disabled="!catalogi.title || loading"
type="primary"
@click="addCatalogMetadata">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
<Plus v-if="!loading" :size="20" />
</template>
Toevoegen
</NcButton>
</div>
</NcModal>
</template>

<script>
import { NcButton, NcModal, NcLoadingIcon, NcNoteCard, NcSelect } from '@nextcloud/vue'
import Plus from 'vue-material-design-icons/Plus.vue'
export default {
name: 'AddCatalogiMetadata',
components: {
NcModal,
NcButton,
NcLoadingIcon,
NcNoteCard,
NcSelect,
// Icons
Plus,
},
data() {
return {
catalogiItem: {
title: '',
summary: '',
description: '',
listed: false,
},
metaData: {},
metaDataLoading: false,
loading: false,
success: null,
error: false,
errorCode: '',
}
},
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 === 'addCatalogiMetadata' && this.hasUpdated) {
if (this.catalogiItem.id === catalogiStore.catalogiItem.id) return
this.hasUpdated = false
}
if (navigationStore.modal === 'addCatalogiMetadata' && !this.hasUpdated) {
catalogiStore.catalogiItem && (this.catalogiItem = catalogiStore.catalogiItem)
this.fetchData(catalogiStore.catalogiItem.id)
this.fetchMetaData(catalogiStore.catalogiItem?.metadata || [])
this.hasUpdated = true
}
},
methods: {
closeModal() {
navigationStore.setModal(false)
this.catalogi = {
title: '',
summary: '',
description: '',
listed: false,
}
},
fetchMetaData(metadataList) {
this.metaDataLoading = true
fetch('/index.php/apps/opencatalogi/api/metadata', {
method: 'GET',
})
.then((response) => {
response.json().then((data) => {
const filteredData = data.results.filter((meta) => !metadataList.includes(meta?.id))
this.metaData = {
options: filteredData.map((metaData) => ({
id: metaData.id,
label: metaData.title,
})),
}
})
this.metaDataLoading = false
})
.catch((err) => {
console.error(err)
this.metaDataLoading = false
})
},
addCatalogMetadata() {
this.loading = true
this.error = false
fetch(
`/index.php/apps/opencatalogi/api/catalogi/${this.catalogi.id}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
...this.catalogi,
metadata: this.catalogi.metadata.push(this.metaData.value.id),
}),
},
)
.then((response) => {
this.loading = false
this.success = response.ok
// Lets refresh the catalogiList
catalogiStore.refreshCatalogiList()
response.json().then((data) => {
catalogiStore.setCatalogiItem(data)
})
// Wait for the user to read the feedback then close the model
const self = this
setTimeout(function() {
self.success = null
self.closeModal()
}, 2000)
})
.catch((err) => {
this.error = err
this.loading = false
})
},
},
}
</script>
<style>
.modal__content {
margin: var(--OC-margin-50);
text-align: center;
}
.zaakDetailsContainer {
margin-block-start: var(--OC-margin-20);
margin-inline-start: var(--OC-margin-20);
margin-inline-end: var(--OC-margin-20);
}
.success {
color: green;
}
</style>
137 changes: 0 additions & 137 deletions src/store/modules/configuration.specs.js

This file was deleted.

Loading

0 comments on commit 87c7eed

Please sign in to comment.