Skip to content

Commit

Permalink
Merge pull request #217 from vsimakhin/216-after-reducing-sub-menu-a-…
Browse files Browse the repository at this point in the history
…new-click-will-expand-them-again

Correct using styles and classes for the sidebar when switching betwe…
  • Loading branch information
vsimakhin authored May 20, 2024
2 parents 5a49ed6 + fcb3763 commit 68e4b6a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
15 changes: 12 additions & 3 deletions app/handlers_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/handlers_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion app/handlers_licensing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/handlers_logbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions app/handlers_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion app/handlers_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
10 changes: 10 additions & 0 deletions app/handlers_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
48 changes: 25 additions & 23 deletions app/templates/base.gohtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{ define "base" }}
{{$api := .API}}
{{$settings := index .Data "settings"}}
{{$activePage := index .Data "activePage"}}
{{$activeSubPage := index .Data "activeSubPage"}}
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -25,13 +27,13 @@
<ul class="sidebar-nav">
<li class="sidebar-header">Pages</li>

<li class="sidebar-item">
<li class="sidebar-item {{if eq $activePage "logbook"}}active{{end}}">
<a class="sidebar-link" href="{{$api.Logbook}}">
<i class="bi bi-book"></i> <span class="align-middle">Logbook</span>
</a>
</li>

<li class="sidebar-item">
<li class="sidebar-item {{if eq $activePage "licensing"}}active{{end}}">
<a class="sidebar-link" href="{{$api.Licensing}}">
<i class="bi bi-file-medical"></i> <span class="align-middle">Licensing</span>
{{if not $settings.DisableLicenseWarning}}{{if .License.Expired}}
Expand All @@ -46,45 +48,45 @@
</a>
</li>

<li class="sidebar-item">
<li class="sidebar-item {{if eq $activePage "map"}}active{{end}}">
<a class="sidebar-link" href="{{$api.Map}}"><i class="bi bi-map"></i> <span class="align-middle">Map</span></a>
</li>

<li class="sidebar-item">
<a data-bs-target="#stats" data-bs-toggle="collapse" class="sidebar-link">
<li class="sidebar-item {{if eq $activePage "stats"}}active{{end}}">
<a data-bs-target="#stats" data-bs-toggle="collapse" class="sidebar-link {{if ne $activePage "stats"}}collapsed{{end}}">
<i class="bi bi-file-bar-graph"></i> <span class="align-middle">Statistics</span>
</a>
<ul id="stats" class="sidebar-dropdown list-unstyled collapse show" data-bs-parent="#sidebar">
<li class="sidebar-item"><a class="sidebar-link" href="{{$api.StatsTotalsPage}}">Totals</a></li>
<li class="sidebar-item"><a class="sidebar-link" href="{{$api.StatsTotalsByYearPage}}">Totals by Year</a></li>
<li class="sidebar-item"><a class="sidebar-link" href="{{$api.StatsTotalsByTypePage}}">Totals by Aircraft Type</a></li>
<li class="sidebar-item"><a class="sidebar-link" href="{{$api.StatsTotalsByClassPage}}">Totals by Aircraft Class</a></li>
<li class="sidebar-item"><a class="sidebar-link" href="{{$api.StatsLimitsPage}}">Limits</a></li>
<ul id="stats" class="sidebar-dropdown list-unstyled collapse {{if eq $activePage "stats"}}show{{end}}" data-bs-parent="#sidebar">
<li class="sidebar-item {{if eq $activeSubPage "totals"}}active{{end}}"><a class="sidebar-link" href="{{$api.StatsTotalsPage}}">Totals</a></li>
<li class="sidebar-item {{if eq $activeSubPage "totalsByYear"}}active{{end}}"><a class="sidebar-link" href="{{$api.StatsTotalsByYearPage}}">Totals by Year</a></li>
<li class="sidebar-item {{if eq $activeSubPage "totalsByType"}}active{{end}}"><a class="sidebar-link" href="{{$api.StatsTotalsByTypePage}}">Totals by Aircraft Type</a></li>
<li class="sidebar-item {{if eq $activeSubPage "totalsByClass"}}active{{end}}"><a class="sidebar-link" href="{{$api.StatsTotalsByClassPage}}">Totals by Aircraft Class</a></li>
<li class="sidebar-item {{if eq $activeSubPage "limits"}}active{{end}}"><a class="sidebar-link" href="{{$api.StatsLimitsPage}}">Limits</a></li>
</ul>
</li>

