diff --git a/app/controllers/dashboard.js b/app/controllers/dashboard.js index a8bccb9..eabd50e 100644 --- a/app/controllers/dashboard.js +++ b/app/controllers/dashboard.js @@ -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); }), diff --git a/app/routes/dashboard.js b/app/routes/dashboard.js index a6b1d4e..c7242b0 100644 --- a/app/routes/dashboard.js +++ b/app/routes/dashboard.js @@ -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); } } diff --git a/app/services/kredits.js b/app/services/kredits.js index 12a58eb..dd8f24e 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -48,6 +48,8 @@ export default Service.extend({ contributionsNeedSync: false, reimbursementsNeedSync: false, + missingHistoricContributionsCount: 0, + init () { this._super(...arguments); this.set('contributors', []); @@ -230,12 +232,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); @@ -371,11 +381,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; @@ -392,7 +403,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')); diff --git a/app/templates/dashboard.hbs b/app/templates/dashboard.hbs index 0235455..4f16575 100644 --- a/app/templates/dashboard.hbs +++ b/app/templates/dashboard.hbs @@ -105,6 +105,32 @@ @showQuickFilter={{this.showQuickFilterConfirmed}} /> + + {{#if this.showFullContributionSync}} +
+ {{#if this.kredits.fetchMissingContributions.isIdle}} +

+ There are + {{this.kredits.missingHistoricContributionsCount}} + contributions, which are not currently loaded/displayed. +

+

+ You can fetch all historic data in one go, and have it stored locally in + your browser: + +

+ {{else}} +

+ Syncing data. Please be patient... +

+

+ (You can leave this website anytime and sync missing data when you come back.) +

+ {{/if}} +
+ {{/if}}