Mercurial > gemma
annotate client/src/lib/filters.js @ 4385:610773d34e4f
hydrological_conditions: decouple diagram from dialogue
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Thu, 12 Sep 2019 15:06:53 +0200 |
parents | 1109a38f7ff1 |
children |
rev | line source |
---|---|
2541
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
2 * without warranty, see README.md and license for details. |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
3 * |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
4 * SPDX-License-Identifier: AGPL-3.0-or-later |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
5 * License-Filename: LICENSES/AGPL-3.0.txt |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
6 * |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
7 * Copyright (C) 2018 by via donau |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
8 * – Österreichische Wasserstraßen-Gesellschaft mbH |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
9 * Software engineering by Intevation GmbH |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
10 * |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
11 * Author(s): |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
12 * Thomas Junk <thomas.junk@intevation.de> |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
13 * Markus Kottländer <markus.kottlaender@intevation.de> |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
14 */ |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
15 |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
16 import locale2 from "locale2"; |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
17 |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
18 export default { |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
19 surveyDate(date) { |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
20 return date |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
21 ? new Date(date).toLocaleDateString(locale2, { |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
22 day: "2-digit", |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
23 month: "2-digit", |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
24 year: "numeric" |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
25 }) |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
26 : ""; |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
27 }, |
2945
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
28 dateTime(date, hideTime) { |
2541
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
29 if (!date) return ""; |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
30 const d = new Date(date); |
2945
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
31 let dateString = d.toLocaleDateString(locale2, { |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
32 day: "2-digit", |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
33 month: "2-digit", |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
34 year: "numeric" |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
35 }); |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
36 if (!hideTime) { |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
37 dateString += |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
38 " - " + |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
39 d.toLocaleTimeString(locale2, { |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
40 hour12: false |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
41 }); |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
42 } |
ab771ea5e4fe
client: importoverview: improved display of date interval
Markus Kottlaender <markus@intevation.de>
parents:
2738
diff
changeset
|
43 return dateString; |
2738
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
44 }, |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
45 sortTable(data, sortColumn, sortDirection, page, pageSize) { |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
46 // clone the array and leave the original intact |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
47 let sortedData = data.filter(d => d); |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
48 |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
49 if (sortColumn && sortDirection) { |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
50 sortedData.sort((a, b) => { |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
51 let valB = sortColumn.split(".").reduce((o, i) => o[i], a) || ""; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
52 let valA = sortColumn.split(".").reduce((o, i) => o[i], b) || ""; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
53 |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
54 if (valA > valB) return sortDirection === "ASC" ? -1 : 1; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
55 if (valA < valB) return sortDirection === "ASC" ? 1 : -1; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
56 |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
57 return 0; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
58 }); |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
59 } |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
60 |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
61 if (page && pageSize) { |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
62 let start = page * pageSize - pageSize; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
63 sortedData = sortedData.slice(start, start + pageSize); |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
64 } |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
65 |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2541
diff
changeset
|
66 return sortedData; |
3576
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
2945
diff
changeset
|
67 }, |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
2945
diff
changeset
|
68 // converts cm to m and formats based on locale |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
2945
diff
changeset
|
69 waterlevel(n) { |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
2945
diff
changeset
|
70 return (n / 100).toLocaleString(locale2, { |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
2945
diff
changeset
|
71 minimumFractionDigits: 2, |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
2945
diff
changeset
|
72 maximumFractionDigits: 2 |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
2945
diff
changeset
|
73 }); |
2541
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
74 } |
468c8dc796cf
client: convert lib helper functions to Vue filters
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
75 }; |