]> source.dussan.org Git - gitea.git/commitdiff
add tree view
authorLunny Xiao <xiaolunwen@gmail.com>
Fri, 14 Mar 2014 15:54:16 +0000 (23:54 +0800)
committerLunny Xiao <xiaolunwen@gmail.com>
Fri, 14 Mar 2014 15:54:16 +0000 (23:54 +0800)
1  2 
models/repo.go
routers/repo/single.go
templates/repo/single.tmpl
web.go

diff --cc models/repo.go
index a44bf69ad3fd267375ba72b6ef0e832895fdf50a,b7b5ac42b02a2493a27261529e98fe8f368768c7..c5fa899f4d63c3af23e9abe2051a2098c1e63c78
@@@ -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 {
        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
  }
index 1d5e601aa30fb680dc735d5a6df93ac2b6a60dcb,489666f406dc8cdd0d0d7e488272ddf9443e6a06..bc35b98e71553ef2368c820178763e829171ce1d
@@@ -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
  
index c83fcd93cd685f5ed9084512974f25b41b48785a,fbd05c4ba74283602bbf54c1e58c527fa3bb8e44..292f8cbdddbc94b1439f72c6892caa7944cda9eb
@@@ -3,11 -3,40 +3,58 @@@
  {{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&nbsp;&nbsp;
+                     <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>&nbsp;
++                {{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" .}}
diff --cc web.go
index 475b662b3907fd97f210b2db5c4eaa93533e9898,8f698e39d74a738e15dbd0e3b94a4551293214d7..c60a262b0052a8a850126b3c855d63dc53629ed7
--- 1/web.go
--- 2/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) {
        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)