category_edit.go 1.3 KB

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