mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Merge pull request #5991 from kevinansfield/tags-search
Add tags to auto-complete search
This commit is contained in:
commit
13943057ed
1 changed files with 32 additions and 4 deletions
|
@ -13,6 +13,7 @@ export default Ember.Component.extend({
|
||||||
posts: Ember.computed.filterBy('content', 'category', 'Posts'),
|
posts: Ember.computed.filterBy('content', 'category', 'Posts'),
|
||||||
pages: Ember.computed.filterBy('content', 'category', 'Pages'),
|
pages: Ember.computed.filterBy('content', 'category', 'Pages'),
|
||||||
users: Ember.computed.filterBy('content', 'category', 'Users'),
|
users: Ember.computed.filterBy('content', 'category', 'Users'),
|
||||||
|
tags: Ember.computed.filterBy('content', 'category', 'Tags'),
|
||||||
|
|
||||||
_store: Ember.inject.service('store'),
|
_store: Ember.inject.service('store'),
|
||||||
_routing: Ember.inject.service('-routing'),
|
_routing: Ember.inject.service('-routing'),
|
||||||
|
@ -32,6 +33,7 @@ export default Ember.Component.extend({
|
||||||
self.set('isLoading', true);
|
self.set('isLoading', true);
|
||||||
promises.pushObject(this._loadPosts());
|
promises.pushObject(this._loadPosts());
|
||||||
promises.pushObject(this._loadUsers());
|
promises.pushObject(this._loadUsers());
|
||||||
|
promises.pushObject(this._loadTags());
|
||||||
|
|
||||||
Ember.RSVP.all(promises).then(function () { }).finally(function () {
|
Ember.RSVP.all(promises).then(function () { }).finally(function () {
|
||||||
self.set('isLoading', false);
|
self.set('isLoading', false);
|
||||||
|
@ -51,7 +53,7 @@ export default Ember.Component.extend({
|
||||||
content.removeObjects(self.get('pages'));
|
content.removeObjects(self.get('pages'));
|
||||||
content.pushObjects(posts.posts.map(function (post) {
|
content.pushObjects(posts.posts.map(function (post) {
|
||||||
return {
|
return {
|
||||||
id: post.id,
|
id: `post.${post.id}`,
|
||||||
title: post.title,
|
title: post.title,
|
||||||
category: post.page ? 'Pages' : 'Posts'
|
category: post.page ? 'Pages' : 'Posts'
|
||||||
};
|
};
|
||||||
|
@ -70,7 +72,7 @@ export default Ember.Component.extend({
|
||||||
content.removeObjects(self.get('users'));
|
content.removeObjects(self.get('users'));
|
||||||
content.pushObjects(users.users.map(function (user) {
|
content.pushObjects(users.users.map(function (user) {
|
||||||
return {
|
return {
|
||||||
id: user.slug,
|
id: `user.${user.slug}`,
|
||||||
title: user.name,
|
title: user.name,
|
||||||
category: 'Users'
|
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 () {
|
_keepSelectionClear: Ember.observer('selection', function () {
|
||||||
if (this.get('selection') !== null) {
|
if (this.get('selection') !== null) {
|
||||||
this.set('selection', null);
|
this.set('selection', null);
|
||||||
|
@ -104,11 +125,18 @@ export default Ember.Component.extend({
|
||||||
if (!selected) { return; }
|
if (!selected) { return; }
|
||||||
|
|
||||||
if (selected.category === 'Posts' || selected.category === 'Pages') {
|
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') {
|
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 () {
|
transition.then(function () {
|
||||||
|
|
Loading…
Reference in a new issue