2017-08-22 10:53:26 +03:00
|
|
|
import Controller from '@ember/controller';
|
2023-04-04 15:43:43 +03:00
|
|
|
import SelectionList from 'ghost-admin/utils/selection-list';
|
2020-02-03 19:27:42 +03:00
|
|
|
import {DEFAULT_QUERY_PARAMS} from 'ghost-admin/helpers/reset-query-params';
|
2022-10-07 20:39:34 +03:00
|
|
|
import {action} from '@ember/object';
|
2022-11-03 14:14:36 +03:00
|
|
|
import {inject} from 'ghost-admin/decorators/inject';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-10-07 20:39:34 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
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'
|
2023-04-14 11:38:16 +03:00
|
|
|
}, {
|
|
|
|
name: 'Email only posts',
|
|
|
|
value: 'sent'
|
2017-11-24 21:53:19 +03:00
|
|
|
}, {
|
|
|
|
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',
|
2023-10-03 12:13:11 +03:00
|
|
|
value: '[paid,tiers]'
|
2020-06-09 14:19:25 +03:00
|
|
|
}];
|
|
|
|
|
2017-11-24 21:53:19 +03:00
|
|
|
const ORDERS = [{
|
2022-10-06 12:23:49 +03:00
|
|
|
name: 'Newest first',
|
2017-11-24 21:53:19 +03:00
|
|
|
value: null
|
|
|
|
}, {
|
2022-10-06 12:23:49 +03:00
|
|
|
name: 'Oldest first',
|
2017-11-24 21:53:19 +03:00
|
|
|
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
|
|
|
export default class PostsController extends Controller {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service feature;
|
2022-10-07 20:39:34 +03:00
|
|
|
@service router;
|
2022-02-01 20:03:45 +03:00
|
|
|
@service session;
|
|
|
|
@service store;
|
2022-02-01 20:59:20 +03:00
|
|
|
|
2022-11-03 14:14:36 +03:00
|
|
|
@inject config;
|
|
|
|
|
2022-10-07 20:39:34 +03:00
|
|
|
// default values for these are set in constructor and defined in `helpers/reset-query-params`
|
|
|
|
queryParams = ['type', 'visibility', 'author', 'tag', 'order'];
|
|
|
|
|
|
|
|
@tracked type = null;
|
|
|
|
@tracked visibility = null;
|
|
|
|
@tracked author = null;
|
|
|
|
@tracked tag = null;
|
|
|
|
@tracked order = null;
|
2023-04-04 15:43:43 +03:00
|
|
|
@tracked selectionList = new SelectionList(this.postsInfinityModel);
|
2022-10-07 20:39:34 +03:00
|
|
|
|
|
|
|
availableTypes = TYPES;
|
|
|
|
availableVisibilities = VISIBILITIES;
|
|
|
|
availableOrders = ORDERS;
|
|
|
|
|
|
|
|
_availableTags = this.store.peekAll('tag');
|
|
|
|
_availableAuthors = this.store.peekAll('user');
|
2017-02-23 21:47:52 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
_hasLoadedTags = false;
|
|
|
|
_hasLoadedAuthors = false;
|
2022-10-07 20:39:34 +03:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
|
|
|
|
Object.assign(this, DEFAULT_QUERY_PARAMS.posts);
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2018-03-19 14:54:54 +03:00
|
|
|
|
2022-10-07 20:39:34 +03:00
|
|
|
get postsInfinityModel() {
|
|
|
|
return this.model;
|
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2023-03-21 12:24:56 +03:00
|
|
|
get totalPosts() {
|
|
|
|
return this.model.meta?.pagination?.total ?? 0;
|
|
|
|
}
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
get showingAll() {
|
2022-10-07 20:39:34 +03:00
|
|
|
const {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
|
|
|
get selectedType() {
|
2022-10-07 20:39:34 +03:00
|
|
|
return this.availableTypes.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
|
|
|
get selectedVisibility() {
|
2022-10-07 20:39:34 +03:00
|
|
|
return this.availableVisibilities.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
|
|
|
get selectedOrder() {
|
2022-10-07 20:39:34 +03:00
|
|
|
return this.availableOrders.findBy('value', this.order) || {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
|
|
|
get availableTags() {
|
2022-10-07 20:39:34 +03:00
|
|
|
const 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}));
|
2022-10-07 20:39:34 +03:00
|
|
|
|
|
|
|
const options = tags.toArray();
|
|
|
|
options.unshift({name: 'All tags', slug: null});
|
2017-03-02 21:35:09 +03:00
|
|
|
|
|
|
|
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
|
|
|
get selectedTag() {
|
2022-10-07 20:39:34 +03:00
|
|
|
const tag = this.tag;
|
|
|
|
const 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
|
|
|
get availableAuthors() {
|
2022-10-07 20:39:34 +03:00
|
|
|
const authors = this._availableAuthors;
|
|
|
|
const options = authors.toArray();
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-10-07 20:39:34 +03:00
|
|
|
options.unshift({name: 'All authors', slug: null});
|
2017-03-02 21:35:09 +03:00
|
|
|
|
|
|
|
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
|
|
|
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
|
|
|
@action
|
|
|
|
changeType(type) {
|
2022-10-07 20:39:34 +03:00
|
|
|
this.type = type.value;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
changeVisibility(visibility) {
|
2022-10-07 20:39:34 +03:00
|
|
|
this.visibility = visibility.value;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2020-06-09 14:19:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
changeAuthor(author) {
|
2022-10-07 20:39:34 +03:00
|
|
|
this.author = author.slug;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-02 21:35:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
changeTag(tag) {
|
2022-10-07 20:39:34 +03:00
|
|
|
this.tag = tag.slug;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-03-07 20:36:28 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
changeOrder(order) {
|
2022-10-07 20:39:34 +03:00
|
|
|
this.order = order.value;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2017-07-13 12:55:13 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
openEditor(post) {
|
2023-10-12 15:17:39 +03:00
|
|
|
this.router.transitionTo('lexical-editor.edit', 'post', post.id);
|
2017-02-23 21:47:52 +03:00
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|