From 7cb0b714c3f779e7d4d383c78b962d9319896f47 Mon Sep 17 00:00:00 2001 From: Helmi Akermi <70575401+hakermi@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:37:19 +0100 Subject: [PATCH] feat: Implement publish note - EXO-73041 - Meeds-io/MIPs#161 (#1212) Implement publish note --- .../portlet/notes/notesPortlet_en.properties | 1 + .../portlet/notes/notesPortlet_fr.properties | 1 + .../main/webapp/WEB-INF/gatein-resources.xml | 9 ++ .../javascript/eXo/wiki/notesService.js | 76 ++++++++++ .../components/NotePublicationDrawer.vue | 2 +- .../components/NoteFullRichEditor.vue | 2 +- .../vue-app/notes-rich-editor/js/Utils.js | 20 +++ .../notes/components/NotesOverview.vue | 121 +++++++++++++--- .../components/menu/NotesActionMenuItems.vue | 136 ++++-------------- .../components/menu/NotesActionsMenu.vue | 7 +- .../components/menu/NotesMobileActionMenu.vue | 3 +- .../main/webapp/vue-app/notes/extensions.js | 86 +++++++++++ .../webapp/vue-app/notes/initComponents.js | 4 +- .../src/main/webapp/vue-app/notes/main.js | 3 +- 14 files changed, 331 insertions(+), 140 deletions(-) create mode 100644 notes-webapp/src/main/webapp/vue-app/notes/extensions.js diff --git a/notes-webapp/src/main/resources/locale/portlet/notes/notesPortlet_en.properties b/notes-webapp/src/main/resources/locale/portlet/notes/notesPortlet_en.properties index 687794b17..f40176194 100644 --- a/notes-webapp/src/main/resources/locale/portlet/notes/notesPortlet_en.properties +++ b/notes-webapp/src/main/resources/locale/portlet/notes/notesPortlet_en.properties @@ -105,6 +105,7 @@ notes.publication.schedule.publish.now.tooltip=By scheduling only a end date you notes.publication.advanced.option.label=Advanced options notes.publication.hide.author.label=Hide author notes.publication.hide.reaction.label=Hide reaction +notes.publication.success.message=Note successfully published popup.confirm=Confirm popup.msg.confirmation=Confirmation diff --git a/notes-webapp/src/main/resources/locale/portlet/notes/notesPortlet_fr.properties b/notes-webapp/src/main/resources/locale/portlet/notes/notesPortlet_fr.properties index 94bf19edf..e83a0e112 100644 --- a/notes-webapp/src/main/resources/locale/portlet/notes/notesPortlet_fr.properties +++ b/notes-webapp/src/main/resources/locale/portlet/notes/notesPortlet_fr.properties @@ -104,6 +104,7 @@ notes.publication.schedule.publish.now.tooltip=En programmant uniquement une dat notes.publication.advanced.option.label=Options avancées notes.publication.hide.author.label=Masquer l'auteur notes.publication.hide.reaction.label=Masquer la réaction +notes.publication.success.message=Note publi\u00E9e avec succ\u00E8s popup.confirm=Confirmer popup.msg.confirmation=Confirmation diff --git a/notes-webapp/src/main/webapp/WEB-INF/gatein-resources.xml b/notes-webapp/src/main/webapp/WEB-INF/gatein-resources.xml index fbb9ee85e..f77772434 100644 --- a/notes-webapp/src/main/webapp/WEB-INF/gatein-resources.xml +++ b/notes-webapp/src/main/webapp/WEB-INF/gatein-resources.xml @@ -49,6 +49,15 @@ false /javascript/notes.bundle.js + + NotePublishExtensions + + + NotesPublication + + + imageCropper + html2canvas diff --git a/notes-webapp/src/main/webapp/javascript/eXo/wiki/notesService.js b/notes-webapp/src/main/webapp/javascript/eXo/wiki/notesService.js index 1b039df14..de811aa81 100644 --- a/notes-webapp/src/main/webapp/javascript/eXo/wiki/notesService.js +++ b/notes-webapp/src/main/webapp/javascript/eXo/wiki/notesService.js @@ -429,3 +429,79 @@ export function removeNoteFeaturedImage(noteId, isDraft, lang) { } }); } + +export async function getNotePublishTargets() { + const targets = await Vue.prototype.$newsTargetingService.getAllowedTargets(); + return targets.map(target => ({ + name: target.name, + label: target?.properties?.label, + tooltipInfo: `${target?.properties?.label}: ${target?.properties?.description || ''}`, + description: target?.properties?.description, + restrictedAudience: target?.restrictedAudience, + })); +} + +export function saveNoteArticle(article) { + if (article?.schedulePostDate) { + article.publicationState = 'staged'; + } + if (article.scheduleUnpublishDate || article?.schedulePostDate) { + article.timeZoneId = new window.Intl.DateTimeFormat().resolvedOptions().timeZone; + } + if (article.publicationState === 'staged') { + return Vue.prototype.$newsService.scheduleNews(article, 'existing_page'); + } else { + return Vue.prototype.$newsService.saveNews(article); + } +} + +export function canPublish(spaceId) { + return Vue.prototype.$newsService.canPublishNews(spaceId); +} + +export function canSchedule(spaceId, articleId) { + return Vue.prototype.$newsService.canScheduleNews(spaceId, articleId); +} + +export async function getSavedNotePublicationSettings(id, lang) { + try { + const article = await Vue.prototype.$newsService.getNewsById(id, false, 'article', lang); + if (!article || article.status === 404) { + return null; + } + return { + activityPosted: article.activityPosted, + published: article.published, + targets: article.targets, + audience: article.audience, + schedulePostDate: article.schedulePostDate, + scheduleUnpublishDate: article.scheduleUnpublishDate, + properties: article.properties ?? {} + }; + } catch (error) { + console.error(error); + throw error; + } +} + +export function updateNotePublication(editScheduleAction, scheduleSettings, article) { + article.timeZoneId = new window.Intl.DateTimeFormat().resolvedOptions().timeZone; + switch (editScheduleAction) { + case 'schedule': + article.publicationState = scheduleSettings?.postDate ? 'staged' : ''; + return Vue.prototype.$newsService.scheduleNews(article, 'article'); + case 'cancel_schedule': + article.schedulePostDate = 0; + article.publicationState = 'draft'; + return Vue.prototype.$newsService.saveNews(article); + case 'publish_now': + article.schedulePostDate = 0; + article.publicationState = 'posted'; + return Vue.prototype.$newsService.saveNews(article); + default: + article.publicationState = 'posted'; + return Vue.prototype.$newsService.updateNews(article, article.activityPosted, 'article', 'POSTING_AND_PUBLISHING'); + } +} + + diff --git a/notes-webapp/src/main/webapp/vue-app/notes-publication/components/NotePublicationDrawer.vue b/notes-webapp/src/main/webapp/vue-app/notes-publication/components/NotePublicationDrawer.vue index bda62e85b..672732776 100644 --- a/notes-webapp/src/main/webapp/vue-app/notes-publication/components/NotePublicationDrawer.vue +++ b/notes-webapp/src/main/webapp/vue-app/notes-publication/components/NotePublicationDrawer.vue @@ -422,7 +422,7 @@ export default { return; } this.$emit('metadata-updated', this.noteObject.properties); - this.$emit('publish', this.noteObject, this.publicationSettings); + this.$emit('publish', this.publicationSettings, this.noteObject,); }, updateCurrentNoteObjectProperties(properties) { this.noteObject.properties.noteId = Number(properties.noteId); diff --git a/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/components/NoteFullRichEditor.vue b/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/components/NoteFullRichEditor.vue index 4afdafebb..a880c9202 100644 --- a/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/components/NoteFullRichEditor.vue +++ b/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/components/NoteFullRichEditor.vue @@ -402,7 +402,7 @@ export default { } this.postAndPublishNote(); }, - postAndPublishNote(note, publicationSettings) { + postAndPublishNote(publicationSettings, note) { if (this.newPublicationDrawerEnabled) { this.noteObject = note; this.updateData(); diff --git a/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/js/Utils.js b/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/js/Utils.js index 96dc12934..ee6dfb071 100644 --- a/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/js/Utils.js +++ b/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/js/Utils.js @@ -155,3 +155,23 @@ export function isSameContent(content, originalContent) { function getString(body) { return new DOMParser().parseFromString(body, 'text/html').documentElement.textContent.replace(/ /g, '').trim(); } + +export function noteToArticle(note, spaceId) { + return { + id: note.id, + title: note.title, + body: note.content, + author: note.author, + published: note.published, + targets: note.targets, + spaceId: spaceId, + publicationState: 'posted', + schedulePostDate: note.schedulePostDate, + timeZoneId: null, + activityPosted: note.activityPosted, + audience: note.audience, + draftPage: false, + scheduleUnpublishDate: note.scheduleUnpublishDate, + properties: note?.properties + }; +} diff --git a/notes-webapp/src/main/webapp/vue-app/notes/components/NotesOverview.vue b/notes-webapp/src/main/webapp/vue-app/notes/components/NotesOverview.vue index dd1d2aac7..1d0a79f35 100644 --- a/notes-webapp/src/main/webapp/vue-app/notes/components/NotesOverview.vue +++ b/notes-webapp/src/main/webapp/vue-app/notes/components/NotesOverview.vue @@ -279,15 +279,23 @@ + + :note="note" /> + :note="note" /> @@ -301,21 +309,28 @@ ref="noteVersionsHistoryDrawer" /> - + +