mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
b905085d6f
fixes https://github.com/TryGhost/Team/issues/1993 - Allows filtering members by opened, clicked and received email - Adds clicked_links filter relation to Member model. - Adds emails filter relation to Member model. - Adds opened_emails filter expansion to Member model. - Updated GhResourceSelect to be able to only show list posts by setting the `type` attribute to `email`. - Improved code reuse in `filter-value` component.
99 lines
2.5 KiB
JavaScript
99 lines
2.5 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class GhResourceSelect extends Component {
|
|
@service store;
|
|
|
|
@tracked _options = [];
|
|
|
|
get renderInPlace() {
|
|
return this.args.renderInPlace === undefined ? false : this.args.renderInPlace;
|
|
}
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.fetchOptionsTask.perform();
|
|
}
|
|
|
|
get options() {
|
|
return this._options;
|
|
}
|
|
|
|
get flatOptions() {
|
|
const options = [];
|
|
|
|
function getOptions(option) {
|
|
if (option.options) {
|
|
return option.options.forEach(getOptions);
|
|
}
|
|
|
|
options.push(option);
|
|
}
|
|
|
|
this._options.forEach(getOptions);
|
|
|
|
return options;
|
|
}
|
|
|
|
get selectedOptions() {
|
|
const resources = this.args.resources || [];
|
|
return this.flatOptions.filter(option => resources.find(resource => resource.id === option.id));
|
|
}
|
|
|
|
@action
|
|
onChange(options) {
|
|
this.args.onChange(options);
|
|
}
|
|
|
|
get placeholderText() {
|
|
if (this.args.type === 'email') {
|
|
return 'Select an email';
|
|
}
|
|
return 'Select a page/post';
|
|
}
|
|
|
|
@task
|
|
*fetchOptionsTask() {
|
|
const options = yield [];
|
|
|
|
if (this.args.type === 'email') {
|
|
const posts = yield this.store.query('post', {filter: '(status:published,status:sent)+newsletter_id:-null', limit: 'all'});
|
|
options.push({
|
|
groupName: 'Emails',
|
|
options: posts.map(mapResource)
|
|
});
|
|
this._options = options;
|
|
return;
|
|
}
|
|
|
|
const posts = yield this.store.query('post', {filter: 'status:published', limit: 'all'});
|
|
const pages = yield this.store.query('page', {filter: 'status:published', limit: 'all'});
|
|
|
|
function mapResource(resource) {
|
|
return {
|
|
name: resource.title,
|
|
id: resource.id
|
|
};
|
|
}
|
|
|
|
if (posts.length > 0) {
|
|
options.push({
|
|
groupName: 'Posts',
|
|
options: posts.map(mapResource)
|
|
});
|
|
}
|
|
|
|
if (pages.length > 0) {
|
|
options.push({
|
|
groupName: 'Pages',
|
|
options: pages.map(mapResource)
|
|
});
|
|
}
|
|
|
|
this._options = options;
|
|
}
|
|
}
|