mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Added <GhMembersFilterCount @filter="..." />
no issue - added generic members filter component - updated `<GhRecipientFilterCount />` to use the new generic component with `subscribed:true` added to the filter
This commit is contained in:
parent
937eac51ad
commit
9adfad67d2
5 changed files with 31 additions and 31 deletions
1
ghost/admin/app/components/gh-members-filter-count.hbs
Normal file
1
ghost/admin/app/components/gh-members-filter-count.hbs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{this.memberCount}}
|
23
ghost/admin/app/components/gh-members-filter-count.js
Normal file
23
ghost/admin/app/components/gh-members-filter-count.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import Component from '@glimmer/component';
|
||||||
|
import {inject as service} from '@ember/service';
|
||||||
|
import {task} from 'ember-concurrency-decorators';
|
||||||
|
import {tracked} from '@glimmer/tracking';
|
||||||
|
|
||||||
|
export default class GhMembersFilterCountComponent extends Component {
|
||||||
|
@service membersCountCache;
|
||||||
|
|
||||||
|
@tracked memberCount;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
this.getMembersCountTask.perform();
|
||||||
|
}
|
||||||
|
|
||||||
|
@task
|
||||||
|
*getMembersCountTask() {
|
||||||
|
this.memberCount = yield this.membersCountCache.countString(
|
||||||
|
this.args.filter,
|
||||||
|
{knownCount: this.args.knownCount}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1,5 @@
|
||||||
{{this.recipientCount}}
|
{{#if @filter}}
|
||||||
|
<GhMembersFilterCount @filter={{concat "subscribed:true+(" @filter ")"}} @knownCount={{@knownCount}} />
|
||||||
|
{{else}}
|
||||||
|
no members
|
||||||
|
{{/if}}
|
|
@ -1,28 +0,0 @@
|
||||||
import Component from '@glimmer/component';
|
|
||||||
import {inject as service} from '@ember/service';
|
|
||||||
import {task} from 'ember-concurrency-decorators';
|
|
||||||
import {tracked} from '@glimmer/tracking';
|
|
||||||
|
|
||||||
export default class GhRecipientFilterCountComponent extends Component {
|
|
||||||
@service membersCountCache;
|
|
||||||
|
|
||||||
@tracked recipientCount;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super(...arguments);
|
|
||||||
this.getRecipientCountTask.perform();
|
|
||||||
}
|
|
||||||
|
|
||||||
@task
|
|
||||||
*getRecipientCountTask() {
|
|
||||||
if (!this.args.filter) {
|
|
||||||
this.recipientCount = 'no members';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.recipientCount = yield this.membersCountCache.countString(
|
|
||||||
`subscribed:true+(${this.args.filter})`,
|
|
||||||
{knownCount: this.args.knownCount}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,14 +24,14 @@ export default class MembersCountCacheService extends Service {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
async countString(filter, {knownCount} = {}) {
|
async countString(filter = '', {knownCount} = {}) {
|
||||||
const user = await this.session.user;
|
const user = await this.session.user;
|
||||||
|
|
||||||
const basicFilter = filter.replace(/^subscribed:true\+\((.*)\)$/, '$1');
|
const basicFilter = filter.replace(/^subscribed:true\+\((.*)\)$/, '$1');
|
||||||
const filterParts = basicFilter.split(',');
|
const filterParts = basicFilter.split(',');
|
||||||
const isFree = filterParts.length === 1 && filterParts[0] === 'status:free';
|
const isFree = filterParts.length === 1 && filterParts[0] === 'status:free';
|
||||||
const isPaid = filterParts.length === 1 && filterParts[0] === 'status:-free';
|
const isPaid = filterParts.length === 1 && filterParts[0] === 'status:-free';
|
||||||
const isAll = filterParts.includes('status:free') && filterParts.includes('status:-free');
|
const isAll = !filter || (filterParts.includes('status:free') && filterParts.includes('status:-free');)
|
||||||
|
|
||||||
// editors don't have permission to browse members so can't retrieve a count
|
// editors don't have permission to browse members so can't retrieve a count
|
||||||
// TODO: remove when editors have relevant permissions or we have a different way of fetching counts
|
// TODO: remove when editors have relevant permissions or we have a different way of fetching counts
|
||||||
|
|
Loading…
Add table
Reference in a new issue