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"`
}
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) {
if repo.Owner == nil {
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)
}
var CommitsRangeSize = 50
func (repo *Repository) commitsByRange(id sha1, page int) (*list.List, error) {
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 {
return nil, errors.New(string(stderr))
}

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
@mega-octicon-width: 30px;
padding-top: 15px;
padding-bottom: @footer-margin * 3;
padding-bottom: @footer-margin * 2;
.head {
.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 {

View File

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

View File

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

View File

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

View File

@ -1,48 +1,66 @@
<div id="commits-list">
<div class="panel panel-radius">
<div class="panel-header">
{{if not .IsDiffCompare}}
<form class="search pull-right" action="{{.RepoLink}}/commits/{{.BranchName}}/search" method="get" id="commits-search-form">
<input class="ipt ipt-radius" type="search" name="q" placeholder="{{.i18n.Tr "repo.commits.search"}}" value="{{.Keyword}}" />
<button class="btn btn-black btn-small btn-radius">{{.i18n.Tr "repo.commits.find"}}</button>
</form>
{{end}}
<h4>{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}}</h4>
<h4 class="ui top attached header">
{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}}
{{if .PageIsCommits}}
<div class="ui right">
<form action="{{.RepoLink}}/commits/{{.BranchName}}/search">
<div class="ui tiny search input">
<input name="q" placeholder="{{.i18n.Tr "repo.commits.search"}}" value="{{.Keyword}}" autofocus>
</div>
<table class="panel-body table commit-list table-striped">
<button class="ui black tiny button" data-panel="#add-deploy-key-panel">{{.i18n.Tr "repo.commits.find"}}</button>
</form>
</div>
{{end}}
</h4>
<div class="ui attached table segment">
<table class="ui very basic striped commits table">
<thead>
<tr>
<th class="author">{{.i18n.Tr "repo.commits.author"}}</th>
<th class="sha">SHA1</th>
<th class="message">{{.i18n.Tr "repo.commits.message"}}</th>
<th class="date">{{.i18n.Tr "repo.commits.date"}}</th>
<th>{{.i18n.Tr "repo.commits.author"}}</th>
<th>SHA1</th>
<th>{{.i18n.Tr "repo.commits.message"}}</th>
<th>{{.i18n.Tr "repo.commits.date"}}</th>
</tr>
</thead>
<tbody>
{{ $username := .Username}}
{{ $reponame := .Reponame}}
{{$r := List .Commits}}
{{ $r:= List .Commits}}
{{range $r}}
<tr>
<td class="author">
{{if .User}}
<img class="avatar-20" src="{{.User.AvatarLink}}" alt=""/>&nbsp;&nbsp;&nbsp;<a href="{{AppSubUrl}}/{{.User.Name}}">{{.Author.Name}}</a>
<img class="ui avatar image" src="{{.User.AvatarLink}}" alt=""/>&nbsp;&nbsp;<a href="{{AppSubUrl}}/{{.User.Name}}">{{.Author.Name}}</a>
{{else}}
<img class="avatar-20" src="{{AvatarLink .Author.Email}}" alt=""/>&nbsp;&nbsp;&nbsp;{{.Author.Name}}
<img class="ui avatar image" src="{{AvatarLink .Author.Email}}" alt=""/>&nbsp;&nbsp;{{.Author.Name}}
{{end}}
</td>
<td class="sha"><a rel="nofollow" class="label label-green" href="{{AppSubUrl}}/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 10}} </a></td>
<td class="message"><span class="text-truncate">{{RenderCommitMessage .Summary $.RepoLink}}</span></td>
<td class="sha"><a rel="nofollow" class="ui green label" href="{{AppSubUrl}}/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 10}} </a></td>
<td class="message"><span class="text truncate">{{RenderCommitMessage .Summary $.RepoLink}}</span></td>
<td class="date">{{TimeSince .Author.When $.Lang}}</td>
</tr>
{{end}}
</tbody>
</table>
</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}}
</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,8 +1,7 @@
{{template "ng/base/head" .}}
{{template "ng/base/header" .}}
<div id="repo-wrapper">
{{template "repo/header_old" .}}
<div class="container clear" id="diff-page">
{{template "base/head" .}}
<div class="repository diff">
{{template "repo/header" .}}
<div class="ui container">
{{if .IsDiffCompare }}
<div class="panel panel-info panel-radius compare-head-box">
<div class="panel-header">
@ -10,9 +9,9 @@
<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 class="panel-body compare">
</div>
</div>
{{template "repo/commits_table" .}}
</div>
</div>
{{else}}
<div class="panel panel-info panel-radius diff-head-box">
<div class="panel-header">
@ -42,6 +41,7 @@
</div>
</div>
{{end}}
{{if .DiffNotAvailable}}
<h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4>
{{else}}
@ -131,4 +131,4 @@
{{end}}
</div>
</div>
{{template "ng/base/footer" .}}
{{template "base/footer" .}}