From: Lunny Xiao Date: Fri, 14 Mar 2014 15:54:16 +0000 (+0800) Subject: add tree view X-Git-Tag: v0.9.99~2452 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b27e8e87f8be2d11468e9057254b6c8933e0af33;p=gitea.git add tree view --- b27e8e87f8be2d11468e9057254b6c8933e0af33 diff --cc models/repo.go index a44bf69ad3,b7b5ac42b0..c5fa899f4d --- a/models/repo.go +++ b/models/repo.go @@@ -9,6 -9,6 +9,7 @@@ import "fmt" "io/ioutil" "os" ++ "path" "path/filepath" "strings" "time" @@@ -267,9 -267,8 +268,10 @@@ const ) type RepoFile struct { + Id *git.Oid Type int Name string ++ Path string Message string Created time.Time } @@@ -282,7 -281,7 +284,7 @@@ func (f *RepoFile) IsDir() bool return f.Type == git.FilemodeTree } --func GetReposFiles(userName, reposName, treeName, rpath string) ([]*RepoFile, error) { ++func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { f := RepoPath(userName, reposName) repo, err := git.OpenRepository(f) if err != nil { @@@ -299,8 -298,8 +301,28 @@@ if err != nil { return nil, err } -- var i uint64 = 0 -- for ; i < tree.EntryCount(); i++ { ++ //var i uint64 = 0 ++ if rpath != "" { ++ rpath = rpath + "/" ++ } ++ fmt.Println("...", rpath, "...") ++ ++ tree.Walk(func(dirname string, entry *git.TreeEntry) int { ++ if dirname == rpath { ++ fmt.Println("====", dirname, "==", entry.Name) ++ repofiles = append(repofiles, &RepoFile{ ++ entry.Id, ++ entry.Filemode, ++ entry.Name, ++ path.Join(dirname, entry.Name), ++ lastCommit.Message(), ++ lastCommit.Committer().When, ++ }) ++ } ++ return 0 ++ }) ++ ++ /*for ; i < tree.EntryCount(); i++ { entry := tree.EntryByIndex(i) repofiles = append(repofiles, &RepoFile{ @@@ -310,7 -308,7 +332,7 @@@ lastCommit.Message(), lastCommit.Committer().When, }) -- } ++ }*/ return repofiles, nil } diff --cc routers/repo/single.go index 1d5e601aa3,489666f406..bc35b98e71 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@@ -1,6 -1,6 +1,7 @@@ package repo import ( ++ "strings" "github.com/codegangsta/martini" "github.com/martini-contrib/render" @@@ -13,15 -13,13 +14,27 @@@ func Single(params martini.Params, r re if !data["IsRepositoryValid"].(bool) { return } -- -- files, err := models.GetReposFiles(params["username"], params["reponame"], "HEAD", "/") ++ if params["branchname"] == "" { ++ params["branchname"] = "master" ++ } ++ treename := params["_1"] ++ files, err := models.GetReposFiles(params["username"], params["reponame"], ++ params["branchname"], treename) if err != nil { - data["ErrorMsg"] = err - log.Error("repo.List: %v", err) - r.HTML(200, "base/error", data) + log.Handle(200, "repo.Single", data, r, err) return } ++ data["Username"] = params["username"] ++ data["Reponame"] = params["reponame"] ++ data["Branchname"] = params["branchname"] ++ treenames := strings.Split(treename, "/") ++ Paths := make([]string, 0) ++ for i, _ := range treenames { ++ Paths = append(Paths, strings.Join(treenames[0:i+1], "/")) ++ } ++ data["Paths"] = Paths ++ data["Treenames"] = treenames data["IsRepoToolbarSource"] = true data["Files"] = files diff --cc templates/repo/single.tmpl index c83fcd93cd,fbd05c4ba7..292f8cbddd --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@@ -3,11 -3,40 +3,58 @@@ {{template "repo/nav" .}} {{template "repo/toolbar" .}}
-

Source Files:

- +
+
+ + + +
+ + + + + + + + + + {{range .Files}} + - ++ + + + + {{end}} + +
{{.Name}} ++ {{if .IsDir}} ++ {{.Name}} ++ {{else}} ++ {{.Name}} ++ {{end}}{{.Message}}
+
{{template "base/footer" .}} diff --cc web.go index 475b662b39,8f698e39d7..c60a262b00 --- a/web.go +++ b/web.go @@@ -33,6 -33,6 +33,55 @@@ gogs web` Flags: []cli.Flag{}, } ++func Subtract(left interface{}, right interface{}) interface{} { ++ var rleft, rright int64 ++ var fleft, fright float64 ++ var isInt bool = true ++ switch left.(type) { ++ case int: ++ rleft = int64(left.(int)) ++ case int8: ++ rleft = int64(left.(int8)) ++ case int16: ++ rleft = int64(left.(int16)) ++ case int32: ++ rleft = int64(left.(int32)) ++ case int64: ++ rleft = left.(int64) ++ case float32: ++ fleft = float64(left.(float32)) ++ isInt = false ++ case float64: ++ fleft = left.(float64) ++ isInt = false ++ } ++ ++ switch right.(type) { ++ case int: ++ rright = int64(right.(int)) ++ case int8: ++ rright = int64(right.(int8)) ++ case int16: ++ rright = int64(right.(int16)) ++ case int32: ++ rright = int64(right.(int32)) ++ case int64: ++ rright = right.(int64) ++ case float32: ++ fright = float64(left.(float32)) ++ isInt = false ++ case float64: ++ fleft = left.(float64) ++ isInt = false ++ } ++ ++ if isInt { ++ return rleft - rright ++ } else { ++ return fleft + float64(rleft) - (fright + float64(rright)) ++ } ++} ++ var AppHelpers template.FuncMap = map[string]interface{}{ "AppName": func() string { return base.Cfg.MustValue("", "APP_NAME") @@@ -40,6 -40,7 +89,8 @@@ "AppVer": func() string { return APP_VER }, + "TimeSince": base.TimeSince, ++ "Subtract": Subtract, } func runWeb(*cli.Context) { @@@ -63,8 -64,11 +114,11 @@@ m.Any("/user/delete", auth.SignInRequire(true), user.Delete) m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) - m.Any("/user/setting", auth.SignInRequire(true), user.Setting) + m.Any("/user/setting", auth.SignInRequire(true), binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting) + m.Any("/user/setting/password", auth.SignInRequire(true), binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword) m.Any("/user/setting/ssh", auth.SignInRequire(true), binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys) - m.Any("/user/setting/notification",auth.SignInRequire(true),user.SettingNotification) - m.Any("/user/setting/security",auth.SignInRequire(true),user.SettingSecurity) ++ m.Any("/user/setting/notification", auth.SignInRequire(true), user.SettingNotification) ++ m.Any("/user/setting/security", auth.SignInRequire(true), user.SettingSecurity) m.Get("/user/:username", auth.SignInRequire(false), user.Profile) @@@ -73,6 -77,6 +127,10 @@@ m.Any("/repo/list", auth.SignInRequire(false), repo.List) m.Get("/:username/:reponame/settings", auth.SignInRequire(false), auth.RepoAssignment(true), repo.Setting) ++ m.Get("/:username/:reponame/tree/:branchname/**", ++ auth.SignInRequire(false), auth.RepoAssignment(true), repo.Single) ++ m.Get("/:username/:reponame/tree/:branchname", ++ auth.SignInRequire(false), auth.RepoAssignment(true), repo.Single) m.Get("/:username/:reponame", auth.SignInRequire(false), auth.RepoAssignment(true), repo.Single) //m.Get("/:username/:reponame", repo.Repo)