完成 commits 列表的查询功能
This commit is contained in:
parent
74484ea0be
commit
9bab583bde
|
|
@ -318,4 +318,17 @@ function AddRepo(form) {
|
|||
$('#add-form-loadder').removeClass('active').addClass('disabled');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function searchCommits() {
|
||||
searchForm = $('#search-commit-form');
|
||||
sha = searchForm.form('get value', 'sha');
|
||||
authorEmail = searchForm.form('get value', 'author_email');
|
||||
committerEmail = searchForm.form('get value', 'committer_email');
|
||||
|
||||
if($.trim(sha).length === 0 && $.trim(authorEmail).length === 0 && $.trim(committerEmail).length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
searchForm.submit();
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ package controller
|
|||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
gitee_model "repostats/model/gitee"
|
||||
"repostats/storage"
|
||||
gitee_storage "repostats/storage/gitee"
|
||||
"repostats/utils"
|
||||
|
|
@ -26,40 +27,140 @@ func CommitsPage(ctx *gin.Context) {
|
|||
|
||||
strPage := ctx.DefaultQuery("page", strconv.Itoa(storage.DEFAULT_PAGE_NUMBER))
|
||||
strSize := ctx.DefaultQuery("size", strconv.Itoa(storage.DEFAULT_PAGE_SIZE))
|
||||
sha := ctx.DefaultQuery("sha", "")
|
||||
authorEmail := ctx.DefaultQuery("author_email", "")
|
||||
committerEmail := ctx.DefaultQuery("committer_email", "")
|
||||
|
||||
page, err := strconv.Atoi(strPage)
|
||||
if err != nil || page < storage.DEFAULT_PAGE_NUMBER {
|
||||
page = storage.DEFAULT_PAGE_NUMBER
|
||||
err = nil
|
||||
}
|
||||
|
||||
size, err := strconv.Atoi(strSize)
|
||||
if err != nil || size < storage.DEFAULT_PAGE_SIZE || size > storage.DEFAULT_MAX_PAGE_SIZE {
|
||||
size = storage.DEFAULT_PAGE_SIZE
|
||||
err = nil
|
||||
}
|
||||
|
||||
count, err1 := gitee_storage.FindTotalCommitsCount()
|
||||
commits, err2 := gitee_storage.FindPagedCommits(page, size)
|
||||
if utils.EmptyString(sha) && utils.EmptyString(authorEmail) && utils.EmptyString(committerEmail) {
|
||||
|
||||
count, err := gitee_storage.FindTotalCommitsCount()
|
||||
commits, err := gitee_storage.FindPagedCommits(page, size)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("error %s ", err)
|
||||
ctx.HTML(http.StatusOK, "commits.html", gin.H{
|
||||
"title": "Commit 列表 - RepoStats",
|
||||
"current_url": ctx.Request.URL.Path,
|
||||
"error": "内部错误,请联系管理员",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if err1 != nil || err2 != nil {
|
||||
log.Printf("error1 %s \t error2 %s", err1, err2)
|
||||
ctx.HTML(http.StatusOK, "commits.html", gin.H{
|
||||
"title": "Commit 列表 - RepoStats",
|
||||
"current_url": ctx.Request.URL.Path,
|
||||
"error": "内部错误,请联系管理员",
|
||||
"title": "Commit 列表 - RepoStats",
|
||||
"current_url": ctx.Request.URL.Path,
|
||||
"commits": commits,
|
||||
"total_item": count,
|
||||
"current_page": page,
|
||||
"page_size": size,
|
||||
"first_page": page == 1,
|
||||
"last_page": page >= (count/size)+1,
|
||||
})
|
||||
|
||||
return
|
||||
} //end of if
|
||||
|
||||
if !utils.EmptyString(sha) {
|
||||
found, err := gitee_storage.FindCommitBySha(sha)
|
||||
if err != nil {
|
||||
log.Printf("err %s", err)
|
||||
ctx.HTML(http.StatusOK, "commits.html", gin.H{
|
||||
"title": "Commit 列表 - RepoStats",
|
||||
"current_url": ctx.Request.URL.Path,
|
||||
"error": "内部错误,请联系管理员",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var commits []gitee_model.Commit
|
||||
if !found.IsNilOrEmpty() {
|
||||
commits = append(commits, found)
|
||||
}
|
||||
|
||||
ctx.HTML(http.StatusOK, "commits.html", gin.H{
|
||||
"title": "Commit 列表 - RepoStats",
|
||||
"current_url": ctx.Request.URL.Path,
|
||||
"commits": commits,
|
||||
"total_item": len(commits),
|
||||
"current_page": page,
|
||||
"page_size": size,
|
||||
"first_page": page == 1,
|
||||
"last_page": page >= (len(commits)/size)+1,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ctx.HTML(http.StatusOK, "commits.html", gin.H{
|
||||
"title": "Commit 列表 - RepoStats",
|
||||
"current_url": ctx.Request.URL.Path,
|
||||
"commits": commits,
|
||||
"total_item": count,
|
||||
"current_page": page,
|
||||
"page_size": size,
|
||||
"first_page": page == 1,
|
||||
"last_page": page >= (count/size)+1,
|
||||
})
|
||||
if !utils.EmptyString(authorEmail) {
|
||||
count, err := gitee_storage.FindCommitsCountByAuthorEmail(authorEmail)
|
||||
commits, err := gitee_storage.FindPagedCommitsByAuthorEmail(authorEmail, page, size)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("err %s", err)
|
||||
ctx.HTML(http.StatusOK, "commits.html", gin.H{
|
||||
"title": "Commit 列表 - RepoStats",
|
||||
"current_url": ctx.Request.URL.Path,
|
||||
"error": "内部错误,请联系管理员",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.HTML(http.StatusOK, "commits.html", gin.H{
|
||||
"title": "Commit 列表 - RepoStats",
|
||||
"current_url": ctx.Request.URL.Path,
|
||||
"commits": commits,
|
||||
"total_item": count,
|
||||
"current_page": page,
|
||||
"page_size": size,
|
||||
"first_page": page == 1,
|
||||
"last_page": page >= (count/size)+1,
|
||||
"author_email": authorEmail,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if !utils.EmptyString(committerEmail) {
|
||||
|
||||
count, err := gitee_storage.FindCommitsCountByCommitterEmail(committerEmail)
|
||||
commits, err := gitee_storage.FindPagedCommitsByCommitterEmail(committerEmail, page, size)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("err %s", err)
|
||||
ctx.HTML(http.StatusOK, "commits.html", gin.H{
|
||||
"title": "Commit 列表 - RepoStats",
|
||||
"current_url": ctx.Request.URL.Path,
|
||||
"error": "内部错误,请联系管理员",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.HTML(http.StatusOK, "commits.html", gin.H{
|
||||
"title": "Commit 列表 - RepoStats",
|
||||
"current_url": ctx.Request.URL.Path,
|
||||
"commits": commits,
|
||||
"total_item": count,
|
||||
"current_page": page,
|
||||
"page_size": size,
|
||||
"first_page": page == 1,
|
||||
"last_page": page >= (count/size)+1,
|
||||
"committer_email": committerEmail,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 删除 commit
|
||||
|
|
|
|||
|
|
@ -53,6 +53,38 @@ func FindCommits() ([]gitee_model.Commit, error) {
|
|||
return found, err
|
||||
}
|
||||
|
||||
func FindCommitsCountByAuthorEmail(email string) (int, error) {
|
||||
var count int
|
||||
query := `SELECT count(c.sha) FROM gitee.commits c WHERE c.author_email = $1`
|
||||
return count, storage.DbGet(query, &count, email)
|
||||
}
|
||||
|
||||
func FindCommitsCountByCommitterEmail(email string) (int, error) {
|
||||
var count int
|
||||
query := `SELECT count(c.sha) FROM gitee.commits c WHERE c.committer_email = $1`
|
||||
return count, storage.DbGet(query, &count, email)
|
||||
}
|
||||
|
||||
func FindPagedCommitsByAuthorEmail(email string, page, size int) ([]gitee_model.Commit, error) {
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
commits := []gitee_model.Commit{}
|
||||
query := commitQueryPrefix + ` WHERE c.author_email = $1 ORDER BY c.author_date DESC LIMIT $2 OFFSET $3`
|
||||
offset := (page - 1) * size
|
||||
return commits, storage.DbSelect(query, &commits, email, size, offset)
|
||||
}
|
||||
|
||||
func FindPagedCommitsByCommitterEmail(email string, page, size int) ([]gitee_model.Commit, error) {
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
commits := []gitee_model.Commit{}
|
||||
query := commitQueryPrefix + ` WHERE c.committer_email = $1 ORDER BY c.author_date DESC LIMIT $2 OFFSET $3`
|
||||
offset := (page - 1) * size
|
||||
return commits, storage.DbSelect(query, &commits, email, size, offset)
|
||||
}
|
||||
|
||||
func FindCommitBySha(sha string) (gitee_model.Commit, error) {
|
||||
found := gitee_model.Commit{}
|
||||
query := commitQueryPrefix + ` WHERE c.sha = $1 ORDER BY c.author_date DESC`
|
||||
|
|
|
|||
|
|
@ -11,19 +11,43 @@
|
|||
<tr>
|
||||
<th colspan="11">
|
||||
<p>共计 <span style="color: red;">{{.total_item}}</span> 条记录,当前 <span style="color: red;">{{.current_page}} </span> / <span style="color: red;">{{add (div .total_item .page_size) 1}}</span> 页</p>
|
||||
<p>
|
||||
<form id="search-commit-form" class="ui mini form" method="GET" accept="/admin/commits">
|
||||
<div class="inline fields">
|
||||
<div class="ui field">
|
||||
<label>Commit Sha</label>
|
||||
<input type="text" name="sha" placeholder="Commit Sha" value="{{.sha}}">
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<label>Author Email</label>
|
||||
<input type="text" name="author_email" placeholder="Author Email" value="{{.author_email}}">
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<label>Committer Email</label>
|
||||
<input type="text" name="committer_email" placeholder="Committer Email" value="{{.committer_email}}">
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<a class="ui mini positive button" onclick="javascript:searchCommits()">查询</a>
|
||||
<a target="_self" href="/admin/commits" class="ui mini button">重置</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="search-commit-message" class="ui error message"></div>
|
||||
</form>
|
||||
</form>
|
||||
</p>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="center aligned collapsing">序号</th>
|
||||
<th class="center aligned collapsing">Sha</th>
|
||||
<th class="center aligned collapsing">仓库编号</th>
|
||||
<th class="center aligned collapsing">Sha</th>
|
||||
<th>提交信息</th>
|
||||
<th class="center aligned collapsing">Author</th>
|
||||
<th class="center aligned collapsing">Author Date</th>
|
||||
<th class="center aligned collapsing">Author Email</th>
|
||||
<th class="center aligned collapsing">Author Email</th>
|
||||
<th class="center aligned collapsing">Author Date</th>
|
||||
<th class="center aligned collapsing">Committer</th>
|
||||
<th class="center aligned collapsing">Committer Date</th>
|
||||
<th class="center aligned collapsing">Committer Email</th>
|
||||
<th class="center aligned collapsing">Committer Email</th>
|
||||
<th class="center aligned collapsing">Committer Date</th>
|
||||
<th class="center aligned">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -31,12 +55,12 @@
|
|||
{{range $i,$c := .commits}}
|
||||
<tr>
|
||||
<td class="center aligned collapsing">{{add $i 1}}</td>
|
||||
<td class="center aligned collapsing">{{substr 0 8 $c.Sha}}</td>
|
||||
<td class="center aligned collapsing"><a target="_blank" href="/admin/repos?id={{$c.RepoID}}">{{$c.RepoID}}</a></td>
|
||||
<td class="center aligned collapsing">{{$c.Sha}}</td>
|
||||
<td><a href="{{$c.HtmlUrl}}" target="_blank">{{$c.Detail.Message}}</a></td>
|
||||
<td class="center aligned collapsing">{{$c.Detail.Author.Name}}</td>
|
||||
<td class="center aligned collapsing">{{$c.Detail.Author.Email}}</td>
|
||||
<td class="center aligned collapsing">{{$c.Detail.Author.Date | date "2006-01-02 15:04:05"}}</td>
|
||||
<td class="center aligned collapsing">{{$c.Detail.Author.Email}}</td>
|
||||
<td class="center aligned collapsing">{{$c.Detail.Author.Date | date "2006-01-02 15:04:05"}}</td>
|
||||
<td class="center aligned collapsing">{{$c.Detail.Committer.Name}}</td>
|
||||
<td class="center aligned collapsing">{{$c.Detail.Committer.Email}}</td>
|
||||
<td class="center aligned collapsing">{{$c.Detail.Committer.Date | date "2006-01-02 15:04:05"}}</td>
|
||||
|
|
@ -51,11 +75,11 @@
|
|||
<tr>
|
||||
<td colspan="11" class="center aligned">
|
||||
<div class="ui tiny pagination menu">
|
||||
<a class="item" target="_self" href="{{.current_url}}?page=1&size={{.page_size}}">首页</a>
|
||||
<a class="{{if .first_page}}disabled{{end}} item" target="_self" href="{{.current_url}}?page={{sub .current_page 1}}&size={{.page_size}}"><<</a>
|
||||
<a class="item" target="_self" href="{{.current_url}}?page=1&size={{.page_size}}&sha={{.sha}}&author_email={{.author_email}}&committer_email={{.committer_email}}">首页</a>
|
||||
<a class="{{if .first_page}}disabled{{end}} item" target="_self" href="{{.current_url}}?page={{sub .current_page 1}}&size={{.page_size}}&author_email={{.author_email}}&committer_email={{.committer_email}}"><<</a>
|
||||
<div class="active item">{{.current_page}}</div>
|
||||
<a class="{{if .last_page}}disabled{{end}} item" target="_self" href="{{.current_url}}?page={{add .current_page 1}}&size={{.page_size}}">>></a>
|
||||
<a class="item" target="_self" href="{{.current_url}}?page={{add (div .total_item .page_size) 1}}&size={{.page_size}}">末页</a>
|
||||
<a class="{{if .last_page}}disabled{{end}} item" target="_self" href="{{.current_url}}?page={{add .current_page 1}}&size={{.page_size}}&author_email={{.author_email}}&committer_email={{.committer_email}}">>></a>
|
||||
<a class="item" target="_self" href="{{.current_url}}?page={{add (div .total_item .page_size) 1}}&size={{.page_size}}&author_email={{.author_email}}&committer_email={{.committer_email}}">末页</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@
|
|||
<code style="word-break: break-word;">{{.oauth_info}}</code>
|
||||
</div>
|
||||
{{end}}
|
||||
<button id="btn-gitee-authorize" class="ui button" type="button">应用授权</button>
|
||||
<button id="btn-gitee-token" class="ui button" type="button">获取 Token</button>
|
||||
<button id="btn-gitee-authorize" class="ui positive button" type="button">应用授权</button>
|
||||
<button id="btn-gitee-token" class="ui primary button" type="button">获取 Token</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="eight wide column">
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div id="grafana-token-message" class="ui error message"></div>
|
||||
<button id="btn-grafana-token" class="ui button" type="button">获取 Token</button>
|
||||
<button id="btn-grafana-token" class="ui positive button" type="button">获取 Token</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="eight wide column">
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<tr>
|
||||
<th colspan="11">
|
||||
<p>共计 <span style="color: red;">{{.total_item}}</span> 条记录,当前 <span style="color: red;">{{.current_page}}</span> / <span style="color: red;">{{add (div .total_item .page_size) 1}}</span> 页 </p>
|
||||
<p><button onclick="showRepoModal()" class="ui mini button">添加仓库</button></p>
|
||||
<p><button onclick="showRepoModal()" class="ui mini positive button">添加仓库</button></p>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
@ -81,10 +81,10 @@
|
|||
<p>
|
||||
以下均是有效链接:
|
||||
<ul>
|
||||
<li>https://gitee.com/barat/ohurlshortener</li>
|
||||
<li>https://gitee.com/barat</li>
|
||||
<li>https://gitee.com/openharmony</li>
|
||||
<li>https://gitee.com/openharmony/community</li>
|
||||
<li>http://gitee.com/barat </li>
|
||||
<li>https://gitee.com/openharmony </li>
|
||||
<li>https://gitee.com/barat/ohurlshortener</li>
|
||||
<li>https://gitee.com/openharmony/community </li>
|
||||
</ul>
|
||||
</p>
|
||||
<form id="add-repo-form" class="ui form">
|
||||
|
|
@ -100,7 +100,7 @@
|
|||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui cancel button">取消</div>
|
||||
<div class="ui primary approve button">添加</div>
|
||||
<div class="ui positive approve button">添加</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!--end of admin-right-content-->
|
||||
|
|
|
|||
Loading…
Reference in New Issue