diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 1124e3470..da6baa169 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -34,6 +34,7 @@ type Cloudbrain struct { ContainerIp string CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + DeletedAt time.Time `xorm:"deleted"` CanDebug bool `xorm:"-"` User *User `xorm:"-"` @@ -359,3 +360,12 @@ func updateJob(e Engine, job *Cloudbrain) error { _, err := sess.Cols("status", "container_id", "container_ip").Update(job) return err } + +func DeleteJob(job *Cloudbrain) error { + return deleteJob(x, job) +} + +func deleteJob(e Engine, job *Cloudbrain) error { + _, err := e.ID(job.ID).Delete(job) + return err +} diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 14160ec94..0d7937c5d 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -253,6 +253,29 @@ func CloudBrainStop(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") } +func CloudBrainDel(ctx *context.Context) { + var jobID = ctx.Params(":jobid") + task, err := models.GetCloudbrainByJobID(jobID) + if err != nil { + ctx.ServerError("GetCloudbrainByJobID failed", err) + return + } + + if task.Status != string(models.JobStopped) { + log.Error("the job(%s) has not been stopped", task.JobName) + ctx.ServerError("the job has not been stopped", errors.New("the job has not been stopped")) + return + } + + err = models.DeleteJob(task) + if err != nil { + ctx.ServerError("DeleteJob failed", err) + return + } + + ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") +} + func downloadCode(repo *models.Repository, codePath string) error { if err := git.Clone(repo.RepoPath(), codePath, git.CloneRepoOptions{}); err != nil { log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 814af1fd9..c7f969e76 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -899,6 +899,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/debug", reqRepoCloudBrainReader, repo.CloudBrainDebug) m.Post("/commit_image", reqRepoCloudBrainWriter, bindIgnErr(auth.CommitImageCloudBrainForm{}), repo.CloudBrainCommitImage) m.Post("/stop", reqRepoCloudBrainWriter, repo.CloudBrainStop) + m.Post("/del", reqRepoCloudBrainWriter, repo.CloudBrainDel) }) m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainNew) m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl index 5361db7dd..18c5053e2 100755 --- a/templates/repo/cloudbrain/index.tmpl +++ b/templates/repo/cloudbrain/index.tmpl @@ -1,4 +1,176 @@ + {{template "base/head" .}} + + +
@@ -15,22 +187,33 @@
{{template "repo/header" .}} +
-
+ + +

{{.i18n.Tr "repo.cloudbrain"}}

+
+
{{if .Permission.CanWrite $.UnitTypeCloudBrain}} {{.i18n.Tr "repo.cloudbrain.new"}} {{end}}
+ +
+ +
+ +
@@ -38,70 +221,96 @@
+ +
{{range .Tasks}}
+ + + +
{{.Status}}
+ +
{{svg "octicon-flame" 16}} {{TimeSinceUnix .CreatedUnix $.Lang}}
+ + + + +
+ +
+ {{$.CsrfTokenHtml}} + + 删除 +
+
+
+ + + +
-
- {{$.CsrfTokenHtml}} - 停止 -
-
+
+ {{$.CsrfTokenHtml}} + 停止 +
+
- - 提交镜像 - -
{{end}} {{template "base/paginate" .}}
+
+ +
+ +
+
+ +
+ + +
+
+ +
{{template "base/footer" .}} - - \ No newline at end of file + \ No newline at end of file diff --git a/templates/repo/cloudbrain/new.tmpl b/templates/repo/cloudbrain/new.tmpl index a94bf1fe2..dff4ca646 100755 --- a/templates/repo/cloudbrain/new.tmpl +++ b/templates/repo/cloudbrain/new.tmpl @@ -81,19 +81,7 @@ } } -
@@ -122,7 +110,7 @@
- {{range .images}} {{end}} @@ -130,7 +118,7 @@
- {{range .attachments}} {{end}} @@ -169,3 +157,17 @@
{{template "base/footer" .}} + + \ No newline at end of file