tags input in editor, #41

This commit is contained in:
Mo Bitar
2017-01-21 18:51:56 -06:00
parent 80f784e47a
commit 8e6a00b8d9
11 changed files with 77 additions and 148 deletions

View File

@@ -5,7 +5,8 @@ angular.module('app.frontend')
scope: {
save: "&",
remove: "&",
note: "="
note: "=",
updateTags: "&"
},
templateUrl: 'frontend/editor.html',
replace: true,
@@ -16,7 +17,7 @@ angular.module('app.frontend')
link:function(scope, elem, attrs, ctrl) {
/**
* Insert 4 spaces when a tab key is pressed,
* Insert 4 spaces when a tab key is pressed,
* only used when inside of the text editor.
*/
var handleTab = function (event) {
@@ -85,6 +86,7 @@ angular.module('app.frontend')
this.editorMode = 'edit';
this.showExtensions = false;
this.showMenu = false;
this.loadTagsString();
if(note.safeText().length == 0 && note.dummy) {
this.focusTitle(100);
@@ -236,4 +238,29 @@ angular.module('app.frontend')
this.focusEditor(100);
}
/* Tags */
this.loadTagsString = function() {
var string = "";
for(var tag of this.note.tags) {
string += "#" + tag.title + " ";
}
this.tagsString = string;
}
this.updateTagsFromTagsString = function($event) {
$event.target.blur();
var tags = this.tagsString.split("#");
tags = _.filter(tags, function(tag){
return tag.length > 0;
})
tags = _.map(tags, function(tag){
return tag.trim();
})
this.note.dummy = false;
this.updateTags()(this.note, tags);
}
});

View File

@@ -17,6 +17,23 @@ angular.module('app.frontend')
$scope.tags = modelManager.tags;
$scope.allTag.notes = modelManager.notes;
/*
Editor Callbacks
*/
$scope.updateTagsForNote = function(note, stringTags) {
note.removeAllRelationships();
var tags = [];
for(var tagString of stringTags) {
tags.push(modelManager.findOrCreateTagByTitle(tagString));
}
for(var tag of tags) {
modelManager.createRelationshipBetweenItems(note, tag);
}
console.log("updating tags for note", note, tags);
apiController.sync();
}
/*
Tags Ctrl Callbacks
*/
@@ -43,20 +60,6 @@ angular.module('app.frontend')
apiController.sync(callback);
}
/*
Called to update the tag of a note after drag and drop change
The note object is a copy of the original
*/
$scope.tagsUpdateNoteTag = function(noteCopy, newTag, oldTag) {
var originalNote = _.find(modelManager.notes, {uuid: noteCopy.uuid});
if(!newTag.all) {
modelManager.createRelationshipBetweenItems(newTag, originalNote);
}
apiController.sync(function(){});
}
/*
Notes Ctrl Callbacks
*/

View File

@@ -102,9 +102,4 @@ angular.module('app.frontend')
return validNotes.length;
}
this.handleDrop = function(e, newTag, note) {
this.updateNoteTag()(note, newTag, this.selectedTag);
}.bind(this)
});