Show tags in tag view if more than one, sort tags alphabetically in note cell, editor pane

This commit is contained in:
Mo Bitar
2018-02-06 10:13:32 -06:00
parent 09eff0db7e
commit cbd0198e5c
5 changed files with 29 additions and 21 deletions

View File

@@ -297,11 +297,7 @@ angular.module('app')
*/ */
this.loadTagsString = function() { this.loadTagsString = function() {
var string = ""; this.tagsString = this.note.tagsString();
for(var tag of this.note.tags) {
string += "#" + tag.title + " ";
}
this.tagsString = string;
} }
this.addTag = function(tag) { this.addTag = function(tag) {
@@ -326,16 +322,18 @@ angular.module('app')
} }
this.updateTagsFromTagsString = function() { this.updateTagsFromTagsString = function() {
var tags = this.tagsString.split("#"); if(this.tagsString == this.note.tagsString()) {
tags = _.filter(tags, function(tag){ return;
return tag.length > 0; }
})
tags = _.map(tags, function(tag){ var strings = this.tagsString.split("#").filter((string) => {
return tag.trim(); return string.length > 0;
}).map((string) => {
return string.trim();
}) })
this.note.dummy = false; this.note.dummy = false;
this.updateTags()(this.note, tags); this.updateTags()(this.note, strings);
} }

View File

@@ -257,4 +257,17 @@ angular.module('app')
authManager.syncUserPreferences(); 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;
}
}); });

View File

@@ -87,13 +87,9 @@ class Tag extends Item {
return this.notes; return this.notes;
} }
static arrayToDisplayString(tags, includeComma) { static arrayToDisplayString(tags) {
return tags.map(function(tag, i){ return tags.sort((a, b) => {return a.title > b.title}).map(function(tag, i){
var text = "#" + tag.title; return "#" + tag.title;
if(i != tags.length - 1) {
text += includeComma ? ", " : " ";
}
return text;
}).join(" "); }).join(" ");
} }
} }

View File

@@ -11,7 +11,8 @@
#note-tags-component-container{"ng-if" => "ctrl.tagsComponent"} #note-tags-component-container{"ng-if" => "ctrl.tagsComponent"}
%component-view.component-view{ "component" => "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();", %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"} .sn-component{"ng-if" => "ctrl.note"}
.app-bar.no-edges .app-bar.no-edges

View File

@@ -54,7 +54,7 @@
%i.icon.ion-ios-box %i.icon.ion-ios-box
%strong.medium Archived %strong.medium Archived
.tags-string{"ng-if" => "ctrl.tag.all && !ctrl.hideTags"} .tags-string{"ng-if" => "ctrl.shouldShowTags(note)"}
.faded {{note.tagsString()}} .faded {{note.tagsString()}}
.name{"ng-if" => "note.title"} .name{"ng-if" => "note.title"}