mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
Fixed PublishOptions newsletter setup
refs https://github.com/TryGhost/Team/issues/1542 - assigning the result of `peekAll('newsletter').filter()` to `newsletters` doesn't work because the live peekAll array gets transformed to a static array so it was always blank - assigned result of `peekAll('newsletter')` to `allNewsletters` and replaced `newsletters` property with a getter that uses `allNewsletters` to return an array of filtered and sorted newsletters - fixed incorrect sort order for `defaultNewsletter` - assigned default newsletter to tracked `newsletter` property as part of setup once newsletters have been fetched - updated publish-flow template to show a real count and newsletter name
This commit is contained in:
parent
7ea5bdcdf8
commit
357bbf56cf
@ -33,11 +33,11 @@
|
||||
<div class="gh-publish-setting-title">
|
||||
{{svg-jar "member"}}
|
||||
<div class="gh-publish-setting-trigger">
|
||||
235
|
||||
{{#let (members-count-fetcher query=(hash filter=@data.publishOptions.recipientFilter)) as |countFetcher|}}
|
||||
{{countFetcher.count}}
|
||||
{{/let}}
|
||||
{{#unless @data.publishOptions.onlyDefaultNewsletter}}
|
||||
<span>
|
||||
Charts of the Week
|
||||
</span>
|
||||
<span>{{@data.publishOptions.newsletter.name}}</span>
|
||||
{{/unless}}
|
||||
subscribers
|
||||
</div>
|
||||
|
@ -112,19 +112,30 @@ export class PublishOptions {
|
||||
this.publishType = newValue;
|
||||
}
|
||||
|
||||
// newsletter --------------------------------------------------------------
|
||||
// recipients --------------------------------------------------------------
|
||||
|
||||
newsletters = []; // set in constructor
|
||||
// set in constructor because services are not injected
|
||||
allNewsletters = [];
|
||||
|
||||
@tracked newsletter = null; // set to default in constructor
|
||||
|
||||
get newsletters() {
|
||||
return this.allNewsletters
|
||||
.filter(n => n.status === 'active')
|
||||
.sort(({sortOrder: a}, {sortOrder: b}) => a - b);
|
||||
}
|
||||
|
||||
get defaultNewsletter() {
|
||||
return this.newsletters.sort(({sortOrder: a}, {sortOrder: b}) => b - a)[0];
|
||||
return this.newsletters[0];
|
||||
}
|
||||
|
||||
get onlyDefaultNewsletter() {
|
||||
return this.newsletters.length === 1;
|
||||
}
|
||||
|
||||
// recipients --------------------------------------------------------------
|
||||
get recipientFilter() {
|
||||
return `newsletters:${this.newsletter.slug}`;
|
||||
}
|
||||
|
||||
// setup -------------------------------------------------------------------
|
||||
|
||||
@ -138,7 +149,7 @@ export class PublishOptions {
|
||||
// these need to be set here rather than class-level properties because
|
||||
// unlike Ember-based classes the services are not injected so can't be
|
||||
// used until after they are assigned above
|
||||
this.newsletters = this.store.peekAll('newsletter').filter(n => n.status === 'active');
|
||||
this.allNewsletters = this.store.peekAll('newsletter');
|
||||
|
||||
this.setupTask.perform();
|
||||
}
|
||||
@ -149,6 +160,8 @@ export class PublishOptions {
|
||||
|
||||
// TODO: set up initial state / defaults
|
||||
|
||||
this.newsletter = this.defaultNewsletter;
|
||||
|
||||
if (this.emailUnavailable || this.emailDisabled) {
|
||||
this.publishType = 'publish';
|
||||
}
|
||||
@ -163,7 +176,7 @@ export class PublishOptions {
|
||||
// TODO: query limit service
|
||||
|
||||
// newsletters
|
||||
const fetchNewsletters = this.store.findAll('newsletter', {reload: true});
|
||||
const fetchNewsletters = this.store.query('newsletter', {status: 'active', limit: 'all'});
|
||||
|
||||
yield Promise.all([countTotalMembers, fetchNewsletters]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user