From 7b0aa7ab0b4867cc6c05e031a54101efa48e11f5 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 18 Jun 2020 23:53:57 +0200 Subject: [PATCH] parser status indication --- src/public/app/widgets/note_attributes.js | 58 +++++++++++++------ src/public/app/widgets/note_title.js | 2 +- src/public/app/widgets/promoted_attributes.js | 2 +- .../app/widgets/type_widgets/editable_code.js | 8 +-- .../app/widgets/type_widgets/editable_text.js | 2 +- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/public/app/widgets/note_attributes.js b/src/public/app/widgets/note_attributes.js index c71e4daf4..2cf49c9c4 100644 --- a/src/public/app/widgets/note_attributes.js +++ b/src/public/app/widgets/note_attributes.js @@ -3,7 +3,6 @@ import libraryLoader from "../services/library_loader.js"; import noteAutocompleteService from "../services/note_autocomplete.js"; import treeCache from "../services/tree_cache.js"; import server from "../services/server.js"; -import utils from "../services/utils.js"; import ws from "../services/ws.js"; import SpacedUpdate from "../services/spaced_update.js"; import attributesParser from "../services/attribute_parser.js"; @@ -81,6 +80,10 @@ const TPL = ` margin-bottom: 5px !important; } +.note-attributes.error .note-attributes-editor { + border-color: red !important; +} + .attr-extras { display: block; background-color: var(--accented-background-color); @@ -109,7 +112,7 @@ const TPL = `
-
+
`; @@ -119,10 +122,8 @@ export default class NoteAttributesWidget extends TabAwareWidget { constructor() { super(); - this.spacedUpdate = new SpacedUpdate(async () => { - const content = this.textEditor.getData(); - - this.parse(content); + this.spacedUpdate = new SpacedUpdate(() => { + this.parseAttributes(); this.$attrExtras.hide(); }); @@ -141,19 +142,46 @@ export default class NoteAttributesWidget extends TabAwareWidget { const keycode = (e.keyCode ? e.keyCode : e.which); if (keycode === 13) { - const attributes = attributesParser.lexAndParse(this.textEditor.getData()); + this.triggerCommand('focusOnDetail', {tabId: this.tabContext.tabId}); - await server.put(`notes/${this.noteId}/attributes2`, attributes, this.componentId); + await this.save(); } this.$attrExtras.hide(); }); - this.$editor.on('blur', () => this.$attrExtras.hide()); + this.$editor.on('blur', () => { + this.save(); + + this.$attrExtras.hide(); + }); return this.$widget; } + async save() { + const attributes = this.parseAttributes(); + + if (attributes) { + await server.put(`notes/${this.noteId}/attributes2`, attributes, this.componentId); + } + } + + parseAttributes() { + try { + const attrs = attributesParser.lexAndParse(this.textEditor.getData()); + + this.$widget.removeClass("error"); + this.$widget.removeAttr("title"); + + return attrs; + } + catch (e) { + this.$widget.attr("title", e.message); + this.$widget.addClass("error"); + } + } + async initEditor() { await libraryLoader.requireLibrary(libraryLoader.CKEDITOR); @@ -413,15 +441,9 @@ export default class NoteAttributesWidget extends TabAwareWidget { return searchStr; } - parse(content) { - if (content.startsWith('

')) { - content = content.substr(3); + async focusOnAttributesEvent({tabId}) { + if (this.tabContext.tabId === tabId) { + this.$editor.trigger('focus'); } - - if (content.endsWith('

')) { - content = content.substr(0, content - 4); - } - - console.log(content); } } diff --git a/src/public/app/widgets/note_title.js b/src/public/app/widgets/note_title.js index 010e074c6..ae5ac4202 100644 --- a/src/public/app/widgets/note_title.js +++ b/src/public/app/widgets/note_title.js @@ -23,7 +23,7 @@ const TPL = ` } - + `; export default class NoteTitleWidget extends TabAwareWidget { diff --git a/src/public/app/widgets/promoted_attributes.js b/src/public/app/widgets/promoted_attributes.js index 448fbb5a1..f5e496ebc 100644 --- a/src/public/app/widgets/promoted_attributes.js +++ b/src/public/app/widgets/promoted_attributes.js @@ -98,7 +98,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget { const $tr = $(""); const $labelCell = $("").append(valueAttr.name); const $input = $("") - .prop("tabindex", definitionAttr.position) + .prop("tabindex", 200 + definitionAttr.position) .prop("attribute-id", valueAttr.noteId === this.noteId ? valueAttr.attributeId : '') // if not owned, we'll force creation of a new attribute instead of updating the inherited one .prop("attribute-type", valueAttr.type) .prop("attribute-name", valueAttr.name) diff --git a/src/public/app/widgets/type_widgets/editable_code.js b/src/public/app/widgets/type_widgets/editable_code.js index 8bedc1ac7..b3d7efd4b 100644 --- a/src/public/app/widgets/type_widgets/editable_code.js +++ b/src/public/app/widgets/type_widgets/editable_code.js @@ -88,7 +88,7 @@ export default class EditableCodeTypeWidget extends TypeWidget { async initEditor() { await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR); - + CodeMirror.keyMap.default["Shift-Tab"] = "indentLess"; CodeMirror.keyMap.default["Tab"] = "indentMore"; @@ -108,7 +108,7 @@ export default class EditableCodeTypeWidget extends TypeWidget { lint: true, gutters: ["CodeMirror-lint-markers"], lineNumbers: true, - tabindex: 100, + tabindex: 300, // we linewrap partly also because without it horizontal scrollbar displays only when you scroll // all the way to the bottom of the note. With line wrap there's no horizontal scrollbar so no problem lineWrapping: true, @@ -117,7 +117,7 @@ export default class EditableCodeTypeWidget extends TypeWidget { this.codeEditor.on('change', () => this.spacedUpdate.scheduleUpdate()); } - + async doRefresh(note) { const noteComplement = await this.tabContext.getNoteComplement(); @@ -255,4 +255,4 @@ export default class EditableCodeTypeWidget extends TypeWidget { }); } } -} \ No newline at end of file +} diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js index d7923cc66..e413b8e2c 100644 --- a/src/public/app/widgets/type_widgets/editable_text.js +++ b/src/public/app/widgets/type_widgets/editable_text.js @@ -72,7 +72,7 @@ const TPL = ` } -
+
`;