Mercurial > gemma
comparison client/src/store/fairwayavailability.js @ 4329:83eb99662a91
client: improve ability to test FW diagrams
* Restructure code in fairwayavailability.js to seperate external data
retrieval and adding the data into the store. Good side effects are
that using a mutation for setting test data is easier and only
one commit call is necessary, which means less clutter in the state history.
* Adding an example how to use this for testing to docs/developers.md .
* Bump copyright year for one file.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Wed, 04 Sep 2019 17:05:43 +0200 |
parents | 9f03eb3817d6 |
children | 47aa3be2a7de |
comparison
equal
deleted
inserted
replaced
4328:ff21b742b106 | 4329:83eb99662a91 |
---|---|
2 * without warranty, see README.md and license for details. | 2 * without warranty, see README.md and license for details. |
3 * | 3 * |
4 * SPDX-License-Identifier: AGPL-3.0-or-later | 4 * SPDX-License-Identifier: AGPL-3.0-or-later |
5 * License-Filename: LICENSES/AGPL-3.0.txt | 5 * License-Filename: LICENSES/AGPL-3.0.txt |
6 * | 6 * |
7 * Copyright (C) 2018 by via donau | 7 * Copyright (C) 2018, 2019 by via donau |
8 * – Österreichische Wasserstraßen-Gesellschaft mbH | 8 * – Österreichische Wasserstraßen-Gesellschaft mbH |
9 * Software engineering by Intevation GmbH | 9 * Software engineering by Intevation GmbH |
10 * | 10 * |
11 * Author(s): | 11 * Author(s): |
12 * Thomas Junk <thomas.junk@intevation.de> | 12 * Thomas Junk <thomas.junk@intevation.de> |
176 state.widthlimit2 = widthlimit2; | 176 state.widthlimit2 = widthlimit2; |
177 }, | 177 }, |
178 setSelectedFairwayAvailability: (state, feature) => { | 178 setSelectedFairwayAvailability: (state, feature) => { |
179 state.selectedFairwayAvailabilityFeature = feature; | 179 state.selectedFairwayAvailabilityFeature = feature; |
180 }, | 180 }, |
181 setFwData: (state, fwData) => { | |
182 state.fwData = fwData; | |
183 }, | |
184 setFwLNWLData: (state, fwLNWLData) => { | 181 setFwLNWLData: (state, fwLNWLData) => { |
185 state.fwLNWLData = fwLNWLData; | 182 state.fwLNWLData = fwLNWLData; |
186 }, | 183 }, |
187 setCSV: (state, csv) => { | 184 setCSV: (state, csv) => { |
188 state.csv = csv; | 185 state.csv = csv; |
193 ); | 190 ); |
194 if (existingIndex !== -1) | 191 if (existingIndex !== -1) |
195 state.fwLNWLOverviewData.splice(existingIndex, 1); | 192 state.fwLNWLOverviewData.splice(existingIndex, 1); |
196 state.fwLNWLOverviewData.push(data); | 193 state.fwLNWLOverviewData.push(data); |
197 }, | 194 }, |
198 setLegend: (state, header) => { | 195 setLegendLNWL: (state, headerLNWL) => { |
199 const headerEntries = header.split(","); | 196 state.headerLNWL = headerLNWL; |
197 }, | |
198 // See docs/developers.md for an example how to directly | |
199 // call this method for testing. | |
200 setAvailableFairwayDepthData: (state, data) => { | |
201 state.csv = data; | |
202 const csv = data.split("\n").filter(x => x !== ""); //omit empty lines | |
203 | |
204 // setLegend | |
205 const headerEntries = csv.shift().split(","); | |
200 headerEntries.shift(); | 206 headerEntries.shift(); |
201 headerEntries.shift(); | 207 headerEntries.shift(); |
202 state.legend = headerEntries.map(x => { | 208 state.legend = headerEntries.map(x => { |
203 let entry = x.split("#")[1]; // split leading # | 209 let entry = x.split("#")[1]; // split leading # |
204 entry = entry.replace("[h]", "").trim(); // omit unit | 210 entry = entry.replace("[h]", "").trim(); // omit unit |
205 return entry; | 211 return entry; |
206 }); | 212 }); |
207 }, | 213 |
208 setLegendLNWL: (state, headerLNWL) => { | 214 state.fwData = transformAFD(csv); |
209 this.headerLNWL = headerLNWL; | |
210 } | 215 } |
211 }, | 216 }, |
212 actions: { | 217 actions: { |
213 loadAvailableFairwayDepth: ({ commit }, options) => { | 218 loadAvailableFairwayDepth: ({ commit }, options) => { |
214 return new Promise((resolve, reject) => { | 219 return new Promise((resolve, reject) => { |
245 )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}${additionalParams}`; | 250 )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}${additionalParams}`; |
246 HTTP.get(URL, { | 251 HTTP.get(URL, { |
247 headers: { "X-Gemma-Auth": localStorage.getItem("token") } | 252 headers: { "X-Gemma-Auth": localStorage.getItem("token") } |
248 }) | 253 }) |
249 .then(response => { | 254 .then(response => { |
250 const { data } = response; | 255 commit("setAvailableFairwayDepthData", response.data); |
251 commit("setCSV", data); | |
252 const csv = data.split("\n").filter(x => x !== ""); //omit empty lines | |
253 commit("setLegend", csv.shift()); | |
254 let transformed = transformAFD(csv); | |
255 commit("setFwData", transformed); | |
256 resolve(response); | 256 resolve(response); |
257 }) | 257 }) |
258 .catch(error => { | 258 .catch(error => { |
259 reject(error); | 259 reject(error); |
260 }); | 260 }); |