mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.7 KiB
73 lines
1.7 KiB
10 years ago
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package admin
|
||
|
|
||
|
import (
|
||
9 years ago
|
"github.com/Unknwon/com"
|
||
9 years ago
|
"github.com/Unknwon/paginater"
|
||
8 years ago
|
log "gopkg.in/clog.v1"
|
||
10 years ago
|
|
||
|
"github.com/gogits/gogs/models"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/context"
|
||
|
"github.com/gogits/gogs/pkg/setting"
|
||
10 years ago
|
)
|
||
|
|
||
|
const (
|
||
8 years ago
|
NOTICES = "admin/notice"
|
||
10 years ago
|
)
|
||
|
|
||
8 years ago
|
func Notices(c *context.Context) {
|
||
|
c.Data["Title"] = c.Tr("admin.notices")
|
||
|
c.Data["PageIsAdmin"] = true
|
||
|
c.Data["PageIsAdminNotices"] = true
|
||
10 years ago
|
|
||
9 years ago
|
total := models.CountNotices()
|
||
8 years ago
|
page := c.QueryInt("page")
|
||
9 years ago
|
if page <= 1 {
|
||
|
page = 1
|
||
|
}
|
||
8 years ago
|
c.Data["Page"] = paginater.New(int(total), setting.UI.Admin.NoticePagingNum, page, 5)
|
||
9 years ago
|
|
||
8 years ago
|
notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum)
|
||
10 years ago
|
if err != nil {
|
||
8 years ago
|
c.Handle(500, "Notices", err)
|
||
10 years ago
|
return
|
||
|
}
|
||
8 years ago
|
c.Data["Notices"] = notices
|
||
9 years ago
|
|
||
8 years ago
|
c.Data["Total"] = total
|
||
|
c.HTML(200, NOTICES)
|
||
10 years ago
|
}
|
||
|
|
||
8 years ago
|
func DeleteNotices(c *context.Context) {
|
||
|
strs := c.QueryStrings("ids[]")
|
||
9 years ago
|
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 := models.DeleteNoticesByIDs(ids); err != nil {
|
||
8 years ago
|
c.Flash.Error("DeleteNoticesByIDs: " + err.Error())
|
||
|
c.Status(500)
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Flash.Success(c.Tr("admin.notices.delete_success"))
|
||
|
c.Status(200)
|
||
10 years ago
|
}
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func EmptyNotices(c *context.Context) {
|
||
9 years ago
|
if err := models.DeleteNotices(0, 0); err != nil {
|
||
8 years ago
|
c.Handle(500, "DeleteNotices", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
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(setting.AppSubURL + "/admin/notices")
|
||
10 years ago
|
}
|