Add tags to auto-complete search

refs #5845
- display matched tags in auto-complete dropdown, load tag edit screen when selected
- fix bug where only 1 search item with the same ID would be displayed (eg. if a post and tag both had an ID of 1 it would only show the first-loaded item)
This commit is contained in:
Kevin Ansfield 2015-10-22 16:03:52 +01:00
parent aa02c85756
commit ffd282f28b

View File

@ -13,6 +13,7 @@ export default Ember.Component.extend({
posts: Ember.computed.filterBy('content', 'category', 'Posts'),
pages: Ember.computed.filterBy('content', 'category', 'Pages'),
users: Ember.computed.filterBy('content', 'category', 'Users'),
tags: Ember.computed.filterBy('content', 'category', 'Tags'),
_store: Ember.inject.service('store'),
_routing: Ember.inject.service('-routing'),
@ -32,6 +33,7 @@ export default Ember.Component.extend({
self.set('isLoading', true);
promises.pushObject(this._loadPosts());
promises.pushObject(this._loadUsers());
promises.pushObject(this._loadTags());
Ember.RSVP.all(promises).then(function () { }).finally(function () {
self.set('isLoading', false);
@ -51,7 +53,7 @@ export default Ember.Component.extend({
content.removeObjects(self.get('pages'));
content.pushObjects(posts.posts.map(function (post) {
return {
id: post.id,
id: `post.${post.id}`,
title: post.title,
category: post.page ? 'Pages' : 'Posts'
};
@ -70,7 +72,7 @@ export default Ember.Component.extend({
content.removeObjects(self.get('users'));
content.pushObjects(users.users.map(function (user) {
return {
id: user.slug,
id: `user.${user.slug}`,
title: user.name,
category: 'Users'
};
@ -78,6 +80,25 @@ export default Ember.Component.extend({
});
},
_loadTags: function () {
var store = this.get('_store'),
tagsUrl = store.adapterFor('tag').urlForQuery({}, 'tag') + '/',
tagsQuery = {fields: 'name,slug', limit: 'all'},
content = this.get('content'),
self = this;
return ajax(tagsUrl, {data: tagsQuery}).then(function (tags) {
content.removeObjects(self.get('tags'));
content.pushObjects(tags.tags.map(function (tag) {
return {
id: `tag.${tag.slug}`,
title: tag.name,
category: 'Tags'
};
}));
});
},
_keepSelectionClear: Ember.observer('selection', function () {
if (this.get('selection') !== null) {
this.set('selection', null);
@ -104,11 +125,18 @@ export default Ember.Component.extend({
if (!selected) { return; }
if (selected.category === 'Posts' || selected.category === 'Pages') {
transition = self.get('_routing.router').transitionTo('editor.edit', selected.id);
let id = selected.id.replace('post.', '');
transition = self.get('_routing.router').transitionTo('editor.edit', id);
}
if (selected.category === 'Users') {
transition = self.get('_routing.router').transitionTo('team.user', selected.id);
let id = selected.id.replace('user.', '');
transition = self.get('_routing.router').transitionTo('team.user', id);
}
if (selected.category === 'Tags') {
let id = selected.id.replace('tag.', '');
transition = self.get('_routing.router').transitionTo('settings.tags.tag', id);
}
transition.then(function () {