notice.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package admin
  2. import (
  3. "gitote/gitote/models"
  4. "gitote/gitote/pkg/context"
  5. "gitote/gitote/pkg/setting"
  6. "github.com/Unknwon/com"
  7. "gitlab.com/yoginth/paginater"
  8. log "gopkg.in/clog.v1"
  9. )
  10. const (
  11. NOTICES = "admin/notice"
  12. )
  13. func Notices(c *context.Context) {
  14. c.Data["Title"] = "System Notices"
  15. c.Data["PageIsAdmin"] = true
  16. c.Data["PageIsAdminNotices"] = true
  17. total := models.CountNotices()
  18. page := c.QueryInt("page")
  19. if page <= 1 {
  20. page = 1
  21. }
  22. c.Data["Page"] = paginater.New(int(total), setting.UI.Admin.NoticePagingNum, page, 5)
  23. notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum)
  24. if err != nil {
  25. c.Handle(500, "Notices", err)
  26. return
  27. }
  28. c.Data["Notices"] = notices
  29. c.Data["Total"] = total
  30. c.HTML(200, NOTICES)
  31. }
  32. func DeleteNotices(c *context.Context) {
  33. strs := c.QueryStrings("ids[]")
  34. ids := make([]int64, 0, len(strs))
  35. for i := range strs {
  36. id := com.StrTo(strs[i]).MustInt64()
  37. if id > 0 {
  38. ids = append(ids, id)
  39. }
  40. }
  41. if err := models.DeleteNoticesByIDs(ids); err != nil {
  42. c.Flash.Error("DeleteNoticesByIDs: " + err.Error())
  43. c.Status(500)
  44. } else {
  45. c.Flash.Success("System notices have been deleted successfully.")
  46. c.Status(200)
  47. }
  48. }
  49. func EmptyNotices(c *context.Context) {
  50. if err := models.DeleteNotices(0, 0); err != nil {
  51. c.Handle(500, "DeleteNotices", err)
  52. return
  53. }
  54. log.Trace("System notices deleted by admin (%s): [start: %d]", c.User.Name, 0)
  55. c.Flash.Success("System notices have been deleted successfully.")
  56. c.Redirect(setting.AppSubURL + "/admin/notices")
  57. }