repos.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. "github.com/gogits/gogs/models"
  9. "github.com/gogits/gogs/pkg/context"
  10. "github.com/gogits/gogs/pkg/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 []*models.Repository
  25. count int64
  26. err error
  27. )
  28. keyword := c.Query("q")
  29. if len(keyword) == 0 {
  30. repos, err = models.Repositories(page, setting.UI.Admin.RepoPagingNum)
  31. if err != nil {
  32. c.Handle(500, "Repositories", err)
  33. return
  34. }
  35. count = models.CountRepositories(true)
  36. } else {
  37. repos, count, err = models.SearchRepositoryByName(&models.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 = models.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 := models.GetRepositoryByID(c.QueryInt64("id"))
  61. if err != nil {
  62. c.Handle(500, "GetRepositoryByID", err)
  63. return
  64. }
  65. if err := models.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. }