mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 12:30:41 +01:00
refactor(ui): move constants to file constants.js
This commit is contained in:
parent
d87a0147d5
commit
d8ce55ae84
@ -45,6 +45,10 @@ func (d *BoltDb) getTasks(projectID int, template *db.Template, params db.Retrie
|
||||
return true
|
||||
}, &tasks)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var templates = make(map[int]db.Template)
|
||||
var users = make(map[int]db.User)
|
||||
|
||||
@ -53,10 +57,7 @@ func (d *BoltDb) getTasks(projectID int, template *db.Template, params db.Retrie
|
||||
tpl, ok := templates[task.TemplateID]
|
||||
if !ok {
|
||||
if template == nil {
|
||||
tpl, err = d.GetTemplate(task.ProjectID, task.TemplateID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tpl, _ = d.GetTemplate(task.ProjectID, task.TemplateID)
|
||||
} else {
|
||||
tpl = *template
|
||||
}
|
||||
|
17
web2/src/lib/constants.js
Normal file
17
web2/src/lib/constants.js
Normal file
@ -0,0 +1,17 @@
|
||||
export const TEMPLATE_TYPE_ICONS = {
|
||||
'': 'mdi-cog',
|
||||
build: 'mdi-wrench',
|
||||
deploy: 'mdi-rocket-launch',
|
||||
};
|
||||
|
||||
export const TEMPLATE_TYPE_TITLES = {
|
||||
'': 'Task',
|
||||
build: 'Build',
|
||||
deploy: 'Deploy',
|
||||
};
|
||||
|
||||
export const TEMPLATE_TYPE_ACTION_TITLES = {
|
||||
'': 'Run',
|
||||
build: 'Build',
|
||||
deploy: 'Deploy',
|
||||
};
|
@ -13,14 +13,14 @@
|
||||
</div>
|
||||
</v-toolbar>
|
||||
<v-data-table
|
||||
:headers="headers"
|
||||
:items="items"
|
||||
:footer-props="{ itemsPerPageOptions: [20] }"
|
||||
class="mt-4"
|
||||
:headers="headers"
|
||||
:items="items"
|
||||
:footer-props="{ itemsPerPageOptions: [20] }"
|
||||
class="mt-4"
|
||||
>
|
||||
<template v-slot:item.tpl_alias="{ item }">
|
||||
<v-icon class="mr-3" small>
|
||||
{{ getTemplateActionIcon(item) }}
|
||||
{{ TEMPLATE_TYPE_ICONS[item.type] }}
|
||||
</v-icon>
|
||||
<a :href="
|
||||
'/project/' + item.project_id +
|
||||
@ -31,7 +31,7 @@
|
||||
</template>
|
||||
|
||||
<template v-slot:item.status="{ item }">
|
||||
<TaskStatus :status="item.status" />
|
||||
<TaskStatus :status="item.status"/>
|
||||
</template>
|
||||
|
||||
<template v-slot:item.start="{ item }">
|
||||
@ -50,10 +50,15 @@ import ItemListPageBase from '@/components/ItemListPageBase';
|
||||
import EventBus from '@/event-bus';
|
||||
import TaskStatus from '@/components/TaskStatus.vue';
|
||||
import socket from '@/socket';
|
||||
import { TEMPLATE_TYPE_ICONS } from '@/lib/constants';
|
||||
|
||||
export default {
|
||||
mixins: [ItemListPageBase],
|
||||
|
||||
data() {
|
||||
return { TEMPLATE_TYPE_ICONS };
|
||||
},
|
||||
|
||||
components: { TaskStatus },
|
||||
|
||||
watch: {
|
||||
@ -67,19 +72,6 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
getTemplateActionIcon(item) {
|
||||
switch (item.tpl_type) {
|
||||
case 'task':
|
||||
return 'mdi-cog';
|
||||
case 'build':
|
||||
return 'mdi-wrench';
|
||||
case 'deploy':
|
||||
return 'mdi-rocket-launch';
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
},
|
||||
|
||||
showTaskLog(taskId) {
|
||||
EventBus.$emit('i-show-task', {
|
||||
taskId,
|
||||
|
@ -1,63 +1,64 @@
|
||||
<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
|
||||
<div v-if="!isLoaded">
|
||||
<v-progress-linear
|
||||
indeterminate
|
||||
color="primary darken-2"
|
||||
indeterminate
|
||||
color="primary darken-2"
|
||||
></v-progress-linear>
|
||||
</div>
|
||||
<div v-else>
|
||||
<EditDialog
|
||||
:max-width="700"
|
||||
v-model="editDialog"
|
||||
save-button-text="Save"
|
||||
title="Edit Template"
|
||||
@save="loadData()"
|
||||
:max-width="700"
|
||||
v-model="editDialog"
|
||||
save-button-text="Save"
|
||||
title="Edit Template"
|
||||
@save="loadData()"
|
||||
>
|
||||
<template v-slot:form="{ onSave, onError, needSave, needReset }">
|
||||
<TemplateForm
|
||||
:project-id="projectId"
|
||||
:item-id="itemId"
|
||||
@save="onSave"
|
||||
@error="onError"
|
||||
:need-save="needSave"
|
||||
:need-reset="needReset"
|
||||
:project-id="projectId"
|
||||
:item-id="itemId"
|
||||
@save="onSave"
|
||||
@error="onError"
|
||||
:need-save="needSave"
|
||||
:need-reset="needReset"
|
||||
/>
|
||||
</template>
|
||||
</EditDialog>
|
||||
|
||||
<EditDialog
|
||||
v-model="copyDialog"
|
||||
save-button-text="Create"
|
||||
title="New Template"
|
||||
@save="onTemplateCopied"
|
||||
v-model="copyDialog"
|
||||
save-button-text="Create"
|
||||
title="New Template"
|
||||
@save="onTemplateCopied"
|
||||
>
|
||||
<template v-slot:form="{ onSave, onError, needSave, needReset }">
|
||||
<TemplateForm
|
||||
:project-id="projectId"
|
||||
item-id="new"
|
||||
:source-item-id="itemId"
|
||||
@save="onSave"
|
||||
@error="onError"
|
||||
:need-save="needSave"
|
||||
:need-reset="needReset"
|
||||
:project-id="projectId"
|
||||
item-id="new"
|
||||
:source-item-id="itemId"
|
||||
@save="onSave"
|
||||
@error="onError"
|
||||
:need-save="needSave"
|
||||
:need-reset="needReset"
|
||||
/>
|
||||
</template>
|
||||
</EditDialog>
|
||||
|
||||
<YesNoDialog
|
||||
title="Delete template"
|
||||
text="Are you really want to delete this template?"
|
||||
v-model="deleteDialog"
|
||||
@yes="remove()"
|
||||
title="Delete template"
|
||||
text="Are you really want to delete this template?"
|
||||
v-model="deleteDialog"
|
||||
@yes="remove()"
|
||||
/>
|
||||
|
||||
<v-toolbar flat color="white">
|
||||
<v-app-bar-nav-icon @click="showDrawer()"></v-app-bar-nav-icon>
|
||||
<v-toolbar-title class="breadcrumbs">
|
||||
<router-link
|
||||
class="breadcrumbs__item breadcrumbs__item--link"
|
||||
:to="`/project/${projectId}/templates/`"
|
||||
>Task Templates</router-link>
|
||||
class="breadcrumbs__item breadcrumbs__item--link"
|
||||
:to="`/project/${projectId}/templates/`"
|
||||
>Task Templates
|
||||
</router-link>
|
||||
<v-icon>mdi-chevron-right</v-icon>
|
||||
<span class="breadcrumbs__item">{{ item.alias }}</span>
|
||||
</v-toolbar-title>
|
||||
@ -65,25 +66,25 @@
|
||||
<v-spacer></v-spacer>
|
||||
|
||||
<v-btn
|
||||
icon
|
||||
color="error"
|
||||
@click="deleteDialog = true"
|
||||
icon
|
||||
color="error"
|
||||
@click="deleteDialog = true"
|
||||
>
|
||||
<v-icon>mdi-delete</v-icon>
|
||||
</v-btn>
|
||||
|
||||
<v-btn
|
||||
icon
|
||||
color="black"
|
||||
@click="copyDialog = true"
|
||||
icon
|
||||
color="black"
|
||||
@click="copyDialog = true"
|
||||
>
|
||||
<v-icon>mdi-content-copy</v-icon>
|
||||
</v-btn>
|
||||
|
||||
<v-btn
|
||||
icon
|
||||
color="black"
|
||||
@click="editDialog = true"
|
||||
icon
|
||||
color="black"
|
||||
@click="editDialog = true"
|
||||
>
|
||||
<v-icon>mdi-pencil</v-icon>
|
||||
</v-btn>
|
||||
@ -98,7 +99,8 @@
|
||||
elevation="2"
|
||||
class="mb-0 ml-4 mr-4 mb-2"
|
||||
v-if="item.description"
|
||||
>{{ item.description }}</v-alert>
|
||||
>{{ item.description }}
|
||||
</v-alert>
|
||||
|
||||
<v-row>
|
||||
<v-col>
|
||||
@ -119,12 +121,12 @@
|
||||
<v-list two-line subheader>
|
||||
<v-list-item>
|
||||
<v-list-item-icon>
|
||||
<v-icon>{{ getTypeIcon() }}</v-icon>
|
||||
<v-icon>{{ TEMPLATE_TYPE_ICONS[item.type] }}</v-icon>
|
||||
</v-list-item-icon>
|
||||
|
||||
<v-list-item-content>
|
||||
<v-list-item-title>Type</v-list-item-title>
|
||||
<v-list-item-subtitle>{{ item.type }}</v-list-item-subtitle>
|
||||
<v-list-item-subtitle>{{ TEMPLATE_TYPE_TITLES[item.type] }}</v-list-item-subtitle>
|
||||
</v-list-item-content>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
@ -179,21 +181,21 @@
|
||||
</v-container>
|
||||
|
||||
<v-data-table
|
||||
:headers="headers"
|
||||
:items="tasks"
|
||||
:footer-props="{ itemsPerPageOptions: [20] }"
|
||||
class="mt-0"
|
||||
:headers="headers"
|
||||
:items="tasks"
|
||||
:footer-props="{ itemsPerPageOptions: [20] }"
|
||||
class="mt-0"
|
||||
>
|
||||
<template v-slot:item.id="{ item }">
|
||||
<a @click="showTaskLog(item.id)">#{{ item.id }}</a>
|
||||
</template>
|
||||
|
||||
<template v-slot:item.status="{ item }">
|
||||
<TaskStatus :status="item.status" />
|
||||
<TaskStatus :status="item.status"/>
|
||||
</template>
|
||||
|
||||
<template v-slot:item.start="{ item }">
|
||||
{{ item.start | formatDate }}
|
||||
{{ item.start | formatDate }}
|
||||
</template>
|
||||
|
||||
<template v-slot:item.end="{ item }">
|
||||
@ -213,6 +215,7 @@ import YesNoDialog from '@/components/YesNoDialog.vue';
|
||||
import EditDialog from '@/components/EditDialog.vue';
|
||||
import TemplateForm from '@/components/TemplateForm.vue';
|
||||
import TaskStatus from '@/components/TaskStatus.vue';
|
||||
import { TEMPLATE_TYPE_ICONS, TEMPLATE_TYPE_TITLES } from '../../lib/constants';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -225,6 +228,8 @@ export default {
|
||||
|
||||
data() {
|
||||
return {
|
||||
TEMPLATE_TYPE_ICONS,
|
||||
TEMPLATE_TYPE_TITLES,
|
||||
headers: [
|
||||
{
|
||||
text: 'Task ID',
|
||||
@ -277,10 +282,10 @@ export default {
|
||||
},
|
||||
isLoaded() {
|
||||
return this.item
|
||||
&& this.tasks
|
||||
&& this.inventory
|
||||
&& this.environment
|
||||
&& this.repositories;
|
||||
&& this.tasks
|
||||
&& this.inventory
|
||||
&& this.environment
|
||||
&& this.repositories;
|
||||
},
|
||||
},
|
||||
|
||||
@ -301,18 +306,6 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
getTypeIcon() {
|
||||
switch (this.item.type) {
|
||||
case 'task':
|
||||
return 'mdi-cog';
|
||||
case 'build':
|
||||
return 'mdi-wrench';
|
||||
case 'deploy':
|
||||
return 'mdi-rocket-launch';
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
},
|
||||
|
||||
showTaskLog(taskId) {
|
||||
EventBus.$emit('i-show-task', {
|
||||
|
@ -75,7 +75,7 @@
|
||||
>
|
||||
<template v-slot:item.alias="{ item }">
|
||||
<v-icon class="mr-3" small>
|
||||
{{ getTemplateActionIcon(item) }}
|
||||
{{ TEMPLATE_TYPE_ICONS[item.type] }}
|
||||
</v-icon>
|
||||
<router-link
|
||||
:to="`/project/${projectId}/templates/${item.id}`">{{ item.alias }}</router-link>
|
||||
@ -116,7 +116,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">mdi-replay</v-icon>
|
||||
{{ getTemplateActionTitle(item) }}
|
||||
{{ TEMPLATE_TYPE_ACTION_TITLES[item.type] }}
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-data-table>
|
||||
@ -140,6 +140,7 @@ import TaskForm from '@/components/TaskForm.vue';
|
||||
import TableSettingsSheet from '@/components/TableSettingsSheet.vue';
|
||||
import EventBus from '@/event-bus';
|
||||
import TaskStatus from '@/components/TaskStatus.vue';
|
||||
import { TEMPLATE_TYPE_ACTION_TITLES, TEMPLATE_TYPE_ICONS } from '../../lib/constants';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -151,6 +152,8 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
TEMPLATE_TYPE_ICONS,
|
||||
TEMPLATE_TYPE_ACTION_TITLES,
|
||||
inventory: null,
|
||||
environment: null,
|
||||
repositories: null,
|
||||
@ -190,32 +193,6 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
getTemplateActionIcon(item) {
|
||||
switch (item.type) {
|
||||
case 'task':
|
||||
return 'mdi-cog';
|
||||
case 'build':
|
||||
return 'mdi-wrench';
|
||||
case 'deploy':
|
||||
return 'mdi-rocket-launch';
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
},
|
||||
|
||||
getTemplateActionTitle(item) {
|
||||
switch (item.type) {
|
||||
case 'task':
|
||||
return 'Run';
|
||||
case 'build':
|
||||
return 'Build';
|
||||
case 'deploy':
|
||||
return 'Deploy';
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
},
|
||||
|
||||
createTask(itemId) {
|
||||
this.itemId = itemId;
|
||||
this.newTaskDialog = true;
|
||||
|
Loading…
Reference in New Issue
Block a user