comparison client/src/store/bottlenecks.js @ 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 002e57f99dc9
children 660147046ddd
comparison
equal deleted inserted replaced
5290:da3fd4c3d1b5 5291:d62587503a39
13 * Thomas Junk <thomas.junk@intevation.de> 13 * Thomas Junk <thomas.junk@intevation.de>
14 */ 14 */
15 import { HTTP } from "@/lib/http"; 15 import { HTTP } from "@/lib/http";
16 import { WFS } from "ol/format"; 16 import { WFS } from "ol/format";
17 import { displayError } from "@/lib/errors"; 17 import { displayError } from "@/lib/errors";
18 import { 18 import { compareAsc } from "date-fns";
19 and as andFilter,
20 greaterThanOrEqualTo,
21 lessThanOrEqualTo
22 } from "ol/format/filter";
23
24 // initial state 19 // initial state
25 const init = () => { 20 const init = () => {
26 return { 21 return {
27 bottlenecks: [], 22 bottlenecks: [],
28 bottlenecksList: [], 23 bottlenecksList: [],
187 propertyNames: [ 182 propertyNames: [
188 "objnam", 183 "objnam",
189 "responsible_country", 184 "responsible_country",
190 "limiting", 185 "limiting",
191 "reference_water_levels" 186 "reference_water_levels"
192 ], 187 ]
193 filter: andFilter(
194 lessThanOrEqualTo("valid_from", new Date().toISOString()),
195 greaterThanOrEqualTo("valid_to", new Date().toISOString())
196 )
197 }); 188 });
198 HTTP.post( 189 HTTP.post(
199 "/internal/wfs", 190 "/internal/wfs",
200 new XMLSerializer().serializeToString( 191 new XMLSerializer().serializeToString(
201 bottleneckFeatureCollectionRequest 192 bottleneckFeatureCollectionRequest
206 "Content-type": "text/xml; charset=UTF-8" 197 "Content-type": "text/xml; charset=UTF-8"
207 } 198 }
208 } 199 }
209 ) 200 )
210 .then(response => { 201 .then(response => {
211 commit("setBottlenecks", response.data.features); 202 // Filter bottlenecks to get them unique with the latest time for each one.
203 const bottlenecks = response.data.features;
204 let btnIds = [],
205 filteredBottlenceks = [];
206 bottlenecks.forEach(btn => {
207 const btnName = btn.properties.bottleneck_id;
208 if (btnIds.indexOf(btnName) === -1) {
209 btnIds.push(btnName);
210 filteredBottlenceks.push(btn);
211 } else {
212 let btnToCompare = filteredBottlenceks.find(
213 b => b.properties.bottleneck_id === btnName
214 );
215 if (
216 compareAsc(
217 btn.properties.date_info,
218 btnToCompare.properties.date_info
219 ) === 1
220 ) {
221 const index = filteredBottlenceks.findIndex(
222 x => x.properties.bottleneck_id === btnName
223 );
224 filteredBottlenceks[index] = btn;
225 }
226 }
227 });
228 commit("setBottlenecks", filteredBottlenceks);
212 resolve(response); 229 resolve(response);
213 }) 230 })
214 .catch(error => { 231 .catch(error => {
215 reject(error); 232 reject(error);
216 }); 233 });