mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
a3c71b8ba8
no issue - added a `transitionTo` after deleting a custom view that transitions to the `posts` route with default query params - refactored `reset-posts-query` helper to a more generic `reset-query-params` helper - moved default query params definitions to this helper and expose them so we have a single source of truth - exposed `resetQueryParams()` function from the helper for use outside of templates - adjust the function and helper behaviour to accept the route name as the first param so that `router.currentRouteName` can be used as a generic reset
137 lines
3.6 KiB
JavaScript
137 lines
3.6 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import {DEFAULT_QUERY_PARAMS} from 'ghost-admin/helpers/reset-query-params';
|
|
import {alias} from '@ember/object/computed';
|
|
import {computed} from '@ember/object';
|
|
import {get} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
const TYPES = [{
|
|
name: 'All posts',
|
|
value: null
|
|
}, {
|
|
name: 'Draft posts',
|
|
value: 'draft'
|
|
}, {
|
|
name: 'Published posts',
|
|
value: 'published'
|
|
}, {
|
|
name: 'Scheduled posts',
|
|
value: 'scheduled'
|
|
}, {
|
|
name: 'Featured posts',
|
|
value: 'featured'
|
|
}];
|
|
|
|
const ORDERS = [{
|
|
name: 'Newest',
|
|
value: null
|
|
}, {
|
|
name: 'Oldest',
|
|
value: 'published_at asc'
|
|
}, {
|
|
name: 'Recently updated',
|
|
value: 'updated_at desc'
|
|
}];
|
|
|
|
export default Controller.extend({
|
|
|
|
store: service(),
|
|
|
|
// default values for these are set in `init` and defined in `helpers/reset-query-params`
|
|
queryParams: ['type', 'author', 'tag', 'order'],
|
|
|
|
_hasLoadedTags: false,
|
|
_hasLoadedAuthors: false,
|
|
|
|
availableTypes: null,
|
|
availableOrders: null,
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
this.availableTypes = TYPES;
|
|
this.availableOrders = ORDERS;
|
|
this.setProperties(DEFAULT_QUERY_PARAMS.posts);
|
|
},
|
|
|
|
postsInfinityModel: alias('model'),
|
|
|
|
showingAll: computed('type', 'author', 'tag', function () {
|
|
let {type, author, tag} = this.getProperties(['type', 'author', 'tag']);
|
|
|
|
return !type && !author && !tag;
|
|
}),
|
|
|
|
selectedType: computed('type', function () {
|
|
let types = this.get('availableTypes');
|
|
return types.findBy('value', this.get('type')) || {value: '!unknown'};
|
|
}),
|
|
|
|
selectedOrder: computed('order', function () {
|
|
let orders = this.get('availableOrders');
|
|
return orders.findBy('value', this.get('order')) || {value: '!unknown'};
|
|
}),
|
|
|
|
_availableTags: computed(function () {
|
|
return this.get('store').peekAll('tag');
|
|
}),
|
|
|
|
availableTags: computed('_availableTags.[]', function () {
|
|
let tags = this.get('_availableTags')
|
|
.filter(tag => tag.get('id') !== null)
|
|
.sort((tagA, tagB) => tagA.name.localeCompare(tagB.name, undefined, {ignorePunctuation: true}));
|
|
let options = tags.toArray();
|
|
options.unshiftObject({name: 'All tags', slug: null});
|
|
|
|
return options;
|
|
}),
|
|
|
|
selectedTag: computed('tag', '_availableTags.[]', function () {
|
|
let tag = this.get('tag');
|
|
let tags = this.get('availableTags');
|
|
|
|
return tags.findBy('slug', tag) || {slug: '!unknown'};
|
|
}),
|
|
|
|
_availableAuthors: computed(function () {
|
|
return this.get('store').peekAll('user');
|
|
}),
|
|
|
|
availableAuthors: computed('_availableAuthors.[]', function () {
|
|
let authors = this.get('_availableAuthors');
|
|
let options = authors.toArray();
|
|
|
|
options.unshiftObject({name: 'All authors', slug: null});
|
|
|
|
return options;
|
|
}),
|
|
|
|
selectedAuthor: computed('author', 'availableAuthors.[]', function () {
|
|
let author = this.get('author');
|
|
let authors = this.get('availableAuthors');
|
|
|
|
return authors.findBy('slug', author) || {slug: '!unknown'};
|
|
}),
|
|
|
|
actions: {
|
|
changeType(type) {
|
|
this.set('type', get(type, 'value'));
|
|
},
|
|
|
|
changeAuthor(author) {
|
|
this.set('author', get(author, 'slug'));
|
|
},
|
|
|
|
changeTag(tag) {
|
|
this.set('tag', get(tag, 'slug'));
|
|
},
|
|
|
|
changeOrder(order) {
|
|
this.set('order', get(order, 'value'));
|
|
},
|
|
|
|
openEditor(post) {
|
|
this.transitionToRoute('editor.edit', 'post', post.get('id'));
|
|
}
|
|
}
|
|
});
|