# HG changeset patch # User Sascha Wilde # Date 1538124963 -7200 # Node ID 0f61bfc2104145372c23e3808e20e09f20b4047f # Parent 157a3e42d4afce09dbc5f38c3f28e1446d21940b Added end point to get style (colour) information for feature. diff -r 157a3e42d4af -r 0f61bfc21041 pkg/controllers/routes.go --- a/pkg/controllers/routes.go Fri Sep 28 10:46:01 2018 +0200 +++ b/pkg/controllers/routes.go Fri Sep 28 10:56:03 2018 +0200 @@ -54,6 +54,11 @@ NoConn: true, })).Methods(http.MethodGet) + // System Settings + api.Handle("/system/style/{feature}/{attr}", any(&JSONHandler{ + Handle: getFeatureStyle, + })).Methods(http.MethodGet) + // Password resets. api.Handle("/users/passwordreset", &JSONHandler{ Input: func() interface{} { return new(models.PWResetUser) }, diff -r 157a3e42d4af -r 0f61bfc21041 pkg/controllers/system.go --- a/pkg/controllers/system.go Fri Sep 28 10:46:01 2018 +0200 +++ b/pkg/controllers/system.go Fri Sep 28 10:56:03 2018 +0200 @@ -2,13 +2,23 @@ import ( "database/sql" + "fmt" "io/ioutil" "net/http" "strings" + "gemma.intevation.de/gemma/pkg/models" "github.com/gorilla/mux" ) +const ( + getFeatureColourSQL = `SELECT r,g,b,a +FROM systemconf.feature_colours +WHERE feature_name = $1 AND style_attr = $2` +) + +// System status end points + func showSystemLog( _ interface{}, req *http.Request, _ *sql.Conn, @@ -51,3 +61,39 @@ } return } + +// Map/Feature style end points + +func getFeatureStyle( + _ interface{}, + req *http.Request, + db *sql.Conn, +) (jr JSONResult, err error) { + + feature := mux.Vars(req)["feature"] + attr := mux.Vars(req)["attr"] + + c := models.Colour{} + err = db.QueryRowContext( + req.Context(), + getFeatureColourSQL, + feature, attr, + ).Scan(&c.R, &c.G, &c.B, &c.A) + + switch { + case err == sql.ErrNoRows: + err = JSONError{ + Code: http.StatusNotFound, + Message: "Requestes style not found.", + } + return + case err != nil: + return + } + + jr.Result = &struct { + Colour models.Colour `json:"colour"` + Code string `json:"code"` + }{c, fmt.Sprintf("rgba(%d, %d, %d, %g)", c.R, c.G, c.B, c.A)} + return +} diff -r 157a3e42d4af -r 0f61bfc21041 pkg/models/system.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/models/system.go Fri Sep 28 10:56:03 2018 +0200 @@ -0,0 +1,10 @@ +package models + +type ( + Colour struct { + R int `json:"r"` + G int `json:"g"` + B int `json:"b"` + A float32 `json:"a"` + } +) diff -r 157a3e42d4af -r 0f61bfc21041 schema/auth.sql --- a/schema/auth.sql Fri Sep 28 10:46:01 2018 +0200 +++ b/schema/auth.sql Fri Sep 28 10:56:03 2018 +0200 @@ -10,8 +10,9 @@ -- -- Privileges for waterway_user -- -GRANT USAGE ON SCHEMA public, users, waterway TO waterway_user; +GRANT USAGE ON SCHEMA public, users, waterway, systemconf TO waterway_user; GRANT SELECT ON ALL TABLES IN SCHEMA public, users, waterway TO waterway_user; +GRANT SELECT ON systemconf.feature_colours TO waterway_user; GRANT UPDATE (pw, map_extent, email_address) ON users.list_users TO waterway_user;