From f78c66fdc3678d1a77f52913aba945a793aa5d87 Mon Sep 17 00:00:00 2001 From: raul Date: Fri, 31 May 2024 08:57:52 +0200 Subject: [PATCH] Add page for selecting province to pull weather from --- cmd/serverFunc.go | 14 +++++--------- cmd/templates/index.html | 12 ++++++------ cmd/templates/redirect.html | 27 +++++++++++++++++++++++++++ cmd/templates/style.css | 7 ++++++- 4 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 cmd/templates/redirect.html diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index fcae361..a2d17f4 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -28,7 +28,7 @@ func server() { LoadHTMLFromEmbedFS(r, templatesFolder, "templates/*.html") r.StaticFileFS("/style.css", "./templates/style.css", http.FS(templatesFolder)) - r.GET("/", autoDetectProvince) + r.GET("/", chooseProvince) r.GET("/:local", returnProvince) r.GET("/api/:localidad", returnAPIWeather) r.GET("/api/:localidad/:dia", returnAPIWeather) @@ -36,16 +36,13 @@ func server() { r.Run(":" + listenPort) } -func autoDetectProvince(c *gin.Context) { - // c.HTML(http.StatusOK, "templates/index.html", gin.H{ - // "title": "Hello world!", - // }) - - // TODO: Try to autodetect the province of the IP and show the correct corresponding weather +func chooseProvince(c *gin.Context) { + c.HTML(http.StatusOK, "templates/redirect.html", gin.H{ + "Localidades": localidades, + }) } func returnProvince(c *gin.Context) { - // TODO: Return prettified HTML representation of the weather based on url parameter localidad := c.Param("local") if isAv := localityIsAvailable(localidad); isAv != true { c.String(http.StatusNotFound, "The locality doesn't exist or is currently not supported, sorry\n") @@ -56,7 +53,6 @@ func returnProvince(c *gin.Context) { if err != nil { e := fmt.Sprint(err) c.String(http.StatusInternalServerError, e) - //c.String(500, jsonData) return } diff --git a/cmd/templates/index.html b/cmd/templates/index.html index db6c327..9c1fb80 100644 --- a/cmd/templates/index.html +++ b/cmd/templates/index.html @@ -13,22 +13,22 @@
    -
  • +
  • Source code

  • -
  • +
  • API Docs

  • -
  • +
  • But why though?

  • -
  • +
  • -

    diff --git a/cmd/templates/redirect.html b/cmd/templates/redirect.html new file mode 100644 index 0000000..0f6d7d8 --- /dev/null +++ b/cmd/templates/redirect.html @@ -0,0 +1,27 @@ + + + + + AEMET Client + + + + + + +
    +
    + +
      + {{ range $key, $value := .Localidades }} +
    • +

      {{ $key }}

      +
    • + {{ end }} +
    +
    +
    +
    + + + diff --git a/cmd/templates/style.css b/cmd/templates/style.css index 4e31dc1..52444fc 100644 --- a/cmd/templates/style.css +++ b/cmd/templates/style.css @@ -9,6 +9,10 @@ table { margin-right: auto; } +.optionCap { + text-transform: capitalize; +} + ul { text-align: center; list-style: none; @@ -17,11 +21,12 @@ ul { padding: 0; } -li { +li.hor { display: inline-flex; margin-right: 20px; } + table * { text-align: center; }