2017-08-22 10:53:26 +03:00
|
|
|
import Controller from '@ember/controller';
|
2018-01-11 01:57:43 +03:00
|
|
|
import {alias} from '@ember/object/computed';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {get} from '@ember/object';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2017-11-24 21:53:19 +03:00
|
|
|
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'
|
2018-11-26 15:26:45 +03:00
|
|
|
}, {
|
|
|
|
name: 'Recently updated',
|
|
|
|
value: 'updated_at desc'
|
2017-11-24 21:53:19 +03:00
|
|
|
}];
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
export default Controller.extend({
|
2014-06-17 23:17:08 +04:00
|
|
|
|
2017-10-30 12:38:01 +03:00
|
|
|
session: service(),
|
|
|
|
store: service(),
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2017-03-07 20:36:28 +03:00
|
|
|
queryParams: ['type', 'author', 'tag', 'order'],
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2017-02-23 21:47:52 +03:00
|
|
|
type: null,
|
2017-03-02 21:35:09 +03:00
|
|
|
author: null,
|
|
|
|
tag: null,
|
2017-03-07 20:36:28 +03:00
|
|
|
order: null,
|
2017-02-23 21:47:52 +03:00
|
|
|
|
2017-03-02 21:35:09 +03:00
|
|
|
_hasLoadedTags: false,
|
|
|
|
_hasLoadedAuthors: false,
|
2017-02-23 21:47:52 +03:00
|
|
|
|
2017-11-24 21:53:19 +03:00
|
|
|
availableTypes: null,
|
|
|
|
availableOrders: null,
|
2017-03-07 20:36:28 +03:00
|
|
|
|
2018-03-19 14:54:54 +03:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.availableTypes = TYPES;
|
|
|
|
this.availableOrders = ORDERS;
|
|
|
|
},
|
|
|
|
|
2018-01-11 20:43:23 +03:00
|
|
|
postsInfinityModel: alias('model'),
|
|
|
|
|
2017-03-02 21:35:09 +03:00
|
|
|
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'));
|
|
|
|
}),
|
|
|
|
|
2017-03-07 20:36:28 +03:00
|
|
|
selectedOrder: computed('order', function () {
|
|
|
|
let orders = this.get('availableOrders');
|
|
|
|
return orders.findBy('value', this.get('order'));
|
|
|
|
}),
|
|
|
|
|
2017-03-02 21:35:09 +03:00
|
|
|
_availableTags: computed(function () {
|
|
|
|
return this.get('store').peekAll('tag');
|
|
|
|
}),
|
|
|
|
|
|
|
|
availableTags: computed('_availableTags.[]', function () {
|
2018-11-07 18:06:28 +03:00
|
|
|
let tags = this.get('_availableTags')
|
|
|
|
.filter(tag => tag.get('id') !== null)
|
2019-01-02 12:58:55 +03:00
|
|
|
.sort((tagA, tagB) => tagA.name.localeCompare(tagB.name, undefined, {ignorePunctuation: true}));
|
2017-03-02 21:35:09 +03:00
|
|
|
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);
|
2017-02-23 21:47:52 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
actions: {
|
2017-03-02 21:35:09 +03:00
|
|
|
changeType(type) {
|
|
|
|
this.set('type', get(type, 'value'));
|
|
|
|
},
|
|
|
|
|
|
|
|
changeAuthor(author) {
|
|
|
|
this.set('author', get(author, 'slug'));
|
|
|
|
},
|
|
|
|
|
|
|
|
changeTag(tag) {
|
|
|
|
this.set('tag', get(tag, 'slug'));
|
2017-03-07 20:36:28 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
changeOrder(order) {
|
|
|
|
this.set('order', get(order, 'value'));
|
2017-07-13 12:55:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
openEditor(post) {
|
2019-02-22 06:17:33 +03:00
|
|
|
this.transitionToRoute('editor.edit', 'post', post.get('id'));
|
2017-02-23 21:47:52 +03:00
|
|
|
}
|
|
|
|
}
|
2014-05-24 07:25:20 +04:00
|
|
|
});
|