mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.0 KiB
88 lines
2.0 KiB
10 years ago
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package admin
|
||
|
|
||
|
import (
|
||
8 years ago
|
"github.com/Unknwon/paginater"
|
||
8 years ago
|
log "gopkg.in/clog.v1"
|
||
|
|
||
10 years ago
|
"github.com/gogits/gogs/models"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/context"
|
||
|
"github.com/gogits/gogs/pkg/setting"
|
||
10 years ago
|
)
|
||
|
|
||
|
const (
|
||
8 years ago
|
REPOS = "admin/repo/list"
|
||
10 years ago
|
)
|
||
|
|
||
8 years ago
|
func Repos(c *context.Context) {
|
||
|
c.Data["Title"] = c.Tr("admin.repositories")
|
||
|
c.Data["PageIsAdmin"] = true
|
||
|
c.Data["PageIsAdminRepositories"] = true
|
||
10 years ago
|
|
||
8 years ago
|
page := c.QueryInt("page")
|
||
8 years ago
|
if page <= 0 {
|
||
|
page = 1
|
||
|
}
|
||
|
|
||
|
var (
|
||
|
repos []*models.Repository
|
||
|
count int64
|
||
|
err error
|
||
|
)
|
||
|
|
||
8 years ago
|
keyword := c.Query("q")
|
||
8 years ago
|
if len(keyword) == 0 {
|
||
|
repos, err = models.Repositories(page, setting.UI.Admin.RepoPagingNum)
|
||
|
if err != nil {
|
||
8 years ago
|
c.Handle(500, "Repositories", err)
|
||
8 years ago
|
return
|
||
|
}
|
||
|
count = models.CountRepositories(true)
|
||
|
} else {
|
||
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
|
||
|
Keyword: keyword,
|
||
|
OrderBy: "id ASC",
|
||
|
Private: true,
|
||
|
Page: page,
|
||
|
PageSize: setting.UI.Admin.RepoPagingNum,
|
||
|
})
|
||
|
if err != nil {
|
||
8 years ago
|
c.Handle(500, "SearchRepositoryByName", err)
|
||
8 years ago
|
return
|
||
|
}
|
||
|
}
|
||
8 years ago
|
c.Data["Keyword"] = keyword
|
||
|
c.Data["Total"] = count
|
||
|
c.Data["Page"] = paginater.New(int(count), setting.UI.Admin.RepoPagingNum, page, 5)
|
||
8 years ago
|
|
||
|
if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
|
||
8 years ago
|
c.Handle(500, "LoadAttributes", err)
|
||
8 years ago
|
return
|
||
|
}
|
||
8 years ago
|
c.Data["Repos"] = repos
|
||
8 years ago
|
|
||
8 years ago
|
c.HTML(200, REPOS)
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
8 years ago
|
func DeleteRepo(c *context.Context) {
|
||
|
repo, err := models.GetRepositoryByID(c.QueryInt64("id"))
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
c.Handle(500, "GetRepositoryByID", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
if err := models.DeleteRepository(repo.MustOwner().ID, repo.ID); err != nil {
|
||
8 years ago
|
c.Handle(500, "DeleteRepository", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)
|
||
|
|
||
8 years ago
|
c.Flash.Success(c.Tr("repo.settings.deletion_success"))
|
||
|
c.JSON(200, map[string]interface{}{
|
||
|
"redirect": setting.AppSubURL + "/admin/repos?page=" + c.Query("page"),
|
||
9 years ago
|
})
|
||
|
}
|