@@ -9,7 +9,15 @@ export default Component.extend({
|
||||
kredits: service(),
|
||||
|
||||
attributes: null,
|
||||
contributors: alias('kredits.contributorsSorted'),
|
||||
|
||||
contributors: computed('kredits.contributorsSorted.[]', function() {
|
||||
return this.kredits.contributorsSorted.map(c => {
|
||||
return {
|
||||
id: c.id.toString(),
|
||||
name: c.name
|
||||
}
|
||||
})
|
||||
}),
|
||||
|
||||
isValidContributor: notEmpty('contributorId'),
|
||||
isValidKind: notEmpty('kind'),
|
||||
@@ -57,6 +65,8 @@ export default Component.extend({
|
||||
|
||||
const attributes = this.getProperties(Object.keys(this.attributes));
|
||||
|
||||
attributes.contributorId = parseInt(this.contributorId);
|
||||
|
||||
let dateInput = (attributes.date instanceof Array) ?
|
||||
attributes.date[0] : attributes.date;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<p>
|
||||
<select required onchange={{action (mut this.contributorId) value="target.value"}}>
|
||||
<option value="" selected disabled hidden></option>
|
||||
{{#each @contributors as |contributor|}}
|
||||
{{#each this.contributors as |contributor|}}
|
||||
<option value={{contributor.id}} selected={{eq this.contributorId contributor.id}}>{{contributor.name}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
|
||||
@@ -24,10 +24,9 @@ export default Component.extend({
|
||||
contributors: sort('kredits.contributors', 'contributorsSorting'),
|
||||
|
||||
contributorsActive: computed('contributors.[]', 'contributions', function() {
|
||||
const activeIds = new Set(this.contributions.mapBy('contributorId')
|
||||
.map(id => id.toString()));
|
||||
const activeIds = new Set(this.contributions.mapBy('contributorId'));
|
||||
|
||||
return this.contributors.filter(c => activeIds.has(c.id.toString()));
|
||||
return this.contributors.filter(c => activeIds.has(c.id));
|
||||
}),
|
||||
|
||||
contributionKinds: computed('contributions.[]', function() {
|
||||
@@ -42,7 +41,7 @@ export default Component.extend({
|
||||
c.amount <= 500) { included = false; }
|
||||
|
||||
if (isPresent(this.contributorId) &&
|
||||
c.contributorId.toString() !== this.contributorId.toString()) { included = false; }
|
||||
c.contributorId !== parseInt(this.contributorId)) { included = false; }
|
||||
|
||||
if (isPresent(this.contributionKind) &&
|
||||
c.kind !== this.contributionKind) { included = false; }
|
||||
|
||||
@@ -3,7 +3,6 @@ import { isEmpty, isPresent } from '@ember/utils';
|
||||
import moment from 'moment';
|
||||
|
||||
export default EmberObject.extend({
|
||||
|
||||
// Contract
|
||||
id: null,
|
||||
contributorId: null,
|
||||
@@ -48,5 +47,4 @@ export default EmberObject.extend({
|
||||
serialize () {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -22,5 +22,4 @@ export default EmberObject.extend({
|
||||
serialize () {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -6,19 +6,15 @@ export default Route.extend({
|
||||
kredits: service(),
|
||||
|
||||
model(params) {
|
||||
const contribution = this.kredits.contributions.findBy('id', parseInt(params.id));
|
||||
contribution.contributorId = contribution.contributorId.toString();
|
||||
|
||||
return contribution;
|
||||
return this.kredits.contributions.findBy('id', parseInt(params.id));
|
||||
},
|
||||
|
||||
setupController (controller, model) {
|
||||
this._super(controller, model);
|
||||
|
||||
controller.set('attributes', model.getProperties([
|
||||
'kind', 'amount', 'description', 'url', 'details'
|
||||
'contributorId', 'kind', 'amount', 'description', 'url', 'details'
|
||||
]));
|
||||
controller.set('attributes.contributorId', model.contributorId.toString());
|
||||
controller.set('attributes.date', model.jsDate);
|
||||
}
|
||||
|
||||
|
||||
+15
-13
@@ -160,12 +160,12 @@ export default Service.extend({
|
||||
kreditsByContributor: computed('contributionsUnconfirmed.@each.vetoed', 'contributors.[]', function() {
|
||||
const contributionsUnconfirmed = this.contributionsUnconfirmed.filterBy('vetoed', false);
|
||||
const contributionsGrouped = groupBy(contributionsUnconfirmed, 'contributorId');
|
||||
const contributorsWithUnconfirmed = contributionsGrouped.map(c => c.value.toString());
|
||||
const contributorsWithUnconfirmed = contributionsGrouped.map(c => c.value);
|
||||
const contributorsWithOnlyConfirmed = this.contributors.reject(c => contributorsWithUnconfirmed.includes(c.id))
|
||||
|
||||
const kreditsByContributor = contributionsGrouped.map(c => {
|
||||
const amountUnconfirmed = c.items.mapBy('amount').reduce((a, b) => a + b);
|
||||
const contributor = this.contributors.findBy('id', c.value.toString());
|
||||
const contributor = this.contributors.findBy('id', c.value);
|
||||
|
||||
return EmberObject.create({
|
||||
contributor: contributor,
|
||||
@@ -275,7 +275,7 @@ export default Service.extend({
|
||||
});
|
||||
},
|
||||
|
||||
loadContributorFromData(data) {
|
||||
loadContributorFromData (data) {
|
||||
const contributor = Contributor.create(processContributorData(data));
|
||||
const loadedContributor = this.contributors.findBy('id', contributor.id);
|
||||
if (loadedContributor) { this.contributors.removeObject(loadedContributor); }
|
||||
@@ -285,7 +285,7 @@ export default Service.extend({
|
||||
|
||||
async cacheLoadedContributors () {
|
||||
for (const c of this.contributors) {
|
||||
await this.browserCache.contributors.setItem(c.id, c.serialize());
|
||||
await this.browserCache.contributors.setItem(c.id.toString(), c.serialize());
|
||||
}
|
||||
console.debug(`[kredits] Cached ${this.contributors.length} contributors in browser storage`);
|
||||
return Promise.resolve();
|
||||
@@ -340,7 +340,7 @@ export default Service.extend({
|
||||
|
||||
loadContributionFromData(data) {
|
||||
const contribution = Contribution.create(processContributionData(data));
|
||||
contribution.set('contributor', this.contributors.findBy('id', data.contributorId.toString()));
|
||||
contribution.set('contributor', this.contributors.findBy('id', data.contributorId));
|
||||
const loadedContribution = this.contributions.findBy('id', contribution.id);
|
||||
if (loadedContribution) { this.contributions.removeObject(loadedContribution); }
|
||||
this.contributions.pushObject(contribution);
|
||||
@@ -349,7 +349,7 @@ export default Service.extend({
|
||||
|
||||
async cacheLoadedContributions () {
|
||||
for (const c of this.contributions) {
|
||||
await this.browserCache.contributions.setItem(c.id, c.serialize());
|
||||
await this.browserCache.contributions.setItem(c.id.toString(), c.serialize());
|
||||
}
|
||||
console.debug(`[kredits] Cached ${this.contributions.length} contributions in browser storage`);
|
||||
return Promise.resolve();
|
||||
@@ -575,7 +575,7 @@ export default Service.extend({
|
||||
|
||||
loadReimbursementFromData(data) {
|
||||
const obj = Reimbursement.create(processReimbursementData(data));
|
||||
obj.set('contributor', this.contributors.findBy('id', data.recipientId.toString()));
|
||||
obj.set('contributor', this.contributors.findBy('id', data.recipientId));
|
||||
this.removeObjectFromCollectionIfLoaded('reimbursements', obj.id);
|
||||
this.reimbursements.pushObject(obj);
|
||||
return obj;
|
||||
@@ -589,7 +589,7 @@ export default Service.extend({
|
||||
console.debug('[kredits] add reimbursement response', data);
|
||||
const reimbursement = Reimbursement.create(attributes);
|
||||
reimbursement.setProperties({
|
||||
contributor: this.contributors.findBy('id', attributes.recipientId.toString()),
|
||||
contributor: this.contributors.findBy('id', attributes.recipientId),
|
||||
pendingTx: data,
|
||||
confirmedAt: this.currentBlock + 40320
|
||||
});
|
||||
@@ -645,13 +645,15 @@ export default Service.extend({
|
||||
const contributorData = await this.kredits.Contributor.getById(contributorId);
|
||||
const newContributor = Contributor.create(contributorData);
|
||||
|
||||
const oldContributor = this.contributors.findBy('id', contributorId.toString());
|
||||
// TODO check for actual differences in the contributor data first
|
||||
|
||||
const oldContributor = this.contributors.findBy('id', contributorId);
|
||||
if (oldContributor) {
|
||||
console.debug('[kredits] old contributor', oldContributor);
|
||||
// console.debug('[kredits] cached contributor', oldContributor);
|
||||
this.contributors.removeObject(oldContributor);
|
||||
}
|
||||
|
||||
console.debug('[kredits] new contributor', newContributor);
|
||||
// console.debug('[kredits] incoming contributor data', newContributor);
|
||||
this.contributors.pushObject(newContributor);
|
||||
},
|
||||
|
||||
@@ -660,13 +662,13 @@ export default Service.extend({
|
||||
|
||||
const pendingContribution = this.contributions.find(c => {
|
||||
return (c.id === null) &&
|
||||
(c.contributorId.toString() === contributorId.toString()) &&
|
||||
(c.contributorId === contributorId) &&
|
||||
(c.amount.toString() === amount.toString());
|
||||
});
|
||||
|
||||
if (pendingContribution) {
|
||||
const attributes = await this.kredits.Contribution.getById(id);
|
||||
attributes.contributor = this.contributors.findBy('id', attributes.contributorId.toString());
|
||||
attributes.contributor = this.contributors.findBy('id', attributes.contributorId);
|
||||
const newContribution = Contribution.create(attributes);
|
||||
this.contributions.addObject(newContribution);
|
||||
this.contributions.removeObject(pendingContribution);
|
||||
|
||||
@@ -8,9 +8,8 @@ export default function processContributionData(data) {
|
||||
}
|
||||
|
||||
const otherProperties = [
|
||||
'id', 'contributorId', 'amount', 'vetoed',
|
||||
'ipfsHash', 'kind', 'description', 'details',
|
||||
'url', 'date', 'time', 'pendingTx'
|
||||
'id', 'contributorId', 'amount', 'vetoed', 'ipfsHash', 'kind',
|
||||
'description', 'details', 'url', 'date', 'time', 'pendingTx'
|
||||
];
|
||||
|
||||
otherProperties.forEach(prop => {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
export default function processContributorData(data) {
|
||||
const processed = {
|
||||
id: data.id.toString(),
|
||||
balance: data.balanceInt,
|
||||
totalKreditsEarned: data.totalKreditsEarned,
|
||||
contributionsCount: data.contributionsCount?.toNumber()
|
||||
}
|
||||
|
||||
const otherProperties = [
|
||||
'account', 'accounts', 'ipfsHash', 'isCore', 'kind', 'name', 'url',
|
||||
'id', 'account', 'accounts', 'ipfsHash', 'isCore', 'kind', 'name', 'url',
|
||||
'github_username', 'github_uid', 'wiki_username', 'zoom_display_name'
|
||||
];
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -18,7 +18,7 @@ const data = [
|
||||
|
||||
data.forEach(attrs => {
|
||||
const c = Model.create(processContributionData(attrs));
|
||||
c.set('contributor', contributors.findBy('id', attrs.contributorId.toString()));
|
||||
c.set('contributor', contributors.findBy('id', attrs.contributorId));
|
||||
items.push(c);
|
||||
});
|
||||
|
||||
|
||||
Vendored
+3
-3
@@ -4,9 +4,9 @@ import processContributorData from 'kredits-web/utils/process-contributor-data';
|
||||
const contributors = [];
|
||||
|
||||
const data = [
|
||||
{ id: '1', name: 'Bumi', totalKreditsEarned: 11500, github_uid: 318 },
|
||||
{ id: '2', name: 'Râu Cao', totalKreditsEarned: 3000, github_uid: 842 },
|
||||
{ id: '3', name: 'Manuel', totalKreditsEarned: 0, github_uid: 54812 }
|
||||
{ id: 1, name: 'Bumi', totalKreditsEarned: 11500, github_uid: 318 },
|
||||
{ id: 2, name: 'Râu Cao', totalKreditsEarned: 3000, github_uid: 842 },
|
||||
{ id: 3, name: 'Manuel', totalKreditsEarned: 0, github_uid: 54812 }
|
||||
];
|
||||
|
||||
data.forEach(attrs => {
|
||||
|
||||
@@ -16,8 +16,10 @@ module('Integration | Component | contribution-list', function(hooks) {
|
||||
});
|
||||
|
||||
test('it renders filtered contributions', async function(assert) {
|
||||
let service = this.owner.lookup('service:kredits');
|
||||
service.set('contributors', contributors);
|
||||
let kredits = this.owner.lookup('service:kredits');
|
||||
kredits.set('contributors', contributors);
|
||||
|
||||
debugger;
|
||||
|
||||
this.set('fixtures', contributions);
|
||||
await render(hbs`{{contribution-list contributions=fixtures showQuickFilter=true}}`);
|
||||
|
||||
@@ -8,14 +8,14 @@ module('Integration | Component | user-avatar', function(hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function(assert) {
|
||||
this.set('bumi', contributors.findBy('id', '1'));
|
||||
this.set('bumi', contributors.findBy('id', 1));
|
||||
await render(hbs`{{user-avatar contributor=bumi}}`);
|
||||
|
||||
assert.dom(this.element).hasText('');
|
||||
});
|
||||
|
||||
test('default image source URL', async function(assert) {
|
||||
this.set('bumi', contributors.findBy('id', '1'));
|
||||
this.set('bumi', contributors.findBy('id', 1));
|
||||
await render(hbs`{{user-avatar contributor=bumi}}`);
|
||||
|
||||
assert.equal(this.element.querySelector('img').src,
|
||||
@@ -23,7 +23,7 @@ module('Integration | Component | user-avatar', function(hooks) {
|
||||
});
|
||||
|
||||
test('size-specific image source URLs', async function(assert) {
|
||||
this.set('bumi', contributors.findBy('id', '1'));
|
||||
this.set('bumi', contributors.findBy('id', 1));
|
||||
this.set('size', 'medium');
|
||||
|
||||
await render(hbs`{{user-avatar contributor=bumi size=size}}`);
|
||||
|
||||
@@ -8,7 +8,7 @@ module('Unit | Utility | process-contributor-data', function() {
|
||||
|
||||
test('formats the data correctly', function(assert) {
|
||||
// TODO use integers everywhere for IDs
|
||||
assert.ok(typeof result.id === 'string');
|
||||
assert.ok(typeof result.id === 'number');
|
||||
assert.ok(typeof result.balance === 'number');
|
||||
assert.ok(typeof result.totalKreditsEarned === 'number');
|
||||
assert.ok(typeof result.contributionsCount === 'number');
|
||||
|
||||
Reference in New Issue
Block a user