Move sorted contributors to kredits service
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
import Component from '@ember/component';
|
import Component from '@ember/component';
|
||||||
import { computed } from '@ember/object';
|
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 { assign } from '@ember/polyfills';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import { inject as service } from '@ember/service';
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
|
kredits: service(),
|
||||||
|
|
||||||
attributes: null,
|
attributes: null,
|
||||||
contributors: Object.freeze([]),
|
contributors: alias('kredits.contributorsSorted'),
|
||||||
|
|
||||||
isValidContributor: notEmpty('contributorId'),
|
isValidContributor: notEmpty('contributorId'),
|
||||||
isValidKind: notEmpty('kind'),
|
isValidKind: notEmpty('kind'),
|
||||||
@@ -72,7 +74,5 @@ export default Component.extend({
|
|||||||
})
|
})
|
||||||
.finally(() => this.set('inProgress', false));
|
.finally(() => this.set('inProgress', false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import Kredits from 'kredits-contracts';
|
|||||||
import Service from '@ember/service';
|
import Service from '@ember/service';
|
||||||
import EmberObject from '@ember/object';
|
import EmberObject from '@ember/object';
|
||||||
import { computed } 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 { isEmpty, isPresent } from '@ember/utils';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
|
|
||||||
@@ -39,6 +39,10 @@ export default Service.extend({
|
|||||||
currentUserIsCore: alias('currentUser.isCore'),
|
currentUserIsCore: alias('currentUser.isCore'),
|
||||||
hasAccounts: notEmpty('currentUserAccounts'),
|
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
|
// When data was loaded from cache, we need to fetch updates from the network
|
||||||
contributorsNeedSync: false,
|
contributorsNeedSync: false,
|
||||||
contributionsNeedSync: false,
|
contributionsNeedSync: false,
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<AddContribution @contributors={{this.sortedContributors}}
|
<AddContribution @attributes={{this.model.params}}
|
||||||
@attributes={{this.model.params}}
|
|
||||||
@save={{action "save"}} />
|
@save={{action "save"}} />
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -49,4 +49,12 @@ module('Unit | Service | kredits', function(hooks) {
|
|||||||
assert.equal(c3.amountUnconfirmed, 5000, 'correct amount unconfirmed');
|
assert.equal(c3.amountUnconfirmed, 5000, 'correct amount unconfirmed');
|
||||||
assert.equal(c3.amountTotal, 5000, 'correct amount total');
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user