Mercurial > gemma
changeset 3490:624c64670d48
fairwayavailability: omit switch statement and streamline endpointselection
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 27 May 2019 16:59:39 +0200 |
parents | e6673f35d5d1 |
children | da58cf951342 |
files | client/src/store/fairwayavailability.js |
diffstat | 1 files changed, 16 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/store/fairwayavailability.js Mon May 27 16:38:36 2019 +0200 +++ b/client/src/store/fairwayavailability.js Mon May 27 16:59:39 2019 +0200 @@ -220,25 +220,14 @@ : feature.get("objnam"); [from, to] = getIntervallBorders(from, to, frequency); let additionalParams = ""; - let endpoint = ""; - switch (type) { - case TYPES.BOTTLENECK: - endpoint = "bottleneck"; - if (limitingFactor === LIMITINGFACTORS.DEPTH) - additionalParams = `&breaks=${depthLimit1},${depthLimit2}`; - if (limitingFactor === LIMITINGFACTORS.WIDTH) - additionalParams = `&breaks=${widthLimit1},${widthLimit2}`; - break; - case TYPES.SECTION: - endpoint = "section"; - additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`; - break; - case TYPES.STRETCH: - endpoint = "stretch"; - additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`; - break; - default: - throw new Error("Wrong selection"); + let endpoint = type; + if (type === TYPES.BOTTLENECK) { + if (limitingFactor === LIMITINGFACTORS.DEPTH) + additionalParams = `&breaks=${depthLimit1},${depthLimit2}`; + if (limitingFactor === LIMITINGFACTORS.WIDTH) + additionalParams = `&breaks=${widthLimit1},${widthLimit2}`; + } else if (type == TYPES.SECTION || type == TYPES.STRETCH) { + additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`; } const start = encodeURIComponent("00:00:00+00:00"); const end = encodeURIComponent("23:59:59+00:00"); @@ -283,26 +272,14 @@ const start = encodeURIComponent("00:00:00+00:00"); const end = encodeURIComponent("23:59:59+00:00"); let additionalParams = ""; - let endpoint = ""; - switch (type) { - case TYPES.BOTTLENECK: - endpoint = "bottleneck"; - if (limitingFactor === LIMITINGFACTORS.DEPTH) - additionalParams = `&breaks=${depthLimit1},${depthLimit2}`; - if (limitingFactor === LIMITINGFACTORS.WIDTH) - additionalParams = `&breaks=${widthLimit1},${widthLimit2}`; - break; - case TYPES.SECTION: - endpoint = "section"; - additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`; - break; - case TYPES.STRETCH: - endpoint = "stretch"; - additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`; - break; - default: - endpoint = "bottleneck"; - break; + let endpoint = type || TYPES.BOTTLENECK; + if (type === TYPES.BOTTLENECK) { + if (limitingFactor === LIMITINGFACTORS.DEPTH) + additionalParams = `&breaks=${depthLimit1},${depthLimit2}`; + if (limitingFactor === LIMITINGFACTORS.WIDTH) + additionalParams = `&breaks=${widthLimit1},${widthLimit2}`; + } else if (type == TYPES.SECTION || type == TYPES.STRETCH) { + additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`; } const URL = `data/${endpoint}/availability/${encodeURIComponent( name