"fmt"
"io/ioutil"
"os"
++ "path"
"path/filepath"
"strings"
"time"
)
type RepoFile struct {
+ Id *git.Oid
Type int
Name string
++ Path string
Message string
Created time.Time
}
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 {
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{
lastCommit.Message(),
lastCommit.Committer().When,
})
-- }
++ }*/
return repofiles, nil
}
package repo
import (
++ "strings"
"github.com/codegangsta/martini"
"github.com/martini-contrib/render"
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
{{template "repo/nav" .}}
{{template "repo/toolbar" .}}
<div id="gogs-body" class="container">
- <h4>Source Files:</h4>
- <ul>
- {{range .Files}}
- <li>{{.Name}} - {{.Id}} - {{.Message}} - {{.Created}} - {{.IsFile}} - {{.IsDir}}</li>
- {{end}}
- </ul>
+ <div id="gogs-source">
+ <div id="gogs-source-toolbar">
+ <button class="btn btn-default pull-right"><i class="fa fa-plus-square"></i>Add File</button>
+ <div class="dropdown branch-switch">
+ <a href="#" class="btn btn-success dropdown-toggle" data-toggle="dropdown"><i class="fa fa-chain"></i>master
+ <b class="caret"></b></a>
+ <ul class="dropdown-menu">
+ <li><a class="current" href="/{{.RepositoryLink}}/branch/master">master</a></li>
+ <li><a href="//{{.RepositoryLink}}/branch/develop">develop</a></li>
+ </ul>
+ </div>
+ <ol class="breadcrumb">
+ <li class="root dir">{{.Repository.Name}}</li>
- <li class="dir">Dir</li>
++ {{$paths := .Paths}}
++ {{ $username := .Username}}
++ {{ $reponame := .Reponame}}
++ {{ $branchname := .Branchname}}
++ {{ $treenames := .Treenames}}
++ {{ $n := len $treenames}}
++ {{ $l := Subtract $n 1}}
++ {{range $i, $v := $treenames}}
++ <li class="dir">
++ {{if eq $i $l}}{{$v}}
++ {{else}}
++ <a href="/{{$username}}/{{$reponame}}/tree/{{$branchname}}/{{index $paths $i}}">{{$v}}</a>
++ {{end}}</li>
++ {{end}}
+ </ol>
+ </div>
+ <table id="gogs-source-table" class="table table-hover">
+ <thead class="hidden">
+ <tr>
+ <th class="name">Filename</th>
+ <th class="date">Date modified</th>
+ <th class="text">Message</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{range .Files}}
+ <tr {{if .IsDir}}class="is-dir"{{end}}>
- <td class="name"><i class="fa {{if .IsDir}}fa-folder{{else}}fa-file{{end}}"></i><a href="#">{{.Name}}</a></td>
++ <td class="name"><i class="fa {{if .IsDir}}fa-folder{{else}}fa-file{{end}}"></i>
++ {{if .IsDir}}
++ <a href="/{{$username}}/{{$reponame}}/tree/{{$branchname}}/{{.Path}}">{{.Name}}</a>
++ {{else}}
++ <a href="#">{{.Name}}</a>
++ {{end}}</td>
+ <td class="date"><time datetime="{{.Created}}" data-title="true" title="{{.Created}}">{{TimeSince .Created}}</time></td>
+ <td class="text">{{.Message}}</td>
+ </tr>
+ {{end}}
+ </tbody>
+ </table>
+ </div>
</div>
{{template "base/footer" .}}
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")
"AppVer": func() string {
return APP_VER
},
+ "TimeSince": base.TimeSince,
++ "Subtract": Subtract,
}
func runWeb(*cli.Context) {
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)
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)