diff --git a/src/entities/api_token.js b/src/entities/api_token.js index 7275bec79..90c5374b5 100644 --- a/src/entities/api_token.js +++ b/src/entities/api_token.js @@ -9,8 +9,6 @@ class ApiToken extends Entity { static get hashedProperties() { return ["apiTokenId", "token", "dateCreated", "isDeleted"]; } beforeSaving() { - super.beforeSaving(); - if (!this.isDeleted) { this.isDeleted = false; } @@ -18,6 +16,8 @@ class ApiToken extends Entity { if (!this.dateCreated) { this.dateCreated = dateUtils.nowDate(); } + + super.beforeSaving(); } } diff --git a/src/entities/attribute.js b/src/entities/attribute.js index b4ce46fc6..ae9a99e33 100644 --- a/src/entities/attribute.js +++ b/src/entities/attribute.js @@ -10,13 +10,24 @@ class Attribute extends Entity { static get primaryKeyName() { return "attributeId"; } static get hashedProperties() { return ["attributeId", "noteId", "type", "name", "value", "isInheritable", "dateModified", "dateCreated"]; } + constructor(row) { + super(row); + + try { + this.value = JSON.parse(this.value); + } + catch(e) {} + } + async getNote() { return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]); } - async beforeSaving() { - super.beforeSaving(); + isDefinition() { + return this.type === 'label' || this.type === 'relation'; + } + async beforeSaving() { if (!this.value) { // null value isn't allowed this.value = ""; @@ -39,6 +50,8 @@ class Attribute extends Entity { } this.dateModified = dateUtils.nowDate(); + + super.beforeSaving(); } } diff --git a/src/entities/branch.js b/src/entities/branch.js index 36d237df1..5e04eeb7e 100644 --- a/src/entities/branch.js +++ b/src/entities/branch.js @@ -16,8 +16,6 @@ class Branch extends Entity { } async beforeSaving() { - super.beforeSaving(); - if (this.notePosition === undefined) { const maxNotePos = await sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [this.parentNoteId]); this.notePosition = maxNotePos === null ? 0 : maxNotePos + 1; @@ -32,6 +30,8 @@ class Branch extends Entity { } this.dateModified = dateUtils.nowDate(); + + super.beforeSaving(); } } diff --git a/src/entities/image.js b/src/entities/image.js index a59adad3a..8470bb976 100644 --- a/src/entities/image.js +++ b/src/entities/image.js @@ -9,8 +9,6 @@ class Image extends Entity { static get hashedProperties() { return ["imageId", "format", "checksum", "name", "isDeleted", "dateModified", "dateCreated"]; } beforeSaving() { - super.beforeSaving(); - if (!this.isDeleted) { this.isDeleted = false; } @@ -20,6 +18,8 @@ class Image extends Entity { } this.dateModified = dateUtils.nowDate(); + + super.beforeSaving(); } } diff --git a/src/entities/label.js b/src/entities/label.js index 2270dfac3..fd10b3859 100644 --- a/src/entities/label.js +++ b/src/entities/label.js @@ -15,8 +15,6 @@ class Label extends Entity { } async beforeSaving() { - super.beforeSaving(); - if (!this.value) { // null value isn't allowed this.value = ""; @@ -35,6 +33,8 @@ class Label extends Entity { } this.dateModified = dateUtils.nowDate(); + + super.beforeSaving(); } } diff --git a/src/entities/note_image.js b/src/entities/note_image.js index 45cc880a3..0dac7aa27 100644 --- a/src/entities/note_image.js +++ b/src/entities/note_image.js @@ -18,8 +18,6 @@ class NoteImage extends Entity { } beforeSaving() { - super.beforeSaving(); - if (!this.isDeleted) { this.isDeleted = false; } @@ -29,6 +27,8 @@ class NoteImage extends Entity { } this.dateModified = dateUtils.nowDate(); + + super.beforeSaving(); } } diff --git a/src/entities/note_revision.js b/src/entities/note_revision.js index 546f1a0ac..462d6176b 100644 --- a/src/entities/note_revision.js +++ b/src/entities/note_revision.js @@ -22,11 +22,11 @@ class NoteRevision extends Entity { } beforeSaving() { - super.beforeSaving(); - if (this.isProtected) { protectedSessionService.encryptNoteRevision(this); } + + super.beforeSaving(); } } diff --git a/src/entities/option.js b/src/entities/option.js index 9bd3ebf06..f4ed9d1f9 100644 --- a/src/entities/option.js +++ b/src/entities/option.js @@ -9,9 +9,9 @@ class Option extends Entity { static get hashedProperties() { return ["name", "value"]; } beforeSaving() { - super.beforeSaving(); - this.dateModified = dateUtils.nowDate(); + + super.beforeSaving(); } } diff --git a/src/entities/recent_note.js b/src/entities/recent_note.js index 42f6a343a..3f71e6545 100644 --- a/src/entities/recent_note.js +++ b/src/entities/recent_note.js @@ -9,8 +9,6 @@ class RecentNote extends Entity { static get hashedProperties() { return ["branchId", "notePath", "dateCreated", "isDeleted"]; } beforeSaving() { - super.beforeSaving(); - if (!this.isDeleted) { this.isDeleted = false; } @@ -18,6 +16,8 @@ class RecentNote extends Entity { if (!this.dateCreated) { this.dateCreated = dateUtils.nowDate(); } + + super.beforeSaving(); } } diff --git a/src/entities/relation.js b/src/entities/relation.js index 1c98fcd60..76e938c61 100644 --- a/src/entities/relation.js +++ b/src/entities/relation.js @@ -19,8 +19,6 @@ class Relation extends Entity { } async beforeSaving() { - super.beforeSaving(); - if (this.position === undefined) { this.position = 1 + await sql.getValue(`SELECT COALESCE(MAX(position), 0) FROM relations WHERE sourceNoteId = ?`, [this.sourceNoteId]); } @@ -38,6 +36,8 @@ class Relation extends Entity { } this.dateModified = dateUtils.nowDate(); + + super.beforeSaving(); } } diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js index 24597a7d5..8bc6d8583 100644 --- a/src/public/javascripts/dialogs/attributes.js +++ b/src/public/javascripts/dialogs/attributes.js @@ -22,10 +22,10 @@ function AttributesModel() { this.availableLabelTypes = [ { text: "Text", value: "text" }, - { text: "Integer", value: "integer" }, - { text: "Decimal", value: "decimal" }, + { text: "Number", value: "number" }, { text: "Boolean", value: "boolean" }, - { text: "Date", value: "date" } + { text: "Date", value: "date" }, + { text: "DateTime", value: "datetime" } ]; this.multiplicityTypes = [ @@ -57,15 +57,17 @@ function AttributesModel() { for (const attr of attributes) { attr.labelValue = attr.type === 'label' ? attr.value : ''; attr.relationValue = attr.type === 'relation' ? attr.value : ''; - attr.labelDefinition = (attr.type === 'label-definition' && attr.value) ? JSON.parse(attr.value) : { + attr.labelDefinition = (attr.type === 'label-definition' && attr.value) ? attr.value : { labelType: "text", multiplicityType: "singlevalue", isPromoted: true }; - attr.relationDefinition = (attr.type === 'relation-definition' && attr.value) ? JSON.parse(attr.value) : { + attr.relationDefinition = attr.type === ('relation-definition' && attr.value) ? attr.value : { multiplicityType: "singlevalue", isPromoted: true }; + + delete attr.value; } self.attributes(attributes.map(ko.observable)); @@ -140,10 +142,10 @@ function AttributesModel() { attr.value = attr.relationValue; } else if (attr.type === 'label-definition') { - attr.value = JSON.stringify(attr.labelDefinition); + attr.value = attr.labelDefinition; } else if (attr.type === 'relation-definition') { - attr.value = JSON.stringify(attr.relationDefinition); + attr.value = attr.relationDefinition; } delete attr.labelValue; @@ -158,11 +160,7 @@ function AttributesModel() { infoService.showMessage("Attributes have been saved."); - // FIXME FIXME FIXME FIXME FIXME - // FIXME FIXME FIXME FIXME FIXME - // FIXME FIXME FIXME FIXME FIXME - // FIXME FIXME FIXME FIXME FIXME - //noteDetailService.loadAttributeList(); + noteDetailService.loadAttributes(); }; function addLastEmptyRow() { diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 9558adbdc..416d4a858 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -32,6 +32,7 @@ const $relationList = $("#relation-list"); const $relationListInner = $("#relation-list-inner"); const $childrenOverview = $("#children-overview"); const $scriptArea = $("#note-detail-script-area"); +const $promotedAttributes = $("#note-detail-promoted-attributes"); let currentNote = null; @@ -193,6 +194,8 @@ async function loadNoteDetail(noteId) { $scriptArea.html(''); await bundleService.executeRelationBundles(getCurrentNote(), 'runOnNoteView'); + + await loadAttributes(); } async function showChildrenOverview(hideChildrenOverview) { @@ -220,6 +223,39 @@ async function showChildrenOverview(hideChildrenOverview) { $childrenOverview.show(); } +async function loadAttributes() { + $promotedAttributes.empty(); + + const noteId = getCurrentNoteId(); + + const attributes = await server.get('notes/' + noteId + '/attributes'); + + console.log(attributes); + + const promoted = attributes.filter(attr => (attr.type === 'label-definition' || attr.type === 'relation-definition') && attr.value.isPromoted); + + let idx = 1; + + if (promoted.length > 0) { + for (const promotedAttr of promoted) { + if (promotedAttr.type === 'label-definition') { + const inputId = "promoted-input-" + idx; + const $div = $("
").addClass("class", "form-group"); + const $label = $("