From b7eb0cd940b29c76053726ab995922e5e795de97 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Tue, 12 Oct 2021 18:59:16 +0500 Subject: [PATCH] feat(ui): task template icons --- db/Template.go | 7 ++-- db/sql/task.go | 26 ++++++++++---- db/sql/template.go | 13 +++++++ web2/src/views/project/Templates.vue | 52 ++++++++++++++++++++++++---- 4 files changed, 81 insertions(+), 17 deletions(-) diff --git a/db/Template.go b/db/Template.go index e649e48e..76618974 100644 --- a/db/Template.go +++ b/db/Template.go @@ -25,9 +25,10 @@ type Template struct { VaultKeyID *int `db:"vault_key_id" json:"vault_key_id"` VaultKey AccessKey `db:"-" json:"-"` - Type string `db:"type" json:"type"` - StartVersion *string `db:"start_version" json:"start_version"` - BuildTemplateID *int `db:"build_template_id" json:"build_template_id"` + Type string `db:"type" json:"type"` + StartVersion *string `db:"start_version" json:"start_version"` + BuildTemplateID *int `db:"build_template_id" json:"build_template_id"` + LastTask *TaskWithTpl `db:"-" json:"last_task"` } func FillTemplate(d Store, template *Template) (err error) { diff --git a/db/sql/task.go b/db/sql/task.go index 898dc23c..3a76bf39 100644 --- a/db/sql/task.go +++ b/db/sql/task.go @@ -31,8 +31,17 @@ func (d *SqlDb) CreateTaskOutput(output db.TaskOutput) (db.TaskOutput, error) { return output, err } -func (d *SqlDb) getTasks(projectID int, templateID* int, params db.RetrieveQueryParams) (tasks []db.TaskWithTpl, err error) { - q := squirrel.Select("task.*, tpl.playbook as tpl_playbook, `user`.name as user_name, tpl.alias as tpl_alias"). + +func (d *SqlDb) getTasks(projectID int, templateID* int, params db.RetrieveQueryParams, tasks interface{}) (err error) { + fields := "task.*" + + switch tasks.(type) { + case *[]db.TaskWithTpl: + fields += ", tpl.playbook as tpl_playbook, `user`.name as user_name, tpl.alias as tpl_alias" + break + } + + q := squirrel.Select(fields). From("task"). Join("project__template as tpl on task.template_id=tpl.id"). LeftJoin("`user` on task.user_id=`user`.id"). @@ -50,11 +59,12 @@ func (d *SqlDb) getTasks(projectID int, templateID* int, params db.RetrieveQuery query, args, _ := q.ToSql() - _, err = d.selectAll(&tasks, query, args...) + _, err = d.selectAll(tasks, query, args...) return } + func (d *SqlDb) GetTask(projectID int, taskID int) (task db.Task, err error) { q := squirrel.Select("task.*"). From("task"). @@ -76,12 +86,14 @@ func (d *SqlDb) GetTask(projectID int, taskID int) (task db.Task, err error) { return } -func (d *SqlDb) GetTemplateTasks(projectID int, templateID int, params db.RetrieveQueryParams) ([]db.TaskWithTpl, error) { - return d.getTasks(projectID, &templateID, params) +func (d *SqlDb) GetTemplateTasks(projectID int, templateID int, params db.RetrieveQueryParams) (tasks []db.TaskWithTpl, err error) { + err = d.getTasks(projectID, &templateID, params, &tasks) + return } -func (d *SqlDb) GetProjectTasks(projectID int, params db.RetrieveQueryParams) ([]db.TaskWithTpl, error) { - return d.getTasks(projectID, nil, params) +func (d *SqlDb) GetProjectTasks(projectID int, params db.RetrieveQueryParams) (tasks []db.TaskWithTpl, err error) { + err = d.getTasks(projectID, nil, params, &tasks) + return } func (d *SqlDb) DeleteTaskWithOutputs(projectID int, taskID int) (err error) { diff --git a/db/sql/template.go b/db/sql/template.go index 6f42e0b7..34a81c6f 100644 --- a/db/sql/template.go +++ b/db/sql/template.go @@ -124,6 +124,19 @@ func (d *SqlDb) GetTemplates(projectID int, params db.RetrieveQueryParams) (temp } _, err = d.selectAll(&templates, query, args...) + + for i := range templates { + tpl := &templates[i] + var tasks []db.TaskWithTpl + err = d.getTasks(projectID, &tpl.ID, db.RetrieveQueryParams{Count: 1}, &tasks) + if err != nil { + return + } + if len(tasks) > 0 { + tpl.LastTask = &tasks[0] + } + } + return } diff --git a/web2/src/views/project/Templates.vue b/web2/src/views/project/Templates.vue index 62ef9218..7327c496 100644 --- a/web2/src/views/project/Templates.vue +++ b/web2/src/views/project/Templates.vue @@ -74,9 +74,31 @@ :items-per-page="Number.MAX_VALUE" > + + +