Skip to content

Commit

Permalink
feat: Enhance treeview navigation display in article details when pub…
Browse files Browse the repository at this point in the history
…lish note with navigation - EXO-75747 - Meeds-io/MIPs#161

Enhance treeview navigation display in article details when publish note with navigation using same template as in the edit mode
  • Loading branch information
hakermi committed Dec 13, 2024
1 parent 00be4ec commit 40967a8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
8 changes: 7 additions & 1 deletion content-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.meeds.notes</groupId>
<artifactId>notes-webapp</artifactId>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.meeds.commons</groupId>
<artifactId>commons-api</artifactId>
Expand Down Expand Up @@ -117,7 +123,7 @@
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>platform-ui-skin,commons-extension-webapp</includeArtifactIds>
<includeArtifactIds>platform-ui-skin,commons-extension-webapp,notes-webapp</includeArtifactIds>
<outputDirectory>${project.build.directory}/src/main/webapp</outputDirectory>
<excludes>**/custom-variables.less</excludes>
</configuration>
Expand Down
14 changes: 14 additions & 0 deletions content-webapp/src/main/webapp/skin/less/newsDetails.less
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@import "variables.less";
@import "../../ckeditor/skins/common/extendedRichContent.less";
@import (less) "../../ckeditor/plugins/codesnippet/lib/highlight/styles/monokai_sublime.css";

@grayDark: #333;

.singlePageApplicationTDContainer {
Expand Down Expand Up @@ -108,6 +109,19 @@
background: rgba(0, 0, 0, 0.5);
color: @whiteColorDefault
}

.content-treeview-processor {
@import (less) "../../toc/toc.css";

.navigation-img-wrapper .image-navigation,
.navigation-img-wrapper .image-navigation * {
cursor: pointer !important;
}

.navigation-img-wrapper figure #remove-treeview {
display: none !important;
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export default {
this.$root.$on('open-edit-publishing-drawer', this.openPublicationDrawer);
this.$root.$on('refer-article-to-note', this.referArticle);
this.$root.$on('move-page', this.moveArticlePage);
this.bindTreeViewNavigationClickListener();
},
methods: {
moveArticlePage(page, newParentPage) {
Expand Down Expand Up @@ -446,6 +447,14 @@ export default {
alertLink: message.alertLink
}}));
},
bindTreeViewNavigationClickListener() {
const self = this;
document.addEventListener('click', function (event) {
if (event.target.closest('.image-navigation')) {
window.location.href = self.articlePage.url;
}
});
},
}
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
</div>
</div>
<div
class="mt-8 rich-editor-content extended-rich-content"
class="mt-8 content-treeview-processor rich-editor-content extended-rich-content"
v-sanitized-html="newsBody">
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import * as publishService from './publishService';
import {initPublishExtension} from './extensions.js';

const treeViewNavigationTemplate = `
<div
id="note-children-container"
class="navigation-img-wrapper"
contenteditable="false">
<figure class="image-navigation" contenteditable="false">
<img src="/notes/images/children.png" role="presentation"/>
<img src="/notes/images/trash.png" id="remove-treeview" alt="remove treeview"/>
<figcaption class="note-navigation-label">Navigation</figcaption>
</figure>
</div>
<p></p>`;

document.addEventListener('note-navigation-updated', handleNoteNavigationUpdate);
document.addEventListener('publish-note', publishNote);
Expand All @@ -16,13 +28,21 @@ function publishNote(event) {
updateSavedPublicationSettings(article.id);
});
} else {
checkInsertTocNavigationTemplate(article);
publishService.saveNoteArticle(article, spaceId).then((article) => {
emitNotePublished(false, !!article?.schedulePostDate, article?.url);
updateSavedPublicationSettings(article.id);
});
}
}

function checkInsertTocNavigationTemplate(article) {
if (article.isHomeDefaultContent && article.hasChildren) {
article.content = treeViewNavigationTemplate;
publishService.updateArticlePage(article);
}
}

function handleNoteNavigationUpdate(event) {
const {noteId} = event.detail;
publishService.getSavedNotePublicationSettings(noteId).then(settings => {
Expand All @@ -42,7 +62,7 @@ function updateSavedPublicationSettings(noteId) {
});
}

function extractNoteIdFormUrl() {
function extractNoteIdFromUrl() {
const url = window.location.href;
const regex = /\/notes\/(\d+)$/;
const match = regex.exec(url);
Expand All @@ -61,7 +81,8 @@ function emitNotePublished(edit, isPublishSchedule, link) {

export async function init() {
try {
const noteId = extractNoteIdFormUrl();
const wikiOwner = `/spaces/${eXo.env.portal.spaceGroup}`;
const noteId = extractNoteIdFromUrl() ?? (await publishService.getNoteHomePage('group', wikiOwner))?.id;
const [canPublish, savedSettings, targets] = await Promise.all([
publishService.canPublish(spaceId),
publishService.getSavedNotePublicationSettings(noteId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export async function getSavedNotePublicationSettings(id, lang) {
}
}

export function getNoteHomePage(type, owner) {
return newsService.getPageByTypeOwnerAndName(type, owner, 'Home');
}

export function updateArticlePage(page) {
return newsService.updateArticlePage(page);
}

export function saveNoteArticle(article, spaceId) {
article = noteToArticle(article, spaceId);
if (article?.schedulePostDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,11 @@ export function getArticlePage(pageId) {
export function moveArticlePage(page, newParentPage) {
return Vue.prototype.$notesService.moveNotes(page, newParentPage);
}

export function getPageByTypeOwnerAndName(type, owner, name) {
return Vue.prototype.$notesService.getNote(type, owner, name);
}

export function updateArticlePage(page) {
return Vue.prototype.$notesService.updateNoteById(page);
}

0 comments on commit 40967a8

Please sign in to comment.