From 35df6dbf439eed5ef29883b1620a3e5426cbc5da Mon Sep 17 00:00:00 2001 From: palytoxin Date: Mon, 20 Jul 2020 14:58:47 +0800 Subject: [PATCH] improve --- models/cloudbrain.go | 19 +++++++++++++++++++ routers/repo/cloudbrain.go | 8 +++++++- templates/repo/cloudbrain/show.tmpl | 12 +++++++++--- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 2485ef5d3..acfb37e08 100644 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -1,6 +1,7 @@ package models import ( + "errors" "fmt" "code.gitea.io/gitea/modules/setting" @@ -75,6 +76,7 @@ type CloudbrainsOptions struct { ListOptions RepoID int64 // include all repos if empty UserID int64 + JobID int64 JobStatus CloudbrainStatus SortType string CloudbrainIDs []int64 @@ -97,6 +99,12 @@ func Cloudbrains(opts *CloudbrainsOptions) ([]*Cloudbrain, int64, error) { ) } + if (opts.JobID) > 0 { + cond.And( + builder.Eq{"cloudbrain.job_id": opts.JobID}, + ) + } + switch opts.JobStatus { case JobWaiting: cond.And(builder.Eq{"cloudbrain.status": int(JobWaiting)}) @@ -144,3 +152,14 @@ func CreateCloudbrain(cloudbrain *Cloudbrain) (err error) { return nil } + +func GetCloudbrainByJobID(jobID string) (*Cloudbrain, error) { + cb := &Cloudbrain{JobID: jobID} + has, err := x.Get(cb) + if err != nil { + return nil, err + } else if !has { + return nil, errors.New("cloudbrain task is not found") + } + return cb, nil +} diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index aaf1ed6da..01910d93d 100644 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -90,7 +90,13 @@ func CloudBrainShow(ctx *context.Context) { ctx.Data["PageIsCloudBrain"] = true var jobID = ctx.Params(":jobid") - var result, err = cloudbrain.GetJob(jobID) + task, err := models.GetCloudbrainByJobID(jobID) + if err != nil { + ctx.Data["error"] = err.Error() + } + ctx.Data["task"] = task + + result, err := cloudbrain.GetJob(jobID) if err != nil { ctx.Data["error"] = err.Error() } diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index 771934005..29c2f5096 100644 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -4,12 +4,18 @@
{{template "base/alert" .}} -
{{.jobID}}
+ {{with .task}} +

jobname:

+
{{.JobName}}

-

err

+

jobid:

+
{{.JobID}}
+
+ {{end}} +

err:

{{.error}}

-

result

+

result:

{{.result}}