small fixes

This commit is contained in:
zadam 2020-02-18 22:16:20 +01:00
parent d288c1b052
commit 2e3534dfb7
4 changed files with 23 additions and 6 deletions

View File

@ -36,7 +36,7 @@ const RELATION_DEFINITION = 'relation-definition';
class Note extends Entity { class Note extends Entity {
static get entityName() { return "notes"; } static get entityName() { return "notes"; }
static get primaryKeyName() { return "noteId"; } static get primaryKeyName() { return "noteId"; }
static get hashedProperties() { return ["noteId", "title", "type", "isProtected", "isDeleted", "deleteId"]; } static get hashedProperties() { return ["noteId", "title", "type", "mime", "isProtected", "isDeleted", "deleteId"]; }
/** /**
* @param row - object containing database row from "notes" table * @param row - object containing database row from "notes" table

View File

@ -101,6 +101,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
this.toggle(true); this.toggle(true);
this.type = await this.getWidgetType(); this.type = await this.getWidgetType();
this.mime = this.note.mime;
if (!(this.type in this.typeWidgets)) { if (!(this.type in this.typeWidgets)) {
const clazz = typeWidgetClasses[this.type]; const clazz = typeWidgetClasses[this.type];
@ -218,10 +219,12 @@ export default class NoteDetailWidget extends TabAwareWidget {
} }
async entitiesReloadedEvent({loadResults}) { async entitiesReloadedEvent({loadResults}) {
// we should test what happens when the loaded note is deleted // FIXME: we should test what happens when the loaded note is deleted
if (loadResults.isNoteContentReloaded(this.noteId, this.componentId)) { if (loadResults.isNoteContentReloaded(this.noteId, this.componentId)
this.refreshWithNote(this.note, this.notePath); || (loadResults.isNoteReloaded(this.noteId, this.componentId) && (this.type !== await this.getWidgetType() || this.mime !== this.note.mime))) {
this.handleEvent('noteTypeMimeChanged', {noteId: this.noteId});
} }
} }

View File

@ -118,6 +118,10 @@ export default class NoteTypeWidget extends TabAwareWidget {
} }
async save(type, mime) { async save(type, mime) {
if (type === this.note.type && mime === this.note.mime) {
return;
}
if (type !== this.note.type && !await this.confirmChangeIfContent()) { if (type !== this.note.type && !await this.confirmChangeIfContent()) {
return; return;
} }
@ -125,8 +129,6 @@ export default class NoteTypeWidget extends TabAwareWidget {
await server.put('notes/' + this.noteId await server.put('notes/' + this.noteId
+ '/type/' + encodeURIComponent(type) + '/type/' + encodeURIComponent(type)
+ '/mime/' + encodeURIComponent(mime)); + '/mime/' + encodeURIComponent(mime));
this.update();
} }
async confirmChangeIfContent() { async confirmChangeIfContent() {
@ -139,4 +141,10 @@ export default class NoteTypeWidget extends TabAwareWidget {
const confirmDialog = await import("../dialogs/confirm.js"); const confirmDialog = await import("../dialogs/confirm.js");
return await confirmDialog.confirm("It is not recommended to change note type when note content is not empty. Do you want to continue anyway?"); return await confirmDialog.confirm("It is not recommended to change note type when note content is not empty. Do you want to continue anyway?");
} }
async entitiesReloadedEvent({loadResults}) {
if (loadResults.isNoteReloaded(this.noteId, this.componentId)) {
this.refresh();
}
}
} }

View File

@ -36,6 +36,12 @@ export default class TabAwareWidget extends BasicWidget {
} }
} }
noteTypeMimeChangedEvent({noteId}) {
if (this.noteId === noteId) {
this.refresh();
}
}
noteSwitched() { noteSwitched() {
this.refresh(); this.refresh();
} }