Mercurial > gemma
annotate client/src/components/identify/formatter.js @ 4230:f3b733fd119a
Identify: Improve formatter for Identify tool
The main usecase of the formatter is providing a key-value structure for
displaying information in the identify box.
Therefore the assumption seems justified, that a value displayed
in the identify tool should be human readable.
This isn't the case for values, which are javascript objects like "Feature".
That said, it seems valid to exclude such values, which are instances of "Feature".
This improves the solution of ommiting one specific "feature" to a more general
solution of omitting every "feature".
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Tue, 20 Aug 2019 17:15:06 +0200 |
parents | bb66e144dece |
children | 57c38087fe18 |
rev | line source |
---|---|
4230
f3b733fd119a
Identify: Improve formatter for Identify tool
Thomas Junk <thomas.junk@intevation.de>
parents:
4224
diff
changeset
|
1 import Feature from "ol/Feature"; |
f3b733fd119a
Identify: Improve formatter for Identify tool
Thomas Junk <thomas.junk@intevation.de>
parents:
4224
diff
changeset
|
2 |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
3 const formatter = { |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
4 all(p) { |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
5 if (p.key === "objnam") p.key = "Name"; |
2573
4486ca003b55
client: added objname to identify formatter
Markus Kottlaender <markus@intevation.de>
parents:
2509
diff
changeset
|
6 if (p.key === "objname") p.key = "Name"; |
2509
3dc7c0f60a62
client: identify box: formatted fa_date_info and fa_critical
Markus Kottlaender <markus@intevation.de>
parents:
2458
diff
changeset
|
7 if (p.key === "staging_done" || p.key === "fa_critical") |
3dc7c0f60a62
client: identify box: formatted fa_date_info and fa_critical
Markus Kottlaender <markus@intevation.de>
parents:
2458
diff
changeset
|
8 p.val = p.val ? "yes" : "no"; |
3485
ef4803f87631
Add 'translation' and bottleneck attributes for measurement availability
Tom Gottfried <tom@intevation.de>
parents:
3362
diff
changeset
|
9 if ( |
3635
6d6577a87963
Do not show missing date as Unix epoch
Tom Gottfried <tom@intevation.de>
parents:
3505
diff
changeset
|
10 (p.key === "date_info" || |
6d6577a87963
Do not show missing date as Unix epoch
Tom Gottfried <tom@intevation.de>
parents:
3505
diff
changeset
|
11 p.key === "fa_date_info" || |
6d6577a87963
Do not show missing date as Unix epoch
Tom Gottfried <tom@intevation.de>
parents:
3505
diff
changeset
|
12 p.key === "gm_measuredate") && |
6d6577a87963
Do not show missing date as Unix epoch
Tom Gottfried <tom@intevation.de>
parents:
3505
diff
changeset
|
13 p.val !== null |
3485
ef4803f87631
Add 'translation' and bottleneck attributes for measurement availability
Tom Gottfried <tom@intevation.de>
parents:
3362
diff
changeset
|
14 ) { |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
15 p.val = new Date(p.val).toLocaleString(); |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
16 } |
2743
4063adda3095
client: identified box: moved bbox zoom button to feature headers and removed bbox from the feature's properties list
Markus Kottlaender <markus@intevation.de>
parents:
2573
diff
changeset
|
17 |
4063adda3095
client: identified box: moved bbox zoom button to feature headers and removed bbox from the feature's properties list
Markus Kottlaender <markus@intevation.de>
parents:
2573
diff
changeset
|
18 // remove certain props |
4063adda3095
client: identified box: moved bbox zoom button to feature headers and removed bbox from the feature's properties list
Markus Kottlaender <markus@intevation.de>
parents:
2573
diff
changeset
|
19 let propsToRemove = ["bbox"]; |
4063adda3095
client: identified box: moved bbox zoom button to feature headers and removed bbox from the feature's properties list
Markus Kottlaender <markus@intevation.de>
parents:
2573
diff
changeset
|
20 if (propsToRemove.indexOf(p.key) !== -1) return null; |
4063adda3095
client: identified box: moved bbox zoom button to feature headers and removed bbox from the feature's properties list
Markus Kottlaender <markus@intevation.de>
parents:
2573
diff
changeset
|
21 |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
22 return p; |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
23 }, |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
24 bottlenecks_geoserver: { |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
25 label: "Bottleneck", |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
26 props: p => { |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
27 if (p.key === "bottleneck_id") p.key = "ID"; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
28 if (p.key === "responsible_country") p.key = "Responsible Country"; |
2509
3dc7c0f60a62
client: identify box: formatted fa_date_info and fa_critical
Markus Kottlaender <markus@intevation.de>
parents:
2458
diff
changeset
|
29 if (p.key === "fa_date_info") p.key = "Fairway Date"; |
3dc7c0f60a62
client: identify box: formatted fa_date_info and fa_critical
Markus Kottlaender <markus@intevation.de>
parents:
2458
diff
changeset
|
30 if (p.key === "fa_critical") p.key = "Fairway Critical"; |
3359
af6d8020b4a6
client: identify: improved label formatting
Markus Kottlaender <markus@intevation.de>
parents:
3309
diff
changeset
|
31 if (p.key === "gauge_objname") p.key = "Reference Gauge"; |
af6d8020b4a6
client: identify: improved label formatting
Markus Kottlaender <markus@intevation.de>
parents:
3309
diff
changeset
|
32 if (p.key === "source_organization") p.key = "Source Organization"; |
3485
ef4803f87631
Add 'translation' and bottleneck attributes for measurement availability
Tom Gottfried <tom@intevation.de>
parents:
3362
diff
changeset
|
33 if (p.key === "gm_measuredate") p.key = "Gauge Waterlevel Date"; |
3359
af6d8020b4a6
client: identify: improved label formatting
Markus Kottlaender <markus@intevation.de>
parents:
3309
diff
changeset
|
34 if (p.key === "gm_waterlevel") p.key = "Gauge Waterlevel"; |
3485
ef4803f87631
Add 'translation' and bottleneck attributes for measurement availability
Tom Gottfried <tom@intevation.de>
parents:
3362
diff
changeset
|
35 if (p.key === "gm_n_14d") p.key = "G.W. Count in Last 14 Days"; |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
36 // remove certain props |
4224
bb66e144dece
client: fix identify for bottlenecks
Bernhard Reiter <bernhard@intevation.de>
parents:
3636
diff
changeset
|
37 // * gauge_obj is another feature object and we want to stay flat |
bb66e144dece
client: fix identify for bottlenecks
Bernhard Reiter <bernhard@intevation.de>
parents:
3636
diff
changeset
|
38 // for display (if left in causes a |
bb66e144dece
client: fix identify for bottlenecks
Bernhard Reiter <bernhard@intevation.de>
parents:
3636
diff
changeset
|
39 // TypeError: Converting circular structure to JSON |
bb66e144dece
client: fix identify for bottlenecks
Bernhard Reiter <bernhard@intevation.de>
parents:
3636
diff
changeset
|
40 // somewhere later) |
4230
f3b733fd119a
Identify: Improve formatter for Identify tool
Thomas Junk <thomas.junk@intevation.de>
parents:
4224
diff
changeset
|
41 if (p.val instanceof Feature) { |
f3b733fd119a
Identify: Improve formatter for Identify tool
Thomas Junk <thomas.junk@intevation.de>
parents:
4224
diff
changeset
|
42 return null; |
f3b733fd119a
Identify: Improve formatter for Identify tool
Thomas Junk <thomas.junk@intevation.de>
parents:
4224
diff
changeset
|
43 } |
f3b733fd119a
Identify: Improve formatter for Identify tool
Thomas Junk <thomas.junk@intevation.de>
parents:
4224
diff
changeset
|
44 let propsToRemove = ["nobjnm", "reference_water_levels", "fa_data"]; |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
45 if (propsToRemove.indexOf(p.key) !== -1) return null; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
46 |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
47 return p; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
48 } |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
49 }, |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
50 fairway_dimensions: { |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
51 label: "Fairway Dimensions" |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
52 }, |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
53 waterway_area: { |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
54 label: "Waterway Area" |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
55 }, |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
56 distance_marks_geoserver: { |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
57 label: "Distance Mark" |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
58 }, |
3081
9107c959bb3b
client: Changed distance marks ashore to WMS layer.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2743
diff
changeset
|
59 distance_marks_ashore_geoserver: { |
9107c959bb3b
client: Changed distance marks ashore to WMS layer.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2743
diff
changeset
|
60 label: "Distance Mark ashore" |
9107c959bb3b
client: Changed distance marks ashore to WMS layer.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2743
diff
changeset
|
61 }, |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
62 waterway_axis: { |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
63 label: "Waterway Axis" |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
64 }, |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
65 waterway_profiles: { |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2439
diff
changeset
|
66 label: "Waterway Profile" |
2439
c3c014435e88
client: identify box: formatted streches
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
67 }, |
c3c014435e88
client: identify box: formatted streches
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
68 stretches_geoserver: { |
3636
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
69 label: "Stretch", |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
70 props: p => { |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
71 if (p.key === "gm_measuredate") p.key = "Min. Gauge Waterlevel Date"; |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
72 if (p.key === "gm_n_14d") p.key = "Min. G.W. Count in Last 14 Days"; |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
73 |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
74 return p; |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
75 } |
2458
204b0baac93c
client: identified box: added gauges to formatter
Markus Kottlaender <markus@intevation.de>
parents:
2441
diff
changeset
|
76 }, |
3309
80037790032d
client: fully implemented sections
Markus Kottlaender <markus@intevation.de>
parents:
3081
diff
changeset
|
77 sections_geoserver: { |
3636
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
78 label: "Section", |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
79 props: p => { |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
80 if (p.key === "gm_measuredate") p.key = "Min. Gauge Waterlevel Date"; |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
81 if (p.key === "gm_n_14d") p.key = "Min. G.W. Count in Last 14 Days"; |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
82 |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
83 return p; |
89a39783c20a
Add forecast and measurement quality parameters to sections and stretches
Tom Gottfried <tom@intevation.de>
parents:
3635
diff
changeset
|
84 } |
3309
80037790032d
client: fully implemented sections
Markus Kottlaender <markus@intevation.de>
parents:
3081
diff
changeset
|
85 }, |
2458
204b0baac93c
client: identified box: added gauges to formatter
Markus Kottlaender <markus@intevation.de>
parents:
2441
diff
changeset
|
86 gauges_geoserver: { |
3362
bda4034304b1
client: identify: added formatting for latest gauge waterlevel
Markus Kottlaender <markus@intevation.de>
parents:
3359
diff
changeset
|
87 label: "Gauge", |
bda4034304b1
client: identify: added formatting for latest gauge waterlevel
Markus Kottlaender <markus@intevation.de>
parents:
3359
diff
changeset
|
88 props: p => { |
3485
ef4803f87631
Add 'translation' and bottleneck attributes for measurement availability
Tom Gottfried <tom@intevation.de>
parents:
3362
diff
changeset
|
89 if (p.key === "gm_measuredate") p.key = "Latest Waterlevel Date"; |
3362
bda4034304b1
client: identify: added formatting for latest gauge waterlevel
Markus Kottlaender <markus@intevation.de>
parents:
3359
diff
changeset
|
90 if (p.key === "gm_waterlevel") p.key = "Latest Waterlevel"; |
3485
ef4803f87631
Add 'translation' and bottleneck attributes for measurement availability
Tom Gottfried <tom@intevation.de>
parents:
3362
diff
changeset
|
91 if (p.key === "gm_n_14d") p.key = "Measurement Count in Last 14 Days"; |
3362
bda4034304b1
client: identify: added formatting for latest gauge waterlevel
Markus Kottlaender <markus@intevation.de>
parents:
3359
diff
changeset
|
92 |
3505
d136ceed5d41
client: identify: remove unwanted attributes from bottlenecks and gauges
Markus Kottlaender <markus@intevation.de>
parents:
3485
diff
changeset
|
93 // remove certain props |
d136ceed5d41
client: identify: remove unwanted attributes from bottlenecks and gauges
Markus Kottlaender <markus@intevation.de>
parents:
3485
diff
changeset
|
94 let propsToRemove = ["nsc_data"]; |
d136ceed5d41
client: identify: remove unwanted attributes from bottlenecks and gauges
Markus Kottlaender <markus@intevation.de>
parents:
3485
diff
changeset
|
95 if (propsToRemove.indexOf(p.key) !== -1) return null; |
d136ceed5d41
client: identify: remove unwanted attributes from bottlenecks and gauges
Markus Kottlaender <markus@intevation.de>
parents:
3485
diff
changeset
|
96 |
3362
bda4034304b1
client: identify: added formatting for latest gauge waterlevel
Markus Kottlaender <markus@intevation.de>
parents:
3359
diff
changeset
|
97 return p; |
bda4034304b1
client: identify: added formatting for latest gauge waterlevel
Markus Kottlaender <markus@intevation.de>
parents:
3359
diff
changeset
|
98 } |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
99 } |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
100 }; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
101 |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
102 export { formatter }; |