Add explore/commits page

master
Vitaliy Filippov 2017-04-23 18:35:16 +03:00
parent 9fa0822570
commit 64250dbe44
9 changed files with 561 additions and 457 deletions

View File

@ -181,6 +181,7 @@ func runWeb(ctx *cli.Context) error {
ctx.Redirect(setting.AppSubURL + "/explore/repos")
})
m.Get("/repos", routers.ExploreRepos)
m.Get("/commits", routers.ExploreCommits)
m.Get("/users", routers.ExploreUsers)
m.Get("/organizations", routers.ExploreOrganizations)
}, ignSignIn)

View File

@ -140,9 +140,11 @@ issues.in_your_repos = In your repositories
[explore]
repos = Repositories
commits = Commits
users = Users
organizations = Organizations
search = Search
commits.repo = Repository
[auth]
create_new_account = Create New Account

View File

@ -140,9 +140,11 @@ issues.in_your_repos=В ваших репозиториях
[explore]
repos=Репозитории
commits=Коммиты
users=Пользователи
organizations=Организации
search=Поиск
commits.repo=Репозиторий
[auth]
create_new_account=Создать новый аккаунт

View File

@ -8,6 +8,7 @@ import (
"time"
"fmt"
"github.com/go-xorm/xorm"
"github.com/go-xorm/builder"
)
@ -25,15 +26,32 @@ type Commit struct {
Repo *Repository `xorm:"-"`
}
func FulltextSearchCommits(q string) ([]*Commit, error) {
func FulltextSearchCommits(userid int64, q string, limit int, offset int) ([]*Commit, int64, error) {
sess := x.NewSession()
sess.Where(builder.Match{"message", q})
sess.Join("INNER", "repository", "repository.id = commit.repo_id")
if userid > 0 {
sess.Join("LEFT", "access", "access.repo_id = commit.repo_id AND access.user_id="+string(userid))
sess.Where("NOT repository.is_private OR access.user_id IS NOT NULL OR repository.owner_id="+string(userid))
} else {
sess.Where("NOT repository.is_private")
}
if q != "" {
sess.Where(builder.Match{"message", q})
}
var countSess xorm.Session
countSess = *sess
count, err := countSess.Count(new(Commit))
if err != nil {
return nil, 0, fmt.Errorf("Count: %v", err)
}
sess.OrderBy("commit.committer_time DESC")
sess.Limit(limit, offset)
commits := make([]*Commit, 0)
if err := sess.Find(&commits); err != nil {
return nil, fmt.Errorf("Find: %v", err)
return nil, 0, fmt.Errorf("Find: %v", err)
}
if len(commits) == 0 {
return commits, nil
return commits, count, nil
}
// Load repositories
set := make(map[int64]*Repository)
@ -46,13 +64,16 @@ func FulltextSearchCommits(q string) ([]*Commit, error) {
}
repos := make([]*Repository, 0, len(ids))
if err := sess.In("id", ids).Find(&repos); err != nil {
return nil, fmt.Errorf("find users: %v", err)
return nil, 0, fmt.Errorf("Find repos: %v", err)
}
if err = RepositoryList(repos).LoadAttributes(); err != nil {
return nil, 0, fmt.Errorf("Load repo attrs: %v", err)
}
for i := range repos {
set[repos[i].ID] = repos[i]
}
for i := range commits {
commits[i].Repo = set[repos[i].RepoID]
commits[i].Repo = set[commits[i].RepoID]
}
return commits, nil
return commits, count, nil
}

File diff suppressed because one or more lines are too long

View File

@ -16,6 +16,7 @@ import (
const (
HOME = "home"
EXPLORE_REPOS = "explore/repos"
EXPLORE_COMMITS = "explore/commits"
EXPLORE_USERS = "explore/users"
EXPLORE_ORGANIZATIONS = "explore/organizations"
)
@ -77,6 +78,32 @@ func ExploreRepos(ctx *context.Context) {
ctx.HTML(200, EXPLORE_REPOS)
}
func ExploreCommits(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreCommits"] = true
page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
keyword := ctx.Query("q")
commits, count, err := models.FulltextSearchCommits(
ctx.UserID(), keyword, setting.UI.ExplorePagingNum,
setting.UI.ExplorePagingNum * (page-1))
if err != nil {
ctx.Handle(500, "FulltextSearchCommits", err)
return
}
ctx.Data["Keyword"] = keyword
ctx.Data["Total"] = count
ctx.Data["Page"] = paginater.New(int(count), setting.UI.ExplorePagingNum, page, 5)
ctx.Data["Commits"] = commits
ctx.HTML(200, EXPLORE_COMMITS)
}
type UserSearchOptions struct {
Type models.UserType
Counter func() int64

View File

@ -0,0 +1,34 @@
{{if .Commits}}
<div class="ui attached table segment">
<table class="ui very basic striped fixed table single line" id="commits-table">
<thead>
<tr>
<th class="three wide">{{.i18n.Tr "explore.commits.repo"}}</th>
<th class="four wide">{{.i18n.Tr "repo.commits.author"}}</th>
<th class="nine wide message"><span class="sha">SHA1</span> {{.i18n.Tr "repo.commits.message"}}</th>
<th class="three wide right aligned">{{.i18n.Tr "repo.commits.date"}}</th>
</tr>
</thead>
<tbody>
{{range .Commits}}
<tr>
<td class="repo">
<a rel="nofollow" class="name" href="{{.Repo.Link}}">{{.Repo.Owner.Name}}/{{.Repo.Name}}</a>
</td>
<td class="author">
<img class="ui avatar image" src="{{AvatarLink .AuthorEmail}}" alt=""/>&nbsp;&nbsp;{{.AuthorName}}
</td>
<td class="message collapsing has-emoji">
<a rel="nofollow" class="ui sha label" href="{{.Repo.Link}}/commit/{{.Sha}}">{{ShortSHA1 .Sha}}</a>
<span>{{RenderCommitMessage false .Message .Repo.Link .Repo.ComposeMetas}}</span>
</td>
<td class="grey text right aligned">{{TimeSince .AuthorTime $.Lang}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
{{end}}

View File

@ -0,0 +1,14 @@
{{template "base/head" .}}
<div class="explore commits">
<div class="ui container">
<div class="ui grid">
{{template "explore/navbar" .}}
<div class="twelve wide column content">
{{template "explore/search" .}}
{{template "explore/commit_list" .}}
{{template "explore/page" .}}
</div>
</div>
</div>
</div>
{{template "base/footer" .}}

View File

@ -4,6 +4,9 @@
<a class="{{if .PageIsExploreRepositories}}active{{end}} item" href="{{AppSubURL}}/explore/repos">
<span class="octicon octicon-repo"></span> {{.i18n.Tr "explore.repos"}}
</a>
<a class="{{if .PageIsExploreCommits}}active{{end}} item" href="{{AppSubURL}}/explore/commits">
<span class="octicon octicon-git-commit"></span> {{.i18n.Tr "explore.commits"}}
</a>
<a class="{{if .PageIsExploreUsers}}active{{end}} item" href="{{AppSubURL}}/explore/users">
<span class="octicon octicon-person"></span> {{.i18n.Tr "explore.users"}}
</a>