only save new tags
This commit is contained in:
@@ -56,11 +56,28 @@ angular.module('app.frontend')
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$scope.updateTagsForNote = function(note, stringTags) {
|
$scope.updateTagsForNote = function(note, stringTags) {
|
||||||
note.removeAllRelationships();
|
var toRemove = [];
|
||||||
|
for(var tag of note.tags) {
|
||||||
|
if(stringTags.indexOf(tag.title) === -1) {
|
||||||
|
// remove this tag
|
||||||
|
toRemove.push(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(var tagToRemove of toRemove) {
|
||||||
|
note.removeItemAsRelationship(tagToRemove);
|
||||||
|
tagToRemove.removeItemAsRelationship(note);
|
||||||
|
tagToRemove.setDirty(true);
|
||||||
|
}
|
||||||
|
|
||||||
var tags = [];
|
var tags = [];
|
||||||
for(var tagString of stringTags) {
|
for(var tagString of stringTags) {
|
||||||
tags.push(modelManager.findOrCreateTagByTitle(tagString));
|
var existingRelationship = _.find(note.tags, {title: tagString});
|
||||||
|
if(!existingRelationship) {
|
||||||
|
tags.push(modelManager.findOrCreateTagByTitle(tagString));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var tag of tags) {
|
for(var tag of tags) {
|
||||||
modelManager.createRelationshipBetweenItems(note, tag);
|
modelManager.createRelationshipBetweenItems(note, tag);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user