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