From 45a98257463e1fce36093f60ff97073274d8845c Mon Sep 17 00:00:00 2001 From: Rens Hamburger Date: Sun, 20 Oct 2019 23:05:44 +0200 Subject: [PATCH] Reduce data usage --- src/components/BlockPanel.vue | 2 +- src/components/HelloWorld.vue | 59 ----------------------------------- src/router.js | 8 ----- src/services/ResultService.js | 43 ++++++++++++++++++++----- src/views/About.vue | 5 --- src/views/Home.vue | 18 ----------- 6 files changed, 36 insertions(+), 99 deletions(-) delete mode 100644 src/components/HelloWorld.vue delete mode 100644 src/views/About.vue delete mode 100644 src/views/Home.vue diff --git a/src/components/BlockPanel.vue b/src/components/BlockPanel.vue index d4c68a8..2f498e2 100644 --- a/src/components/BlockPanel.vue +++ b/src/components/BlockPanel.vue @@ -90,7 +90,7 @@ const blocks = await this.resultService.update(); this.updateFields(blocks); } catch (e) { - this.updateFields(this.resultService.getLastReggataData()); + this.updateFields(this.resultService.getLastRegattaData()); return false; } } else { diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue deleted file mode 100644 index fcbab02..0000000 --- a/src/components/HelloWorld.vue +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - diff --git a/src/router.js b/src/router.js index 37eeef5..9036209 100644 --- a/src/router.js +++ b/src/router.js @@ -1,17 +1,9 @@ import Vue from 'vue'; import Router from 'vue-router'; -import Home from './views/Home.vue'; Vue.use(Router); export default new Router({ mode: 'history', base: process.env.BASE_URL, - routes: [ - { - path: '/', - name: 'home', - component: Home, - }, - ], }); diff --git a/src/services/ResultService.js b/src/services/ResultService.js index 23342ee..ae523b6 100644 --- a/src/services/ResultService.js +++ b/src/services/ResultService.js @@ -16,6 +16,9 @@ export class ResultService extends Service { this.endCount = 0; this.regatta = null; this.lastReults = null; + this._fieldIndex = null; + this._blockIndex = null; + this.blocks = null; } /** @@ -38,20 +41,40 @@ export class ResultService extends Service { * @return {Promise} */ async update() { + if (this.regatta === null) { + const regatta = await this._initRegatta(); + this.regatta = JSON.stringify(regatta.regatta); + this.blocks = JSON.parse(JSON.stringify(regatta.regatta)); + this._blockIndex = 0; + this._fieldIndex = 0; + } const data = await this._update(); - this.regatta = JSON.stringify(data.regatta); - return data.regatta; + const regattaData = JSON.parse(this.regatta); + regattaData[this._blockIndex][this._fieldIndex].crews = data.field; + this.regatta = JSON.stringify(regattaData); + if (++this._fieldIndex === this.blocks[this._blockIndex].length) { + this._fieldIndex = 0; + if (++this._blockIndex === this.blocks.length) { + this._blockIndex = 0; + } + } + return regattaData; } - getLastReggataData() { + getLastRegattaData() { return JSON.parse(this.regatta); } + _initRegatta() { + return this._fetch(`/beamer/getRegattaData/${this.regattaId}/${this.presetId}`); + } + /** * @private */ _update() { - return this._fetch(`/beamer/getRegattaData/${this.regattaId}/${this.presetId}`); + const fieldCode = this.blocks[this._blockIndex][this._fieldIndex].fieldnameshort; + return this._fetch(`/beamer/getField/${this.regattaId}/${this.presetId}/${fieldCode.replace(/\+/g, '%2B')}`); } _updateLastResults() { @@ -66,7 +89,11 @@ export class ResultService extends Service { let fieldCount = 0; blocks = blocks.map(block => { block = block.map((field) => { - field.crewCount = field.crews.teams.length; + if (field.crews) { + field.crewCount = field.crews.teams.length; + } else { + field.crewCount = 0; + } return field; }); block.crewCount = block.reduce((sum, field) => { @@ -88,18 +115,18 @@ export class ResultService extends Service { field.crews.teams.length = 0; } } - if (count + field.crews.teams.length + fieldCount > this.endCount) { + if (count + field.crewCount + fieldCount > this.endCount) { field.crews.teams.length = Math.max(0, this.endCount - count - 1 - fieldCount); } count += field.crewCount; - if (field.crews.teams.length) { + if (field.crewCount) { fieldCount++; } }); this.endCount -= fieldCount; this.fields[this.fields.length - 1] = this.fields[this.fields.length - 1].filter(field => { - return field.crews.teams.length > 0; + return field.crewCount; }); } else { count += block.crewCount; diff --git a/src/views/About.vue b/src/views/About.vue deleted file mode 100644 index 3fa2807..0000000 --- a/src/views/About.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/src/views/Home.vue b/src/views/Home.vue deleted file mode 100644 index 7d4b5e2..0000000 --- a/src/views/Home.vue +++ /dev/null @@ -1,18 +0,0 @@ - - -