Mercurial > gemma
annotate pkg/geoserver/templates.go @ 4017:639bdb17c3f2
Fixed offset for fairway box
This was broken by
changeset: 4080:bf86f9a08733
user: Thomas Junk <thomas.junk@intevation.de>
Date: Thu Jul 18 15:04:30 2019 +0200
summary: improve fairwaydiagram printing positioning
For the record: I think the current implementation exceptionally
flawed. Instead of adding extra offset parameters to the diagram
elements the whole building block with all contained elements should
be translated in one step, that would be less cluttered and less error
prone...
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 19 Jul 2019 16:59:25 +0200 |
parents | 3fcc4e11fc00 |
children | 8aff98c84a5a |
rev | line source |
---|---|
3826
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
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:
3831
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
3826
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
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:
3831
diff
changeset
|
13 // * Markus Kottländer <markus.kottlaender@intevation.de> |
3826
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 package geoserver |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import ( |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
18 "context" |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
19 "database/sql" |
3826
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "strings" |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
21 "text/template" |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
22 |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
23 "gemma.intevation.de/gemma/pkg/auth" |
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:
3831
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/models" |
3826
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 ) |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
27 const ( |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
28 selectClassBreaksSQL = ` |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
29 SELECT config_val FROM sys_admin.system_config |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
30 WHERE config_key = $1` |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
31 ) |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
32 |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
33 func init() { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
34 RegisterStylePreprocessor( |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
35 "sounding_results_contour_lines_geoserver", |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
36 templateContourLinesFunc("morphology_classbreaks")) |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
37 RegisterStylePreprocessor( |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
38 "sounding_differences", |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
39 templateContourLinesFunc("morphology_classbreaks_compare")) |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
40 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
41 |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
42 func templateContourLinesFunc(configKey string) func(string) (string, error) { |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
43 return func(data string) (string, error) { |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
44 return templateContourLines(data, configKey) |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
45 } |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
46 } |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
47 |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
48 func templateContourLines(data, configKey string) (string, error) { |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
49 tmpl, err := template.New("template").Parse(data) |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
50 if err != nil { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
51 return "", err |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
52 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
53 |
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:
3831
diff
changeset
|
54 var cb []models.ClassBreak |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
55 |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
56 if cb, err = countourLinesClassBreaks(configKey); err != nil { |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
57 return "", err |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
58 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
59 |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
60 var buf strings.Builder |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
61 if err = tmpl.Execute(&buf, cb); err != nil { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
62 return "", err |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
63 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
64 return buf.String(), nil |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
65 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
66 |
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:
3831
diff
changeset
|
67 func countourLinesClassBreaks(configKey string) ([]models.ClassBreak, error) { |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
68 |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
69 var config string |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
70 ctx := context.Background() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
71 if err := auth.RunAs( |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
72 ctx, |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
73 "sys_admin", |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
74 func(conn *sql.Conn) error { |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
75 return conn.QueryRowContext( |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
76 ctx, |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
77 selectClassBreaksSQL, |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
78 configKey, |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
79 ).Scan(&config) |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
80 }, |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
81 ); err != nil { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
82 return nil, err |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
83 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
84 |
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:
3831
diff
changeset
|
85 cc, err := models.ParseColorValues(config) |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
86 if err != nil { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
87 return nil, err |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
88 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
89 |
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:
3831
diff
changeset
|
90 return cc.ClassBreaks(), nil |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
91 } |