Mercurial > gemma
annotate pkg/controllers/system.go @ 3929:45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 11 Jul 2019 18:54:22 +0200 |
parents | 3fcc4e11fc00 |
children | 49564382ffff |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
12 // * Sascha Wilde <sascha.wilde@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
13 |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
14 package controllers |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
15 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
16 import ( |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
17 "bytes" |
3929
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
18 "context" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
19 "database/sql" |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
20 "fmt" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
21 "io/ioutil" |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
22 "log" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
23 "net/http" |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
24 "strings" |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
25 "sync" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
26 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
27 "github.com/gorilla/mux" |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
28 |
3929
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
29 "gemma.intevation.de/gemma/pkg/auth" |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
30 "gemma.intevation.de/gemma/pkg/config" |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
31 "gemma.intevation.de/gemma/pkg/geoserver" |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
32 "gemma.intevation.de/gemma/pkg/models" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
33 ) |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
34 |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
35 const ( |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
36 getFeatureColourSQL = `SELECT r,g,b,a |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
37 FROM systemconf.feature_colours |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
38 WHERE feature_name = $1 AND style_attr = $2` |
846
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
39 setFeatureColourSQL = `UPDATE systemconf.feature_colours |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
40 SET (r, g, b, a) = ($3, $4, $5, $6) |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
41 WHERE feature_name = $1 AND style_attr = $2` |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
42 |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
43 getSettingsSQL = ` |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
44 SELECT config_key, config_val |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
45 FROM sys_admin.system_config` |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
46 |
3834
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
47 getConfigSQL = ` |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
48 SELECT config_val |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
49 FROM sys_admin.system_config |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
50 WHERE config_key = $1` |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
51 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
52 updateSettingSQL = ` |
3630
2467e619cf67
Fixed more SQL typos.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3629
diff
changeset
|
53 INSERT INTO sys_admin.system_config (config_key, config_val) |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
54 VALUES ($1, $2) |
3629
1825a1bc9fb1
Fixed typo in SQL statement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3628
diff
changeset
|
55 ON CONFLICT (config_key) DO UPDATE SET config_val = $2` |
3929
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
56 |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
57 deleteSoundingDiffsSQL = ` |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
58 DELETE FROM caching.sounding_differences` |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
59 ) |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
60 |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
61 // System status end points |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
62 |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
63 func showSystemLog( |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
64 _ interface{}, req *http.Request, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
65 _ *sql.Conn, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
66 ) (jr JSONResult, err error) { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
67 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
68 serviceName := mux.Vars(req)["service"] |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
69 fileName := mux.Vars(req)["file"] |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
70 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
71 // The following check is currently most likely unnecessary as I wasn't |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
72 // able to inject a verbatim '/' via the middleware, but better be on |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
73 // the safe site... |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
74 if strings.Contains(fileName, "/") { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
75 err = JSONError{http.StatusBadRequest, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
76 "error: no slashes allowed in file name"} |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
77 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
78 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
79 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
80 var path string |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
81 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
82 switch serviceName { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
83 case "apache2", "postgresql": |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
84 path = "/var/log/" + serviceName + "/" + fileName |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
85 default: |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
86 err = JSONError{http.StatusBadRequest, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
87 "error: invalid service: " + serviceName} |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
88 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
89 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
90 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
91 var txt []byte |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
92 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
93 if txt, err = ioutil.ReadFile(path); err != nil { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
94 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
95 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
96 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
97 jr = JSONResult{ |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
98 Result: struct { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
99 Path string `json:"path"` |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
100 Content string `json:"content"` |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
101 }{path, string(txt)}, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
102 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
103 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
104 } |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
105 |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
106 func getSystemConfig( |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
107 _ interface{}, req *http.Request, |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
108 _ *sql.Conn, |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
109 ) (jr JSONResult, err error) { |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
110 |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
111 cfg := config.PublishedConfig() |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
112 if cfg == "" { |
3108
8a4fb02ee60a
Send empty JSON document when calling GET /api/system/config and "published-config" is not configure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3104
diff
changeset
|
113 jr = JSONResult{Result: strings.NewReader("{}")} |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
114 return |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
115 } |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
116 |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
117 var data []byte |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
118 if data, err = ioutil.ReadFile(cfg); err != nil { |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
119 return |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
120 } |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
121 |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
122 jr = JSONResult{Result: bytes.NewReader(data)} |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
123 return |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
124 } |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
125 |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
126 func getSystemSettings( |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
127 _ interface{}, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
128 req *http.Request, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
129 conn *sql.Conn, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
130 ) (jr JSONResult, err error) { |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
131 |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
132 var rows *sql.Rows |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
133 if rows, err = conn.QueryContext(req.Context(), getSettingsSQL); err != nil { |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
134 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
135 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
136 defer rows.Close() |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
137 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
138 settings := map[string]string{} |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
139 |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
140 for rows.Next() { |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
141 var key, val string |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
142 if err = rows.Scan(&key, &val); err != nil { |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
143 return |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
144 } |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
145 settings[key] = val |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
146 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
147 if err = rows.Err(); err != nil { |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
148 return |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
149 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
150 |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
151 jr = JSONResult{Result: settings} |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
152 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
153 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
154 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
155 type reconfFunc func(sql.NullString, string) (func(), error) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
156 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
157 var ( |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
158 reconfigureFuncsMu sync.Mutex |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
159 reconfigureFuncs = map[string]reconfFunc{} |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
160 ) |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
161 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
162 func registerReconfigureFunc(key string, fn reconfFunc) { |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
163 reconfigureFuncsMu.Lock() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
164 defer reconfigureFuncsMu.Unlock() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
165 reconfigureFuncs[key] = fn |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
166 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
167 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
168 func reconfigureFunc(key string) reconfFunc { |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
169 reconfigureFuncsMu.Lock() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
170 defer reconfigureFuncsMu.Unlock() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
171 return reconfigureFuncs[key] |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
172 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
173 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
174 func reconfigureClassBreaks(old sql.NullString, curr, which string, recalc func()) (func(), error) { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
175 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
176 // If new values are broken, don't proceed. |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
177 currCVs, err := models.ParseColorValues(curr) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
178 if err != nil { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
179 return nil, err |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
180 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
181 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
182 doBoth := func() { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
183 log.Printf("info: Trigger re-calculation of %s.", which) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
184 geoserver.ReconfigureStyle(which) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
185 recalc() |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
186 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
187 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
188 if !old.Valid { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
189 return doBoth, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
190 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
191 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
192 oldCVs, err := models.ParseColorValues(old.String) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
193 if err != nil { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
194 log.Printf("warn: old config value is broken: %v\n", err) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
195 return doBoth, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
196 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
197 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
198 if len(currCVs) != len(oldCVs) { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
199 return doBoth, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
200 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
201 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
202 colorChanged := false |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
203 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
204 for i := range currCVs { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
205 if currCVs[i].Value != oldCVs[i].Value { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
206 return doBoth, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
207 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
208 if currCVs[i].Color != oldCVs[i].Color { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
209 colorChanged = true |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
210 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
211 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
212 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
213 // Only the color changed -> no expensive recalc needed. |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
214 if colorChanged { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
215 log.Println("info: Only colors changed.") |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
216 return func() { geoserver.ReconfigureStyle(which) }, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
217 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
218 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
219 return nil, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
220 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
221 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
222 func init() { |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
223 registerReconfigureFunc("morphology_classbreaks", |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
224 func(old sql.NullString, curr string) (func(), error) { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
225 return reconfigureClassBreaks( |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
226 old, curr, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
227 "sounding_results_contour_lines_geoserver", |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
228 func() { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
229 log.Println( |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
230 "todo: Trigger expensive recalculation of sounding result contours.") |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
231 }) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
232 }) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
233 registerReconfigureFunc("morphology_classbreaks_compare", |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
234 func(old sql.NullString, curr string) (func(), error) { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
235 return reconfigureClassBreaks( |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
236 old, curr, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
237 "sounding_differences", |
3929
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
238 func() { go deleteSoundingDiffs() }) |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
239 }) |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
240 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
241 |
3929
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
242 func deleteSoundingDiffs() { |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
243 // TODO: Better do that in import queue? |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
244 ctx := context.Background() |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
245 |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
246 if err := auth.RunAs(ctx, "sys_admin", |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
247 func(conn *sql.Conn) error { |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
248 _, err := conn.ExecContext(ctx, deleteSoundingDiffsSQL) |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
249 return err |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
250 }, |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
251 ); err != nil { |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
252 log.Printf("error: Cleaning sounding diffs cache failed: %v\n", err) |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
253 } |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
254 } |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
255 |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
256 func setSystemSettings( |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
257 input interface{}, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
258 req *http.Request, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
259 conn *sql.Conn, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
260 ) (jr JSONResult, err error) { |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
261 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
262 settings := input.(*map[string]string) |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
263 |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
264 ctx := req.Context() |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
265 var tx *sql.Tx |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
266 if tx, err = conn.BeginTx(ctx, nil); err != nil { |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
267 return |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
268 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
269 defer tx.Rollback() |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
270 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
271 var setStmt *sql.Stmt |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
272 if setStmt, err = tx.PrepareContext(ctx, updateSettingSQL); err != nil { |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
273 return |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
274 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
275 defer setStmt.Close() |
3834
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
276 var getStmt *sql.Stmt |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
277 if getStmt, err = tx.PrepareContext(ctx, getConfigSQL); err != nil { |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
278 return |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
279 } |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
280 defer getStmt.Close() |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
281 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
282 reconfigure := map[string]func(){} |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
283 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
284 for key, value := range *settings { |
3834
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
285 var old sql.NullString |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
286 err = getStmt.QueryRowContext(ctx, key).Scan(&old) |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
287 switch { |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
288 case err == sql.ErrNoRows: |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
289 old.Valid, err = false, nil |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
290 case err != nil: |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
291 return |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
292 } |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
293 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
294 if cmp := reconfigureFunc(key); cmp != nil { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
295 var fn func() |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
296 if fn, err = cmp(old, value); err != nil { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
297 return |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
298 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
299 if fn != nil { |
3834
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
300 reconfigure[key] = fn |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
301 } |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
302 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
303 |
3630
2467e619cf67
Fixed more SQL typos.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3629
diff
changeset
|
304 if _, err = setStmt.ExecContext(ctx, key, value); err != nil { |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
305 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
306 } |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
307 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
308 |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
309 if err = tx.Commit(); err != nil { |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
310 return |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
311 } |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
312 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
313 for _, fn := range reconfigure { |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
314 fn() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
315 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
316 |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
317 jr = JSONResult{ |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
318 Code: http.StatusCreated, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
319 Result: struct { |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
320 Result string `json:"result"` |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
321 }{"success"}, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
322 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
323 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
324 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
325 |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
326 // Map/Feature style end points |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
327 |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
328 func getFeatureStyle( |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
329 _ interface{}, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
330 req *http.Request, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
331 db *sql.Conn, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
332 ) (jr JSONResult, err error) { |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
333 |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
334 feature := mux.Vars(req)["feature"] |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
335 attr := mux.Vars(req)["attr"] |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
336 |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
337 c := models.Colour{} |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
338 err = db.QueryRowContext( |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
339 req.Context(), |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
340 getFeatureColourSQL, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
341 feature, attr, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
342 ).Scan(&c.R, &c.G, &c.B, &c.A) |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
343 |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
344 switch { |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
345 case err == sql.ErrNoRows: |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
346 err = JSONError{ |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
347 Code: http.StatusNotFound, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
348 Message: "Requestes style not found.", |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
349 } |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
350 return |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
351 case err != nil: |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
352 return |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
353 } |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
354 |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
355 jr.Result = &struct { |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
356 Colour models.Colour `json:"colour"` |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
357 Code string `json:"code"` |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
358 }{c, fmt.Sprintf("rgba(%d, %d, %d, %g)", c.R, c.G, c.B, c.A)} |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
359 return |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
360 } |
846
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
361 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
362 func setFeatureStyle( |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
363 input interface{}, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
364 req *http.Request, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
365 db *sql.Conn, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
366 ) (jr JSONResult, err error) { |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
367 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
368 feature := mux.Vars(req)["feature"] |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
369 attr := mux.Vars(req)["attr"] |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
370 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
371 c := input.(*models.Colour) |
854
83c271cb2344
Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents:
850
diff
changeset
|
372 if !c.IsValid() { |
83c271cb2344
Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents:
850
diff
changeset
|
373 err = JSONError{http.StatusBadRequest, "error: invalid colours"} |
83c271cb2344
Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents:
850
diff
changeset
|
374 return |
83c271cb2344
Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents:
850
diff
changeset
|
375 } |
846
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
376 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
377 var res sql.Result |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
378 res, err = db.ExecContext( |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
379 req.Context(), |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
380 setFeatureColourSQL, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
381 feature, attr, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
382 c.R, c.G, c.B, c.A) |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
383 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
384 if err != nil { |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
385 return |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
386 } |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
387 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
388 if n, err2 := res.RowsAffected(); err2 == nil && n == 0 { |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
389 err = JSONError{ |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
390 Code: http.StatusNotFound, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
391 Message: "Requestes style not found.", |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
392 } |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
393 return |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
394 } |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
395 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
396 jr = JSONResult{ |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
397 Code: http.StatusCreated, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
398 Result: struct { |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
399 Result string `json:"result"` |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
400 }{"success"}, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
401 } |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
402 return |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
403 } |