mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
attributes are now updated only if their type and name does not change, in case of relation not even value must change. If they do, the old attribute is deleted and new is created instead
This commit is contained in:
parent
d2e3aedf7f
commit
88213c1bbd
@ -116,6 +116,20 @@ class Attribute extends Entity {
|
||||
delete pojo.isOwned;
|
||||
delete pojo.__note;
|
||||
}
|
||||
|
||||
createClone(type, name, value) {
|
||||
return new Attribute({
|
||||
noteId: this.noteId,
|
||||
type: type,
|
||||
name: name,
|
||||
value: value,
|
||||
position: this.position,
|
||||
isInheritable: this.isInheritable,
|
||||
isDeleted: false,
|
||||
utcDateCreated: this.utcDateCreated,
|
||||
utcDateModified: this.utcDateModified
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Attribute;
|
@ -71,7 +71,7 @@ class Branch extends Entity {
|
||||
delete pojo.origParentNoteId;
|
||||
}
|
||||
|
||||
getClone(parentNoteId, notePosition) {
|
||||
createClone(parentNoteId, notePosition) {
|
||||
return new Branch({
|
||||
noteId: this.noteId,
|
||||
parentNoteId: parentNoteId,
|
||||
|
@ -18,6 +18,27 @@ async function updateNoteAttribute(req) {
|
||||
let attribute;
|
||||
if (body.attributeId) {
|
||||
attribute = await repository.getAttribute(body.attributeId);
|
||||
|
||||
if (attribute.noteId !== noteId) {
|
||||
return [400, `Attribute ${body.attributeId} is not owned by ${noteId}`];
|
||||
}
|
||||
|
||||
if (body.type !== attribute.type
|
||||
|| body.name !== attribute.name
|
||||
|| (body.type === 'relation' && body.value !== attribute.value)) {
|
||||
|
||||
if (body.type !== 'relation' || !!body.value.trim()) {
|
||||
const newAttribute = attribute.createClone(body.type, body.name, body.value);
|
||||
await newAttribute.save();
|
||||
}
|
||||
|
||||
attribute.isDeleted = true;
|
||||
await attribute.save();
|
||||
|
||||
return {
|
||||
attributeId: attribute.attributeId
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (body.type === 'relation' && !body.value.trim()) {
|
||||
@ -30,10 +51,6 @@ async function updateNoteAttribute(req) {
|
||||
attribute.type = body.type;
|
||||
}
|
||||
|
||||
if (attribute.noteId !== noteId) {
|
||||
return [400, `Attribute ${body.attributeId} is not owned by ${noteId}`];
|
||||
}
|
||||
|
||||
if (body.value.trim()) {
|
||||
attribute.value = body.value;
|
||||
}
|
||||
@ -78,6 +95,21 @@ async function updateNoteAttributes(req) {
|
||||
if (attributeEntity.noteId !== noteId) {
|
||||
return [400, `Attribute ${attributeEntity.noteId} is not owned by ${noteId}`];
|
||||
}
|
||||
|
||||
if (attribute.type !== attributeEntity.type
|
||||
|| attribute.name !== attributeEntity.name
|
||||
|| (attribute.type === 'relation' && attribute.value !== attributeEntity.value)) {
|
||||
|
||||
if (attribute.type !== 'relation' || !!attribute.value.trim()) {
|
||||
const newAttribute = attribute.createClone(attribute.type, attribute.name, attribute.value);
|
||||
await newAttribute.save();
|
||||
}
|
||||
|
||||
attributeEntity.isDeleted = true;
|
||||
await attributeEntity.save();
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if it was "created" and then immediatelly deleted, we just don't create it at all
|
||||
|
Loading…
x
Reference in New Issue
Block a user