Support any number of tag intersections

This commit is contained in:
James Kiesel
2016-08-15 15:30:17 -04:00
parent d3792c0149
commit 037e9bb7b8
8 changed files with 56 additions and 25 deletions

View File

@@ -43,7 +43,7 @@ export default Ember.Controller.extend(BulkTopicSelection, {
needs: ["application"],
tag: null,
secondaryTag: null,
additionalTags: null,
list: null,
canAdminTag: Ember.computed.alias("currentUser.staff"),
filterMode: null,
@@ -73,8 +73,8 @@ export default Ember.Controller.extend(BulkTopicSelection, {
}.property(),
showAdminControls: function() {
return !this.get('secondaryTag') && this.get('canAdminTag') && !this.get('category');
}.property('secondaryTag', 'canAdminTag', 'category'),
return this.get('additionalTags') && this.get('canAdminTag') && !this.get('category');
}.property('additionalTags', 'canAdminTag', 'category'),
loadMoreTopics() {
return this.get("list").loadMore();

View File

@@ -132,7 +132,7 @@ export default function() {
this.route('showCategory' + filter.capitalize(), {path: '/c/:category/:tag_id/l/' + filter});
this.route('showParentCategory' + filter.capitalize(), {path: '/c/:parent_category/:category/:tag_id/l/' + filter});
});
this.route('show', {path: 'intersection/:tag_id/:secondary_tag_id'});
this.route('show', {path: 'intersection/:tag_id/*additional_tags'});
});
this.resource('tagGroups', {path: '/tag_groups'}, function() {

View File

@@ -14,8 +14,11 @@ export default Discourse.Route.extend({
var tag = this.store.createRecord("tag", { id: Handlebars.Utils.escapeExpression(params.tag_id) }),
f = '';
if (params.secondary_tag_id) {
this.set("secondaryTag", this.store.createRecord("tag", { id: Handlebars.Utils.escapeExpression(params.secondary_tag_id) }));
if (params.additional_tags) {
this.set("additionalTags", _.compact(params.additional_tags.split('/')).map((tag) => {
return this.store.createRecord("tag", { id: Handlebars.Utils.escapeExpression(tag) });
}));
this.set("additionalTagIds", _.pluck(this.get("additionalTags"), 'id'));
}
if (params.category) {
@@ -50,7 +53,6 @@ export default Discourse.Route.extend({
const parentCategorySlug = this.get('parentCategorySlug');
const filter = this.get('navMode');
const tag_id = (tag ? tag.id : 'none');
const secondary_tag_id = this.get('secondaryTag.id');
if (categorySlug) {
var category = Discourse.Category.findBySlug(categorySlug, parentCategorySlug);
@@ -61,8 +63,8 @@ export default Discourse.Route.extend({
}
this.set('category', category);
} else if (secondary_tag_id) {
params.filter = `tags/intersection/${tag_id}/${secondary_tag_id}`;
} else if (_.any(this.get("additionalTags"))) {
params.filter = `tags/intersection/${tag_id}/${this.get('additionalTagIds').join('/')}`;
this.set('category', null);
} else {
params.filter = `tags/${tag_id}/l/${filter}`;
@@ -102,7 +104,7 @@ export default Discourse.Route.extend({
this.controllerFor('tags.show').setProperties({
model,
tag: model,
secondaryTag: this.get('secondaryTag'),
additionalTags: this.get('additionalTags'),
category: this.get('category'),
filterMode: this.get('filterMode'),
navMode: this.get('navMode'),
@@ -132,7 +134,7 @@ export default Discourse.Route.extend({
// Pre-fill the tags input field
if (controller.get('model.id')) {
var c = self.controllerFor('composer').get('model');
c.set('tags', _.compact([controller.get('model.id'), controller.get('secondaryTag.id')]));
c.set('tags', _.flatten([controller.get('model.id')], controller.get('additionalTagIds')));
}
});
},

View File

@@ -5,7 +5,7 @@
<div class="list-controls">
<div class="container">
{{#if tagNotification}}
{{#unless secondaryTag}}
{{#unless additionalTags}}
{{tag-notifications-button action="changeTagNotification"
notificationLevel=tagNotification.notification_level}}
{{/unless}}
@@ -33,10 +33,10 @@
{{#link-to 'tags'}}{{i18n "tagging.tags"}}{{/link-to}}
{{fa-icon "angle-right"}}
{{discourse-tag-bound tagRecord=tag style="simple"}}
{{#if secondaryTag}}
{{#each additionalTags as |tag|}}
<span>&amp;</span>
{{discourse-tag-bound tagRecord=secondaryTag style="simple"}}
{{/if}}
{{discourse-tag-bound tagRecord=tag style="simple"}}
{{/each}}
</h2>
{{/if}}
</div>