feat(ui): task template icons

This commit is contained in:
Denis Gukov 2021-10-12 18:59:16 +05:00
parent 0f72ce182d
commit b7eb0cd940
4 changed files with 81 additions and 17 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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
}

View File

@ -74,9 +74,31 @@
:items-per-page="Number.MAX_VALUE"
>
<template v-slot:item.alias="{ item }">
<router-link :to="`/project/${projectId}/templates/${item.id}`">
{{ item.alias }}
</router-link>
<v-icon class="mr-3" small>
{{ getTemplateActionIcon(item) }}
</v-icon>
<router-link
:to="`/project/${projectId}/templates/${item.id}`">{{ item.alias }}</router-link>
</template>
<template v-slot:item.last_task="{ item }">
<div class="mt-3 mb-2" v-if="item.last_task != null">
<div style="display: flex; justify-content: left; align-items: center;">
<a class="mr-2" @click="showTaskLog(item.last_task.id)">#{{ item.last_task.id }}</a>
<TaskStatus :status="item.last_task.status"/>
<span v-if="item.last_task.version != null" class="ml-2">
v{{ item.last_task.version }}
</span>
</div>
<div style="color: gray; font-size: 14px;">
by {{ item.last_task.user_name }} {{ item.last_task.created|formatDate }}
</div>
</div>
<div
v-else class="mt-3 mb-2"
style="height: 53px; display: flex; align-items: center; color: gray;"
>Not launched
</div>
</template>
<template v-slot:item.inventory_id="{ item }">
@ -93,7 +115,7 @@
<template v-slot:item.actions="{ item }">
<v-btn text color="black" class="pl-1 pr-2" @click="createTask(item.id)">
<v-icon class="pr-1">{{ getTemplateActionIcon(item) }}</v-icon>
<v-icon class="pr-1">mdi-replay</v-icon>
{{ getTemplateActionTitle(item) }}
</v-btn>
</template>
@ -107,7 +129,9 @@
/>
</div>
</template>
<style>
</style>
<script>
import ItemListPageBase from '@/components/ItemListPageBase';
import TemplateForm from '@/components/TemplateForm.vue';
@ -115,9 +139,12 @@ import axios from 'axios';
import TaskForm from '@/components/TaskForm.vue';
import TableSettingsSheet from '@/components/TableSettingsSheet.vue';
import EventBus from '@/event-bus';
import TaskStatus from '@/components/TaskStatus.vue';
export default {
components: { TemplateForm, TaskForm, TableSettingsSheet },
components: {
TemplateForm, TaskForm, TableSettingsSheet, TaskStatus,
},
mixins: [ItemListPageBase],
async created() {
await this.loadData();
@ -157,14 +184,20 @@ export default {
});
},
showTaskLog(taskId) {
EventBus.$emit('i-show-task', {
taskId,
});
},
getTemplateActionIcon(item) {
switch (item.type) {
case 'task':
return 'mdi-play';
return 'mdi-cog';
case 'build':
return 'mdi-wrench';
case 'deploy':
return 'mdi-package-up';
return 'mdi-rocket-launch';
default:
throw new Error();
}
@ -194,6 +227,11 @@ export default {
text: 'Alias',
value: 'alias',
},
{
text: 'Status',
value: 'last_task',
sortable: false,
},
{
text: 'Playbook',
value: 'playbook',