repos.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. log "gopkg.in/clog.v1"
  8. "gogs.io/gogs/internal/context"
  9. "gogs.io/gogs/internal/db"
  10. "gogs.io/gogs/internal/setting"
  11. )
  12. const (
  13. REPOS = "admin/repo/list"
  14. )
  15. func Repos(c *context.Context) {
  16. c.Data["Title"] = c.Tr("admin.repositories")
  17. c.Data["PageIsAdmin"] = true
  18. c.Data["PageIsAdminRepositories"] = true
  19. page := c.QueryInt("page")
  20. if page <= 0 {
  21. page = 1
  22. }
  23. var (
  24. repos []*db.Repository
  25. count int64
  26. err error
  27. )
  28. keyword := c.Query("q")
  29. if len(keyword) == 0 {
  30. repos, err = db.Repositories(page, setting.UI.Admin.RepoPagingNum)
  31. if err != nil {
  32. c.Handle(500, "Repositories", err)
  33. return
  34. }
  35. count = db.CountRepositories(true)
  36. } else {
  37. repos, count, err = db.SearchRepositoryByName(&db.SearchRepoOptions{
  38. Keyword: keyword,
  39. OrderBy: "id ASC",
  40. Private: true,
  41. Page: page,
  42. PageSize: setting.UI.Admin.RepoPagingNum,
  43. })
  44. if err != nil {
  45. c.Handle(500, "SearchRepositoryByName", err)
  46. return
  47. }
  48. }
  49. c.Data["Keyword"] = keyword
  50. c.Data["Total"] = count
  51. c.Data["Page"] = paginater.New(int(count), setting.UI.Admin.RepoPagingNum, page, 5)
  52. if err = db.RepositoryList(repos).LoadAttributes(); err != nil {
  53. c.Handle(500, "LoadAttributes", err)
  54. return
  55. }
  56. c.Data["Repos"] = repos
  57. c.HTML(200, REPOS)
  58. }
  59. func DeleteRepo(c *context.Context) {
  60. repo, err := db.GetRepositoryByID(c.QueryInt64("id"))
  61. if err != nil {
  62. c.Handle(500, "GetRepositoryByID", err)
  63. return
  64. }
  65. if err := db.DeleteRepository(repo.MustOwner().ID, repo.ID); err != nil {
  66. c.Handle(500, "DeleteRepository", err)
  67. return
  68. }
  69. log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)
  70. c.Flash.Success(c.Tr("repo.settings.deletion_success"))
  71. c.JSON(200, map[string]interface{}{
  72. "redirect": setting.AppSubURL + "/admin/repos?page=" + c.Query("page"),
  73. })
  74. }