mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
c51bce7358
refs. https://github.com/TryGhost/Team/issues/205 Major update to Ghost Admin UI including: - improved general consistency (typography, colors and contrast, UI components, icons) - new design for post and pages lists, improved discoverability of filters - search moved to modal - account menu is decoupled from ghost logo - further usability fixes
165 lines
4.2 KiB
JavaScript
165 lines
4.2 KiB
JavaScript
import Controller from '@ember/controller';
|
|
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({
|
|
|
|
session: service(),
|
|
store: service(),
|
|
|
|
queryParams: ['type', 'author', 'tag', 'order'],
|
|
|
|
type: null,
|
|
author: null,
|
|
tag: null,
|
|
order: null,
|
|
|
|
_hasLoadedTags: false,
|
|
_hasLoadedAuthors: false,
|
|
|
|
availableTypes: null,
|
|
availableOrders: null,
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
this.availableTypes = TYPES;
|
|
this.availableOrders = ORDERS;
|
|
},
|
|
|
|
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'));
|
|
}),
|
|
|
|
selectedOrder: computed('order', function () {
|
|
let orders = this.get('availableOrders');
|
|
return orders.findBy('value', this.get('order'));
|
|
}),
|
|
|
|
_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);
|
|
}),
|
|
|
|
_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);
|
|
}),
|
|
|
|
typeClassNames: computed('type', function () {
|
|
let classNames = 'gh-contentfilter-menu gh-contentfilter-type';
|
|
if (this.get('type')) {
|
|
classNames = classNames + ' gh-contentfilter-selected';
|
|
}
|
|
return classNames;
|
|
}),
|
|
|
|
authorClassNames: computed('author', function () {
|
|
let classNames = 'gh-contentfilter-menu gh-contentfilter-author';
|
|
if (this.get('author')) {
|
|
classNames = classNames + ' gh-contentfilter-selected';
|
|
}
|
|
return classNames;
|
|
}),
|
|
|
|
tagClassNames: computed('tag', function () {
|
|
let classNames = 'gh-contentfilter-menu gh-contentfilter-tag';
|
|
if (this.get('tag')) {
|
|
classNames = classNames + ' gh-contentfilter-selected';
|
|
}
|
|
return classNames;
|
|
}),
|
|
|
|
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'));
|
|
}
|
|
}
|
|
});
|