Skip to content

Commit

Permalink
fixed api issues and publish
Browse files Browse the repository at this point in the history
  • Loading branch information
remko48 committed Aug 13, 2024
1 parent a574f93 commit a40b455
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 139 deletions.
11 changes: 4 additions & 7 deletions src/dialogs/attachment/CopyAttachmentDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,11 @@ export default {
.then((response) => {
this.loading = false
this.succes = true
// Lets refresh the attachment list
response.json().then((data) => {
publicationStore.setAttachmentItem(data)
})
if (publicationStore.publicationItem?.id) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem.id)
// @todo update the publication item
if (publicationStore.publicationItem) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem)
}
// Wait for the user to read the feedback then close the model
const self = this
setTimeout(function() {
Expand Down
56 changes: 27 additions & 29 deletions src/dialogs/attachment/DeleteAttachmentDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,37 @@ export default {
this.loading = false
this.succes = true
// Lets refresh the attachment list
if (publicationStore.publicationItem?.id) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem.id)
// @todo update the publication item
}
this.filterdAttachments = publicationStore.publicationItem.attachments.filter((attachment) => { return parseInt(attachment) !== parseInt(publicationStore.attachmentItem.id) })
if (publicationStore.publicationItem) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem)
this.filterdAttachments = publicationStore.publicationItem.attachments.filter((attachment) => { return parseInt(attachment) !== parseInt(publicationStore.attachmentItem.id) })
fetch(
`/index.php/apps/opencatalogi/api/publications/${publicationStore.publicationItem.id}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
fetch(
`/index.php/apps/opencatalogi/api/publications/${publicationStore.publicationItem.id}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
...publicationStore.publicationItem,
attachments: [...this.filterdAttachments],
}),
},
body: JSON.stringify({
...publicationStore.publicationItem,
attachments: [...this.filterdAttachments],
}),
},
)
.then((response) => {
this.loading = false
)
.then((response) => {
this.loading = false
// Lets refresh the publicationList
publicationStore.refreshPublicationList()
response.json().then((data) => {
publicationStore.setPublicationItem(data)
// Lets refresh the publicationList
publicationStore.refreshPublicationList()
response.json().then((data) => {
publicationStore.setPublicationItem(data)
})
})
})
.catch((err) => {
this.error = err
this.loading = false
})
.catch((err) => {
this.error = err
this.loading = false
})
}
// Wait for the user to read the feedback then close the model
const self = this
Expand Down
18 changes: 7 additions & 11 deletions src/dialogs/attachment/DepublishAttachmentDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { publicationStore, navigationStore } from '../../store/store.js'
v-if="!succes"
:disabled="loading"
type="primary"
@click="CopyAttachment()">
@click="depublishAttachment()">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
<PublishOff v-if="!loading" :size="20" />
Expand Down Expand Up @@ -67,10 +67,9 @@ export default {
}
},
methods: {
CopyAttachment() {
depublishAttachment() {
this.loading = true
publicationStore.attachmentItem.status = 'retracted'
publicationStore.attachmentItem.published = ''
publicationStore.attachmentItem.published = null
fetch(
`/index.php/apps/opencatalogi/api/attachments/${publicationStore.attachmentItem.id}`,
{
Expand All @@ -84,14 +83,11 @@ export default {
.then((response) => {
this.loading = false
this.succes = true
// Lets refresh the attachment list
response.json().then((data) => {
publicationStore.setAttachmentItem(data)
})
if (publicationStore.publicationItem?.id) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem.id)
// @todo update the publication item
if (publicationStore.publicationItem) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem)
}
// Wait for the user to read the feedback then close the model
const self = this
setTimeout(function() {
Expand Down
38 changes: 16 additions & 22 deletions src/dialogs/attachment/PublishAttachmentDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export default {
methods: {
PublishAttachment() {
this.loading = true
publicationStore.attachmentItem.status = 'published'
fetch(
`/index.php/apps/opencatalogi/api/attachments/${publicationStore.attachmentItem.id}`,
{
Expand All @@ -79,27 +78,22 @@ export default {
},
body: JSON.stringify(publicationStore.attachmentItem),
},
)
.then((response) => {
this.loading = false
this.succes = true
// Lets refresh the attachment list
response.json().then((data) => {
publicationStore.setAttachmentItem(data)
})
if (publicationStore.publicationItem?.id) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem.id)
// @todo update the publication item
}
publicationStore.getConceptAttachments()
// Wait for the user to read the feedback then close the model
const self = this
setTimeout(function() {
self.succes = false
publicationStore.setAttachmentItem(false)
navigationStore.setDialog(false)
}, 2000)
})
).then((response) => {
this.loading = false
this.succes = true
if (publicationStore.publicationItem) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem)
}
// Wait for the user to read the feedback then close the model
const self = this
setTimeout(function() {
self.succes = false
publicationStore.setAttachmentItem(false)
navigationStore.setDialog(false)
}, 2000)
})
.catch((err) => {
this.error = err
this.loading = false
Expand Down
63 changes: 31 additions & 32 deletions src/modals/attachment/AddAttachmentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import Plus from 'vue-material-design-icons/Plus.vue'
import axios from 'axios'
const { files, open: openFileUpload, reset } = useFileDialog()
const { files, open: openFileUpload, reset } = useFileDialog({ multiple: false })
export default {
name: 'AddAttachmentModal',
Expand Down Expand Up @@ -126,6 +126,7 @@ export default {
axios.post('/index.php/apps/opencatalogi/api/attachments', {
...(publicationStore.attachmentItem),
published: null,
_file: files.value ? files.value[0] : '',
}, {
headers: {
Expand All @@ -140,40 +141,38 @@ export default {
this.success = true
reset()
// Lets refresh the attachment list
if (publicationStore.publicationItem?.id) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem.id)
// @todo update the publication item
}
fetch(
`/index.php/apps/opencatalogi/api/publications/${publicationStore.publicationItem.id}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
if (publicationStore.publicationItem) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem)
fetch(
`/index.php/apps/opencatalogi/api/publications/${publicationStore.publicationItem.id}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
...publicationStore.publicationItem,
attachments: [...publicationStore.publicationItem.attachments, response.data.id],
}),
},
body: JSON.stringify({
...publicationStore.publicationItem,
attachments: [...publicationStore.publicationItem.attachments, response.data.id],
}),
},
)
.then((response) => {
this.loading = false
// Lets refresh the publicationList
publicationStore.refreshPublicationList()
response.json().then((data) => {
publicationStore.setPublicationItem(data)
})
)
.then((response) => {
this.loading = false
})
.catch((err) => {
this.error = err
this.loading = false
})
// store.refreshCatalogiList()
// Lets refresh the publicationList
publicationStore.refreshPublicationList()
response.json().then((data) => {
publicationStore.setPublicationItem(data)
})
})
.catch((err) => {
this.error = err
this.loading = false
})
// store.refreshCatalogiList()
}
publicationStore.setAttachmentItem(response)
// Wait for the user to read the feedback then close the model
Expand Down
5 changes: 2 additions & 3 deletions src/modals/attachment/EditAttachmentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ export default {
this.loading = false
this.success = response.ok
// Lets refresh the catalogiList
if (publicationStore.publicationItem?.id) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem.id)
// @todo update the publication item
if (publicationStore.publicationItem) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem)
}
response.json().then((data) => {
publicationStore.setAttachmentItem(data)
Expand Down
26 changes: 0 additions & 26 deletions src/store/modules/publication.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,6 @@ export const usePublicationStore = defineStore(
)
},
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
},
)
},
getPublicationAttachmentsById(publication) { // @todo this might belong in a service?
fetch(
`/index.php/apps/opencatalogi/api/publications/${publication.id}/attachments`,
{
Expand Down
23 changes: 14 additions & 9 deletions src/views/publications/PublicationDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { catalogiStore, metadataStore, navigationStore, publicationStore } from
</template>
Eigenschap toevoegen
</NcActionButton>
<NcActionButton @click="navigationStore.setModal('AddAttachment')">
<NcActionButton @click="addAttachment">
<template #icon>
<FilePlusOutline :size="20" />
</template>
Expand Down Expand Up @@ -215,14 +215,14 @@ import { catalogiStore, metadataStore, navigationStore, publicationStore } from
:bold="false"
:active="publicationStore.attachmentId === attachment.id"
:force-display-actions="true"
:details="attachment?.status">
:details="(attachment?.published && attachment?.published <= now.toISOString()) ? 'Gepubliseerd' : 'Niet gepubliseerd'">
<template #icon>
<CheckCircle v-if="attachment?.status === 'published'"
:class="attachment?.published && 'publishedIcon'"
<CheckCircle v-if="attachment?.published && attachment?.published <= now.toISOString()"
:class="attachment?.published <= now.toISOString() && 'publishedIcon'"
disable-menu
:size="44" />
<ExclamationThick v-if="attachment?.status !== 'published'"
:class="!attachment?.published && 'warningIcon'"
<ExclamationThick v-if="!attachment?.published || attachment?.published > now.toISOString()"
:class="!attachment?.published && 'warningIcon' || attachment?.published > now.toISOString() && 'warningIcon'"
disable-menu
:size="44" />
</template>
Expand All @@ -242,13 +242,13 @@ import { catalogiStore, metadataStore, navigationStore, publicationStore } from
</template>
Download
</NcActionButton>
<NcActionButton v-if="attachment.status !== 'published'" @click="publicationStore.setAttachmentItem(attachment); navigationStore.setDialog('publishAttachment')">
<NcActionButton v-if="!attachment?.published || attachment?.published > now.toISOString()" @click="publicationStore.setAttachmentItem(attachment); navigationStore.setDialog('publishAttachment')">
<template #icon>
<Publish :size="20" />
</template>
Publiceren
</NcActionButton>
<NcActionButton v-if="attachment.status === 'published'" @click="publicationStore.setAttachmentItem(attachment); navigationStore.setDialog('depublishAttachment')">
<NcActionButton v-if="attachment?.published && attachment?.published <= now.toISOString()" @click="publicationStore.setAttachmentItem(attachment); navigationStore.setDialog('depublishAttachment')">
<template #icon>
<PublishOff :size="20" />
</template>
Expand Down Expand Up @@ -416,6 +416,7 @@ export default {
attachments: [],
catalogi: [],
metadata: [],
now: new Date(),
prive: false,
loading: false,
catalogiLoading: false,
Expand Down Expand Up @@ -478,7 +479,7 @@ export default {
// this.oldZaakId = id
this.fetchCatalogi(data.catalogi)
this.fetchMetaData(data.metaData)
publicationStore.getPublicationAttachmentsById(data)
publicationStore.getPublicationAttachments(data)
// this.loading = false
})
})
Expand Down Expand Up @@ -523,6 +524,10 @@ export default {
if (loading) { this.metaDataLoading = false }
})
},
addAttachment() {
publicationStore.setAttachmentItem([])
navigationStore.setModal('AddAttachment')
},
deletePublication() {
publicationStore.setPublicationItem(this.publication)
navigationStore.setModal('deletePublication')
Expand Down

0 comments on commit a40b455

Please sign in to comment.