subscription_add.go 1017 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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/ui/session"
  10. "github.com/miniflux/miniflux/ui/view"
  11. )
  12. // AddSubscription shows the form to add a new feed.
  13. func (c *Controller) AddSubscription(w http.ResponseWriter, r *http.Request) {
  14. ctx := context.New(r)
  15. sess := session.New(c.store, ctx)
  16. view := view.New(c.tpl, ctx, sess)
  17. user, err := c.store.UserByID(ctx.UserID())
  18. if err != nil {
  19. html.ServerError(w, err)
  20. return
  21. }
  22. categories, err := c.store.Categories(user.ID)
  23. if err != nil {
  24. html.ServerError(w, err)
  25. return
  26. }
  27. view.Set("categories", categories)
  28. view.Set("menu", "feeds")
  29. view.Set("user", user)
  30. view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
  31. html.OK(w, r, view.Render("add_subscription"))
  32. }