Move sorted contributors to kredits service

This commit is contained in:
2020-08-12 22:51:52 +02:00
parent ef0fc11edf
commit f63d14d7b4
4 changed files with 18 additions and 7 deletions
+4 -4
View File
@@ -1,13 +1,15 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import { and, notEmpty } from '@ember/object/computed';
import { alias, and, notEmpty } from '@ember/object/computed';
import { assign } from '@ember/polyfills';
import moment from 'moment';
import { inject as service } from '@ember/service';
export default Component.extend({
kredits: service(),
attributes: null,
contributors: Object.freeze([]),
contributors: alias('kredits.contributorsSorted'),
isValidContributor: notEmpty('contributorId'),
isValidKind: notEmpty('kind'),
@@ -72,7 +74,5 @@ export default Component.extend({
})
.finally(() => this.set('inProgress', false));
}
}
});
+5 -1
View File
@@ -4,7 +4,7 @@ import Kredits from 'kredits-contracts';
import Service from '@ember/service';
import EmberObject from '@ember/object';
import { computed } from '@ember/object';
import { alias, notEmpty } from '@ember/object/computed';
import { alias, filterBy, notEmpty, sort } from '@ember/object/computed';
import { isEmpty, isPresent } from '@ember/utils';
import { inject as service } from '@ember/service';
@@ -39,6 +39,10 @@ export default Service.extend({
currentUserIsCore: alias('currentUser.isCore'),
hasAccounts: notEmpty('currentUserAccounts'),
contributorsMined: filterBy('contributors', 'id'),
contributorsSorting: Object.freeze(['name:asc']),
contributorsSorted: sort('contributorsMined', 'contributorsSorting'),
// When data was loaded from cache, we need to fetch updates from the network
contributorsNeedSync: false,
contributionsNeedSync: false,
+1 -2
View File
@@ -6,8 +6,7 @@
</header>
<div class="content">
<AddContribution @contributors={{this.sortedContributors}}
@attributes={{this.model.params}}
<AddContribution @attributes={{this.model.params}}
@save={{action "save"}} />
</div>
</section>
+8
View File
@@ -49,4 +49,12 @@ module('Unit | Service | kredits', function(hooks) {
assert.equal(c3.amountUnconfirmed, 5000, 'correct amount unconfirmed');
assert.equal(c3.amountTotal, 5000, 'correct amount total');
});
test('#contributorsSorted', function(assert) {
let service = this.owner.lookup('service:kredits');
service.set('contributors', contributors);
assert.ok(service.contributorsSorted instanceof Array, 'is an array');
assert.equal(service.contributorsSorted[1].name, 'Manuel', 'sorts by name');
});
});