Files
Gogs/internal/route/admin/notice.go

71 lines
1.6 KiB
Go
Raw Permalink Normal View History

2014-10-08 18:29:18 -04:00
package admin
import (
"net/http"
"github.com/unknwon/com"
"github.com/unknwon/paginater"
log "unknwon.dev/clog/v2"
2014-10-08 18:29:18 -04:00
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/context"
"gogs.io/gogs/internal/database"
2014-10-08 18:29:18 -04:00
)
const (
2017-04-05 09:17:21 -04:00
NOTICES = "admin/notice"
2014-10-08 18:29:18 -04:00
)
2017-06-03 07:26:09 -04:00
func Notices(c *context.Context) {
c.Title("admin.notices")
2017-06-03 07:26:09 -04:00
c.Data["PageIsAdmin"] = true
c.Data["PageIsAdminNotices"] = true
2014-10-08 18:29:18 -04:00
total := database.Handle.Notices().Count(c.Req.Context())
2017-06-03 07:26:09 -04:00
page := c.QueryInt("page")
if page <= 1 {
page = 1
}
c.Data["Page"] = paginater.New(int(total), conf.UI.Admin.NoticePagingNum, page, 5)
2015-09-25 12:58:39 -04:00
notices, err := database.Handle.Notices().List(c.Req.Context(), page, conf.UI.Admin.NoticePagingNum)
2014-10-08 18:29:18 -04:00
if err != nil {
c.Error(err, "list notices")
2014-10-08 18:29:18 -04:00
return
}
2017-06-03 07:26:09 -04:00
c.Data["Notices"] = notices
2015-09-25 12:58:39 -04:00
2017-06-03 07:26:09 -04:00
c.Data["Total"] = total
c.Success(NOTICES)
2014-10-08 18:29:18 -04:00
}
2017-06-03 07:26:09 -04:00
func DeleteNotices(c *context.Context) {
strs := c.QueryStrings("ids[]")
ids := make([]int64, 0, len(strs))
for i := range strs {
id := com.StrTo(strs[i]).MustInt64()
if id > 0 {
ids = append(ids, id)
}
}
if err := database.Handle.Notices().DeleteByIDs(c.Req.Context(), ids...); err != nil {
2017-06-03 07:26:09 -04:00
c.Flash.Error("DeleteNoticesByIDs: " + err.Error())
c.Status(http.StatusInternalServerError)
} else {
2017-06-03 07:26:09 -04:00
c.Flash.Success(c.Tr("admin.notices.delete_success"))
c.Status(http.StatusOK)
2014-10-08 18:29:18 -04:00
}
}
2017-06-03 07:26:09 -04:00
func EmptyNotices(c *context.Context) {
if err := database.Handle.Notices().DeleteAll(c.Req.Context()); err != nil {
c.Error(err, "delete notices")
return
}
2017-06-03 07:26:09 -04:00
log.Trace("System notices deleted by admin (%s): [start: %d]", c.User.Name, 0)
c.Flash.Success(c.Tr("admin.notices.delete_success"))
c.Redirect(conf.Server.Subpath + "/admin/notices")
2014-10-08 18:29:18 -04:00
}