Make full data sync optional, start via button
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import Controller from '@ember/controller';
|
||||
import { computed } from '@ember/object';
|
||||
import { alias, not, sort } from '@ember/object/computed';
|
||||
import { alias, gt, not, sort } from '@ember/object/computed';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default Controller.extend({
|
||||
@@ -33,6 +33,8 @@ export default Controller.extend({
|
||||
showQuickFilterUnconfirmed: false,
|
||||
showQuickFilterConfirmed: false,
|
||||
|
||||
showFullContributionSync: gt('kredits.missingHistoricContributionsCount', 0),
|
||||
|
||||
showIntroText: computed('kredits.{hasAccounts,currentUser}', function(){
|
||||
return (!this.kredits.hasAccounts || !this.kredits.currentUser);
|
||||
}),
|
||||
|
||||
@@ -11,8 +11,11 @@ export default class DashboardRoute extends Route {
|
||||
schedule('afterRender', this.kredits.syncContributions,
|
||||
this.kredits.syncContributions.perform);
|
||||
}
|
||||
schedule('afterRender', this.kredits.fetchMissingContributions,
|
||||
this.kredits.fetchMissingContributions.perform);
|
||||
// TODO fetch automatically under a certain threshold
|
||||
// The browser might delete cached data and we don't need manual re-syncs
|
||||
// depending on how little is missing
|
||||
// schedule('afterRender', this.kredits.fetchMissingContributions,
|
||||
// this.kredits.fetchMissingContributions.perform);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-3
@@ -48,6 +48,8 @@ export default Service.extend({
|
||||
contributionsNeedSync: false,
|
||||
reimbursementsNeedSync: false,
|
||||
|
||||
missingHistoricContributionsCount: 0,
|
||||
|
||||
init () {
|
||||
this._super(...arguments);
|
||||
this.set('contributors', []);
|
||||
@@ -227,12 +229,20 @@ export default Service.extend({
|
||||
await this.loadObjectsFromCache('Contribution');
|
||||
this.set('contributionsNeedSync', true);
|
||||
} else {
|
||||
await this.fetchContributions({ page: { size: 30 } });
|
||||
await this.fetchContributions({ page: { size: 40 } });
|
||||
}
|
||||
|
||||
await this.updateMissingHistoricContributionsCount();
|
||||
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
async updateMissingHistoricContributionsCount () {
|
||||
const contributionsCount = await this.kredits.Contribution.count;
|
||||
this.set('missingHistoricContributionsCount', contributionsCount - this.contributions.length);
|
||||
console.debug(`Missing ${this.missingHistoricContributionsCount} historic contributions (out of ${contributionsCount} overall)`)
|
||||
},
|
||||
|
||||
addContributor (attributes) {
|
||||
if (attributes.github_uid) {
|
||||
const uidInt = parseInt(attributes.github_uid);
|
||||
@@ -368,11 +378,12 @@ export default Service.extend({
|
||||
syncContributions: task(function * () {
|
||||
yield this.fetchNewContributions.perform();
|
||||
yield this.syncUnconfirmedContributions.perform();
|
||||
yield this.updateMissingHistoricContributionsCount();
|
||||
this.set('contributionsNeedSync', false);
|
||||
}).group('contributionTasks'),
|
||||
|
||||
fetchNewContributions: task(function * () {
|
||||
const count = yield this.kredits.Contribution.functions.contributionsCount();
|
||||
const count = yield this.kredits.Contribution.count;
|
||||
const lastKnownContributionId = Math.max.apply(null, this.contributions.mapBy('id'));
|
||||
const toFetch = count - lastKnownContributionId;
|
||||
|
||||
@@ -389,7 +400,7 @@ export default Service.extend({
|
||||
}),
|
||||
|
||||
fetchMissingContributions: task(function * () {
|
||||
const count = yield this.kredits.Contribution.functions.contributionsCount();
|
||||
const count = yield this.kredits.Contribution.count;
|
||||
const allIds = [...Array(count+1).keys()];
|
||||
allIds.shift(); // remove first item, which is 0
|
||||
const loadedContributions = new Set(this.contributions.mapBy('id'));
|
||||
|
||||
@@ -105,6 +105,32 @@
|
||||
@showQuickFilter={{this.showQuickFilterConfirmed}} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{{#if this.showFullContributionSync}}
|
||||
<section id="sync-all-contributions">
|
||||
{{#if this.kredits.fetchMissingContributions.isIdle}}
|
||||
<p style="margin-bottom: 1rem;">
|
||||
There are
|
||||
<strong>{{this.kredits.missingHistoricContributionsCount}}</strong>
|
||||
contributions, which are not currently loaded/displayed.
|
||||
</p>
|
||||
<p>
|
||||
You can fetch all historic data in one go, and have it stored locally in
|
||||
your browser:
|
||||
<button type="button" {{on "click" (perform this.kredits.fetchMissingContributions)}} class="small">
|
||||
fetch all data
|
||||
</button>
|
||||
</p>
|
||||
{{else}}
|
||||
<p style="margin-bottom: 1rem;">
|
||||
Syncing data. Please be patient...
|
||||
</p>
|
||||
<p>
|
||||
(You can leave this website anytime and sync missing data when you come back.)
|
||||
</p>
|
||||
{{/if}}
|
||||
</section>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div id="details">
|
||||
|
||||
Reference in New Issue
Block a user