Skip to content

Commit

Permalink
Merge pull request #5 from ConductionNL/feature/DIMOC-236/Attachments…
Browse files Browse the repository at this point in the history
…-page-refactor

feature/DIMOC-236/Attachments-page-refactor
  • Loading branch information
remko48 authored Aug 13, 2024
2 parents cf11326 + ee63b98 commit f54d26a
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 76 deletions.
4 changes: 2 additions & 2 deletions lib/Db/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public function jsonSerialize(): array
'hash' => $this->hash,
'anonymization' => $this->anonymization,
'language' => $this->language,
'modified' => $this->modified->format('c'),
'published' => $this->published->format('c'),
'modified' => $this->modified?->format('c'),
'published' => $this->published?->format('c'),
'license' => $this->license,
];

Expand Down
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
36 changes: 32 additions & 4 deletions src/dialogs/attachment/DeleteAttachmentDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
},
data() {
return {
filterdAttachments: [],
loading: false,
succes: false,
error: false,
Expand All @@ -83,10 +83,38 @@ 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
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',
},
body: JSON.stringify({
...publicationStore.publicationItem,
attachments: [...this.filterdAttachments],
}),
},
)
.then((response) => {
this.loading = false
// Lets refresh the publicationList
publicationStore.refreshPublicationList()
response.json().then((data) => {
publicationStore.setPublicationItem(data)
})
})
.catch((err) => {
this.error = err
this.loading = false
})
}
// Wait for the user to read the feedback then close the model
const self = this
setTimeout(function() {
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
6 changes: 3 additions & 3 deletions src/entities/publication/publication.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export const mockPublicationsData = (): TPublication[] => [
key: 'anyvalue',
streetNumber: 1,
object: {
blabla: 'bla'
},
array: ['appel', 'peer', 0, [], {}]
blabla: 'bla',
},
array: ['appel', 'peer', 0, [], {}],
},
attachments: [],
attachmentCount: 1,
Expand Down
59 changes: 46 additions & 13 deletions src/modals/attachment/AddAttachmentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { navigationStore, publicationStore } from '../../store/store.js'
</NcNoteCard>
</div>
<div v-if="success === null" class="form-group">
<NcTextField :disabled="loading"
<NcTextField :disabled="(files && true) || loading"
label="Titel"
maxlength="255"
:value.sync="publicationStore.attachmentItem.title"
Expand All @@ -38,13 +38,13 @@ import { navigationStore, publicationStore } from '../../store/store.js'
label="Toegangs URL"
maxlength="255"
:value.sync="publicationStore.attachmentItem.accessUrl" />
<NcTextField :disabled="loading"
<NcTextField :disabled="(files && true) || loading"
label="Download URL"
maxlength="255"
:value.sync="publicationStore.attachmentItem.downloadUrl" />
<div class="addFileButtonGroup">
<NcButton v-if="success === null && !files"
:disabled="loading"
:disabled="checkIfDisabled() || loading"
type="primary"
@click="openFileUpload()">
<template #icon>
Expand All @@ -54,7 +54,7 @@ import { navigationStore, publicationStore } from '../../store/store.js'
</NcButton>

<NcButton v-if="success === null && files"
:disabled="loading"
:disabled="checkIfDisabled() || loading"
type="primary"
@click="reset()">
<template #icon>
Expand All @@ -64,7 +64,7 @@ import { navigationStore, publicationStore } from '../../store/store.js'
</NcButton>
</div>
<NcButton v-if="success === null"
:disabled="!publicationStore.attachmentItem.title || !files || loading"
:disabled="loading"
type="primary"
@click="addAttachment()">
<template #icon>
Expand All @@ -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 @@ -115,12 +115,18 @@ export default {
closeModal() {
navigationStore.modal = false
},
checkIfDisabled() {
if (publicationStore.attachmentItem.downloadUrl || publicationStore.attachmentItem.title) return true
return false
},
addAttachment() {
this.loading = true
this.errorMessage = false
axios.post('/index.php/apps/opencatalogi/api/attachments', {
...(publicationStore.attachmentItem),
published: null,
_file: files.value ? files.value[0] : '',
}, {
headers: {
Expand All @@ -131,15 +137,42 @@ export default {
'Publication-Title': publicationStore.publicationItem.title,
},
}).then((response) => {
this.loading = false
this.success = true
reset()
// Lets refresh the attachment list
if (publicationStore.publicationItem?.id) {
publicationStore.getPublicationAttachments(publicationStore.publicationItem.id)
// @todo update the publication item
}
// store.refreshCatalogiList()
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],
}),
},
)
.then((response) => {
this.loading = false
// 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 All @@ -150,7 +183,7 @@ export default {
}, 2000)
})
.catch((err) => {
this.error = err
this.error = err.response?.data?.error ?? err
this.loading = false
})
},
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
2 changes: 1 addition & 1 deletion src/store/modules/publication.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const usePublicationStore = defineStore(
},
getPublicationAttachments(publication) { // @todo this might belong in a service?
fetch(
'/index.php/apps/opencatalogi/api/attachments',
`/index.php/apps/opencatalogi/api/publications/${publication.id}/attachments`,
{
method: 'GET',
},
Expand Down
Loading

0 comments on commit f54d26a

Please sign in to comment.