updated default year used on frontend
This commit is contained in:
Borna Rajković 2024-01-07 22:01:58 +01:00
parent 6bd0c9e37c
commit 76ef62bb96
4 changed files with 6 additions and 7 deletions

View File

@ -67,20 +67,19 @@ func main() {
c.AbortWithError(http.StatusBadRequest, err) c.AbortWithError(http.StatusBadRequest, err)
return return
} }
countries, _ := countryService.Find()
years, _ := yearService.Find() years, _ := yearService.Find()
if search.Year == nil { if search.Year == nil {
c.HTML(http.StatusOK, "index.gohtml", gin.H{"Years": years, "Countries": countries, "Search": search}) c.HTML(http.StatusOK, "index.gohtml", gin.H{"Year": time.Now().Year(), "Years": years})
return return
} }
countries, _ := countryService.Find()
holidays, _ := holidayService.Find(search, holiday.Paging{PageSize: 100}) holidays, _ := holidayService.Find(search, holiday.Paging{PageSize: 100})
c.HTML(http.StatusOK, "results.gohtml", gin.H{"Years": years, "Countries": countries, "Search": search, "Holidays": mapHolidays(holidays).Holidays}) c.HTML(http.StatusOK, "results.gohtml", gin.H{"Years": years, "Countries": countries, "Search": search, "Holidays": mapHolidays(holidays).Holidays})
}) })
g.GET("/documentation", func(c *gin.Context) { g.GET("/documentation", func(c *gin.Context) {
countries, _ := countryService.Find() countries, _ := countryService.Find()
years, _ := yearService.Find() years, _ := yearService.Find()
c.HTML(http.StatusOK, "documentation.gohtml", gin.H{"Years": years, "Countries": countries}) c.HTML(http.StatusOK, "documentation.gohtml", gin.H{"Year": time.Now().Year(), "Years": years, "Countries": countries})
}) })
log.Fatal(http.ListenAndServe(":5281", g)) log.Fatal(http.ListenAndServe(":5281", g))
} }

View File

@ -1,7 +1,7 @@
# scripts for building app # scripts for building app
# requires go 1.19+ and git installed # requires go 1.19+ and git installed
VERSION := 0.3.0 VERSION := 0.3.1
serve: serve:
go run ./... go run ./...

View File

@ -58,7 +58,7 @@
<label for="dsy-year">Godina</label> <label for="dsy-year">Godina</label>
<select id="dsy-year" name="year"> <select id="dsy-year" name="year">
{{range $entry := .Years}} {{range $entry := .Years}}
<option value="{{$entry}}">{{$entry}}</option> <option {{if eq $.Year $entry}}selected{{end}} value="{{$entry}}">{{$entry}}</option>
{{end}} {{end}}
</select> </select>
</section> </section>

View File

@ -22,7 +22,7 @@
<label for="year">Za godinu:</label> <label for="year">Za godinu:</label>
<select id="year" name="year"> <select id="year" name="year">
{{range $entry := .Years}} {{range $entry := .Years}}
<option {{if intpeq $.Search.Year $entry}}selected{{end}} value="{{$entry}}">{{$entry}}</option> <option {{if eq $.Year $entry}}selected{{end}} value="{{$entry}}">{{$entry}}</option>
{{end}} {{end}}
</select> </select>
</div> </div>