From cbd0198e5c54bc6e86c3a6f4f6fb0b604ffc36c9 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Tue, 6 Feb 2018 10:13:32 -0600 Subject: [PATCH] Show tags in tag view if more than one, sort tags alphabetically in note cell, editor pane --- .../javascripts/app/controllers/editor.js | 22 +++++++++---------- .../javascripts/app/controllers/notes.js | 13 +++++++++++ app/assets/javascripts/app/models/app/tag.js | 10 +++------ app/assets/templates/editor.html.haml | 3 ++- app/assets/templates/notes.html.haml | 2 +- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/app/controllers/editor.js b/app/assets/javascripts/app/controllers/editor.js index 55f54fbcb..5fc7b4218 100644 --- a/app/assets/javascripts/app/controllers/editor.js +++ b/app/assets/javascripts/app/controllers/editor.js @@ -297,11 +297,7 @@ angular.module('app') */ this.loadTagsString = function() { - var string = ""; - for(var tag of this.note.tags) { - string += "#" + tag.title + " "; - } - this.tagsString = string; + this.tagsString = this.note.tagsString(); } this.addTag = function(tag) { @@ -326,16 +322,18 @@ angular.module('app') } this.updateTagsFromTagsString = function() { - var tags = this.tagsString.split("#"); - tags = _.filter(tags, function(tag){ - return tag.length > 0; - }) - tags = _.map(tags, function(tag){ - return tag.trim(); + if(this.tagsString == this.note.tagsString()) { + return; + } + + var strings = this.tagsString.split("#").filter((string) => { + return string.length > 0; + }).map((string) => { + return string.trim(); }) this.note.dummy = false; - this.updateTags()(this.note, tags); + this.updateTags()(this.note, strings); } diff --git a/app/assets/javascripts/app/controllers/notes.js b/app/assets/javascripts/app/controllers/notes.js index 878e7486e..a89e9fffa 100644 --- a/app/assets/javascripts/app/controllers/notes.js +++ b/app/assets/javascripts/app/controllers/notes.js @@ -257,4 +257,17 @@ angular.module('app') authManager.syncUserPreferences(); } + this.shouldShowTags = function(note) { + if(this.hideTags) { + return false; + } + + if(this.tag.all) { + return true; + } + + // Inside a tag, only show tags string if note contains tags other than this.tag + return note.tags && note.tags.length > 1; + } + }); diff --git a/app/assets/javascripts/app/models/app/tag.js b/app/assets/javascripts/app/models/app/tag.js index f94ee4151..b83585234 100644 --- a/app/assets/javascripts/app/models/app/tag.js +++ b/app/assets/javascripts/app/models/app/tag.js @@ -87,13 +87,9 @@ class Tag extends Item { return this.notes; } - static arrayToDisplayString(tags, includeComma) { - return tags.map(function(tag, i){ - var text = "#" + tag.title; - if(i != tags.length - 1) { - text += includeComma ? ", " : " "; - } - return text; + static arrayToDisplayString(tags) { + return tags.sort((a, b) => {return a.title > b.title}).map(function(tag, i){ + return "#" + tag.title; }).join(" "); } } diff --git a/app/assets/templates/editor.html.haml b/app/assets/templates/editor.html.haml index 924030f23..884bd8335 100644 --- a/app/assets/templates/editor.html.haml +++ b/app/assets/templates/editor.html.haml @@ -11,7 +11,8 @@ #note-tags-component-container{"ng-if" => "ctrl.tagsComponent"} %component-view.component-view{ "component" => "ctrl.tagsComponent"} %input.tags-input{"ng-if" => "!(ctrl.tagsComponent && ctrl.tagsComponent.active)", "type" => "text", "ng-keyup" => "$event.keyCode == 13 && $event.target.blur();", - "ng-model" => "ctrl.tagsString", "placeholder" => "#tags", "ng-blur" => "ctrl.updateTagsFromTagsString($event, ctrl.tagsString)"} + "ng-model" => "ctrl.tagsString", "placeholder" => "#tags", "ng-blur" => "ctrl.updateTagsFromTagsString($event, ctrl.tagsString)", + "spellcheck" => "false"} .sn-component{"ng-if" => "ctrl.note"} .app-bar.no-edges diff --git a/app/assets/templates/notes.html.haml b/app/assets/templates/notes.html.haml index 67ac906ac..5797b152a 100644 --- a/app/assets/templates/notes.html.haml +++ b/app/assets/templates/notes.html.haml @@ -54,7 +54,7 @@ %i.icon.ion-ios-box %strong.medium Archived - .tags-string{"ng-if" => "ctrl.tag.all && !ctrl.hideTags"} + .tags-string{"ng-if" => "ctrl.shouldShowTags(note)"} .faded {{note.tagsString()}} .name{"ng-if" => "note.title"}