notice.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(ctx *context.Context) {
  17. ctx.Data["Title"] = ctx.Tr("admin.notices")
  18. ctx.Data["PageIsAdmin"] = true
  19. ctx.Data["PageIsAdminNotices"] = true
  20. total := models.CountNotices()
  21. page := ctx.QueryInt("page")
  22. if page <= 1 {
  23. page = 1
  24. }
  25. ctx.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. ctx.Handle(500, "Notices", err)
  29. return
  30. }
  31. ctx.Data["Notices"] = notices
  32. ctx.Data["Total"] = total
  33. ctx.HTML(200, NOTICES)
  34. }
  35. func DeleteNotices(ctx *context.Context) {
  36. strs := ctx.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. ctx.Flash.Error("DeleteNoticesByIDs: " + err.Error())
  46. ctx.Status(500)
  47. } else {
  48. ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
  49. ctx.Status(200)
  50. }
  51. }
  52. func EmptyNotices(ctx *context.Context) {
  53. if err := models.DeleteNotices(0, 0); err != nil {
  54. ctx.Handle(500, "DeleteNotices", err)
  55. return
  56. }
  57. log.Trace("System notices deleted by admin (%s): [start: %d]", ctx.User.Name, 0)
  58. ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
  59. ctx.Redirect(setting.AppSubURL + "/admin/notices")
  60. }