<li class="sidebar-item">
<a data-bs-target="#export" data-bs-toggle="collapse" class="sidebar-link">
<li class="sidebar-item {{if eq $activePage "export"}}active{{end}}">
<a data-bs-target="#export" data-bs-toggle="collapse" class="sidebar-link {{if ne $activePage "export"}}collapsed{{end}}">
<i class="bi bi-file-earmark-arrow-down"></i> <span class="align-middle">Export</span>
</a>
<ul id="export" class="sidebar-dropdown list-unstyled collapse show" data-bs-parent="#sidebar">
<li class="sidebar-item"><a class="sidebar-link" href="{{$api.ExportPDFA4Page}}">PDF A4</a></li>
<li class="sidebar-item"><a class="sidebar-link" href="{{$api.ExportPDFA5Page}}">PDF A5</a></li>
<li class="sidebar-item"><a class="sidebar-link" href="{{$api.ExportCSVXLSPage}}">CSV&XLS</a></li>
<ul id="export" class="sidebar-dropdown list-unstyled collapse {{if eq $activePage "export"}}show{{end}}" data-bs-parent="#sidebar">
<li class="sidebar-item {{if eq $activeSubPage "pdfa4"}}active{{end}}"><a class="sidebar-link" href="{{$api.ExportPDFA4Page}}">PDF A4</a></li>
<li class="sidebar-item {{if eq $activeSubPage "pdfa5"}}active{{end}}"><a class="sidebar-link" href="{{$api.ExportPDFA5Page}}">PDF A5</a></li>
<li class="sidebar-item {{if eq $activeSubPage "csv"}}active{{end}}"><a class="sidebar-link" href="{{$api.ExportCSVXLSPage}}">CSV&XLS</a></li>
</ul>
</li>

<li class="sidebar-item">
<li class="sidebar-item {{if eq $activePage "import"}}active{{end}}">
<a class="sidebar-link" href="{{$api.Import}}"><i class="bi bi-file-earmark-arrow-up"></i> <span class="align-middle">Import (beta)</span></a>
</li>

<li class="sidebar-item">
<a data-bs-target="#settings" data-bs-toggle="collapse" class="sidebar-link">
<li class="sidebar-item {{if eq $activePage "settings"}}active{{end}}">
<a data-bs-target="#settings" data-bs-toggle="collapse" class="sidebar-link {{if ne $activePage "settings"}}collapsed{{end}}">
<i class="bi bi-gear"></i> <span class="align-middle">Settings</span>
</a>
<ul id="settings" class="sidebar-dropdown list-unstyled collapse show" data-bs-parent="#sidebar">
<li class="sidebar-item"><a class="sidebar-link" href="{{$api.Settings}}">General</a></li>
<li class="sidebar-item"><a class="sidebar-link" href="{{$api.SettingsAirportDB}}">Airports</a></li>
<ul id="settings" class="sidebar-dropdown list-unstyled collapse {{if eq $activePage "settings"}}show{{end}}" data-bs-parent="#sidebar">
<li class="sidebar-item {{if eq $activeSubPage "general"}}active{{end}}"><a class="sidebar-link" href="{{$api.Settings}}">General</a></li>
<li class="sidebar-item {{if eq $activeSubPage "airports"}}active{{end}}"><a class="sidebar-link" href="{{$api.SettingsAirportDB}}">Airports</a></li>
</ul>
</li>

Expand Down

0 comments on commit 68e4b6a

Please sign in to comment.