notice.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package admin
  5. import (
  6. "github.com/Unknwon/com"
  7. "github.com/Unknwon/paginater"
  8. log "gopkg.in/clog.v1"
  9. "github.com/gogits/gogs/models"
  10. "github.com/gogits/gogs/pkg/context"
  11. "github.com/gogits/gogs/pkg/setting"
  12. )
  13. const (
  14. NOTICES = "admin/notice"
  15. )
  16. func Notices(c *context.Context) {
  17. c.Data["Title"] = c.Tr("admin.notices")
  18. c.Data["PageIsAdmin"] = true
  19. c.Data["PageIsAdminNotices"] = true
  20. total := models.CountNotices()
  21. page := c.QueryInt("page")
  22. if page <= 1 {
  23. page = 1
  24. }
  25. c.Data["Page"] = paginater.New(int(total), setting.UI.Admin.NoticePagingNum, page, 5)
  26. notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum)
  27. if err != nil {
  28. c.Handle(500, "Notices", err)
  29. return
  30. }
  31. c.Data["Notices"] = notices
  32. c.Data["Total"] = total
  33. c.HTML(200, NOTICES)
  34. }
  35. func DeleteNotices(c *context.Context) {
  36. strs := c.QueryStrings("ids[]")
  37. ids := make([]int64, 0, len(strs))
  38. for i := range strs {
  39. id := com.StrTo(strs[i]).MustInt64()
  40. if id > 0 {
  41. ids = append(ids, id)
  42. }
  43. }
  44. if err := models.DeleteNoticesByIDs(ids); err != nil {
  45. c.Flash.Error("DeleteNoticesByIDs: " + err.Error())
  46. c.Status(500)
  47. } else {
  48. c.Flash.Success(c.Tr("admin.notices.delete_success"))
  49. c.Status(200)
  50. }
  51. }
  52. func EmptyNotices(c *context.Context) {
  53. if err := models.DeleteNotices(0, 0); err != nil {
  54. c.Handle(500, "DeleteNotices", err)
  55. return
  56. }
  57. log.Trace("System notices deleted by admin (%s): [start: %d]", c.User.Name, 0)
  58. c.Flash.Success(c.Tr("admin.notices.delete_success"))
  59. c.Redirect(setting.AppSubURL + "/admin/notices")
  60. }