notice.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2015 - Present, The Gogs Authors. All rights reserved.
  2. // Copyright 2018 - Present, Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package admin
  7. import (
  8. "gitote/gitote/models"
  9. "gitote/gitote/pkg/context"
  10. "gitote/gitote/pkg/setting"
  11. "gitlab.com/gitote/com"
  12. "gitlab.com/yoginth/paginater"
  13. log "gopkg.in/clog.v1"
  14. )
  15. const (
  16. // NoticesTPL page template
  17. NoticesTPL = "admin/notice"
  18. )
  19. // Notices shows admin notices page
  20. func Notices(c *context.Context) {
  21. c.Data["Title"] = "System Notices"
  22. c.Data["PageIsAdmin"] = true
  23. c.Data["PageIsAdminNotices"] = true
  24. total := models.CountNotices()
  25. page := c.QueryInt("page")
  26. if page <= 1 {
  27. page = 1
  28. }
  29. c.Data["Page"] = paginater.New(int(total), setting.UI.Admin.NoticePagingNum, page, 5)
  30. notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum)
  31. if err != nil {
  32. c.Handle(500, "Notices", err)
  33. return
  34. }
  35. c.Data["Notices"] = notices
  36. c.Data["Total"] = total
  37. c.HTML(200, NoticesTPL)
  38. }
  39. // DeleteNotices deletes notices
  40. func DeleteNotices(c *context.Context) {
  41. strs := c.QueryStrings("ids[]")
  42. ids := make([]int64, 0, len(strs))
  43. for i := range strs {
  44. id := com.StrTo(strs[i]).MustInt64()
  45. if id > 0 {
  46. ids = append(ids, id)
  47. }
  48. }
  49. if err := models.DeleteNoticesByIDs(ids); err != nil {
  50. c.Flash.Error("DeleteNoticesByIDs: " + err.Error())
  51. c.Status(500)
  52. } else {
  53. c.Flash.Success("System notices have been deleted successfully.")
  54. c.Status(200)
  55. }
  56. }
  57. // EmptyNotices emty notices list
  58. func EmptyNotices(c *context.Context) {
  59. if err := models.DeleteNotices(0, 0); err != nil {
  60. c.Handle(500, "DeleteNotices", err)
  61. return
  62. }
  63. log.Trace("System notices deleted by admin (%s): [start: %d]", c.User.Name, 0)
  64. c.Flash.Success("System notices have been deleted successfully.")
  65. c.Redirect(setting.AppSubURL + "/admin/notices")
  66. }