new commits table

This commit is contained in:
Unknwon 2015-08-20 20:18:49 +08:00
parent d7c3c79c00
commit aa65761d81
14 changed files with 163 additions and 90 deletions

View File

@ -166,6 +166,13 @@ type Repository struct {
Updated time.Time `xorm:"UPDATED"` Updated time.Time `xorm:"UPDATED"`
} }
func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
switch colName {
case "updated":
repo.Updated = regulateTimeZone(repo.Updated)
}
}
func (repo *Repository) getOwner(e Engine) (err error) { func (repo *Repository) getOwner(e Engine) (err error) {
if repo.Owner == nil { if repo.Owner == nil {
repo.Owner, err = getUserByID(e, repo.OwnerID) repo.Owner, err = getUserByID(e, repo.OwnerID)

View File

@ -275,9 +275,11 @@ func (repo *Repository) searchCommits(id sha1, keyword string) (*list.List, erro
return parsePrettyFormatLog(repo, stdout) return parsePrettyFormatLog(repo, stdout)
} }
var CommitsRangeSize = 50
func (repo *Repository) commitsByRange(id sha1, page int) (*list.List, error) { func (repo *Repository) commitsByRange(id sha1, page int) (*list.List, error) {
stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", id.String(), stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", id.String(),
"--skip="+com.ToStr((page-1)*50), "--max-count=50", prettyLogFormat) "--skip="+com.ToStr((page-1)*CommitsRangeSize), "--max-count="+com.ToStr(CommitsRangeSize), prettyLogFormat)
if err != nil { if err != nil {
return nil, errors.New(string(stderr)) return nil, errors.New(string(stderr))
} }

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
.admin { .admin {
padding-top: 15px; padding-top: 15px;
padding-bottom: @footer-margin * 3; padding-bottom: @footer-margin * 2;
.table.segment { .table.segment {
padding: 0; padding: 0;

View File

@ -92,6 +92,13 @@ img {
&.small { &.small {
font-size: 0.75em; font-size: 0.75em;
} }
&.truncate {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: inline-block;
}
} }
.message { .message {

View File

@ -9,7 +9,11 @@
.ui.attached.header { .ui.attached.header {
background: #f0f0f0; background: #f0f0f0;
.right { .right {
margin-top: -6px; margin-top: -5px;
.button {
padding: 8px 10px;
font-weight: normal;
}
} }
} }
.repository { .repository {

View File

@ -1,5 +1,5 @@
.home { .home {
padding-bottom: @footer-margin * 3; padding-bottom: @footer-margin * 2;
.logo { .logo {
max-width: 250px; max-width: 250px;
} }

View File

@ -1,6 +1,6 @@
.install { .install {
padding-top: 45px; padding-top: 45px;
padding-bottom: @footer-margin * 3; padding-bottom: @footer-margin * 2;
form { form {
@input-padding: 320px !important; @input-padding: 320px !important;
label { label {

View File

@ -2,7 +2,7 @@
@mega-octicon-width: 30px; @mega-octicon-width: 30px;
padding-top: 15px; padding-top: 15px;
padding-bottom: @footer-margin * 3; padding-bottom: @footer-margin * 2;
.head { .head {
.column { .column {
@ -424,6 +424,52 @@
} }
} }
} }
&.commits {
.header {
.ui.right {
.search {
input {
font-weight: normal;
padding: 5px 10px;
}
}
.button {
float: right;
margin-left: 5px;
margin-top: 1px;
}
}
}
}
.commits.table {
font-size: 13px;
th, td {
&:first-child {
padding-left: 15px;
}
}
td {
line-height: 15px;
}
.author {
min-width: 180px;
}
.sha {
a {
font-family: Consolas, Menlo, Monaco, "Lucida Console", monospace;
font-size: 14px;
padding: 6px 10px 4px 10px;
font-weight: normal;
}
}
.message span {
max-width: 500px;
}
.date {
width: 120px;
}
}
} }
.ui.comments { .ui.comments {

View File

@ -1,6 +1,6 @@
.user { .user {
padding-top: 15px; padding-top: 15px;
padding-bottom: @footer-margin * 3; padding-bottom: @footer-margin * 2;
&.settings { &.settings {
.key.list { .key.list {

View File

@ -9,6 +9,7 @@ import (
"path" "path"
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/Unknwon/paginater"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
@ -44,7 +45,7 @@ func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
} }
func Commits(ctx *middleware.Context) { func Commits(ctx *middleware.Context) {
ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["PageIsCommits"] = true
userName := ctx.Repo.Owner.Name userName := ctx.Repo.Owner.Name
repoName := ctx.Repo.Repository.Name repoName := ctx.Repo.Repository.Name
@ -64,19 +65,11 @@ func Commits(ctx *middleware.Context) {
return return
} }
// Calculate and validate page number. page := ctx.QueryInt("page")
page, _ := com.StrTo(ctx.Query("p")).Int() if page <= 1 {
if page < 1 {
page = 1 page = 1
} }
lastPage := page - 1 ctx.Data["Page"] = paginater.New(commitsCount, git.CommitsRangeSize, page, 5)
if lastPage < 0 {
lastPage = 0
}
nextPage := page + 1
if page*50 > commitsCount {
nextPage = 0
}
// Both `git log branchName` and `git log commitId` work. // Both `git log branchName` and `git log commitId` work.
commits, err := ctx.Repo.Commit.CommitsByRange(page) commits, err := ctx.Repo.Commit.CommitsByRange(page)
@ -91,14 +84,11 @@ func Commits(ctx *middleware.Context) {
ctx.Data["Username"] = userName ctx.Data["Username"] = userName
ctx.Data["Reponame"] = repoName ctx.Data["Reponame"] = repoName
ctx.Data["CommitCount"] = commitsCount ctx.Data["CommitCount"] = commitsCount
ctx.Data["LastPageNum"] = lastPage
ctx.Data["NextPageNum"] = nextPage
ctx.HTML(200, COMMITS) ctx.HTML(200, COMMITS)
} }
func SearchCommits(ctx *middleware.Context) { func SearchCommits(ctx *middleware.Context) {
ctx.Data["IsSearchPage"] = true ctx.Data["PageIsCommits"] = true
ctx.Data["IsRepoToolbarCommits"] = true
keyword := ctx.Query("q") keyword := ctx.Query("q")
if len(keyword) == 0 { if len(keyword) == 0 {
@ -253,7 +243,7 @@ func Diff(ctx *middleware.Context) {
ctx.Data["Parents"] = parents ctx.Data["Parents"] = parents
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", commitId) ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", commitId)
if (commit.ParentCount() > 0) { if commit.ParentCount() > 0 {
ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", parents[0]) ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", parents[0])
} }
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitId) ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitId)

View File

@ -1,9 +1,8 @@
{{template "ng/base/head" .}} {{template "base/head" .}}
{{template "ng/base/header" .}} <div class="repository commits">
<div id="repo-wrapper"> {{template "repo/header" .}}
{{template "repo/header_old" .}} <div class="ui container">
<div class="container clear"> {{template "repo/commits_table" .}}
{{template "repo/commits_table" .}} </div>
</div>
</div> </div>
{{template "ng/base/footer" .}} {{template "base/footer" .}}

View File

@ -1,48 +1,66 @@
<div id="commits-list"> <h4 class="ui top attached header">
<div class="panel panel-radius"> {{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}}
<div class="panel-header"> {{if .PageIsCommits}}
{{if not .IsDiffCompare}} <div class="ui right">
<form class="search pull-right" action="{{.RepoLink}}/commits/{{.BranchName}}/search" method="get" id="commits-search-form"> <form action="{{.RepoLink}}/commits/{{.BranchName}}/search">
<input class="ipt ipt-radius" type="search" name="q" placeholder="{{.i18n.Tr "repo.commits.search"}}" value="{{.Keyword}}" /> <div class="ui tiny search input">
<button class="btn btn-black btn-small btn-radius">{{.i18n.Tr "repo.commits.find"}}</button> <input name="q" placeholder="{{.i18n.Tr "repo.commits.search"}}" value="{{.Keyword}}" autofocus>
</form> </div>
{{end}} <button class="ui black tiny button" data-panel="#add-deploy-key-panel">{{.i18n.Tr "repo.commits.find"}}</button>
<h4>{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}}</h4> </form>
</div> </div>
<table class="panel-body table commit-list table-striped"> {{end}}
<thead> </h4>
<tr> <div class="ui attached table segment">
<th class="author">{{.i18n.Tr "repo.commits.author"}}</th> <table class="ui very basic striped commits table">
<th class="sha">SHA1</th> <thead>
<th class="message">{{.i18n.Tr "repo.commits.message"}}</th> <tr>
<th class="date">{{.i18n.Tr "repo.commits.date"}}</th> <th>{{.i18n.Tr "repo.commits.author"}}</th>
</tr> <th>SHA1</th>
</thead> <th>{{.i18n.Tr "repo.commits.message"}}</th>
<tbody> <th>{{.i18n.Tr "repo.commits.date"}}</th>
{{ $username := .Username}} </tr>
{{ $reponame := .Reponame}} </thead>
{{$r := List .Commits}} <tbody>
{{range $r}} {{ $username := .Username}}
<tr> {{ $reponame := .Reponame}}
<td class="author"> {{ $r:= List .Commits}}
{{if .User}} {{range $r}}
<img class="avatar-20" src="{{.User.AvatarLink}}" alt=""/>&nbsp;&nbsp;&nbsp;<a href="{{AppSubUrl}}/{{.User.Name}}">{{.Author.Name}}</a> <tr>
{{else}} <td class="author">
<img class="avatar-20" src="{{AvatarLink .Author.Email}}" alt=""/>&nbsp;&nbsp;&nbsp;{{.Author.Name}} {{if .User}}
{{end}} <img class="ui avatar image" src="{{.User.AvatarLink}}" alt=""/>&nbsp;&nbsp;<a href="{{AppSubUrl}}/{{.User.Name}}">{{.Author.Name}}</a>
</td> {{else}}
<td class="sha"><a rel="nofollow" class="label label-green" href="{{AppSubUrl}}/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 10}} </a></td> <img class="ui avatar image" src="{{AvatarLink .Author.Email}}" alt=""/>&nbsp;&nbsp;{{.Author.Name}}
<td class="message"><span class="text-truncate">{{RenderCommitMessage .Summary $.RepoLink}}</span></td> {{end}}
<td class="date">{{TimeSince .Author.When $.Lang}}</td> </td>
</tr> <td class="sha"><a rel="nofollow" class="ui green label" href="{{AppSubUrl}}/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 10}} </a></td>
{{end}} <td class="message"><span class="text truncate">{{RenderCommitMessage .Summary $.RepoLink}}</span></td>
</tbody> <td class="date">{{TimeSince .Author.When $.Lang}}</td>
</table> </tr>
</div>
{{if and (not .IsSearchPage) (not .IsDiffCompare)}}
<ul class="pagination">
{{if .LastPageNum}}<li><a class="btn btn-medium btn-gray btn-radius" href="{{.RepoLink}}/commits/{{.BranchName}}{{if .FileName}}/{{.FileName}}{{end}}?p={{.LastPageNum}}" rel="nofollow">&laquo; {{.i18n.Tr "repo.commits.newer"}}</a></li>{{end}}
{{if .NextPageNum}}<li><a class="btn btn-medium btn-gray btn-radius" href="{{.RepoLink}}/commits/{{.BranchName}}{{if .FileName}}/{{.FileName}}{{end}}?p={{.NextPageNum}}" rel="nofollow">&raquo; {{.i18n.Tr "repo.commits.older"}}</a></li>{{end}}
</ul>
{{end}} {{end}}
</tbody>
</table>
</div> </div>
{{with .Page}}
{{if gt .TotalPages 1}}
<div class="center page buttons">
<div class="ui borderless pagination menu">
<a class="{{if not .HasPrevious}}disabled{{end}} item" {{if .HasPrevious}}href="{{$.RepoLink}}/commits/{{$.BranchName}}{{if $.FileName}}/{{$.FileName}}{{end}}?page={{.Previous}}"{{end}}>
<i class="left arrow icon"></i> {{$.i18n.Tr "repo.issues.previous"}}
</a>
{{range .Pages}}
{{if eq .Num -1}}
<a class="disabled item">...</a>
{{else}}
<a class="{{if .IsCurrent}}active{{end}} item" {{if not .IsCurrent}}href="{{$.RepoLink}}/commits/{{$.BranchName}}{{if $.FileName}}/{{$.FileName}}{{end}}?page={{.Num}}"{{end}}>{{.Num}}</a>
{{end}}
{{end}}
<a class="{{if not .HasNext}}disabled{{end}} item" {{if .HasNext}}href="{{$.RepoLink}}/commits/{{$.BranchName}}{{if $.FileName}}/{{$.FileName}}{{end}}?page={{.Next}}"{{end}}>
{{$.i18n.Tr "repo.issues.next"}} <i class="icon right arrow"></i>
</a>
</div>
</div>
{{end}}
{{end}}

View File

@ -1,19 +1,18 @@
{{template "ng/base/head" .}} {{template "base/head" .}}
{{template "ng/base/header" .}} <div class="repository diff">
<div id="repo-wrapper"> {{template "repo/header" .}}
{{template "repo/header_old" .}} <div class="ui container">
<div class="container clear" id="diff-page"> {{if .IsDiffCompare }}
{{if .IsDiffCompare }}
<div class="panel panel-info panel-radius compare-head-box"> <div class="panel panel-info panel-radius compare-head-box">
<div class="panel-header"> <div class="panel-header">
<a class="pull-right btn btn-blue btn-header btn-medium btn-radius" rel="nofollow" href="{{EscapePound .SourcePath}}">{{.i18n.Tr "repo.diff.browse_source"}}</a> <a class="pull-right btn btn-blue btn-header btn-medium btn-radius" rel="nofollow" href="{{EscapePound .SourcePath}}">{{.i18n.Tr "repo.diff.browse_source"}}</a>
<h4><a href="{{$.RepoLink}}/commit/{{.BeforeCommitId}}" class="label label-green">{{ShortSha .BeforeCommitId}}</a> ... <a href="{{$.RepoLink}}/commit/{{.AfterCommitId}}" class="label label-green">{{ShortSha .AfterCommitId}}</a></h4> <h4><a href="{{$.RepoLink}}/commit/{{.BeforeCommitId}}" class="label label-green">{{ShortSha .BeforeCommitId}}</a> ... <a href="{{$.RepoLink}}/commit/{{.AfterCommitId}}" class="label label-green">{{ShortSha .AfterCommitId}}</a></h4>
</div> </div>
<div class="panel-body compare"> <div class="panel-body compare">
{{template "repo/commits_table" .}}
</div> </div>
</div> </div>
{{else}} {{template "repo/commits_table" .}}
{{else}}
<div class="panel panel-info panel-radius diff-head-box"> <div class="panel panel-info panel-radius diff-head-box">
<div class="panel-header"> <div class="panel-header">
<a class="pull-right btn btn-blue btn-header btn-medium btn-radius" rel="nofollow" href="{{EscapePound .SourcePath}}">{{.i18n.Tr "repo.diff.browse_source"}}</a> <a class="pull-right btn btn-blue btn-header btn-medium btn-radius" rel="nofollow" href="{{EscapePound .SourcePath}}">{{.i18n.Tr "repo.diff.browse_source"}}</a>
@ -41,7 +40,8 @@
</p> </p>
</div> </div>
</div> </div>
{{end}} {{end}}
{{if .DiffNotAvailable}} {{if .DiffNotAvailable}}
<h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4> <h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4>
{{else}} {{else}}
@ -129,6 +129,6 @@
<br> <br>
{{end}} {{end}}
{{end}} {{end}}
</div> </div>
</div> </div>
{{template "ng/base/footer" .}} {{template "base/footer" .}}