cronsun/web/ui/src/components/Job.vue

185 lines
6.0 KiB
Vue
Raw Normal View History

<style scope>
.clearfix:after {content:""; clear:both; display:table;}
</style>
2017-01-18 09:08:07 +00:00
<template>
<div>
2017-03-10 03:06:40 +00:00
<div class="clearfix" style="margin-bottom: 20px;">
<router-link class="ui left floated button" to="/job/executing">查看执行中的任务</router-link>
<button class="ui left floated icon button" v-on:click="refresh"><i class="refresh icon"></i></button>
<router-link class="ui right floated primary button" to="/job/create"><i class="add to calendar icon"></i> 新任务</router-link>
</div>
2017-01-21 10:16:45 +00:00
<form class="ui form">
2017-03-16 10:27:26 +00:00
<div class="two fields">
<div class="field">
<label>任务分组</label>
2017-04-24 06:40:48 +00:00
<Dropdown title="选择分组" v-bind:items="groups" v-on:change="changeGroup" :selected="group"/>
2017-03-16 10:27:26 +00:00
</div>
<div class="field">
<label>节点过滤</label>
2017-04-24 06:40:48 +00:00
<Dropdown title="选择节点" v-bind:items="nodes" v-on:change="changeNode" :selected="node"/>
2017-03-16 10:27:26 +00:00
</div>
2017-01-21 10:16:45 +00:00
</div>
</form>
<table class="ui hover blue table" v-if="jobs.length > 0">
<thead>
<tr>
<th class="collapsing center aligned">操作</th>
<th class="collapsing center aligned">状态</th>
<th width="200px" class="center aligned">分组</th>
2017-03-02 08:34:03 +00:00
<th class="center aligned">用户</th>
<th class="center aligned">名称</th>
<th class="center aligned">最近执行时间</th>
<th class="center aligned">执行结果</th>
</tr>
</thead>
<tbody>
<tr v-for="(job, index) in jobs">
<td class="center aligned">
<div class="ui icon dropdown">
<i class="content icon"></i>
<div class="menu">
<div class="item" v-on:click="$router.push('/job/edit/'+job.group+'/'+job.id)">编辑</div>
<div class="item" v-if="job.pause" v-on:click="changeStatus(job.group, job.id, index, !job.pause)"></div>
<div class="item" v-if="!job.pause" v-on:click="changeStatus(job.group, job.id, index, !job.pause)"></div>
<div class="divider"></div>
<div class="item" style="color:red;" v-on:click="removeJob(job.group, job.id, index)">删除</div>
</div>
</div>
</td>
<td class="center aligned"><i class="icon" v-bind:class="{pause: job.pause, play: !job.pause, green: !job.pause}"></i></td>
<td>{{job.group}}</td>
2017-03-02 08:34:03 +00:00
<td>{{job.user}}</td>
2017-02-17 06:20:58 +00:00
<td><router-link :to="'/job/edit/'+job.group+'/'+job.id">{{job.name}}</router-link></td>
<td>
<span v-if="!job.latestStatus">-</span>
<span v-else>{{formatLatest(job.latestStatus)}}</span>
</td>
<td :class="{error: job.latestStatus && !job.latestStatus.success}">
<span v-if="!job.latestStatus">-</span>
<router-link v-else :to="'/log/'+job.latestStatus.refLogId">{{job.latestStatus.success ? '成功' : '失败'}}</router-link> |
2017-03-10 08:36:44 +00:00
<router-link :to="{path: 'log', query: {latest:true, ids: job.id}}">latest</router-link> |
<a href="#" title="点此选择节点重新执行任务" v-on:click.prevent="showExecuteJobModal(job.name, job.group, job.id)"><i class="icon repeat"></i></a>
</td>
</tr>
</tbody>
</table>
2017-03-10 08:36:44 +00:00
<ExecuteJob ref="executeJobModal">
2017-01-18 09:08:07 +00:00
</div>
</template>
<script>
2017-01-21 10:16:45 +00:00
import Dropdown from './basic/Dropdown.vue';
2017-03-10 08:36:44 +00:00
import ExecuteJob from './ExecuteJob.vue';
import {formatTime, formatDuration} from '../libraries/functions';
2017-01-21 07:55:36 +00:00
2017-01-18 09:08:07 +00:00
export default {
name: 'job',
2017-01-21 10:16:45 +00:00
data: function(){
return {
groups: [],
group: '',
2017-03-16 10:27:26 +00:00
nodes: [],
node: '',
jobs: []
2017-01-21 10:16:45 +00:00
}
},
mounted: function(){
2017-04-24 06:40:48 +00:00
this.fillParams();
2017-01-21 10:16:45 +00:00
var vm = this;
2017-01-21 10:16:45 +00:00
this.$rest.GET('job/groups').onsucceed(200, (resp)=>{
!resp.includes('default') && resp.unshift('default');
2017-03-16 10:27:26 +00:00
resp.unshift({value: '', name: '所有分组'});
2017-01-21 10:16:45 +00:00
vm.groups = resp;
this.fetchList(this.buildQuery());
2017-01-21 10:16:45 +00:00
}).do();
2017-03-16 10:27:26 +00:00
this.$rest.GET('nodes').onsucceed(200, (resp)=>{
vm.nodes.push({name: '所有节点', value: ''});
for (var i in resp) {
vm.nodes.push(resp[i].id);
}
}).do();
2017-01-21 10:16:45 +00:00
},
watch: {
'$route': function(){
2017-04-24 06:40:48 +00:00
this.fillParams();
this.fetchList(this.buildQuery());
}
},
2017-01-21 10:16:45 +00:00
methods: {
2017-04-24 06:40:48 +00:00
fillParams: function(){
this.group = this.$route.query.group || '';
this.node = this.$route.query.node || '';
},
changeGroup: function(val, text){
var vm = this;
this.group = val;
this.$router.push('job?'+this.buildQuery());
},
2017-03-16 10:27:26 +00:00
changeNode: function(val, text){
var vm = this;
this.node = val;
this.$router.push('job?'+this.buildQuery());
},
buildQuery: function(){
var params = [];
if (this.group) params.push('group='+this.group);
2017-03-16 10:27:26 +00:00
if (this.node) params.push('node='+this.node);
return params.join('&');
},
fetchList: function(query){
var vm = this;
this.$rest.GET('jobs?'+query).onsucceed(200, (resp)=>{
vm.jobs = resp;
vm.$nextTick(()=>{
$(vm.$el).find('table .ui.dropdown').dropdown();
});
}).do();
},
refresh: function(){
this.fetchList(this.buildQuery());
},
removeJob: function(group, id, index){
var vm = this;
this.$rest.DELETE('job/'+group+'-'+id).onsucceed(204, (resp)=>{
vm.jobs.splice(index, 1);
}).do();
},
changeStatus: function(group, id, index, isPause){
var vm = this;
this.$rest.POST('job/'+group+'-'+id, {"pause": isPause}).onsucceed(200, (resp)=>{
2017-02-20 03:58:28 +00:00
vm.refresh();
}).do();
},
formatExecResult: function(st){
if (!st) return '-';
return
},
formatLatest: function(latest){
return formatTime(latest.beginTime, latest.endTime)+',于 '+latest.node+' 耗时 '+formatDuration(latest.beginTime, latest.endTime);
2017-03-10 08:36:44 +00:00
},
showExecuteJobModal: function(jobName, jobGroup, jobId){
this.$refs.executeJobModal.show(jobName, jobGroup, jobId);
}
2017-01-21 10:16:45 +00:00
},
2017-01-18 09:08:07 +00:00
components: {
Dropdown,
2017-03-10 08:36:44 +00:00
ExecuteJob
2017-01-18 09:08:07 +00:00
}
}
</script>