Mercurial > gemma
view pkg/controllers/search.go @ 2549:9bf6b767a56a
client: refactored and improved splitscreen for diagrams
To make different diagrams possible, the splitscreen view needed to be decoupled from the cross profiles.
Also the style has changed to make it more consistent with the rest of the app. The standard box header
is now used and there are collapse and expand animations.
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Fri, 08 Mar 2019 08:50:47 +0100 |
parents | 5bb1e3c1f364 |
children | 571801483a70 |
line wrap: on
line source
// This is Free Software under GNU Affero General Public License v >= 3.0 // without warranty, see README.md and license for details. // // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // // Copyright (C) 2018 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha Wilde <sascha.wilde@intevation.de> // * Sascha Teichmann <sascha.teichmann@intevation.de> package controllers import ( "database/sql" "net/http" "regexp" "strconv" "strings" "gemma.intevation.de/gemma/pkg/models" ) const ( searchHectometreSQL = `SELECT COALESCE(json_agg(r),'[]') FROM (SELECT (location_code).hectometre || ' rhm' AS name, ST_AsGeoJSON(geom)::json AS geom, 'rhm' AS type FROM waterway.distance_marks_virtual WHERE (location_code).hectometre = $1) r` searchMostSQL = `SELECT search_most($1)::text` listBottlenecksSQL = ` SELECT COALESCE(json_agg(r),'[]') FROM ( SELECT objnam AS name, ST_AsGeoJSON(ST_Centroid(area))::json AS geom, 'bottleneck' AS type FROM waterway.bottlenecks ORDER BY objnam) r ` ) var rkmRegex = regexp.MustCompile( "^[[:space:]]*([0-9]+)([,.]([0-9]))?[[:space:]]*$", ) func searchFeature( input interface{}, req *http.Request, db *sql.Conn, ) (jr JSONResult, err error) { s := input.(*models.SearchRequest) if len(s.SearchString) == 0 { err = JSONError{http.StatusBadRequest, "error: empty search string"} return } var result string m := rkmRegex.FindStringSubmatch(s.SearchString) if len(m) != 0 { // Handle search for river kilometre: var hectometre int if hectometre, err = strconv.Atoi(m[1]); err != nil { return } hectometre *= 10 if m[3] != "" { var h int if h, err = strconv.Atoi(m[3]); err != nil { return } hectometre += h } err = db.QueryRowContext( req.Context(), searchHectometreSQL, hectometre, ).Scan(&result) } else { // Hande search for bottlencks: err = db.QueryRowContext( req.Context(), searchMostSQL, s.SearchString, ).Scan(&result) } if err != nil { return } jr.Result = strings.NewReader(result) return } func listBottlenecks( _ interface{}, req *http.Request, conn *sql.Conn, ) (jr JSONResult, err error) { var result string err = conn.QueryRowContext( req.Context(), listBottlenecksSQL).Scan(&result) switch { case err == sql.ErrNoRows: err = JSONError{ Code: http.StatusNotFound, Message: "Cannot find any bottleneck.", } return case err != nil: return } jr = JSONResult{Result: strings.NewReader(result)} return }