mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
note map refactoring
This commit is contained in:
parent
e4ba7d65e8
commit
476b8250c9
@ -745,11 +745,15 @@ class Note extends AbstractEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @return {Note[]} */
|
/** @return {Note[]} */
|
||||||
getSubtreeNotes() {
|
getSubtreeNotes(includeArchived = true) {
|
||||||
|
if (this.isArchived) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const arr = [[this]];
|
const arr = [[this]];
|
||||||
|
|
||||||
for (const childNote of this.children) {
|
for (const childNote of this.children) {
|
||||||
arr.push(childNote.getSubtreeNotes());
|
arr.push(childNote.getSubtreeNotes(includeArchived));
|
||||||
}
|
}
|
||||||
|
|
||||||
return arr.flat();
|
return arr.flat();
|
||||||
|
@ -39,7 +39,7 @@ class NoteContext extends Component {
|
|||||||
utils.closeActiveDialog();
|
utils.closeActiveDialog();
|
||||||
|
|
||||||
this.notePath = resolvedNotePath;
|
this.notePath = resolvedNotePath;
|
||||||
this.noteId = treeService.getNoteIdFromNotePath(resolvedNotePath);
|
({noteId: this.noteId, parentNoteId: this.parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(resolvedNotePath));
|
||||||
|
|
||||||
this.readOnlyTemporarilyDisabled = false;
|
this.readOnlyTemporarilyDisabled = false;
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ import TypeWidget from "./type_widget.js";
|
|||||||
import libraryLoader from "../../services/library_loader.js";
|
import libraryLoader from "../../services/library_loader.js";
|
||||||
import server from "../../services/server.js";
|
import server from "../../services/server.js";
|
||||||
import attributeService from "../../services/attributes.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;">
|
const TPL = `<div class="note-detail-note-map note-detail-printable" style="position: relative;">
|
||||||
<style>
|
<style>
|
||||||
@ -114,7 +116,16 @@ export default class NoteMapTypeWidget extends TypeWidget {
|
|||||||
|
|
||||||
this.graph.d3Force('charge').distanceMax(1000);
|
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);
|
this.renderData(data);
|
||||||
}
|
}
|
||||||
@ -216,11 +227,11 @@ export default class NoteMapTypeWidget extends TypeWidget {
|
|||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadNotesAndRelations() {
|
async loadNotesAndRelations(mapRootNoteId) {
|
||||||
this.linkIdToLinkMap = {};
|
this.linkIdToLinkMap = {};
|
||||||
this.noteIdToLinkCountMap = {};
|
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;
|
this.noteIdToLinkCountMap = resp.noteIdToLinkCountMap;
|
||||||
|
|
||||||
|
@ -101,11 +101,12 @@ function buildDescendantCountMap() {
|
|||||||
return noteIdToCountMap;
|
return noteIdToCountMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGlobalLinkMap() {
|
function getGlobalLinkMap(req) {
|
||||||
|
const mapRootNote = becca.getNote(req.params.noteId);
|
||||||
|
|
||||||
const noteIds = new Set();
|
const noteIds = new Set();
|
||||||
|
|
||||||
const notes = Object.values(becca.notes)
|
const notes = mapRootNote.getSubtreeNotes(false)
|
||||||
.filter(note => !note.isArchived)
|
|
||||||
.map(note => [
|
.map(note => [
|
||||||
note.noteId,
|
note.noteId,
|
||||||
note.isContentAvailable() ? note.title : '[protected]',
|
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 noteIds = new Set();
|
||||||
|
|
||||||
const notes = Object.values(becca.notes)
|
const notes = mapRootNote.getSubtreeNotes(false)
|
||||||
.filter(note => !note.isArchived && !note.hasLabel('excludeFromTreeMap'))
|
.filter(note => !note.hasLabel('excludeFromTreeMap'))
|
||||||
.map(note => [
|
.map(note => [
|
||||||
note.noteId,
|
note.noteId,
|
||||||
note.isContentAvailable() ? note.title : '[protected]',
|
note.isContentAvailable() ? note.title : '[protected]',
|
||||||
|
@ -221,8 +221,8 @@ function register(app) {
|
|||||||
apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute);
|
apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute);
|
||||||
|
|
||||||
apiRoute(POST, '/api/notes/:noteId/link-map', linkMapRoute.getLinkMap);
|
apiRoute(POST, '/api/notes/:noteId/link-map', linkMapRoute.getLinkMap);
|
||||||
apiRoute(POST, '/api/note-map/tree', linkMapRoute.getGlobalTreeMap);
|
apiRoute(POST, '/api/note-map/:noteId/tree', linkMapRoute.getGlobalTreeMap);
|
||||||
apiRoute(POST, '/api/note-map/link', linkMapRoute.getGlobalLinkMap);
|
apiRoute(POST, '/api/note-map/:noteId/link', linkMapRoute.getGlobalLinkMap);
|
||||||
|
|
||||||
apiRoute(GET, '/api/special-notes/inbox/:date', specialNotesRoute.getInboxNote);
|
apiRoute(GET, '/api/special-notes/inbox/:date', specialNotesRoute.getInboxNote);
|
||||||
apiRoute(GET, '/api/special-notes/date/:date', specialNotesRoute.getDateNote);
|
apiRoute(GET, '/api/special-notes/date/:date', specialNotesRoute.getDateNote);
|
||||||
|
@ -46,6 +46,7 @@ const BUILTIN_ATTRIBUTES = [
|
|||||||
{ type: 'label', name: 'datePattern' },
|
{ type: 'label', name: 'datePattern' },
|
||||||
{ type: 'label', name: 'pageSize' },
|
{ type: 'label', name: 'pageSize' },
|
||||||
{ type: 'label', name: 'viewType' },
|
{ type: 'label', name: 'viewType' },
|
||||||
|
{ type: 'label', name: 'mapRootNoteId' },
|
||||||
|
|
||||||
// relation names
|
// relation names
|
||||||
{ type: 'relation', name: 'runOnNoteCreation', isDangerous: true },
|
{ type: 'relation', name: 'runOnNoteCreation', isDangerous: true },
|
||||||
|
@ -81,20 +81,22 @@ function getSinglesNoteRoot() {
|
|||||||
return singlesNoteRoot;
|
return singlesNoteRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGlobalLinkMapNote() {
|
function getGlobalNoteMap() {
|
||||||
let globalLinkMapNote = becca.getNote('globalnotemap');
|
let globalNoteMap = becca.getNote('globalnotemap');
|
||||||
|
|
||||||
if (!globalLinkMapNote) {
|
if (!globalNoteMap) {
|
||||||
globalLinkMapNote = noteService.createNewNote({
|
globalNoteMap = noteService.createNewNote({
|
||||||
noteId: 'globalnotemap',
|
noteId: 'globalnotemap',
|
||||||
title: 'Global Note Map',
|
title: 'Global Note Map',
|
||||||
type: 'note-map',
|
type: 'note-map',
|
||||||
content: '',
|
content: '',
|
||||||
parentNoteId: getSinglesNoteRoot().noteId
|
parentNoteId: getSinglesNoteRoot().noteId
|
||||||
}).note;
|
}).note;
|
||||||
|
|
||||||
|
globalNoteMap.addLabel('mapRootNoteId', 'hoisted');
|
||||||
}
|
}
|
||||||
|
|
||||||
return globalLinkMapNote;
|
return globalNoteMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSqlConsoleRoot() {
|
function getSqlConsoleRoot() {
|
||||||
@ -186,7 +188,7 @@ function createMissingSpecialNotes() {
|
|||||||
getSqlConsoleRoot();
|
getSqlConsoleRoot();
|
||||||
getSinglesNoteRoot();
|
getSinglesNoteRoot();
|
||||||
getSinglesNoteRoot();
|
getSinglesNoteRoot();
|
||||||
getGlobalLinkMapNote();
|
getGlobalNoteMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user