fixes in attribute persistence + WIP on display of promoted attrs

This commit is contained in:
azivner
2018-08-06 08:59:26 +02:00
parent 194ce4f10f
commit 2aab3ad281
16 changed files with 138 additions and 37 deletions

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -22,11 +22,11 @@ class NoteRevision extends Entity {
}
beforeSaving() {
super.beforeSaving();
if (this.isProtected) {
protectedSessionService.encryptNoteRevision(this);
}
super.beforeSaving();
}
}

View File

@@ -9,9 +9,9 @@ class Option extends Entity {
static get hashedProperties() { return ["name", "value"]; }
beforeSaving() {
super.beforeSaving();
this.dateModified = dateUtils.nowDate();
super.beforeSaving();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}