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;
|
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;
|
|
|
|
|
|
|
|
const members = yield this.store.query('member', {limit: 1, filter});
|
2021-05-07 12:02:19 +03:00
|
|
|
this.total = members.meta.pagination.total;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
}
|