From fcb376367c9506c91dd134e3c873a717b320de04 Mon Sep 17 00:00:00 2001 From: Vladimir Simakhin Date: Mon, 20 May 2024 09:26:49 +0200 Subject: [PATCH] Correct using styles and classes for the sidebar when switching between the pages --- CHANGELOG.md | 1 + README.md | 1 + app/handlers_export.go | 15 +++++++++--- app/handlers_import.go | 2 +- app/handlers_licensing.go | 5 +++- app/handlers_logbook.go | 4 +++- app/handlers_map.go | 1 + app/handlers_settings.go | 5 +++- app/handlers_stats.go | 10 ++++++++ app/templates/base.gohtml | 48 ++++++++++++++++++++------------------- 10 files changed, 62 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8080b44..1a2431b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] +- Fix: Correct using styles and classes for the sidebar when switching between the pages - Update: Code cleanup, removing code for synchronization with mobile client (will not continue working on it) - Update: Update golang version (1.21.10) and go packages. diff --git a/README.md b/README.md index d5d5751..f34a603 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ You also can easily export all flight records into EASA style pdf format, print ## [Unreleased] +- Fix: Correct using styles and classes for the sidebar when switching between the pages - Update: Code cleanup, removing code for synchronization with mobile client (will not continue working on it) - Update: Update golang version (1.21.10) and go packages. diff --git a/app/handlers_export.go b/app/handlers_export.go index 42b00b8..ef8c282 100644 --- a/app/handlers_export.go +++ b/app/handlers_export.go @@ -19,21 +19,30 @@ const exportXLS = "xls" // HandlerExportPDFA4Page is a handler for /export-pdf-a4 page func (app *application) HandlerExportPDFA4Page(w http.ResponseWriter, r *http.Request) { - if err := app.renderTemplate(w, r, "export-pdf-a4", &templateData{}); err != nil { + data := make(map[string]interface{}) + data["activePage"] = "export" + data["activeSubPage"] = "pdfa4" + if err := app.renderTemplate(w, r, "export-pdf-a4", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } } // HandlerExportPDFA5Page is a handler for /export-pdf-a5 page func (app *application) HandlerExportPDFA5Page(w http.ResponseWriter, r *http.Request) { - if err := app.renderTemplate(w, r, "export-pdf-a5", &templateData{}); err != nil { + data := make(map[string]interface{}) + data["activePage"] = "export" + data["activeSubPage"] = "pdfa5" + if err := app.renderTemplate(w, r, "export-pdf-a5", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } } // HandlerExportPDFA5Page is a handler for /export-pdf-a5 page func (app *application) HandlerExportCSVXLSPage(w http.ResponseWriter, r *http.Request) { - if err := app.renderTemplate(w, r, "export-csv-xls", &templateData{}); err != nil { + data := make(map[string]interface{}) + data["activePage"] = "export" + data["activeSubPage"] = "csv" + if err := app.renderTemplate(w, r, "export-csv-xls", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } } diff --git a/app/handlers_import.go b/app/handlers_import.go index b231c33..a5d185e 100644 --- a/app/handlers_import.go +++ b/app/handlers_import.go @@ -16,7 +16,7 @@ import ( func (app *application) HandlerImport(w http.ResponseWriter, r *http.Request) { data := make(map[string]interface{}) - + data["activePage"] = "import" if err := app.renderTemplate(w, r, "import", &templateData{Data: data}, "import-mapfields-modal"); err != nil { app.errorLog.Println(err) } diff --git a/app/handlers_licensing.go b/app/handlers_licensing.go index b43146f..503f57d 100644 --- a/app/handlers_licensing.go +++ b/app/handlers_licensing.go @@ -15,7 +15,10 @@ import ( // HandlerLicensing is a handler for /licensing page func (app *application) HandlerLicensing(w http.ResponseWriter, r *http.Request) { - if err := app.renderTemplate(w, r, "licensing", &templateData{}); err != nil { + data := make(map[string]interface{}) + data["activePage"] = "licensing" + + if err := app.renderTemplate(w, r, "licensing", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } } diff --git a/app/handlers_logbook.go b/app/handlers_logbook.go index 9fdcd61..83f8fc8 100644 --- a/app/handlers_logbook.go +++ b/app/handlers_logbook.go @@ -8,7 +8,9 @@ import ( // HandlerLogbook is a handler for /logbook page func (app *application) HandlerLogbook(w http.ResponseWriter, r *http.Request) { - if err := app.renderTemplate(w, r, "logbook", &templateData{}); err != nil { + data := make(map[string]interface{}) + data["activePage"] = "logbook" + if err := app.renderTemplate(w, r, "logbook", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } } diff --git a/app/handlers_map.go b/app/handlers_map.go index 66a024f..2856725 100644 --- a/app/handlers_map.go +++ b/app/handlers_map.go @@ -34,6 +34,7 @@ func (app *application) HandlerMap(w http.ResponseWriter, r *http.Request) { data["classes"] = classes data["models"] = models data["regs"] = regs + data["activePage"] = "map" if err := app.renderTemplate(w, r, "map", &templateData{Data: data}); err != nil { app.errorLog.Println(err) diff --git a/app/handlers_settings.go b/app/handlers_settings.go index 5d93ab0..faac3f4 100644 --- a/app/handlers_settings.go +++ b/app/handlers_settings.go @@ -10,6 +10,8 @@ import ( // HandlerSettings is a handler for Settings page func (app *application) HandlerSettings(w http.ResponseWriter, r *http.Request) { data := make(map[string]interface{}) + data["activePage"] = "settings" + data["activeSubPage"] = "general" if err := app.renderTemplate(w, r, "settings", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } @@ -25,7 +27,8 @@ func (app *application) HandlerSettingsAirportDB(w http.ResponseWriter, r *http. data := make(map[string]interface{}) data["records"] = records - + data["activePage"] = "settings" + data["activeSubPage"] = "airports" if err := app.renderTemplate(w, r, "settings-airportdb", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } diff --git a/app/handlers_stats.go b/app/handlers_stats.go index 6cd213b..69bb294 100644 --- a/app/handlers_stats.go +++ b/app/handlers_stats.go @@ -286,6 +286,8 @@ func (app *application) HandlerStatsLimits(w http.ResponseWriter, r *http.Reques // HandlerStats is a handler for Stats Totals page func (app *application) HandlerStatsTotalsPage(w http.ResponseWriter, r *http.Request) { data := make(map[string]interface{}) + data["activePage"] = "stats" + data["activeSubPage"] = "totals" if err := app.renderTemplate(w, r, "stats-totals", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } @@ -303,6 +305,8 @@ func (app *application) HandlerStatsTotalsByYearPage(w http.ResponseWriter, r *h } data["totalsByYear"] = totalsByYear + data["activePage"] = "stats" + data["activeSubPage"] = "totalsByYear" if err := app.renderTemplate(w, r, "stats-totals-year", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } @@ -311,6 +315,8 @@ func (app *application) HandlerStatsTotalsByYearPage(w http.ResponseWriter, r *h // HandlerStatsTotalsByTypePage is a handler for Stats Totals by Type page func (app *application) HandlerStatsTotalsByTypePage(w http.ResponseWriter, r *http.Request) { data := make(map[string]interface{}) + data["activePage"] = "stats" + data["activeSubPage"] = "totalsByType" if err := app.renderTemplate(w, r, "stats-totals-type", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } @@ -319,6 +325,8 @@ func (app *application) HandlerStatsTotalsByTypePage(w http.ResponseWriter, r *h // HandlerStatsTotalsByClassPage is a handler for Stats Totals by Class page func (app *application) HandlerStatsTotalsByClassPage(w http.ResponseWriter, r *http.Request) { data := make(map[string]interface{}) + data["activePage"] = "stats" + data["activeSubPage"] = "totalsByClass" if err := app.renderTemplate(w, r, "stats-totals-class", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } @@ -339,6 +347,8 @@ func (app *application) HandlerStatsLimitsPage(w http.ResponseWriter, r *http.Re data["last12m"] = totals["Last12M"].Time.Total data["last1y"] = totals["Year"].Time.Total + data["activePage"] = "stats" + data["activeSubPage"] = "limits" if err := app.renderTemplate(w, r, "stats-limits", &templateData{Data: data}); err != nil { app.errorLog.Println(err) } diff --git a/app/templates/base.gohtml b/app/templates/base.gohtml index 4fe63ca..dc63f3f 100644 --- a/app/templates/base.gohtml +++ b/app/templates/base.gohtml @@ -1,6 +1,8 @@ {{ define "base" }} {{$api := .API}} {{$settings := index .Data "settings"}} +{{$activePage := index .Data "activePage"}} +{{$activeSubPage := index .Data "activeSubPage"}} @@ -25,13 +27,13 @@