FIX: tag filter shows when "no tags" is selected

This commit is contained in:
Neil Lalonde 2016-07-25 12:12:43 -04:00
parent b617557cb4
commit e52c0e2087
3 changed files with 30 additions and 16 deletions

View File

@ -20,30 +20,39 @@ export default Ember.Component.extend({
} }
}, },
iconClass: function() { @computed('expanded')
iconClass() {
if (this.get('expanded')) { return "fa fa-caret-down"; } if (this.get('expanded')) { return "fa fa-caret-down"; }
return "fa fa-caret-right"; return "fa fa-caret-right";
}.property('expanded'), },
tagClass: function() { @computed('tagId')
tagClass() {
if (this.get('tagId')) { if (this.get('tagId')) {
return "tag-" + this.get('tagId'); return "tag-" + this.get('tagId');
} else { } else {
return "tag_all"; return "tag_all";
} }
}.property('tagId'), },
allTagsUrl: function() { @computed('firstCategory', 'secondCategory')
allTagsUrl() {
if (this.get('currentCategory')) { if (this.get('currentCategory')) {
return this.get('currentCategory.url') + "?allTags=1"; return this.get('currentCategory.url') + "?allTags=1";
} else { } else {
return "/"; return "/";
} }
}.property('firstCategory', 'secondCategory'), },
allTagsLabel: function() { @computed('tag')
allTagsLabel() {
return I18n.t("tagging.selector_all_tags"); return I18n.t("tagging.selector_all_tags");
}.property('tag'), },
@computed('tagId')
noTagsSelected() {
return this.get('tagId') === 'none';
},
@computed('firstCategory', 'secondCategory') @computed('firstCategory', 'secondCategory')
noTagsUrl() { noTagsUrl() {
@ -59,17 +68,19 @@ export default Ember.Component.extend({
return I18n.t("tagging.selector_no_tags"); return I18n.t("tagging.selector_no_tags");
}, },
dropdownButtonClass: function() { @computed('tag')
dropdownButtonClass() {
var result = 'badge-category category-dropdown-button'; var result = 'badge-category category-dropdown-button';
if (Em.isNone(this.get('tag'))) { if (Em.isNone(this.get('tag'))) {
result += ' home'; result += ' home';
} }
return result; return result;
}.property('tag'), },
clickEventName: function() { @computed('tag')
clickEventName() {
return "click.tag-drop-" + (this.get('tag') || "all"); return "click.tag-drop-" + (this.get('tag') || "all");
}.property('tag'), },
actions: { actions: {
expand: function() { expand: function() {

View File

@ -11,7 +11,7 @@ export default Discourse.Route.extend({
}, },
model(params) { model(params) {
var tag = (params.tag_id === 'none' ? null : this.store.createRecord("tag", { id: Handlebars.Utils.escapeExpression(params.tag_id) })), var tag = this.store.createRecord("tag", { id: Handlebars.Utils.escapeExpression(params.tag_id) }),
f = ''; f = '';
if (params.category) { if (params.category) {
@ -25,7 +25,7 @@ export default Discourse.Route.extend({
if (params.category) { this.set('categorySlug', params.category); } if (params.category) { this.set('categorySlug', params.category); }
if (params.parent_category) { this.set('parentCategorySlug', params.parent_category); } if (params.parent_category) { this.set('parentCategorySlug', params.parent_category); }
if (tag && this.get("currentUser")) { if (tag && tag.get("id") !== "none" && this.get("currentUser")) {
// If logged in, we should get the tag's user settings // If logged in, we should get the tag's user settings
return this.store.find("tagNotification", tag.get("id")).then(tn => { return this.store.find("tagNotification", tag.get("id")).then(tn => {
this.set("tagNotification", tn); this.set("tagNotification", tn);

View File

@ -1,8 +1,11 @@
{{#if showTagDropdown}} {{#if showTagDropdown}}
{{#if tagId}} {{#if tagId}}
<a href {{action "expand"}} class="badge-category {{tagClass}}">{{tagId}}</a> {{#if noTagsSelected}}
<a href {{action "expand"}} class="badge-category {{tagClass}} home">{{noTagsLabel}}</a>
{{else}}
<a href {{action "expand"}} class="badge-category {{tagClass}}">{{tagId}}</a>
{{/if}}
{{else}} {{else}}
<!-- TODO: how to detect "no tags" is currently selected -->
<a href {{action "expand"}} class="badge-category {{tagClass}} home">{{allTagsLabel}}</a> <a href {{action "expand"}} class="badge-category {{tagClass}} home">{{allTagsLabel}}</a>
{{/if}} {{/if}}