Skip to content

Commit

Permalink
create draft by editing attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
sofyenne committed Oct 4, 2024
1 parent 7eff658 commit 70636fc
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
:display-uploaded-files="displayUploadedFilesList"
:source-app="sourceApp"
:show-drawer-overlay="showDrawerOverlay"
:display-create-document-input="displayCreateDocumentInput"
:create-entity-type-folder="createEntityTypeFolder"
:files="files" />
<attachments-list-drawer
Expand Down Expand Up @@ -46,7 +47,8 @@ export default {
openAttachmentsInEditor: false,
displayUploadedFiles: false,
createEntityTypeFolder: true,
showDrawerOverlay: false
showDrawerOverlay: false,
displayCreateDocumentInput: true
};
},
computed: {
Expand Down Expand Up @@ -152,7 +154,7 @@ export default {
this.displayUploadedFiles = config.displayUploadedFiles;
this.createEntityTypeFolder = config.createEntityTypeFolder;
this.showDrawerOverlay = config.showDrawerOverlay;
this.displayCreateDocumentInput = config.displayCreateDocumentInput;
},
startLoadingList() {
if (this.drawerList && this.$refs.attachmentsListDrawer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{{ $t('attachments.alert.sharing.availableFor') }} <b>{{ currentSpaceDisplayName }}</b> {{ $t('attachments.alert.sharing.members') }}
</div>
<attachment-create-document-input
v-if="(!entityType && ! entityId) || !attachToEntity"
v-if="(!entityType && !entityId) || !attachToEntity && displayCreateDocumentInput"
:attachments="attachments"
:max-files-count="maxFilesCount"
:max-files-size="maxFileSize"
Expand All @@ -52,6 +52,7 @@
:current-space="currentSpace"
:current-drive="currentDrive"
:default-folder="defaultFolder"
:display-uploaded-files="displayUploadedFiles"
:entity-id="entityId"
:entity-type="entityType" />
</div>
Expand Down Expand Up @@ -150,6 +151,10 @@ export default {
showDrawerOverlay: {
type: Boolean,
default: false
},
displayCreateDocumentInput: {
type: Boolean,
default: true
}
},
data() {
Expand Down Expand Up @@ -213,14 +218,12 @@ export default {
cancel: this.$t('attachments.no'),
};
},
displayUploadedFilesList() {
return this.attachments && this.attachments.length && this.displayUploadedFiles;
}
},
watch: {
attachments: {
deep: true,
handler() {
console.log('attachmentList', this.attachments);
this.attachmentsChanged = true;
this.displayMessageDestinationFolder = !this.attachments.some(val => val.uploadId != null && val.uploadId !== '');
if (this.attachments.length === 0) {
Expand All @@ -243,13 +246,6 @@ export default {
defaultDrive() {
this.initDefaultDestinationFolderPath(this.defaultFolder);
},
displayUploadedFiles() {
if (this.displayUploadedFiles) {
this.$forceUpdate();
this.newUploadedFiles = Object.assign([], this.attachments);
this.$root.$emit('refresh-uploaded-files-list');
}
},
newUploadedFilesInProgress(newVal) {
if (newVal) {
document.dispatchEvent(new CustomEvent('new-file-upload-progress'));
Expand Down Expand Up @@ -335,6 +331,7 @@ export default {
this.$root.$emit('reset-attachments-upload-input');
document.removeEventListener('paste', this.onPaste, false);
this.$refs.attachmentsAppDrawer.close();
document.dispatchEvent(new CustomEvent('attachments-app-drawer-closed'));
},
uploadAddedAttachments() {
if (this.newUploadedFilesAdded) { //added new uploaded files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,15 @@ export default {
type: String,
default: ''
},
displayUploadedFiles: {
type: Boolean,
default: false
}
},
created() {
if (this.displayUploadedFiles) {
this.updateUploadedFilesList()
}
this.$root.$on('refresh-uploaded-files-list', () => {
this.$forceUpdate();
this.endLoadingAttachmentDrawer();
Expand All @@ -176,6 +183,22 @@ export default {
return !!this.entityId && !!this.entityType;
},
},
watch: {
displayUploadedFiles(newVal) {
if (newVal) {
this.updateUploadedFilesList();
}
},
attachments: {
handler() {
if(this.displayUploadedFiles) {
console.log(this.attachments)
this.updateUploadedFilesList();
}
},
deep: true
}
},
methods: {
openSelectDestinationFolderDrawer() {
this.$root.$emit('open-drive-explorer-drawer', this.currentDrive);
Expand All @@ -185,6 +208,13 @@ export default {
if (!isLoadingDrawer) {
this.$root.$emit('end-loading-attachment-drawer');
}
},
updateUploadedFilesList() {
this.attachments.forEach((attachment) => {
if (!this.newUploadedFiles.find((item) => item.title === attachment.title)) {
this.newUploadedFiles.push(attachment); // Push only if the attachment is not already there
}
});
}
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
<template>
<div class="NoteAttachments">
<attachment-app
v-if="entityId > 0 && entityType && spaceId"
:entity-id="entityId"
:space-id="spaceId"
:default-folder="'Activity Stream Documents'"
:display-uploaded-files="true"
:create-entity-type-folder="false"
:show-drawer-overlay="true"
:entity-type="entityType">
<template #attachmentsButton>
<button
ref="openAttachmentDrawerButton"
@click="openAttachmentDrawer"
class="button-hidden d-none"></button>
</template>
<template #attachedFilesList />
</attachment-app>
</div>
</template>
<script>

<script>
export default {
props: {
entityId: {
Expand All @@ -38,49 +17,94 @@ export default {
lang: {
type: String,
default: ''
},
isEmptyNoteTranslation: {
type: Boolean,
default: false
}
},
data() {
return {
attachments: [],
displayUploadedFiles: true,
createEntityTypeFolder: false,
displayCreateDocumentInput: false,
originalAttachmentsList: [],
attachmentListUpdated: false
};
},
computed: {
attachedFiles() {
return this.attachments;
},
attachmentAppConfiguration() {
return {
'entityId': this.entityId,
'entityType': this.entityType,
'defaultDrive': null,
'defaultFolder': 'Activity Stream Documents',
'spaceId': this.spaceId,
'attachments': this.attachments,
'displayUploadedFiles': this.displayUploadedFiles,
'createEntityTypeFolder': this.createEntityTypeFolder,
'sourceApp': 'note',
'showDrawerOverlay': true,
'attachToEntity': this.attachToEntity,
'displayCreateDocumentInput': this.displayCreateDocumentInput
};
},
attachToEntity() {
return this.entityType !== 'WIKI_PAGE_VERSIONS'
}
},
watch: {
entityId() {
this.refreshButtonDisplayRules();
},
isEmptyNoteTranslation() {
this.refreshButtonDisplayRules();
}
},
created() {
//these events to handel the single and multiple files upload
//synchronizing the draft saving with the editor
document.addEventListener('new-file-upload-progress', this.emitEditorExtensionsUpdatingDataEvent);
document.addEventListener('new-file-upload-done', this.emitEditorExtensionsDataUpdatedEvent);
document.addEventListener('open-notes-attachments', this.openAttachmentDrawer);
document.addEventListener('attachment-removed', this.emitEditorExtensionsDataUpdatedEvent);
document.addEventListener('attachment-added-from-drives', this.emitEditorExtensionsDataUpdatedEvent);
document.addEventListener('note-file-attach-plugin-button-initialized', this.refreshButtonDisplayRules);
document.addEventListener('attachments-app-drawer-closed', this.emitEditorExtensionsDataUpdatedEvent);
document.addEventListener('note-draft-auto-save-done', (event) => {
if (this.attachmentListUpdated && event.detail.draftId) {
this.updateLinkedAttachmentsToEntity(event.detail.draftId);
}
});
},
beforeDestroy() {
document.removeEventListener('open-notes-attachments');
document.removeEventListener('attachment-removed');
document.removeEventListener('note-file-attach-plugin-button-initialized');
},
methods: {
openAttachmentDrawer() {
if (this.entityId > 0 && this.entityType && this.spaceId){
this.$refs.openAttachmentDrawerButton.click();
this.attachments = [];
this.originalAttachmentsList = [];
this.initEntityAttachmentsList().then(() => {
document.dispatchEvent(new CustomEvent('open-attachments-app-drawer', {detail: this.attachmentAppConfiguration}));
})
}
},
emitEditorExtensionsUpdatingDataEvent() {
document.dispatchEvent(new CustomEvent('editor-extensions-data-start-updating', {
detail: {
showAutoSaveMessage: true,
processAutoSave: this.entityType === 'Page'
}
}));
},
emitEditorExtensionsDataUpdatedEvent() {
document.dispatchEvent(new CustomEvent('editor-extensions-data-updated', {
const attachmentAdded = this.attachments.filter((item) => !this.originalAttachmentsList.some(originalItem => originalItem.id === item.id)).length > 0;
const attachmentRemoved = this.originalAttachmentsList.filter((originalItem) => !this.attachments.some(item => item.id === originalItem.id)).length > 0;
this.attachmentListUpdated = attachmentRemoved || attachmentAdded;
document.dispatchEvent(new CustomEvent('note-editor-extensions-data-updated', {
detail: {
showAutoSaveMessage: true,
processAutoSave: this.entityType === 'Page'
processAutoSave: this.attachmentListUpdated && this.entityType === 'WIKI_PAGE_VERSIONS'
}
}));
},
refreshButtonDisplayRules() {
if (this.entityId && this.entityId !== 0) {
if (this.entityId && this.entityId !== 0 && !this.isEmptyNoteTranslation) {
document.dispatchEvent(new CustomEvent('toggle-attach-button', {
detail: { enable: true }
}));
Expand All @@ -89,7 +113,45 @@ export default {
detail: { enable: false }
}));
}
}
},
initEntityAttachmentsList() {
if (this.entityType && this.entityId) {
return this.$attachmentService.getEntityAttachments(this.entityType, this.entityId).then(attachments => {
if (attachments && attachments.length) {
attachments.forEach((attachment) => {
attachment.name = attachments.title;
});
this.attachments.push(...attachments);
this.originalAttachmentsList.push(...attachments);
}
});
} else {return Promise.resolve();}
},
updateLinkedAttachmentsToEntity(entityId) {
const attachmentIds = this.attachments.filter(attachment => attachment.id).map(attachment => attachment.id);
if (attachmentIds.length === 0) {
return this.$attachmentService.removeAllAttachmentsFromEntity(entityId, this.entityType).then(() => {
document.dispatchEvent(new CustomEvent('entity-attachments-updated'));
this.attachmentListUpdated = false;
}).catch(e => {
console.error(e);
this.$refs.attachmentsAppDrawer.endLoading();
this.$root.$emit('alert-message', this.$t('attachments.link.failed'), 'error');
this.attachmentListUpdated = false
});
} else {
return this.$attachmentService.updateLinkedAttachmentsToEntity(entityId, this.entityType, attachmentIds)
.then(() => {
document.dispatchEvent(new CustomEvent('entity-attachments-updated'));
this.attachmentListUpdated = false;
})
.catch(e => {
this.attachmentListUpdated = false;
console.error(e);
this.$root.$emit('alert-message', this.$t('attachments.link.failed'), 'error');
});
}
},
}
};
</script>

0 comments on commit 70636fc

Please sign in to comment.