note map refactoring

This commit is contained in:
zadam 2021-09-20 23:04:41 +02:00
parent e4ba7d65e8
commit 476b8250c9
7 changed files with 40 additions and 20 deletions

View file

@ -745,11 +745,15 @@ class Note extends AbstractEntity {
}
/** @return {Note[]} */
getSubtreeNotes() {
getSubtreeNotes(includeArchived = true) {
if (this.isArchived) {
return [];
}
const arr = [[this]];
for (const childNote of this.children) {
arr.push(childNote.getSubtreeNotes());
arr.push(childNote.getSubtreeNotes(includeArchived));
}
return arr.flat();

View file

@ -39,7 +39,7 @@ class NoteContext extends Component {
utils.closeActiveDialog();
this.notePath = resolvedNotePath;
this.noteId = treeService.getNoteIdFromNotePath(resolvedNotePath);
({noteId: this.noteId, parentNoteId: this.parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(resolvedNotePath));
this.readOnlyTemporarilyDisabled = false;

View file

@ -2,6 +2,8 @@ import TypeWidget from "./type_widget.js";
import libraryLoader from "../../services/library_loader.js";
import server from "../../services/server.js";
import attributeService from "../../services/attributes.js";
import hoistedNoteService from "../../services/hoisted_note.js";
import appContext from "../../services/app_context.js";
const TPL = `<div class="note-detail-note-map note-detail-printable" style="position: relative;">
<style>
@ -114,7 +116,16 @@ export default class NoteMapTypeWidget extends TypeWidget {
this.graph.d3Force('charge').distanceMax(1000);
const data = await this.loadNotesAndRelations();
let mapRootNoteId = this.note.getLabelValue("mapRootNoteId");
if (mapRootNoteId === 'hoisted') {
mapRootNoteId = hoistedNoteService.getHoistedNoteId();
}
else if (!mapRootNoteId) {
mapRootNoteId = appContext.tabManager.getActiveContext().parentNoteId;
}
const data = await this.loadNotesAndRelations(mapRootNoteId);
this.renderData(data);
}
@ -216,11 +227,11 @@ export default class NoteMapTypeWidget extends TypeWidget {
ctx.restore();
}
async loadNotesAndRelations() {
async loadNotesAndRelations(mapRootNoteId) {
this.linkIdToLinkMap = {};
this.noteIdToLinkCountMap = {};
const resp = await server.post(`note-map/${this.mapType}`);
const resp = await server.post(`note-map/${mapRootNoteId}/${this.mapType}`);
this.noteIdToLinkCountMap = resp.noteIdToLinkCountMap;

View file

@ -101,11 +101,12 @@ function buildDescendantCountMap() {
return noteIdToCountMap;
}
function getGlobalLinkMap() {
function getGlobalLinkMap(req) {
const mapRootNote = becca.getNote(req.params.noteId);
const noteIds = new Set();
const notes = Object.values(becca.notes)
.filter(note => !note.isArchived)
const notes = mapRootNote.getSubtreeNotes(false)
.map(note => [
note.noteId,
note.isContentAvailable() ? note.title : '[protected]',
@ -144,11 +145,12 @@ function getGlobalLinkMap() {
};
}
function getGlobalTreeMap() {
function getGlobalTreeMap(req) {
const mapRootNote = becca.getNote(req.params.noteId);
const noteIds = new Set();
const notes = Object.values(becca.notes)
.filter(note => !note.isArchived && !note.hasLabel('excludeFromTreeMap'))
const notes = mapRootNote.getSubtreeNotes(false)
.filter(note => !note.hasLabel('excludeFromTreeMap'))
.map(note => [
note.noteId,
note.isContentAvailable() ? note.title : '[protected]',

View file

@ -221,8 +221,8 @@ function register(app) {
apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute);
apiRoute(POST, '/api/notes/:noteId/link-map', linkMapRoute.getLinkMap);
apiRoute(POST, '/api/note-map/tree', linkMapRoute.getGlobalTreeMap);
apiRoute(POST, '/api/note-map/link', linkMapRoute.getGlobalLinkMap);
apiRoute(POST, '/api/note-map/:noteId/tree', linkMapRoute.getGlobalTreeMap);
apiRoute(POST, '/api/note-map/:noteId/link', linkMapRoute.getGlobalLinkMap);
apiRoute(GET, '/api/special-notes/inbox/:date', specialNotesRoute.getInboxNote);
apiRoute(GET, '/api/special-notes/date/:date', specialNotesRoute.getDateNote);

View file

@ -46,6 +46,7 @@ const BUILTIN_ATTRIBUTES = [
{ type: 'label', name: 'datePattern' },
{ type: 'label', name: 'pageSize' },
{ type: 'label', name: 'viewType' },
{ type: 'label', name: 'mapRootNoteId' },
// relation names
{ type: 'relation', name: 'runOnNoteCreation', isDangerous: true },

View file

@ -81,20 +81,22 @@ function getSinglesNoteRoot() {
return singlesNoteRoot;
}
function getGlobalLinkMapNote() {
let globalLinkMapNote = becca.getNote('globalnotemap');
function getGlobalNoteMap() {
let globalNoteMap = becca.getNote('globalnotemap');
if (!globalLinkMapNote) {
globalLinkMapNote = noteService.createNewNote({
if (!globalNoteMap) {
globalNoteMap = noteService.createNewNote({
noteId: 'globalnotemap',
title: 'Global Note Map',
type: 'note-map',
content: '',
parentNoteId: getSinglesNoteRoot().noteId
}).note;
globalNoteMap.addLabel('mapRootNoteId', 'hoisted');
}
return globalLinkMapNote;
return globalNoteMap;
}
function getSqlConsoleRoot() {
@ -186,7 +188,7 @@ function createMissingSpecialNotes() {
getSqlConsoleRoot();
getSinglesNoteRoot();
getSinglesNoteRoot();
getGlobalLinkMapNote();
getGlobalNoteMap();
}
module.exports = {