mirror of
1
Fork 0

add repo router

This commit is contained in:
Lunny Xiao 2014-03-13 11:56:25 +08:00
parent a9a5fb45f8
commit 08feaf3ded
4 changed files with 34 additions and 5 deletions

View File

@ -5,9 +5,9 @@
package repo package repo
import ( import (
"fmt"
"net/http" "net/http"
"github.com/codegangsta/martini"
"github.com/martini-contrib/render" "github.com/martini-contrib/render"
"github.com/martini-contrib/sessions" "github.com/martini-contrib/sessions"
@ -87,12 +87,29 @@ func Delete(req *http.Request, r render.Render, data base.TmplData, session sess
} }
} }
func List(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { func Repo(params martini.Params, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
data["Title"] = "Repositories" data["Title"] = "Repository"
files, err := models.GetReposFiles(params["username"], params["reponame"], "HEAD", "/")
if err != nil {
data["ErrorMsg"] = err
log.Error("repo.List: %v", err)
r.HTML(200, "base/error", data)
return
}
data["Files"] = files
r.HTML(200, "repo/repo", data)
}
func List(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
u := auth.SignedInUser(session) u := auth.SignedInUser(session)
if u != nil {
r.Redirect("/")
return
}
data["Title"] = "Repositories"
repos, err := models.GetRepositories(u) repos, err := models.GetRepositories(u)
fmt.Println("repos", repos)
if err != nil { if err != nil {
data["ErrorMsg"] = err data["ErrorMsg"] = err
log.Error("repo.List: %v", err) log.Error("repo.List: %v", err)

View File

@ -58,7 +58,7 @@ func runServ(*cli.Context) {
cmd := os.Getenv("SSH_ORIGINAL_COMMAND") cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
if cmd == "" { if cmd == "" {
printf("Hi %s! You've successfully authenticated, but Gogs does not provide shell access.\n", user.Name) println("Hi ", user.Name, "! You've successfully authenticated, but Gogs does not provide shell access.")
return return
} }

10
templates/repo/repo.tmpl Normal file
View File

@ -0,0 +1,10 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div class="container" id="gogs-body">
<ul>
{{range .Files}}
<li>{{.Name}} - {{.Type}}</li>
{{end}}
</ul>
</div>
{{template "base/footer" .}}

2
web.go
View File

@ -70,6 +70,8 @@ func runWeb(*cli.Context) {
m.Get("/user/:username", auth.SignInRequire(false), user.Profile) m.Get("/user/:username", auth.SignInRequire(false), user.Profile)
m.Get("/:username/:reponame", repo.Repo)
m.Any("/repo/create", auth.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create) m.Any("/repo/create", auth.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create)
m.Any("/repo/delete", auth.SignInRequire(true), repo.Delete) m.Any("/repo/delete", auth.SignInRequire(true), repo.Delete)
m.Any("/repo/list", auth.SignInRequire(false), repo.List) m.Any("/repo/list", auth.SignInRequire(false), repo.List)