mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
24b222e927
refs https://github.com/TryGhost/Team/issues/559 Members controller was becoming bloated and difficult to follow due to catering for many different concerns. - converted old modal to newer promise-modal style - pulled full label-adding logic out of the members controller and into the modal so logic is contained in one place - added `{{members-count-fetcher}}` resource that allows for member counts to be fetched directly from templates avoiding duplicated code
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import {Resource} from 'ember-could-get-used-to-this';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class MembersCount extends Resource {
|
|
@service store;
|
|
|
|
@tracked count = null;
|
|
|
|
get value() {
|
|
return {
|
|
isLoading: this.fetchMembersTask.isRunning,
|
|
count: this.count
|
|
};
|
|
}
|
|
|
|
setup() {
|
|
const query = this.args.named.query || {};
|
|
this._query = query;
|
|
this.fetchMembersTask.perform({query});
|
|
}
|
|
|
|
update() {
|
|
// required due to a weird invalidation issue when using Ember Data with ember-could-get-used-to-this
|
|
// TODO: re-test after upgrading to ember-resources
|
|
if (this.args.named.query !== this._query) {
|
|
const query = this.args.named.query || {};
|
|
this._query = query;
|
|
this.fetchMembersTask.perform({query});
|
|
}
|
|
}
|
|
|
|
@task
|
|
*fetchMembersTask({query} = {}) {
|
|
const result = yield this.store.query('member', {...query, limit: 1});
|
|
this.count = result.meta.pagination.total;
|
|
}
|
|
}
|