Add builds UI
This commit is contained in:
99
routers/web/repo/builds/builds.go
Normal file
99
routers/web/repo/builds/builds.go
Normal file
@@ -0,0 +1,99 @@
|
||||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package builds
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
bots_model "code.gitea.io/gitea/models/bots"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
const (
|
||||
tplListBuilds base.TplName = "repo/builds/list"
|
||||
tplViewBuild base.TplName = "repo/builds/view"
|
||||
)
|
||||
|
||||
// MustEnableBuilds check if builds are enabled in settings
|
||||
func MustEnableBuilds(ctx *context.Context) {
|
||||
if unit.TypeBuilds.UnitGlobalDisabled() {
|
||||
ctx.NotFound("EnableTypeBuilds", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.Repo.Repository != nil {
|
||||
if !ctx.Repo.CanRead(unit.TypeBuilds) {
|
||||
ctx.NotFound("MustEnableBuilds", nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func List(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.builds")
|
||||
ctx.Data["PageIsBuildList"] = true
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
opts := bots_model.FindTaskOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
|
||||
},
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
}
|
||||
if ctx.FormString("state") == "closed" {
|
||||
opts.IsClosed = util.OptionalBoolTrue
|
||||
} else {
|
||||
opts.IsClosed = util.OptionalBoolFalse
|
||||
}
|
||||
tasks, err := bots_model.FindTasks(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := tasks.LoadTriggerUser(); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
total, err := bots_model.CountTasks(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Tasks"] = tasks
|
||||
|
||||
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
ctx.HTML(http.StatusOK, tplListBuilds)
|
||||
}
|
||||
|
||||
func ViewBuild(ctx *context.Context) {
|
||||
index := ctx.ParamsInt64("index")
|
||||
task, err := bots_model.GetTaskByRepoAndIndex(ctx.Repo.Repository.ID, index)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Title"] = task.Title + " - " + ctx.Tr("repo.builds")
|
||||
ctx.Data["PageIsBuildList"] = true
|
||||
ctx.Data["Build"] = task
|
||||
|
||||
ctx.HTML(http.StatusOK, tplViewBuild)
|
||||
}
|
||||
Reference in New Issue
Block a user