From 769317777ceff35371fdf6cb327abe07bf2a3468 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 18 Jun 2020 15:25:03 +0200 Subject: [PATCH] Refactor routes * Add specific dashboard route * Port application route to Octane * Fetch/sync contributors in application route, but only sync contributions in dashboard route for now --- app/routes/application.js | 40 +++++++++++++---------------- app/routes/dashboard.js | 18 +++++++++++++ tests/unit/routes/dashboard-test.js | 11 ++++++++ 3 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 app/routes/dashboard.js create mode 100644 tests/unit/routes/dashboard-test.js diff --git a/app/routes/application.js b/app/routes/application.js index 92f0e9d..638ddd3 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -1,39 +1,35 @@ -import { inject as service } from '@ember/service'; import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; import { schedule } from '@ember/runloop'; -export default Route.extend({ - kredits: service(), +export default class ApplicationRoute extends Route { + + @service kredits; beforeModel(/* transition */) { const kredits = this.kredits; return kredits.setup().then(() => { - kredits.get('kredits').preflightChecks().catch((error) => { + kredits.kredits.preflightChecks().catch((error) => { console.error('Kredits preflight check failed!'); console.error(error); }); }).catch((error) => { console.log('Error initializing Kredits', error); }); - }, + } + + model() { + return this.kredits.loadInitialData().then(() => { + this.kredits.addContractEventHandlers() + }); + } afterModel() { - return this.kredits.loadInitialData() - .then(() => { - this.kredits.addContractEventHandlers(); - }) - .then(() => { - if (this.kredits.contributorsNeedSync) { - schedule('afterRender', this.kredits.syncContributors, - this.kredits.syncContributors.perform); - } - if (this.kredits.contributionsNeedSync) { - schedule('afterRender', this.kredits.syncContributions, - this.kredits.syncContributions.perform); - } - schedule('afterRender', this.kredits.fetchMissingContributions, - this.kredits.fetchMissingContributions.perform); - }); + if (this.kredits.contributorsNeedSync) { + schedule('afterRender', this.kredits.syncContributors, + this.kredits.syncContributors.perform); + } } -}); + +} diff --git a/app/routes/dashboard.js b/app/routes/dashboard.js new file mode 100644 index 0000000..a6b1d4e --- /dev/null +++ b/app/routes/dashboard.js @@ -0,0 +1,18 @@ +import Route from '@ember/routing/route'; +import { schedule } from '@ember/runloop'; +import { inject as service } from '@ember/service'; + +export default class DashboardRoute extends Route { + + @service kredits; + + afterModel() { + if (this.kredits.contributionsNeedSync) { + schedule('afterRender', this.kredits.syncContributions, + this.kredits.syncContributions.perform); + } + schedule('afterRender', this.kredits.fetchMissingContributions, + this.kredits.fetchMissingContributions.perform); + } + +} diff --git a/tests/unit/routes/dashboard-test.js b/tests/unit/routes/dashboard-test.js new file mode 100644 index 0000000..26accbd --- /dev/null +++ b/tests/unit/routes/dashboard-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | dashboard', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:dashboard'); + assert.ok(route); + }); +});