notice.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 page template
  12. NOTICES = "admin/notice"
  13. )
  14. // Notices shows admin notices page
  15. func Notices(c *context.Context) {
  16. c.Data["Title"] = "System Notices"
  17. c.Data["PageIsAdmin"] = true
  18. c.Data["PageIsAdminNotices"] = true
  19. total := models.CountNotices()
  20. page := c.QueryInt("page")
  21. if page <= 1 {
  22. page = 1
  23. }
  24. c.Data["Page"] = paginater.New(int(total), setting.UI.Admin.NoticePagingNum, page, 5)
  25. notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum)
  26. if err != nil {
  27. c.Handle(500, "Notices", err)
  28. return
  29. }
  30. c.Data["Notices"] = notices
  31. c.Data["Total"] = total
  32. c.HTML(200, NOTICES)
  33. }
  34. // DeleteNotices deletes notices
  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("System notices have been deleted successfully.")
  49. c.Status(200)
  50. }
  51. }
  52. // EmptyNotices emty notices list
  53. func EmptyNotices(c *context.Context) {
  54. if err := models.DeleteNotices(0, 0); err != nil {
  55. c.Handle(500, "DeleteNotices", err)
  56. return
  57. }
  58. log.Trace("System notices deleted by admin (%s): [start: %d]", c.User.Name, 0)
  59. c.Flash.Success("System notices have been deleted successfully.")
  60. c.Redirect(setting.AppSubURL + "/admin/notices")
  61. }