Mercurial > gemma
changeset 5291:d62587503a39
Client: add bottlenecks filter for the soundingresults import
* Get each bottleneck unique with its latest time.
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Thu, 09 Jul 2020 16:33:25 +0200 |
parents | da3fd4c3d1b5 |
children | 36f308bfc54b |
files | client/src/store/bottlenecks.js |
diffstat | 1 files changed, 29 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/store/bottlenecks.js Wed Jul 08 15:04:14 2020 +0200 +++ b/client/src/store/bottlenecks.js Thu Jul 09 16:33:25 2020 +0200 @@ -15,12 +15,7 @@ import { HTTP } from "@/lib/http"; import { WFS } from "ol/format"; import { displayError } from "@/lib/errors"; -import { - and as andFilter, - greaterThanOrEqualTo, - lessThanOrEqualTo -} from "ol/format/filter"; - +import { compareAsc } from "date-fns"; // initial state const init = () => { return { @@ -189,11 +184,7 @@ "responsible_country", "limiting", "reference_water_levels" - ], - filter: andFilter( - lessThanOrEqualTo("valid_from", new Date().toISOString()), - greaterThanOrEqualTo("valid_to", new Date().toISOString()) - ) + ] }); HTTP.post( "/internal/wfs", @@ -208,7 +199,33 @@ } ) .then(response => { - commit("setBottlenecks", response.data.features); + // Filter bottlenecks to get them unique with the latest time for each one. + const bottlenecks = response.data.features; + let btnIds = [], + filteredBottlenceks = []; + bottlenecks.forEach(btn => { + const btnName = btn.properties.bottleneck_id; + if (btnIds.indexOf(btnName) === -1) { + btnIds.push(btnName); + filteredBottlenceks.push(btn); + } else { + let btnToCompare = filteredBottlenceks.find( + b => b.properties.bottleneck_id === btnName + ); + if ( + compareAsc( + btn.properties.date_info, + btnToCompare.properties.date_info + ) === 1 + ) { + const index = filteredBottlenceks.findIndex( + x => x.properties.bottleneck_id === btnName + ); + filteredBottlenceks[index] = btn; + } + } + }); + commit("setBottlenecks", filteredBottlenceks); resolve(response); }) .catch(error => {