Mercurial > gemma
annotate pkg/controllers/system.go @ 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.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 09 Jul 2019 11:31:49 +0200 |
parents | d68c6be758b6 |
children | 45be361f2d48 |
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" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
18 "database/sql" |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
19 "fmt" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
20 "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
|
21 "log" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
22 "net/http" |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
23 "strings" |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
24 "sync" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
25 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
26 "github.com/gorilla/mux" |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
27 |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
28 "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
|
29 "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
|
30 "gemma.intevation.de/gemma/pkg/models" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
31 ) |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
32 |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
33 const ( |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
34 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
|
35 FROM systemconf.feature_colours |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
36 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
|
37 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
|
38 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
|
39 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
|
40 |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
41 getSettingsSQL = ` |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
42 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
|
43 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
|
44 |
3834
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
45 getConfigSQL = ` |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
50 updateSettingSQL = ` |
3630
2467e619cf67
Fixed more SQL typos.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3629
diff
changeset
|
51 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
|
52 VALUES ($1, $2) |
3629
1825a1bc9fb1
Fixed typo in SQL statement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3628
diff
changeset
|
53 ON CONFLICT (config_key) DO UPDATE SET config_val = $2` |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
54 ) |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
55 |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
56 // System status end points |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
57 |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
58 func showSystemLog( |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
59 _ interface{}, req *http.Request, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
60 _ *sql.Conn, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
61 ) (jr JSONResult, err error) { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
62 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
63 serviceName := mux.Vars(req)["service"] |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
64 fileName := mux.Vars(req)["file"] |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
65 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
66 // 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
|
67 // 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
|
68 // the safe site... |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
69 if strings.Contains(fileName, "/") { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
70 err = JSONError{http.StatusBadRequest, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
71 "error: no slashes allowed in file name"} |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
72 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
73 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
74 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
75 var path string |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
76 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
77 switch serviceName { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
78 case "apache2", "postgresql": |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
79 path = "/var/log/" + serviceName + "/" + fileName |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
80 default: |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
81 err = JSONError{http.StatusBadRequest, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
82 "error: invalid service: " + serviceName} |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
83 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
84 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
85 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
86 var txt []byte |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
87 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
88 if txt, err = ioutil.ReadFile(path); err != nil { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
89 return |
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 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
92 jr = JSONResult{ |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
93 Result: struct { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
94 Path string `json:"path"` |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
95 Content string `json:"content"` |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
96 }{path, string(txt)}, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
97 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
98 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
99 } |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
100 |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
101 func getSystemConfig( |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
102 _ interface{}, req *http.Request, |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
103 _ *sql.Conn, |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
104 ) (jr JSONResult, err error) { |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
105 |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
106 cfg := config.PublishedConfig() |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
107 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
|
108 jr = JSONResult{Result: strings.NewReader("{}")} |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
109 return |
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 |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
112 var data []byte |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
113 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
|
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 jr = JSONResult{Result: bytes.NewReader(data)} |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
118 return |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
119 } |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
120 |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
121 func getSystemSettings( |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
122 _ interface{}, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
123 req *http.Request, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
124 conn *sql.Conn, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
125 ) (jr JSONResult, err error) { |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
126 |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
127 var rows *sql.Rows |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
128 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
|
129 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
130 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
131 defer rows.Close() |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
132 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
133 settings := map[string]string{} |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
134 |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
135 for rows.Next() { |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
136 var key, val string |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
137 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
|
138 return |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
139 } |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
140 settings[key] = val |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
141 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
142 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
|
143 return |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
144 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
145 |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
146 jr = JSONResult{Result: settings} |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
147 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
148 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
149 |
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
|
150 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
|
151 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
152 var ( |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
153 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
|
154 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
|
155 ) |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
156 |
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
|
157 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
|
158 reconfigureFuncsMu.Lock() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
159 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
|
160 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
|
161 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
162 |
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
|
163 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
|
164 reconfigureFuncsMu.Lock() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
165 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
|
166 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
|
167 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
168 |
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
|
169 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
|
170 |
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
|
171 // 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
|
172 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
|
173 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
|
174 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
|
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 |
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 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
|
178 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
|
179 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
|
180 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
|
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 |
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 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
|
184 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
|
185 } |
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 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
|
188 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
|
189 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
|
190 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
|
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 |
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 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
|
194 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
|
195 } |
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 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
|
198 |
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 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
|
200 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
|
201 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
|
202 } |
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 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
|
204 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
|
205 } |
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 } |
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 // 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
|
209 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
|
210 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
|
211 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
|
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 |
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 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
|
215 } |
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 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 "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
|
223 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
|
224 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
|
225 "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
|
226 }) |
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 }) |
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 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
|
229 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
|
230 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
|
231 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
|
232 "sounding_differences", |
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 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
|
234 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
|
235 "todo: Trigger expensive recalculation of sounding differences 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
|
236 }) |
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 }) |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
238 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
239 |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
240 func setSystemSettings( |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
241 input interface{}, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
242 req *http.Request, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
243 conn *sql.Conn, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
244 ) (jr JSONResult, err error) { |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
245 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
246 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
|
247 |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
248 ctx := req.Context() |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
249 var tx *sql.Tx |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
250 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
|
251 return |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
252 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
253 defer tx.Rollback() |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
254 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
255 var setStmt *sql.Stmt |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
256 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
|
257 return |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
258 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 return |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
263 } |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
264 defer getStmt.Close() |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
265 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
266 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
|
267 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
268 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
|
269 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
|
270 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
|
271 switch { |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
272 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
|
273 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
|
274 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
|
275 return |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
276 } |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
277 |
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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 } |
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
|
283 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
|
284 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
|
285 } |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
286 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
287 |
3630
2467e619cf67
Fixed more SQL typos.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3629
diff
changeset
|
288 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
|
289 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
290 } |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
291 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
292 |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
293 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
|
294 return |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
295 } |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
296 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
297 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
|
298 fn() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
299 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
300 |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
301 jr = JSONResult{ |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
302 Code: http.StatusCreated, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
303 Result: struct { |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
304 Result string `json:"result"` |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
305 }{"success"}, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
306 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
307 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
308 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
309 |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
310 // 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
|
311 |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
312 func getFeatureStyle( |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
313 _ interface{}, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
314 req *http.Request, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
315 db *sql.Conn, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
316 ) (jr JSONResult, err error) { |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
317 |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
318 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
|
319 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
|
320 |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
321 c := models.Colour{} |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
322 err = db.QueryRowContext( |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
323 req.Context(), |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
324 getFeatureColourSQL, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
325 feature, attr, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
326 ).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
|
327 |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
328 switch { |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
329 case err == sql.ErrNoRows: |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
330 err = JSONError{ |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
331 Code: http.StatusNotFound, |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
332 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
|
333 } |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
334 return |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
335 case err != nil: |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
336 return |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
337 } |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
338 |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
339 jr.Result = &struct { |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
340 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
|
341 Code string `json:"code"` |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
342 }{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
|
343 return |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
344 } |
846
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
345 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
346 func setFeatureStyle( |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
347 input interface{}, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
348 req *http.Request, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
349 db *sql.Conn, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
350 ) (jr JSONResult, err error) { |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
351 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
352 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
|
353 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
|
354 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
355 c := input.(*models.Colour) |
854
83c271cb2344
Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents:
850
diff
changeset
|
356 if !c.IsValid() { |
83c271cb2344
Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents:
850
diff
changeset
|
357 err = JSONError{http.StatusBadRequest, "error: invalid colours"} |
83c271cb2344
Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents:
850
diff
changeset
|
358 return |
83c271cb2344
Reverted fcb38cedc680 (More tightened color model.)
Sascha Wilde <wilde@intevation.de>
parents:
850
diff
changeset
|
359 } |
846
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
360 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
361 var res sql.Result |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
362 res, err = db.ExecContext( |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
363 req.Context(), |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
364 setFeatureColourSQL, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
365 feature, attr, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
366 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
|
367 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
368 if err != nil { |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
369 return |
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 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
372 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
|
373 err = JSONError{ |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
374 Code: http.StatusNotFound, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
375 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
|
376 } |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
377 return |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
378 } |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
379 |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
380 jr = JSONResult{ |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
381 Code: http.StatusCreated, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
382 Result: struct { |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
383 Result string `json:"result"` |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
384 }{"success"}, |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
385 } |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
386 return |
6902032757e4
Added end point to set style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
840
diff
changeset
|
387 } |