Main project #1

Merged
raul merged 33 commits from testing into main 2024-06-14 07:49:34 +02:00
4 changed files with 44 additions and 16 deletions
Showing only changes of commit f78c66fdc3 - Show all commits

View File

@ -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
}

View File

@ -13,22 +13,22 @@
<div id="main">
<b>
<ul>
<li>
<li class="hor">
<p><a href="https://git.bulgariu.xyz/raul/aemet" target="_blank">Source code</a></p>
</li>
<li>
<li class="hor">
<p><a href="https://git.bulgariu.xyz/raul/aemet" target="_blank">API Docs</a></p>
</li>
<li>
<li class="hor">
<p><a href="https://git.bulgariu.xyz/raul/aemet" target="_blank">But why though?</a></p>
</li>
<li>
<li class="hor">
<p>
<select
<select class="optionCap"
onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option value="">Select...</option>
{{ range $key, $value := .Localidades }}
<option value="{{ $key }}">{{ $key }}</option>
<option value="{{ $key }}" class="optionCap">{{ $key }}</option>
{{ end }}
</select>
</p>

View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>AEMET Client</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="style.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div id="main">
<b>
<ul>
{{ range $key, $value := .Localidades }}
<li>
<p><a href="{{ $key }}" class="optionCap">{{ $key }}</a></p>
</li>
{{ end }}
</ul>
</b>
</div>
</div>
</body>
</html>

View File

@ -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;
}