1
0
Fork 0
miniflux/ui/starred.go

69 lines
1.8 KiB
Go
Raw Normal View History

2017-12-22 14:33:01 -05:00
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package ui
2017-12-22 14:33:01 -05:00
import (
"github.com/miniflux/miniflux/http/handler"
2017-12-22 14:33:01 -05:00
"github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/model"
)
// ShowStarredPage renders the page with all starred entries.
func (c *Controller) ShowStarredPage(ctx *handler.Context, request *handler.Request, response *handler.Response) {
2017-12-22 14:33:01 -05:00
user := ctx.LoggedUser()
offset := request.QueryIntegerParam("offset", 0)
args, err := c.getCommonTemplateArgs(ctx)
if err != nil {
response.HTML().ServerError(err)
return
}
2017-12-28 22:20:14 -05:00
builder := c.store.NewEntryQueryBuilder(user.ID)
2017-12-22 14:33:01 -05:00
builder.WithoutStatus(model.EntryStatusRemoved)
builder.WithStarred()
builder.WithOrder(model.DefaultSortingOrder)
builder.WithDirection(user.EntryDirection)
builder.WithOffset(offset)
builder.WithLimit(nbItemsPerPage)
entries, err := builder.GetEntries()
if err != nil {
response.HTML().ServerError(err)
return
}
count, err := builder.CountEntries()
if err != nil {
response.HTML().ServerError(err)
return
}
response.HTML().Render("starred", args.Merge(tplParams{
"entries": entries,
"total": count,
"pagination": c.getPagination(ctx.Route("starred"), count, offset),
"menu": "starred",
}))
}
// ToggleBookmark handles Ajax request to toggle bookmark value.
func (c *Controller) ToggleBookmark(ctx *handler.Context, request *handler.Request, response *handler.Response) {
2017-12-22 14:33:01 -05:00
user := ctx.LoggedUser()
entryID, err := request.IntegerParam("entryID")
if err != nil {
response.HTML().BadRequest(err)
return
}
if err := c.store.ToggleBookmark(user.ID, entryID); err != nil {
logger.Error("[Controller:UpdateEntryStatus] %v", err)
response.JSON().ServerError(nil)
return
}
response.JSON().Standard("OK")
}