2021-05-07 12:02:19 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-02-09 13:49:38 +03:00
|
|
|
import {task, taskGroup} from 'ember-concurrency';
|
2021-05-07 12:02:19 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
|
|
|
|
export default class GhMembersSegmentCountComponent extends Component {
|
|
|
|
@service store;
|
2021-05-07 12:25:44 +03:00
|
|
|
@service session;
|
2024-01-13 21:13:49 +03:00
|
|
|
@service membersCountCache;
|
2021-05-07 12:02:19 +03:00
|
|
|
|
|
|
|
@tracked total = 0;
|
|
|
|
@tracked segmentTotal = 0;
|
|
|
|
|
|
|
|
@taskGroup fetchTasks;
|
|
|
|
|
|
|
|
@task({group: 'fetchTasks'})
|
|
|
|
*fetchTotalsTask() {
|
|
|
|
this.fetchSegmentTotalTask.perform();
|
|
|
|
|
2021-05-07 14:04:01 +03:00
|
|
|
const filter = this.args.enforcedFilter || undefined;
|
2024-01-13 21:13:49 +03:00
|
|
|
this.total = yield this.membersCountCache.count({filter});
|
2021-05-07 12:02:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@task({group: 'fetchTasks'})
|
|
|
|
*fetchSegmentTotalTask() {
|
|
|
|
if (!this.args.segment) {
|
|
|
|
return this.segmentTotal = 0;
|
|
|
|
}
|
|
|
|
|
2021-05-07 14:04:01 +03:00
|
|
|
let filter;
|
|
|
|
|
|
|
|
if (this.args.enforcedFilter) {
|
|
|
|
filter = `${this.args.enforcedFilter}+(${this.args.segment})`;
|
|
|
|
} else {
|
|
|
|
filter = this.args.segment;
|
|
|
|
}
|
|
|
|
|
|
|
|
const members = yield this.store.query('member', {limit: 1, filter});
|
2021-05-07 12:02:19 +03:00
|
|
|
this.segmentTotal = members.meta.pagination.total;
|
2021-05-07 13:58:05 +03:00
|
|
|
this.args.onSegmentCountChange?.(this.segmentTotal);
|
2021-05-07 12:02:19 +03:00
|
|
|
}
|
|
|
|
}
|