Skip to content

Commit

Permalink
feat: Refactor publish note option integration - EXO-73041 - Meeds-io…
Browse files Browse the repository at this point in the history
…/meeds#161

Refactor publish note option integration
  • Loading branch information
hakermi committed Nov 22, 2024
1 parent 0195c0e commit f16966e
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 160 deletions.
3 changes: 0 additions & 3 deletions notes-webapp/src/main/webapp/WEB-INF/gatein-resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
<minify>false</minify>
<path>/javascript/notes.bundle.js</path>
</script>
<depends>
<module>NotePublishExtensions</module>
</depends>
<depends>
<module>NotesPublication</module>
</depends>
Expand Down
76 changes: 0 additions & 76 deletions notes-webapp/src/main/webapp/javascript/eXo/wiki/notesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,79 +430,3 @@ 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,
fromExternalPage: article.fromExternalPage,
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');
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ export default {
this.cloneScheduleSettings();
this.cloneAdvancedSettings();
this.clonePublicationSettings();
} else {
this.initSettings();
}
this.currentScheduleSettings = structuredClone(this.scheduleSettings);
this.currentAdvancedSettings = structuredClone(this.advancedSettings);
Expand Down Expand Up @@ -401,6 +403,11 @@ export default {
this.$refs?.scheduleOption?.cancelChanges();
this.$refs?.advancedOption?.cancelChanges();
},
initSettings() {
this.scheduleSettings = {};
this.advancedSettings = {};
this.publicationSettings = {post: true};
},
reset() {
setTimeout(() => {
this.cancelChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,18 @@ export default {
},
initSettings() {
if (!this.editMode) {
this.resetSettings();
return;
}
this.hideAuthor = this.savedAdvancedSettings?.hideAuthor;
this.hideReaction = this.savedAdvancedSettings?.hideReaction;
},
cancelChanges() {
this.initSettings();
},
resetSettings() {
this.hideAuthor = false;
this.hideReaction = false;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ export default {
},
initSettings() {
if (!this.editMode) {
this.resetSettings();
return;
}
this.schedule = this.savedScheduleSettings.scheduled;
Expand Down Expand Up @@ -502,6 +503,17 @@ export default {
},
cancelChanges() {
this.initSettings();
},
resetSettings() {
this.schedule = false;
this.savedScheduleSettings = {};
const {startDate, minStartDate, endDate} = this.initDateValues();
this.startDate = startDate;
this.endDate = endDate;
this.minStartDate = minStartDate;
this.minEndDate = minStartDate;
this.endTime = '18:00';
this.startTime= '08:00';
}
}
};
Expand Down
20 changes: 0 additions & 20 deletions notes-webapp/src/main/webapp/vue-app/notes-rich-editor/js/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,6 @@ function getString(body) {
return new DOMParser().parseFromString(body, 'text/html').documentElement.textContent.replace(/&nbsp;/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
};
}

export function sanitizeSrcImageTags(content) {
if (!content) {
return content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default {
openNote(note) {
if (note.noteId !== this.actualNoteId ) {
this.$emit('open-note',note.id);
document.dispatchEvent(new CustomEvent('note-navigation-updated', {detail: note}));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
ref="featuredImageDrawer"
:note="note"
:has-featured-image="hasFeaturedImage" />
<note-publication-target-drawer />
<note-publication-drawer
v-if="newPublicationDrawerEnabled"
ref="publicationDrawer"
Expand Down Expand Up @@ -402,8 +403,6 @@ export default {
note() {
if (!this.note.draftPage) {
this.getNoteVersionByNoteId(this.note.id);
this.getSavedNotePublicationSettings(this.note.id);
this.getCanSchedule();
}
if ( this.note && this.note.breadcrumb && this.note.breadcrumb.length ) {
this.note.breadcrumb[0].title = this.getHomeTitle(this.note.breadcrumb[0].title);
Expand Down Expand Up @@ -610,8 +609,6 @@ export default {
},
created() {
this.getAvailableLanguages();
this.getPublishTargets();
this.getCanPublish();
const queryPath = window.location.search;
const urlParams = new URLSearchParams(queryPath);
if (urlParams.has('translation')) {
Expand Down Expand Up @@ -672,6 +669,7 @@ export default {
this.$root.$on('open-note-import-drawer', this.openImportDrawer);
this.$root.$on('open-publish-drawer', this.openPublishDrawer);
document.addEventListener('notes-extensions-updated', this.refreshOverviewExtensions);
document.addEventListener('note-published', this.handleNotePublished);
this.refreshOverviewExtensions();
},
mounted() {
Expand All @@ -681,60 +679,45 @@ export default {
});
},
methods: {
getSavedNotePublicationSettings(id, lang) {
return this.$notesService.getSavedNotePublicationSettings(id, lang).then(settings => {
if (settings) {
this.note = Object.assign(this.note, settings);
}
this.published = !!settings;
});
},
getCanPublish() {
this.$notesService.canPublish(this.spaceId).then(canPublish => {
this.canPublish = canPublish;
});
},
getCanSchedule() {
this.$notesService.canSchedule(this.spaceId, this.note?.id).then(canSchedule => {
this.canSchedule = canSchedule;
});
},
getPublishTargets() {
this.$notesService.getNotePublishTargets().then(targets => {
this.publishTargets = targets;
});
},
publishNote(publicationSettings, note) {
const scheduleSettings = publicationSettings?.scheduleSettings;
const article = structuredClone(note || this.note);
article.schedulePostDate = scheduleSettings?.postDate;
article.scheduleUnpublishDate = scheduleSettings?.unpublishDate;
article.activityPosted = publicationSettings?.post;
article.published = publicationSettings?.publish;
article.targets = publicationSettings?.selectedTargets;
article.audience = publicationSettings?.selectedAudience;
const noteArticle = structuredClone(note || this.note);
noteArticle.schedulePostDate = scheduleSettings?.postDate;
noteArticle.scheduleUnpublishDate = scheduleSettings?.unpublishDate;
noteArticle.activityPosted = publicationSettings?.post;
noteArticle.published = publicationSettings?.publish;
noteArticle.targets = publicationSettings?.selectedTargets;
noteArticle.audience = publicationSettings?.selectedAudience;
this.isPublishing = true;
if (note) {
this.$notesService.updateNoteById(note).then(() => {
this.$notesService.saveNoteArticle(this.$noteUtils.noteToArticle(article, this.spaceId)).then(() => {
this.isPublishing = false;
this.getSavedNotePublicationSettings(this.note?.id);
this.$refs.publicationDrawer.close();
this.$root.$emit('show-alert', {type: 'success', message: this.$t('notes.publication.success.message')});
});
document.dispatchEvent(new CustomEvent('publish-note', {
detail: {
editPublication: false,
article: noteArticle
}
}));
});
} else {
const editScheduleAction = scheduleSettings?.editScheduleAction;
this.$notesService.updateNotePublication(editScheduleAction, scheduleSettings,
this.$noteUtils.noteToArticle(article, this.spaceId)).then(() => {
this.isPublishing = false;
this.$refs.publicationDrawer.close();
this.$root.$emit('show-alert', {type: 'success', message: this.$t('notes.publication.settings.update.success')});
});
document.dispatchEvent(new CustomEvent('publish-note', {
detail: {
editPublication: true,
article: noteArticle,
scheduleSettings: scheduleSettings,
}
}));
}
},
openPublishDrawer() {
this.$refs.publicationDrawer.open(this.note);
openPublishDrawer(publicationParams) {
const savedSettings = publicationParams?.savedSettings;
this.published = !!savedSettings;
this.publishTargets = publicationParams.targets;
this.canPublish = publicationParams?.canPublish;
this.canSchedule = publicationParams?.canSchedule;
this.note = Object.assign(this.note, savedSettings);
setTimeout(() => {
this.$refs.publicationDrawer.open(this.note);
},200);
},
closeMobileActionMenu() {
setTimeout(() => {
Expand Down Expand Up @@ -1098,7 +1081,7 @@ export default {
openNoteChild(item) {
const noteName = item.path.split('%2F').pop();
this.$root.$emit('open-note-by-name', noteName);
this.getSavedNotePublicationSettings(item.noteId);
document.dispatchEvent(new CustomEvent('note-navigation-updated', {detail: item}));
},
updateNote(noteParam) {
const note = {
Expand Down Expand Up @@ -1191,7 +1174,17 @@ export default {
},
refreshOverviewExtensions() {
this.overviewExtensions = extensionRegistry.loadComponents('NotesOverview') || [];
}
},
handleNotePublished(event) {
const {editPublication} = event.detail;
this.isPublishing = false;
this.$refs.publicationDrawer.close();
this.$root.$emit('show-alert', {
type: 'success',
message: editPublication && this.$t('notes.publication.settings.update.success')
|| this.$t('notes.publication.success.message')
});
},
}
};
</script>
10 changes: 0 additions & 10 deletions notes-webapp/src/main/webapp/vue-app/notes/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ extensionRegistry.registerExtension('NotesMenu', 'menuActionMenu', {
actionEvent: 'note-export-pdf',
enabled: (note) => note?.canView,
});
extensionRegistry.registerExtension('NotesMenu', 'menuActionMenu', {
id: 'publishNote',
labelKey: 'notes.publication.publish.save.label',
icon: 'fas fa-paper-plane',
sortable: true,
cssClass: 'ps-2 pe-4 action-menu-item',
rank: 30,
actionEvent: 'open-publish-drawer',
enabled: (note) => eXo?.env?.portal?.notePublicationEnabled && !note.draftPage,
});
extensionRegistry.registerExtension('NotesMenu', 'menuActionMenu', {
id: 'noteHistory',
labelKey: 'notes.menu.label.noteHistory',
Expand Down

0 comments on commit f16966e

Please sign in to comment.