Files
kredits-web/app/models/contribution.js
T
raucao 33a429c448
CI / Lint (pull_request) Successful in 51s
CI / Test (pull_request) Successful in 1m33s
Group same contributions without URL, make grouping more precise
2026-07-26 17:22:53 +02:00

61 lines
1.5 KiB
JavaScript

import EmberObject, { computed } from '@ember/object';
import { isEmpty, isPresent } from '@ember/utils';
import moment from 'moment';
import contributionGroupingKey from 'kredits-web/utils/contribution-grouping-key';
export default EmberObject.extend({
// Contract
id: null,
contributorId: null,
amount: null,
confirmedAt: null,
vetoed: null,
ipfsHash: null,
// contributor model instance
contributor: null,
// TODO contributor who submitted the contribution
// submittedBy: null,
// IPFS
kind: null,
description: null,
details: null,
url: null,
date: null,
time: null,
pendingTx: null,
init () {
this._super(...arguments);
if (isEmpty(this.details)) this.set('details', {});
},
iso8601Date: computed('date', 'time', function() {
return this.time ? `${this.date}T${this.time}` : this.date;
}),
jsDate: computed('iso8601Date', function() {
return moment(this.iso8601Date).toDate();
}),
hasPendingChanges: computed('pendingTx', function() {
return isPresent(this.pendingTx);
}),
// Stable key shared by all per-contributor contributions created for the
// same piece of work (derived from `url`, `description`, `date`, `amount`,
// and `kind`). Contributions without enough fields to derive a key return
// null and are treated as singletons (not grouped).
groupId: computed('url', 'description', 'date', 'amount', 'kind', function() {
return contributionGroupingKey(this);
}),
serialize () {
return JSON.stringify(this);
}
});