settings_show.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui
  5. import (
  6. "net/http"
  7. "github.com/miniflux/miniflux/http/context"
  8. "github.com/miniflux/miniflux/http/response/html"
  9. "github.com/miniflux/miniflux/locale"
  10. "github.com/miniflux/miniflux/model"
  11. "github.com/miniflux/miniflux/ui/form"
  12. "github.com/miniflux/miniflux/ui/session"
  13. "github.com/miniflux/miniflux/ui/view"
  14. )
  15. // ShowSettings shows the settings page.
  16. func (c *Controller) ShowSettings(w http.ResponseWriter, r *http.Request) {
  17. ctx := context.New(r)
  18. sess := session.New(c.store, ctx)
  19. view := view.New(c.tpl, ctx, sess)
  20. user, err := c.store.UserByID(ctx.UserID())
  21. if err != nil {
  22. html.ServerError(w, err)
  23. return
  24. }
  25. settingsForm := form.SettingsForm{
  26. Username: user.Username,
  27. Theme: user.Theme,
  28. Language: user.Language,
  29. Timezone: user.Timezone,
  30. EntryDirection: user.EntryDirection,
  31. }
  32. timezones, err := c.store.Timezones()
  33. if err != nil {
  34. html.ServerError(w, err)
  35. return
  36. }
  37. view.Set("form", settingsForm)
  38. view.Set("themes", model.Themes())
  39. view.Set("languages", locale.AvailableLanguages())
  40. view.Set("timezones", timezones)
  41. view.Set("menu", "settings")
  42. view.Set("user", user)
  43. view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
  44. html.OK(w, view.Render("settings"))
  45. }