comparison client/src/store/fairwayavailability.js @ 5259:680be197844d

Merged branch new-fwa.
author Sascha Wilde <wilde@intevation.de>
date Wed, 13 May 2020 11:28:34 +0200
parents 09ec6a748fca
children 791a372553a0
comparison
equal deleted inserted replaced
5183:1b5c80ea5582 5259:680be197844d
12 * Thomas Junk <thomas.junk@intevation.de> 12 * Thomas Junk <thomas.junk@intevation.de>
13 */ 13 */
14 14
15 /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "_" }]*/ 15 /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "_" }]*/
16 16
17 import { HTTP } from "@/lib/http";
18 import { 17 import {
18 endOfMonth,
19 endOfQuarter,
20 endOfYear,
19 format, 21 format,
20 startOfMonth, 22 startOfMonth,
21 endOfMonth,
22 startOfYear,
23 endOfYear,
24 startOfQuarter, 23 startOfQuarter,
25 endOfQuarter 24 startOfYear
26 } from "date-fns"; 25 } from "date-fns";
26
27 import { HTTP } from "@/lib/http";
27 28
28 const LIMITINGFACTORS = { 29 const LIMITINGFACTORS = {
29 WIDTH: "width", 30 WIDTH: "width",
30 DEPTH: "depth" 31 DEPTH: "depth"
31 }; 32 };
257 widthLimit2, 258 widthLimit2,
258 limitingFactor, 259 limitingFactor,
259 type 260 type
260 } = options; 261 } = options;
261 let { from, to } = options; 262 let { from, to } = options;
262 let name = feature.hasOwnProperty("properties") 263 let name = "";
263 ? feature.properties.name 264 if (type === TYPES.BOTTLENECK) {
264 : feature.get("objnam"); 265 name = feature.hasOwnProperty("properties")
266 ? feature.properties.bottleneck_id
267 : feature.get("bottleneck_id");
268 } else {
269 name = feature.hasOwnProperty("properties")
270 ? feature.properties.name
271 : feature.get("objnam");
272 }
265 [from, to] = getIntervallBorders(from, to, frequency); 273 [from, to] = getIntervallBorders(from, to, frequency);
266 let additionalParams = ""; 274 let additionalParams = "";
267 let endpoint = type; 275 let endpoint = type;
268 if (type === TYPES.BOTTLENECK) { 276 if (type === TYPES.BOTTLENECK) {
269 if (limitingFactor === LIMITINGFACTORS.DEPTH) 277 if (limitingFactor === LIMITINGFACTORS.DEPTH)
273 } else if (type == TYPES.SECTION || type == TYPES.STRETCH) { 281 } else if (type == TYPES.SECTION || type == TYPES.STRETCH) {
274 additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`; 282 additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`;
275 } 283 }
276 const start = encodeURIComponent("00:00:00+00:00"); 284 const start = encodeURIComponent("00:00:00+00:00");
277 const end = encodeURIComponent("23:59:59+00:00"); 285 const end = encodeURIComponent("23:59:59+00:00");
278 const URL = `data/${endpoint}/fairway-depth/${encodeURIComponent( 286 const URL = `data/fairway/${endpoint}/${encodeURIComponent(
279 name 287 name
280 )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}${additionalParams}`; 288 )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}${additionalParams}`;
281 HTTP.get(URL, { 289 HTTP.get(URL, {
282 headers: { "X-Gemma-Auth": localStorage.getItem("token") } 290 headers: { "X-Gemma-Auth": localStorage.getItem("token") }
283 }) 291 })
302 widthLimit2, 310 widthLimit2,
303 limitingFactor, 311 limitingFactor,
304 type 312 type
305 } = options; 313 } = options;
306 let { from, to } = options; 314 let { from, to } = options;
307 let name = feature.hasOwnProperty("properties") 315 let name = "";
308 ? feature.properties.name 316 if (type === TYPES.BOTTLENECK) {
309 : feature.get("objnam"); 317 name = feature.hasOwnProperty("properties")
318 ? feature.properties.bottleneck_id
319 : feature.get("bottleneck_id");
320 } else {
321 name = feature.hasOwnProperty("properties")
322 ? feature.properties.name
323 : feature.get("objnam");
324 }
310 [from, to] = getIntervallBorders(from, to, frequency); 325 [from, to] = getIntervallBorders(from, to, frequency);
311 const start = encodeURIComponent("00:00:00+00:00"); 326 const start = encodeURIComponent("00:00:00+00:00");
312 const end = encodeURIComponent("23:59:59+00:00"); 327 const end = encodeURIComponent("23:59:59+00:00");
313 let additionalParams = ""; 328 let additionalParams = "";
314 let endpoint = type || TYPES.BOTTLENECK; 329 let endpoint = type || TYPES.BOTTLENECK;
318 if (limitingFactor === LIMITINGFACTORS.WIDTH) 333 if (limitingFactor === LIMITINGFACTORS.WIDTH)
319 additionalParams = `&breaks=${widthLimit1},${widthLimit2}`; 334 additionalParams = `&breaks=${widthLimit1},${widthLimit2}`;
320 } else if (type == TYPES.SECTION || type == TYPES.STRETCH) { 335 } else if (type == TYPES.SECTION || type == TYPES.STRETCH) {
321 additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`; 336 additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`;
322 } 337 }
323 const URL = `data/${endpoint}/availability/${encodeURIComponent( 338 const URL = `data/availability/${endpoint}/${encodeURIComponent(
324 name 339 name
325 )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}${additionalParams}`; 340 )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}${additionalParams}`;
326 HTTP.get(URL, { 341 HTTP.get(URL, {
327 headers: { "X-Gemma-Auth": localStorage.getItem("token") } 342 headers: { "X-Gemma-Auth": localStorage.getItem("token") }
328 }) 343 })