mirror of
https://github.com/zadam/trilium.git
synced 2024-09-21 16:16:04 +08:00
note title widget and protected session entering fixes
This commit is contained in:
parent
647790885d
commit
8b5536ee3a
|
@ -31,6 +31,15 @@ function enterProtectedSession() {
|
|||
return dfd.promise();
|
||||
}
|
||||
|
||||
async function reloadData() {
|
||||
const allNoteIds = Object.keys(treeCache.notes);
|
||||
|
||||
await treeCache.loadInitialTree();
|
||||
|
||||
// make sure that all notes used in the application are loaded, including the ones not shown in the tree
|
||||
await treeCache.reloadNotes(allNoteIds, true);
|
||||
}
|
||||
|
||||
async function setupProtectedSession(password) {
|
||||
const response = await enterProtectedSessionOnServer(password);
|
||||
|
||||
|
@ -42,7 +51,7 @@ async function setupProtectedSession(password) {
|
|||
protectedSessionHolder.setProtectedSessionId(response.protectedSessionId);
|
||||
protectedSessionHolder.touchProtectedSession();
|
||||
|
||||
await treeCache.loadInitialTree();
|
||||
await reloadData();
|
||||
|
||||
await appContext.triggerEvent('treeCacheReloaded');
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ class TreeCache {
|
|||
async loadInitialTree() {
|
||||
const resp = await server.get('tree');
|
||||
|
||||
await this.loadParents(resp, false);
|
||||
|
||||
// clear the cache only directly before adding new content which is important for e.g. switching to protected session
|
||||
|
||||
/** @type {Object.<string, NoteShort>} */
|
||||
|
@ -34,22 +36,22 @@ class TreeCache {
|
|||
/** @type {Object.<string, Promise<NoteComplement>>} */
|
||||
this.noteComplementPromises = {};
|
||||
|
||||
await this.loadParents(resp);
|
||||
this.addResp(resp);
|
||||
}
|
||||
|
||||
async loadParents(resp) {
|
||||
async loadParents(resp, additiveLoad) {
|
||||
const noteIds = new Set(resp.notes.map(note => note.noteId));
|
||||
const missingNoteIds = [];
|
||||
const existingNotes = additiveLoad ? this.notes : {};
|
||||
|
||||
for (const branch of resp.branches) {
|
||||
if (!(branch.parentNoteId in this.notes) && !noteIds.has(branch.parentNoteId) && branch.parentNoteId !== 'none') {
|
||||
if (!(branch.parentNoteId in existingNotes) && !noteIds.has(branch.parentNoteId) && branch.parentNoteId !== 'none') {
|
||||
missingNoteIds.push(branch.parentNoteId);
|
||||
}
|
||||
}
|
||||
|
||||
for (const attr of resp.attributes) {
|
||||
if (attr.type === 'relation' && attr.name === 'template' && !(attr.value in this.notes) && !noteIds.has(attr.value)) {
|
||||
if (attr.type === 'relation' && attr.name === 'template' && !(attr.value in existingNotes) && !noteIds.has(attr.value)) {
|
||||
missingNoteIds.push(attr.value);
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +63,7 @@ class TreeCache {
|
|||
resp.branches = resp.branches.concat(newResp.branches);
|
||||
resp.attributes = resp.attributes.concat(newResp.attributes);
|
||||
|
||||
await this.loadParents(resp);
|
||||
await this.loadParents(resp, additiveLoad);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +156,7 @@ class TreeCache {
|
|||
|
||||
const resp = await server.post('tree/load', { noteIds });
|
||||
|
||||
await this.loadParents(resp);
|
||||
await this.loadParents(resp, true);
|
||||
this.addResp(resp);
|
||||
|
||||
for (const note of resp.notes) {
|
||||
|
|
|
@ -57,6 +57,10 @@ export default class NoteTitleWidget extends TabAwareWidget {
|
|||
|
||||
this.$noteTitle.prop("readonly", note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable());
|
||||
|
||||
this.setProtectedStatus(note);
|
||||
}
|
||||
|
||||
setProtectedStatus(note) {
|
||||
this.$noteTitle.toggleClass("protected", !!note.isProtected);
|
||||
}
|
||||
|
||||
|
@ -88,7 +92,8 @@ export default class NoteTitleWidget extends TabAwareWidget {
|
|||
|
||||
entitiesReloadedEvent({loadResults}) {
|
||||
if (loadResults.isNoteReloaded(this.noteId)) {
|
||||
this.refresh();
|
||||
// not updating the title specifically since the synced title might be older than what the user is currently typing
|
||||
this.setProtectedStatus(this.note);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -486,7 +486,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
return true;
|
||||
}
|
||||
else {
|
||||
const childBranches = await this.getChildBranches(note);
|
||||
const childBranches = this.getChildBranches(note);
|
||||
|
||||
return childBranches.length > 0;
|
||||
}
|
||||
|
@ -497,7 +497,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
|
||||
const noteList = [];
|
||||
|
||||
for (const branch of await this.getChildBranches(parentNote)) {
|
||||
for (const branch of this.getChildBranches(parentNote)) {
|
||||
const node = await this.prepareNode(branch);
|
||||
|
||||
noteList.push(node);
|
||||
|
@ -506,7 +506,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
return noteList;
|
||||
}
|
||||
|
||||
async getChildBranches(parentNote) {
|
||||
getChildBranches(parentNote) {
|
||||
let childBranches = parentNote.getChildBranches();
|
||||
|
||||
if (!childBranches) {
|
||||
|
@ -521,20 +521,6 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
childBranches = childBranches.filter(branch => !imageLinks.find(rel => rel.value === branch.noteId));
|
||||
}
|
||||
|
||||
if (this.hideArchivedNotes) {
|
||||
const filteredBranches = [];
|
||||
|
||||
for (const childBranch of childBranches) {
|
||||
const childNote = await childBranch.getNote();
|
||||
|
||||
if (!childNote.hasLabel('archived')) {
|
||||
filteredBranches.push(childBranch);
|
||||
}
|
||||
}
|
||||
|
||||
childBranches = filteredBranches;
|
||||
}
|
||||
|
||||
return childBranches;
|
||||
}
|
||||
|
||||
|
|
|
@ -617,6 +617,9 @@ class ConsistencyChecks {
|
|||
|
||||
await this.findSyncRowsIssues();
|
||||
|
||||
// root branch should always be expanded
|
||||
await sql.execute("UPDATE branches SET isExpanded = 1 WHERE branchId = 'root'");
|
||||
|
||||
if (this.unrecoveredConsistencyErrors) {
|
||||
// we run this only if basic checks passed since this assumes basic data consistency
|
||||
|
||||
|
|
Loading…
Reference in a new issue