mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
wip
This commit is contained in:
parent
9301679707
commit
368d3b1b97
12
package-lock.json
generated
12
package-lock.json
generated
@ -8875,17 +8875,17 @@
|
||||
"integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw=="
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.0.tgz",
|
||||
"integrity": "sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==",
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.1.tgz",
|
||||
"integrity": "sha512-IQ4ikL8SjBiEDZfk+DFVwqRK8md24RWMEJkdSlgNLkyyAImcjf8SWvU1qFMDOb4igBClbTQ/ugPqXcRwdFTxZw==",
|
||||
"requires": {
|
||||
"glob": "^7.1.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"glob": {
|
||||
"version": "7.1.4",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz",
|
||||
"integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==",
|
||||
"version": "7.1.6",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
|
||||
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
|
||||
"requires": {
|
||||
"fs.realpath": "^1.0.0",
|
||||
"inflight": "^1.0.4",
|
||||
|
@ -59,7 +59,7 @@
|
||||
"portscanner": "2.2.0",
|
||||
"rand-token": "0.4.0",
|
||||
"rcedit": "2.1.0",
|
||||
"rimraf": "3.0.0",
|
||||
"rimraf": "3.0.1",
|
||||
"sanitize-filename": "1.6.3",
|
||||
"sax": "1.2.4",
|
||||
"semver": "7.1.1",
|
||||
|
@ -138,7 +138,6 @@ class AppContext {
|
||||
|
||||
tabNoteSwitchedListener({tabId}) {
|
||||
if (tabId === this.activeTabId) {
|
||||
this._setTitleBar();
|
||||
this._setCurrentNotePathToHash();
|
||||
}
|
||||
}
|
||||
@ -151,23 +150,6 @@ class AppContext {
|
||||
}
|
||||
}
|
||||
|
||||
noteTitleChangedListener() {
|
||||
this._setTitleBar();
|
||||
}
|
||||
|
||||
async _setTitleBar() {
|
||||
document.title = "Trilium Notes";
|
||||
|
||||
const activeTabContext = this.getActiveTabContext();
|
||||
|
||||
if (activeTabContext && activeTabContext.notePath) {
|
||||
const note = await treeCache.getNote(treeService.getNoteIdFromNotePath(activeTabContext.notePath));
|
||||
|
||||
// it helps navigating in history if note title is included in the title
|
||||
document.title += " - " + note.title;
|
||||
}
|
||||
}
|
||||
|
||||
/** @return {TabContext[]} */
|
||||
getTabContexts() {
|
||||
return this.tabContexts;
|
||||
|
@ -8,21 +8,21 @@ async function getTodayNote() {
|
||||
|
||||
/** @return {NoteShort} */
|
||||
async function getDateNote(date) {
|
||||
const note = await server.get('date-notes/date/' + date, {'trilium-source-id': "date-note"});
|
||||
const note = await server.get('date-notes/date/' + date, "date-note");
|
||||
|
||||
return await treeCache.getNote(note.noteId);
|
||||
}
|
||||
|
||||
/** @return {NoteShort} */
|
||||
async function getMonthNote(month) {
|
||||
const note = await server.get('date-notes/month/' + month, {'trilium-source-id': "date-note"});
|
||||
const note = await server.get('date-notes/month/' + month, "date-note");
|
||||
|
||||
return await treeCache.getNote(note.noteId);
|
||||
}
|
||||
|
||||
/** @return {NoteShort} */
|
||||
async function getYearNote(year) {
|
||||
const note = await server.get('date-notes/year/' + year, {'trilium-source-id': "date-note"});
|
||||
const note = await server.get('date-notes/year/' + year, "date-note");
|
||||
|
||||
return await treeCache.getNote(note.noteId);
|
||||
}
|
||||
|
@ -145,9 +145,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
|
||||
currentNoteId: currentNote.noteId,
|
||||
originEntityName: "notes", // currently there's no other entity on frontend which can trigger event
|
||||
originEntityId: originEntity ? originEntity.noteId : null
|
||||
}, {
|
||||
'trilium-source-id': "script"
|
||||
});
|
||||
}, "script");
|
||||
|
||||
if (ret.success) {
|
||||
// wait until all the changes done in the script has been synced to frontend before continuing
|
||||
|
@ -4,7 +4,7 @@ export class LoadResults {
|
||||
this.sourceIdToNoteIds = {};
|
||||
}
|
||||
|
||||
add(noteId, sourceId) {
|
||||
addNote(noteId, sourceId) {
|
||||
this.noteIdToSync[noteId] = this.noteIdToSync[noteId] || [];
|
||||
|
||||
if (!this.noteIdToSync[noteId].includes(sourceId)) {
|
||||
@ -23,6 +23,10 @@ export class LoadResults {
|
||||
}
|
||||
|
||||
isNoteReloaded(noteId, sourceId) {
|
||||
if (!noteId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const sourceIds = this.noteIdToSync[noteId];
|
||||
return sourceIds && !!sourceIds.find(sId => sId !== sourceId);
|
||||
}
|
||||
|
@ -8,13 +8,16 @@ function getHeaders(headers) {
|
||||
// so hypothetical protectedSessionId becomes protectedsessionid on the backend
|
||||
// also avoiding using underscores instead of dashes since nginx filters them out by default
|
||||
const allHeaders = {
|
||||
...{
|
||||
'trilium-source-id': glob.sourceId,
|
||||
'x-csrf-token': glob.csrfToken
|
||||
},
|
||||
...headers
|
||||
};
|
||||
|
||||
for (const headerName in headers) {
|
||||
if (headers[headerName]) {
|
||||
allHeaders[headerName] = headers[headerName];
|
||||
}
|
||||
}
|
||||
|
||||
if (utils.isElectron()) {
|
||||
// passing it explicitely here because of the electron HTTP bypass
|
||||
allHeaders.cookie = document.cookie;
|
||||
@ -23,20 +26,20 @@ function getHeaders(headers) {
|
||||
return allHeaders;
|
||||
}
|
||||
|
||||
async function get(url, headers = {}) {
|
||||
return await call('GET', url, null, headers);
|
||||
async function get(url, sourceId) {
|
||||
return await call('GET', url, null, {'trilium-source-id': sourceId});
|
||||
}
|
||||
|
||||
async function post(url, data, headers = {}) {
|
||||
return await call('POST', url, data, headers);
|
||||
async function post(url, data, sourceId) {
|
||||
return await call('POST', url, data, {'trilium-source-id': sourceId});
|
||||
}
|
||||
|
||||
async function put(url, data, headers = {}) {
|
||||
return await call('PUT', url, data, headers);
|
||||
async function put(url, data, sourceId) {
|
||||
return await call('PUT', url, data, {'trilium-source-id': sourceId});
|
||||
}
|
||||
|
||||
async function remove(url, headers = {}) {
|
||||
return await call('DELETE', url, null, headers);
|
||||
async function remove(url, sourceId) {
|
||||
return await call('DELETE', url, null, {'trilium-source-id': sourceId});
|
||||
}
|
||||
|
||||
let i = 1;
|
||||
|
@ -112,6 +112,20 @@ class TabContext extends Component {
|
||||
this.trigger('tabNoteSwitched', {tabId: this.tabId});
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME
|
||||
async _setTitleBar() {
|
||||
document.title = "Trilium Notes";
|
||||
|
||||
const activeTabContext = this.getActiveTabContext();
|
||||
|
||||
if (activeTabContext && activeTabContext.notePath) {
|
||||
const note = await treeCache.getNote(treeService.getNoteIdFromNotePath(activeTabContext.notePath));
|
||||
|
||||
// it helps navigating in history if note title is included in the title
|
||||
document.title += " - " + note.title;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default TabContext;
|
@ -235,20 +235,20 @@ class TreeCache {
|
||||
const branch = this.branches[sync.entityId];
|
||||
// we assume that the cache contains the old branch state and we add also the old parentNoteId
|
||||
// so that the old parent can also be updated
|
||||
loadResults.add(branch.parentNoteId, sync.sourceId);
|
||||
loadResults.addNote(branch.parentNoteId, sync.sourceId);
|
||||
|
||||
// this should then contain new parentNoteId for which we should also update the cache
|
||||
loadResults.add(sync.parentNoteId, sync.sourceId);
|
||||
loadResults.addNote(sync.parentNoteId, sync.sourceId);
|
||||
|
||||
loadResults.add(sync.noteId, sync.sourceId);
|
||||
loadResults.addNote(sync.noteId, sync.sourceId);
|
||||
});
|
||||
|
||||
syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => loadResults.add(sync.entityId, sync.sourceId));
|
||||
syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => loadResults.addNote(sync.entityId, sync.sourceId));
|
||||
|
||||
syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => loadResults.add(sync.entityId, sync.sourceId));
|
||||
syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => loadResults.addNote(sync.entityId, sync.sourceId));
|
||||
|
||||
// missing reloading the relation target note
|
||||
syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => loadResults.add(sync.noteId, sync.sourceId));
|
||||
syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => loadResults.addNote(sync.noteId, sync.sourceId));
|
||||
|
||||
await this.reloadNotes(loadResults.getNoteIds());
|
||||
|
||||
|
@ -43,7 +43,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
const dto = note.dto;
|
||||
dto.content = noteFull.content = this.getTypeWidget().getContent();
|
||||
|
||||
const resp = await server.put('notes/' + noteId, dto);
|
||||
const resp = await server.put('notes/' + noteId, dto, this.componentId);
|
||||
|
||||
// FIXME: minor - does not propagate to other tab contexts with this note though
|
||||
noteFull.dateModified = resp.dateModified;
|
||||
@ -220,9 +220,9 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
notesReloadedListener({loadResults}) {
|
||||
if (loadResults.isNoteReloaded(this.noteId, this.componentId)) {
|
||||
this.refresh();
|
||||
}
|
||||
notesReloadedListener(data) {
|
||||
super.notesReloadedListener(data);
|
||||
|
||||
return false; // stop propagation to children
|
||||
}
|
||||
}
|
@ -69,10 +69,8 @@ class NoteInfoWidget extends StandardWidget {
|
||||
|
||||
// this is interesting for this widget since dateModified had to change after update
|
||||
noteChangesSavedListener({noteId}) {
|
||||
const note = this.tabContext.note;
|
||||
|
||||
if (note && note.noteId === noteId) {
|
||||
this.refreshWithNote(note);
|
||||
if (this.isNote(noteId)) {
|
||||
this.refreshWithNote(this.note, this.notePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,17 +78,6 @@ export default class NoteTitleWidget extends TabAwareWidget {
|
||||
});
|
||||
}
|
||||
|
||||
noteTitleChangedListener({tabId, title, noteId}) {
|
||||
if (tabId === this.tabContext.tabId
|
||||
|| !this.tabContext.note
|
||||
|| this.tabContext.note.noteId !== noteId) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.$noteTitle.val(title);
|
||||
}
|
||||
|
||||
async refreshWithNote(note) {
|
||||
this.$noteTitle.val(note.title);
|
||||
|
||||
|
@ -427,16 +427,11 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
}
|
||||
}
|
||||
|
||||
async notesReloadedListener({ noteIds, activateNotePath }) {
|
||||
if (!activateNotePath) {
|
||||
async notesReloadedListener({loadResults}) {
|
||||
const activeNode = this.getActiveNode();
|
||||
const activateNotePath = activeNode ? await treeService.getNotePath(activeNode) : null;
|
||||
|
||||
if (activeNode) {
|
||||
activateNotePath = await treeService.getNotePath(activeNode);
|
||||
}
|
||||
}
|
||||
|
||||
for (const noteId of noteIds) {
|
||||
for (const noteId of loadResults.getNoteIds()) {
|
||||
for (const node of this.getNodesByNoteId(noteId)) {
|
||||
const branch = treeCache.getBranch(node.data.branchId, true);
|
||||
|
||||
@ -460,12 +455,6 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
}
|
||||
}
|
||||
|
||||
noteTitleChangedListener({noteId}) {
|
||||
for (const node of this.getNodesByNoteId(noteId)) {
|
||||
treeService.setNodeTitleWithPrefix(node);
|
||||
}
|
||||
}
|
||||
|
||||
async createNoteAfterListener() {
|
||||
const node = this.getActiveNode();
|
||||
const parentNoteId = node.data.parentNoteId;
|
||||
|
@ -24,6 +24,10 @@ export default class TabAwareWidget extends BasicWidget {
|
||||
return this.note && this.note.noteId;
|
||||
}
|
||||
|
||||
get notePath() {
|
||||
return this.tabContext && this.tabContext.notePath;
|
||||
}
|
||||
|
||||
tabNoteSwitchedListener({tabId}) {
|
||||
if (this.isTab(tabId)) {
|
||||
this.noteSwitched();
|
||||
@ -39,20 +43,26 @@ export default class TabAwareWidget extends BasicWidget {
|
||||
}
|
||||
|
||||
refresh() {
|
||||
if (this.tabContext && this.tabContext.note) {
|
||||
if (this.note) {
|
||||
this.toggle(true);
|
||||
this.refreshWithNote(this.tabContext.note, this.tabContext.notePath);
|
||||
this.refreshWithNote(this.note, this.notePath);
|
||||
}
|
||||
else {
|
||||
this.toggle(false);
|
||||
}
|
||||
}
|
||||
|
||||
refreshWithNote(note) {}
|
||||
refreshWithNote(note, notePath) {}
|
||||
|
||||
activeTabChangedListener() {
|
||||
this.tabContext = this.appContext.getActiveTabContext();
|
||||
|
||||
this.activeTabChanged();
|
||||
}
|
||||
|
||||
notesReloadedListener({loadResults}) {
|
||||
if (loadResults.isNoteReloaded(this.noteId, this.componentId)) {
|
||||
this.refreshWithNote(this.note, this.notePath);
|
||||
}
|
||||
}
|
||||
}
|
@ -498,13 +498,6 @@ export default class TabRowWidget extends BasicWidget {
|
||||
return this.$widget.find(`[data-tab-id='${tabId}']`);
|
||||
}
|
||||
|
||||
noteTitleChangedListener({title, noteId}) {
|
||||
this.appContext.getTabContexts()
|
||||
.filter(tc => tc.note && tc.note.noteId === noteId)
|
||||
.map(tc => this.getTabById(tc.tabId))
|
||||
.forEach($el => $el.find('.note-tab-title').text(title));
|
||||
}
|
||||
|
||||
tabRemovedListener({tabId}) {
|
||||
this.removeTab(tabId);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user