Mercurial > gemma
annotate pkg/controllers/printtemplates.go @ 2152:8132434f4093
Surveys controller: Fixed nullable water level.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 08 Feb 2019 11:47:31 +0100 |
parents | 2c67c51d57ad |
children | cdd68f555ad7 |
rev | line source |
---|---|
2148
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package controllers |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "database/sql" |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "net/http" |
2150
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
19 "time" |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
20 |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
21 "gemma.intevation.de/gemma/pkg/models" |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
22 ) |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
23 |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
24 const ( |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
25 listPrintTemplatesSQL = ` |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
26 SELECT |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
27 template_name, |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
28 date_info |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
29 FROM |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
30 users.templates |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
31 ORDER BY date_info DESC` |
2148
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 ) |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 func listPrintTemplates( |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 _ interface{}, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 req *http.Request, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 conn *sql.Conn, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 ) (jr JSONResult, err error) { |
2150
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
39 |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
40 type template struct { |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
41 Name string `json:"name"` |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
42 Time models.Time `json:"time"` |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
43 } |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
44 |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
45 var rows *sql.Rows |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
46 if rows, err = conn.QueryContext(req.Context(), listPrintTemplatesSQL); err != nil { |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
47 return |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
48 } |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
49 defer rows.Close() |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
50 |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
51 templates := []*template{} |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
52 |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
53 for rows.Next() { |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
54 var tmpl template |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
55 var w time.Time |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
56 if err = rows.Scan(&tmpl.Name, &w); err != nil { |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
57 return |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
58 } |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
59 tmpl.Time = models.Time{w} |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
60 templates = append(templates, &tmpl) |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
61 } |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
62 |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2148
diff
changeset
|
63 jr = JSONResult{Result: templates} |
2148
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 return |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 } |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 func fetchPrintTemplate( |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 _ interface{}, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 req *http.Request, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 conn *sql.Conn, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 ) (jr JSONResult, err error) { |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 // TODO: Implement me! |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 return |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 } |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 func createPrintTemplate( |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 _ interface{}, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 req *http.Request, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 conn *sql.Conn, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 ) (jr JSONResult, err error) { |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 // TODO: Implement me! |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 return |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 } |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 func deletePrintTemplate( |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 _ interface{}, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 req *http.Request, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 conn *sql.Conn, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 ) (jr JSONResult, err error) { |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 // TODO: Implement me! |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 return |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 } |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 func updatePrintTemplate( |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 _ interface{}, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 req *http.Request, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 conn *sql.Conn, |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 ) (jr JSONResult, err error) { |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 // TODO: Implement me! |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 return |
4057a1f15174
Print templates: Forget to add controller file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 } |