mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
more cleanup
This commit is contained in:
parent
a0b3bc858d
commit
51dae378a3
@ -278,7 +278,7 @@ export default class NoteAttributesWidget extends TabAwareWidget {
|
|||||||
const attributes = this.parseAttributes();
|
const attributes = this.parseAttributes();
|
||||||
|
|
||||||
if (attributes) {
|
if (attributes) {
|
||||||
await server.put(`notes/${this.noteId}/attributes2`, attributes, this.componentId);
|
await server.put(`notes/${this.noteId}/attributes`, attributes, this.componentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ function deleteNoteAttribute(req) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateNoteAttributes2(req) {
|
function updateNoteAttributes(req) {
|
||||||
const noteId = req.params.noteId;
|
const noteId = req.params.noteId;
|
||||||
const incomingAttributes = req.body;
|
const incomingAttributes = req.body;
|
||||||
|
|
||||||
@ -149,69 +149,6 @@ function updateNoteAttributes2(req) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateNoteAttributes(req) {
|
|
||||||
const noteId = req.params.noteId;
|
|
||||||
const attributes = req.body;
|
|
||||||
|
|
||||||
for (const attribute of attributes) {
|
|
||||||
let attributeEntity;
|
|
||||||
|
|
||||||
if (attribute.attributeId) {
|
|
||||||
attributeEntity = repository.getAttribute(attribute.attributeId);
|
|
||||||
|
|
||||||
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)
|
|
||||||
|| attribute.isInheritable !== attributeEntity.isInheritable) {
|
|
||||||
|
|
||||||
if (attribute.type !== 'relation' || !!attribute.value.trim()) {
|
|
||||||
const newAttribute = attributeEntity.createClone(attribute.type, attribute.name, attribute.value, attribute.isInheritable);
|
|
||||||
newAttribute.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
attributeEntity.isDeleted = true;
|
|
||||||
attributeEntity.save();
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// if it was "created" and then immediatelly deleted, we just don't create it at all
|
|
||||||
if (attribute.isDeleted) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
attributeEntity = new Attribute();
|
|
||||||
attributeEntity.noteId = noteId;
|
|
||||||
}
|
|
||||||
|
|
||||||
attributeEntity.type = attribute.type;
|
|
||||||
attributeEntity.name = attribute.name;
|
|
||||||
attributeEntity.position = attribute.position;
|
|
||||||
attributeEntity.isInheritable = attribute.isInheritable;
|
|
||||||
attributeEntity.isDeleted = attribute.isDeleted;
|
|
||||||
|
|
||||||
if (attributeEntity.type === 'relation' && !attribute.value.trim()) {
|
|
||||||
// relation should never have empty target
|
|
||||||
attributeEntity.isDeleted = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
attributeEntity.value = attribute.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
attributeEntity.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
const note = repository.getNote(noteId);
|
|
||||||
note.invalidateAttributeCache();
|
|
||||||
|
|
||||||
return note.getAttributes();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAttributeNames(req) {
|
function getAttributeNames(req) {
|
||||||
const type = req.query.type;
|
const type = req.query.type;
|
||||||
const query = req.query.query;
|
const query = req.query.query;
|
||||||
@ -260,7 +197,6 @@ function deleteRelation(req) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
updateNoteAttributes,
|
updateNoteAttributes,
|
||||||
updateNoteAttributes2,
|
|
||||||
updateNoteAttribute,
|
updateNoteAttribute,
|
||||||
deleteNoteAttribute,
|
deleteNoteAttribute,
|
||||||
getAttributeNames,
|
getAttributeNames,
|
||||||
|
@ -174,7 +174,6 @@ function register(app) {
|
|||||||
|
|
||||||
apiRoute(GET, '/api/notes/:noteId/attributes', attributesRoute.getEffectiveNoteAttributes);
|
apiRoute(GET, '/api/notes/:noteId/attributes', attributesRoute.getEffectiveNoteAttributes);
|
||||||
apiRoute(PUT, '/api/notes/:noteId/attributes', attributesRoute.updateNoteAttributes);
|
apiRoute(PUT, '/api/notes/:noteId/attributes', attributesRoute.updateNoteAttributes);
|
||||||
apiRoute(PUT, '/api/notes/:noteId/attributes2', attributesRoute.updateNoteAttributes2);
|
|
||||||
apiRoute(PUT, '/api/notes/:noteId/attribute', attributesRoute.updateNoteAttribute);
|
apiRoute(PUT, '/api/notes/:noteId/attribute', attributesRoute.updateNoteAttribute);
|
||||||
apiRoute(PUT, '/api/notes/:noteId/relations/:name/to/:targetNoteId', attributesRoute.createRelation);
|
apiRoute(PUT, '/api/notes/:noteId/relations/:name/to/:targetNoteId', attributesRoute.createRelation);
|
||||||
apiRoute(DELETE, '/api/notes/:noteId/relations/:name/to/:targetNoteId', attributesRoute.deleteRelation);
|
apiRoute(DELETE, '/api/notes/:noteId/relations/:name/to/:targetNoteId', attributesRoute.deleteRelation);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user