notice.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/paginater"
  7. "github.com/gogits/gogs/models"
  8. "github.com/gogits/gogs/modules/base"
  9. "github.com/gogits/gogs/modules/log"
  10. "github.com/gogits/gogs/modules/middleware"
  11. "github.com/gogits/gogs/modules/setting"
  12. )
  13. const (
  14. NOTICES base.TplName = "admin/notice"
  15. )
  16. func Notices(ctx *middleware.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.AdminNoticePagingNum, page, 5)
  26. notices, err := models.Notices(page, setting.AdminNoticePagingNum)
  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 DeleteNotice(ctx *middleware.Context) {
  36. id := ctx.ParamsInt64(":id")
  37. if err := models.DeleteNotice(id); err != nil {
  38. ctx.Handle(500, "DeleteNotice", err)
  39. return
  40. }
  41. log.Trace("System notice deleted by admin(%s): %d", ctx.User.Name, id)
  42. ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
  43. ctx.Redirect("/admin/notices")
  44. }