2017-08-22 10:53:26 +03:00
|
|
|
import Controller from '@ember/controller';
|
2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2020-02-03 19:27:42 +03:00
|
|
|
import {DEFAULT_QUERY_PARAMS} from 'ghost-admin/helpers/reset-query-params';
|
2022-02-01 12:34:03 +03:00
|
|
|
import {action, computed, get} from '@ember/object';
|
2018-01-11 01:57:43 +03:00
|
|
|
import {alias} from '@ember/object/computed';
|
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'
|
|
|
|
}];
|
|
|
|
|
2020-06-09 14:19:25 +03:00
|
|
|
const VISIBILITIES = [{
|
|
|
|
name: 'All access',
|
|
|
|
value: null
|
|
|
|
}, {
|
|
|
|
name: 'Public',
|
|
|
|
value: 'public'
|
|
|
|
}, {
|
|
|
|
name: 'Members-only',
|
|
|
|
value: 'members'
|
|
|
|
}, {
|
|
|
|
name: 'Paid members-only',
|
|
|
|
value: 'paid'
|
|
|
|
}];
|
|
|
|
|
2017-11-24 21:53:19 +03:00
|
|
|
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
|
|
|
}];
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
export default class PostsController extends Controller {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service feature;
|
|
|
|
@service session;
|
|
|
|
@service store;
|
|
|
|
@service settings;
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2022-02-01 20:59:20 +03:00
|
|
|
@service
|
|
|
|
config;
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
// default values for these are set in `init` and defined in `helpers/reset-query-params`
|
|
|
|
queryParams = ['type', 'access', 'author', 'tag', 'order'];
|
2017-02-23 21:47:52 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
_hasLoadedTags = false;
|
|
|
|
_hasLoadedAuthors = false;
|
|
|
|
_hasLoadedSnippets = false;
|
|
|
|
availableTypes = null;
|
|
|
|
availableVisibilities = null;
|
|
|
|
availableOrders = null;
|
2017-03-07 20:36:28 +03:00
|
|
|
|
2018-03-19 14:54:54 +03:00
|
|
|
init() {
|
2022-02-01 12:34:03 +03:00
|
|
|
super.init(...arguments);
|
2018-03-19 14:54:54 +03:00
|
|
|
this.availableTypes = TYPES;
|
|
|
|
this.availableOrders = ORDERS;
|
2020-06-09 14:19:25 +03:00
|
|
|
this.availableVisibilities = VISIBILITIES;
|
2020-02-03 19:27:42 +03:00
|
|
|
this.setProperties(DEFAULT_QUERY_PARAMS.posts);
|
2020-12-04 17:08:48 +03:00
|
|
|
|
2020-12-10 18:13:59 +03:00
|
|
|
if (this.feature.get('emailAnalytics') && !this.availableOrders.findBy('name', 'Open rate')) {
|
2020-12-04 17:08:48 +03:00
|
|
|
this.availableOrders.push({
|
|
|
|
name: 'Open rate',
|
|
|
|
value: 'email.open_rate desc'
|
|
|
|
});
|
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2018-03-19 14:54:54 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@alias('model')
|
|
|
|
postsInfinityModel;
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('type', 'author', 'tag')
|
|
|
|
get showingAll() {
|
2022-01-21 22:25:47 +03:00
|
|
|
let {type, author, tag, visibility} = this;
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2020-06-09 14:19:25 +03:00
|
|
|
return !type && !visibility && !author && !tag;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('type')
|
|
|
|
get selectedType() {
|
2022-01-21 22:25:47 +03:00
|
|
|
let types = this.availableTypes;
|
|
|
|
return types.findBy('value', this.type) || {value: '!unknown'};
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('visibility')
|
|
|
|
get selectedVisibility() {
|
2022-01-21 22:25:47 +03:00
|
|
|
let visibilities = this.availableVisibilities;
|
|
|
|
return visibilities.findBy('value', this.visibility) || {value: '!unknown'};
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2020-06-09 14:19:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('order')
|
|
|
|
get selectedOrder() {
|
2022-01-21 22:25:47 +03:00
|
|
|
let orders = this.availableOrders;
|
|
|
|
return orders.findBy('value', this.order) || {value: '!unknown'};
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-07 20:36:28 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed
|
|
|
|
get _availableTags() {
|
2022-01-21 22:25:47 +03:00
|
|
|
return this.store.peekAll('tag');
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('_availableTags.[]')
|
|
|
|
get availableTags() {
|
2022-01-21 22:25:47 +03:00
|
|
|
let tags = this._availableTags
|
2018-11-07 18:06:28 +03:00
|
|
|
.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;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('tag', '_availableTags.[]')
|
|
|
|
get selectedTag() {
|
2022-01-21 22:25:47 +03:00
|
|
|
let tag = this.tag;
|
|
|
|
let tags = this.availableTags;
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2020-01-20 18:40:32 +03:00
|
|
|
return tags.findBy('slug', tag) || {slug: '!unknown'};
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed
|
|
|
|
get _availableAuthors() {
|
2022-01-21 22:25:47 +03:00
|
|
|
return this.store.peekAll('user');
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('_availableAuthors.[]')
|
|
|
|
get availableAuthors() {
|
2022-01-21 22:25:47 +03:00
|
|
|
let authors = this._availableAuthors;
|
2017-03-02 21:35:09 +03:00
|
|
|
let options = authors.toArray();
|
|
|
|
|
|
|
|
options.unshiftObject({name: 'All authors', slug: null});
|
|
|
|
|
|
|
|
return options;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('author', 'availableAuthors.[]')
|
|
|
|
get selectedAuthor() {
|
2022-01-21 22:25:47 +03:00
|
|
|
let author = this.author;
|
|
|
|
let authors = this.availableAuthors;
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2020-01-20 18:40:32 +03:00
|
|
|
return authors.findBy('slug', author) || {slug: '!unknown'};
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-02-23 21:47:52 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed
|
|
|
|
get snippets() {
|
2020-10-15 20:03:18 +03:00
|
|
|
return this.store.peekAll('snippet');
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2020-10-15 20:03:18 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
changeType(type) {
|
|
|
|
this.set('type', get(type, 'value'));
|
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
changeVisibility(visibility) {
|
|
|
|
this.set('visibility', get(visibility, 'value'));
|
|
|
|
}
|
2020-06-09 14:19:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
changeAuthor(author) {
|
|
|
|
this.set('author', get(author, 'slug'));
|
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
changeTag(tag) {
|
|
|
|
this.set('tag', get(tag, 'slug'));
|
|
|
|
}
|
2017-03-07 20:36:28 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
changeOrder(order) {
|
|
|
|
this.set('order', get(order, 'value'));
|
|
|
|
}
|
2017-07-13 12:55:13 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
openEditor(post) {
|
|
|
|
this.transitionToRoute('editor.edit', 'post', post.get('id'));
|
2017-02-23 21:47:52 +03:00
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|