category_edit.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 // import "miniflux.app/ui"
  5. import (
  6. "net/http"
  7. "miniflux.app/http/request"
  8. "miniflux.app/http/response/html"
  9. "miniflux.app/ui/form"
  10. "miniflux.app/ui/session"
  11. "miniflux.app/ui/view"
  12. )
  13. // EditCategory shows the form to modify a category.
  14. func (c *Controller) EditCategory(w http.ResponseWriter, r *http.Request) {
  15. sess := session.New(c.store, request.SessionID(r))
  16. view := view.New(c.tpl, r, sess)
  17. user, err := c.store.UserByID(request.UserID(r))
  18. if err != nil {
  19. html.ServerError(w, err)
  20. return
  21. }
  22. categoryID := request.RouteInt64Param(r, "categoryID")
  23. category, err := c.store.Category(request.UserID(r), categoryID)
  24. if err != nil {
  25. html.ServerError(w, err)
  26. return
  27. }
  28. if category == nil {
  29. html.NotFound(w)
  30. return
  31. }
  32. categoryForm := form.CategoryForm{
  33. Title: category.Title,
  34. }
  35. view.Set("form", categoryForm)
  36. view.Set("category", category)
  37. view.Set("menu", "categories")
  38. view.Set("user", user)
  39. view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
  40. view.Set("countErrorFeeds", c.store.CountErrorFeeds(user.ID))
  41. html.OK(w, r, view.Render("edit_category"))
  42. }