introduction of refreshWithNote

This commit is contained in:
zadam 2020-01-19 11:37:24 +01:00
parent adb9ce5e93
commit 9f1e777e6d
16 changed files with 49 additions and 44 deletions

View File

@ -60,7 +60,7 @@ window.glob.noteChanged = noteDetailService.noteChanged;
window.glob.refreshTree = treeService.reload;
// required for ESLint plugin
window.glob.getActiveTabNote = appContext.getActiveTabNote;
window.glob.getActiveTabNote = () => appContext.getActiveTabNote();
window.glob.requireLibrary = libraryLoader.requireLibrary;
window.glob.ESLINT = libraryLoader.ESLINT;

View File

@ -23,7 +23,7 @@ class AttributesWidget extends StandardWidget {
return [$showFullButton];
}
async refresh() {
async refreshWithNote() {
const attributes = await this.tabContext.attributes.getAttributes();console.log("attributes", attributes);
const ownedAttributes = attributes.filter(attr => attr.noteId === this.tabContext.note.noteId);

View File

@ -17,6 +17,10 @@ class BasicWidget extends Component {
doRender() {}
toggle(show) {
if (!this.$widget) {
console.log(this.componentId);
}
this.$widget.toggle(show);
}

View File

@ -38,7 +38,7 @@ class CalendarWidget extends StandardWidget {
this.$body.html(TPL);
}
async refresh() {
async refreshWithNote() {
this.init(this.$body, await this.tabContext.note.getLabelValue("dateNote"));
}

View File

@ -19,7 +19,7 @@ class EditedNotesWidget extends StandardWidget {
&& await this.tabContext.note.hasLabel("dateNote");
}
async doRenderBody() {
async refreshWithNote() {
const note = this.tabContext.note;
// remember which title was when we found the similar notes
this.title = note.title;

View File

@ -28,7 +28,7 @@ class LinkMapWidget extends StandardWidget {
return [$showFullButton];
}
async refresh() {
async refreshWithNote() {
this.$body.css('opacity', 0);
this.$body.html(TPL);

View File

@ -31,7 +31,7 @@ class NoteInfoWidget extends StandardWidget {
this.$body.html(TPL);
}
refresh() {
refreshWithNote() {
const $noteId = this.$body.find(".note-info-note-id");
const $dateCreated = this.$body.find(".note-info-date-created");
const $dateModified = this.$body.find(".note-info-date-modified");

View File

@ -30,7 +30,7 @@ export default class NotePathsWidget extends TabAwareWidget {
return this.$widget;
}
async refresh() {
async refreshWithNote() {
const {note, notePath} = this.tabContext;
if (note.noteId === 'root') {

View File

@ -26,7 +26,7 @@ class NoteRevisionsWidget extends StandardWidget {
return [$showFullButton];
}
async refresh() {
async refreshWithNote() {
const note = this.tabContext.note;
const revisionItems = await server.get(`notes/${note.noteId}/revisions`);

View File

@ -130,17 +130,9 @@ export default class NoteTitleWidget extends TabAwareWidget {
return this.$widget;
}
async refresh() {
async refreshWithNote() {
const note = this.tabContext.note;
if (!note) {
this.toggle(false);
return;
}
else {
this.toggle(true);
}
this.$noteTitle.val(note.title);
if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) {

View File

@ -17,15 +17,14 @@ const NOTE_TYPES = [
];
const TPL = `
<style>
.note-type-dropdown {
max-height: 500px;
overflow-y: auto;
overflow-x: hidden;
}
</style>
<div class="dropdown note-type">
<style>
.note-type-dropdown {
max-height: 500px;
overflow-y: auto;
overflow-x: hidden;
}
</style>
<button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn btn-sm dropdown-toggle note-type-button">
Type: <span class="note-type-desc"></span>
<span class="caret"></span>
@ -36,20 +35,20 @@ const TPL = `
export default class NoteTypeWidget extends TabAwareWidget {
doRender() {
const $widget = $(TPL);
this.$widget = $(TPL);
$widget.on('show.bs.dropdown', () => this.renderDropdown());
this.$widget.on('show.bs.dropdown', () => this.renderDropdown());
this.$noteTypeDropdown = $widget.find(".note-type-dropdown");
this.$noteTypeButton = $widget.find(".note-type-button");
this.$noteTypeDesc = $widget.find(".note-type-desc");
this.$executeScriptButton = $widget.find(".execute-script-button");
this.$renderButton = $widget.find('.render-button');
this.$noteTypeDropdown = this.$widget.find(".note-type-dropdown");
this.$noteTypeButton = this.$widget.find(".note-type-button");
this.$noteTypeDesc = this.$widget.find(".note-type-desc");
this.$executeScriptButton = this.$widget.find(".execute-script-button");
this.$renderButton = this.$widget.find('.render-button');
return $widget;
return this.$widget;
}
async refresh() {
async refreshWithNote() {
this.$noteTypeButton.prop("disabled",
() => ["file", "image", "search"].includes(this.tabContext.note.type));

View File

@ -35,14 +35,9 @@ export default class PromotedAttributesWidget extends TabAwareWidget {
return this.$widget;
}
async refresh() {
async refreshWithNote() {
this.$container.empty();
if (!this.tabContext.note) {
this.toggle(false);
return;
}
const attributes = await this.tabContext.attributes.getAttributes();
const promoted = attributes.filter(attr =>

View File

@ -14,7 +14,7 @@ class SimilarNotesWidget extends StandardWidget {
getMaxHeight() { return "200px"; }
async refresh() {
async refreshWithNote() {
// remember which title was when we found the similar notes
this.title = this.tabContext.note.title;

View File

@ -18,12 +18,21 @@ export default class TabAwareWidget extends BasicWidget {
this.refresh();
}
// to override
activeTabChanged() {
this.refresh();
}
refresh() {}
refresh() {
if (this.tabContext && this.tabContext.note) {
this.toggle(true);
this.refreshWithNote();
}
else {
this.toggle(false);
}
}
refreshWithNote() {}
activeTabChangedListener() {
this.tabContext = this.appContext.getActiveTabContext();

View File

@ -35,4 +35,10 @@ export default class TabCachingWidget extends TabAwareWidget {
return false; // stop propagation to children
}
toggle(show) {
for (const tabId in this.widgets) {
this.widgets[tabId].toggle(show && this.tabContext && tabId === this.tabContext.tabId);
}
}
}

View File

@ -22,7 +22,7 @@ class WhatLinksHereWidget extends StandardWidget {
return [$showFullButton];
}
async refresh() {
async refreshWithNote() {
const targetRelations = await this.tabContext.note.getTargetRelations();
if (targetRelations.length === 0) {