note title widget and protected session entering fixes

This commit is contained in:
zadam 2020-05-03 22:49:20 +02:00
parent 647790885d
commit 8b5536ee3a
5 changed files with 30 additions and 25 deletions

View File

@ -31,6 +31,15 @@ function enterProtectedSession() {
return dfd.promise(); 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) { async function setupProtectedSession(password) {
const response = await enterProtectedSessionOnServer(password); const response = await enterProtectedSessionOnServer(password);
@ -42,7 +51,7 @@ async function setupProtectedSession(password) {
protectedSessionHolder.setProtectedSessionId(response.protectedSessionId); protectedSessionHolder.setProtectedSessionId(response.protectedSessionId);
protectedSessionHolder.touchProtectedSession(); protectedSessionHolder.touchProtectedSession();
await treeCache.loadInitialTree(); await reloadData();
await appContext.triggerEvent('treeCacheReloaded'); await appContext.triggerEvent('treeCacheReloaded');

View File

@ -20,6 +20,8 @@ class TreeCache {
async loadInitialTree() { async loadInitialTree() {
const resp = await server.get('tree'); 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 // clear the cache only directly before adding new content which is important for e.g. switching to protected session
/** @type {Object.<string, NoteShort>} */ /** @type {Object.<string, NoteShort>} */
@ -34,22 +36,22 @@ class TreeCache {
/** @type {Object.<string, Promise<NoteComplement>>} */ /** @type {Object.<string, Promise<NoteComplement>>} */
this.noteComplementPromises = {}; this.noteComplementPromises = {};
await this.loadParents(resp);
this.addResp(resp); this.addResp(resp);
} }
async loadParents(resp) { async loadParents(resp, additiveLoad) {
const noteIds = new Set(resp.notes.map(note => note.noteId)); const noteIds = new Set(resp.notes.map(note => note.noteId));
const missingNoteIds = []; const missingNoteIds = [];
const existingNotes = additiveLoad ? this.notes : {};
for (const branch of resp.branches) { 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); missingNoteIds.push(branch.parentNoteId);
} }
} }
for (const attr of resp.attributes) { 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); missingNoteIds.push(attr.value);
} }
} }
@ -61,7 +63,7 @@ class TreeCache {
resp.branches = resp.branches.concat(newResp.branches); resp.branches = resp.branches.concat(newResp.branches);
resp.attributes = resp.attributes.concat(newResp.attributes); 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 }); const resp = await server.post('tree/load', { noteIds });
await this.loadParents(resp); await this.loadParents(resp, true);
this.addResp(resp); this.addResp(resp);
for (const note of resp.notes) { for (const note of resp.notes) {

View File

@ -57,6 +57,10 @@ export default class NoteTitleWidget extends TabAwareWidget {
this.$noteTitle.prop("readonly", note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()); this.$noteTitle.prop("readonly", note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable());
this.setProtectedStatus(note);
}
setProtectedStatus(note) {
this.$noteTitle.toggleClass("protected", !!note.isProtected); this.$noteTitle.toggleClass("protected", !!note.isProtected);
} }
@ -88,7 +92,8 @@ export default class NoteTitleWidget extends TabAwareWidget {
entitiesReloadedEvent({loadResults}) { entitiesReloadedEvent({loadResults}) {
if (loadResults.isNoteReloaded(this.noteId)) { 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);
} }
} }

View File

@ -486,7 +486,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
return true; return true;
} }
else { else {
const childBranches = await this.getChildBranches(note); const childBranches = this.getChildBranches(note);
return childBranches.length > 0; return childBranches.length > 0;
} }
@ -497,7 +497,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
const noteList = []; const noteList = [];
for (const branch of await this.getChildBranches(parentNote)) { for (const branch of this.getChildBranches(parentNote)) {
const node = await this.prepareNode(branch); const node = await this.prepareNode(branch);
noteList.push(node); noteList.push(node);
@ -506,7 +506,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
return noteList; return noteList;
} }
async getChildBranches(parentNote) { getChildBranches(parentNote) {
let childBranches = parentNote.getChildBranches(); let childBranches = parentNote.getChildBranches();
if (!childBranches) { if (!childBranches) {
@ -521,20 +521,6 @@ export default class NoteTreeWidget extends TabAwareWidget {
childBranches = childBranches.filter(branch => !imageLinks.find(rel => rel.value === branch.noteId)); 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; return childBranches;
} }

View File

@ -617,6 +617,9 @@ class ConsistencyChecks {
await this.findSyncRowsIssues(); await this.findSyncRowsIssues();
// root branch should always be expanded
await sql.execute("UPDATE branches SET isExpanded = 1 WHERE branchId = 'root'");
if (this.unrecoveredConsistencyErrors) { if (this.unrecoveredConsistencyErrors) {
// we run this only if basic checks passed since this assumes basic data consistency // we run this only if basic checks passed since this assumes basic data consistency