2017-01-22 07:18:08 +00:00
< style scope >
. clearfix : after { content : "" ; clear : both ; display : table ; }
2017-12-14 08:38:10 +00:00
. ui . fitted . checkbox { min - height : 15 px ; }
2017-01-22 07:18:08 +00:00
< / 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;" >
2017-05-26 09:27:00 +00:00
< router -link class = "ui left floated button" to = "/job/executing" > { { $L ( 'view executing jobs' ) } } < / r o u t e r - l i n k >
2017-03-10 03:06:40 +00:00
< button class = "ui left floated icon button" v -on :click ="refresh" > < i class = "refresh icon" > < / i > < / button >
2017-12-14 08:38:10 +00:00
< div class = "ui icon buttons" >
2017-12-15 07:15:02 +00:00
< button class = "ui left floated icon button" v -on :click ="batched=!batched" > { { $L ( 'batch' ) } } < / button >
2017-12-14 08:38:10 +00:00
< button class = "ui button" : class = "{disabled: batchIds.length == 0}" v-if ="batched" v-on:click="batch('start')" >
< i class = "play icon" > < / i >
< / button >
< button class = "ui button" : class = "{disabled: batchIds.length == 0}" v-if ="batched" v-on:click="batch('pause')" >
< i class = "pause icon" > < / i >
< / button >
< / div >
2017-05-26 09:27:00 +00:00
< router -link class = "ui right floated primary button" to = "/job/create" > < i class = "add to calendar icon" > < / i > { { $L ( 'create job' ) } } < / r o u t e r - l i n k >
2017-02-16 03:57:58 +00:00
< / 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" >
2017-05-26 09:27:00 +00:00
< label > { { $L ( 'group filter' ) } } < / label >
< Dropdown : title = "$L('select a group')" v -bind :items ="groups" v -on :change ="changeGroup" :selected ="group" / >
2017-03-16 10:27:26 +00:00
< / div >
< div class = "field" >
2017-05-26 09:27:00 +00:00
< label > { { $L ( 'node filter' ) } } < / label >
< Dropdown : title = "$L('select a node')" 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 >
2017-02-16 03:57:58 +00:00
< table class = "ui hover blue table" v-if ="jobs.length > 0" >
2017-01-22 07:18:08 +00:00
< thead >
< tr >
2017-05-26 09:27:00 +00:00
< th class = "collapsing center aligned" > { { $L ( 'operation' ) } } < / th >
< th class = "collapsing center aligned" > { { $L ( 'status' ) } } < / th >
2018-10-11 06:29:31 +00:00
< th class = "center aligned" > { { $L ( 'group' ) } } < / th >
2017-05-26 09:27:00 +00:00
< th class = "center aligned" > { { $L ( 'user' ) } } < / th >
< th class = "center aligned" > { { $L ( 'name' ) } } < / th >
< th class = "center aligned" > { { $L ( 'latest executed' ) } } < / th >
< th class = "center aligned" > { { $L ( 'executing result' ) } } < / th >
2017-01-22 07:18:08 +00:00
< / tr >
< / thead >
< tbody >
< tr v-for ="(job, index) in jobs" >
< td class = "center aligned" >
2017-12-14 08:38:10 +00:00
< div class = "ui icon dropdown" v-show ="!batched" >
2017-01-22 07:18:08 +00:00
< i class = "content icon" > < / i >
< div class = "menu" >
2017-05-26 09:27:00 +00:00
< div class = "item" v -on :click ="$router.push('/job/edit/'+job.group+'/'+job.id)" > { { $L ( 'edit' ) } } < / div >
< div class = "item" v-if ="job.pause" v-on:click="changeStatus(job.group, job.id, index, !job.pause)" > {{ $ L ( ' open ' ) }} < / div >
< div class = "item" v-if ="!job.pause" v-on:click="changeStatus(job.group, job.id, index, !job.pause)" > {{ $ L ( ' pause ' ) }} < / div >
2017-03-20 03:15:31 +00:00
< div class = "divider" > < / div >
2017-05-26 09:27:00 +00:00
< div class = "item" style = "color:red;" v -on : click = "removeJob(job.group, job.id, index)" > { { $L ( 'delete' ) } } < / div >
2017-01-22 07:18:08 +00:00
< / div >
< / div >
2017-12-14 08:38:10 +00:00
< div class = "ui fitted checkbox" v-show ="batched" >
< input type = "checkbox" :value ="job.group+'/'+job.id" v-model ="batchIds" > < label > < / label >
< / div >
2017-01-22 07:18:08 +00:00
< / 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 >
2018-03-06 06:11:14 +00:00
< td > { { job . user && job . user . length > 0 ? job . user : '-' } } < / td >
2017-02-17 06:20:58 +00:00
< td > < router -link :to ="'/job/edit/'+job.group+'/'+job.id" > { { job . name } } < / r o u t e r - l i n k > < / t d >
2017-02-14 10:42:41 +00:00
< td >
< span v-if ="!job.latestStatus" > - < / span >
2017-02-21 02:18:39 +00:00
< span v-else > {{ formatLatest ( job.latestStatus ) }} < / span >
2018-10-09 11:22:31 +00:00
< br / >
< span > { { formatNextRunTime ( job . nextRunTime ) } } < / span >
2017-02-14 10:42:41 +00:00
< / td >
2017-02-16 03:57:58 +00:00
< td : class = "{error: job.latestStatus && !job.latestStatus.success}" >
2017-02-14 10:42:41 +00:00
< span v-if ="!job.latestStatus" > - < / span >
2017-05-26 09:27:00 +00:00
< router -link v -else :to ="'/log/'+job.latestStatus.refLogId" > { { $L ( job . latestStatus . success ? 'successed' : 'failed' ) } } < / r o u t e r - l i n k > |
2017-03-10 08:36:44 +00:00
< router -link : to = "{path: 'log', query: {latest:true, ids: job.id}}" > latest < / r o u t e r - l i n k > |
2017-05-26 09:27:00 +00:00
< a href = "#" : title = "$L('click to select a node and re-execute job')" v -on : click.prevent = " showExecuteJobModal ( job.name , job.group , job.id ) " > < i class = "icon repeat" > < / i > < / a >
2017-02-14 10:42:41 +00:00
< / td >
2017-01-22 07:18:08 +00:00
< / tr >
< / tbody >
< / table >
2017-05-26 09:27:00 +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' ;
2017-02-21 02:18:39 +00:00
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 {
2017-12-14 08:38:10 +00:00
batched : false ,
batchIds : [ ] ,
2017-01-22 07:18:08 +00:00
groups : [ ] ,
group : '' ,
2017-03-16 10:27:26 +00:00
nodes : [ ] ,
node : '' ,
2017-01-22 07:18:08 +00:00
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-02-16 03:57:58 +00:00
2017-01-21 10:16:45 +00:00
this . $rest . GET ( 'job/groups' ) . onsucceed ( 200 , ( resp ) => {
! resp . includes ( 'default' ) && resp . unshift ( 'default' ) ;
2017-05-26 09:27:00 +00:00
resp . unshift ( { value : '' , name : vm . $L ( 'all groups' ) } ) ;
2017-01-21 10:16:45 +00:00
vm . groups = resp ;
2017-02-16 03:57:58 +00:00
this . fetchList ( this . buildQuery ( ) ) ;
2017-01-21 10:16:45 +00:00
} ) . do ( ) ;
2017-03-16 10:27:26 +00:00
2018-03-06 06:11:14 +00:00
var nodes = Array . from ( this . $store . getters . dropdownNodes ) ;
nodes . unshift ( { value : '' , name : this . $L ( 'all nodes' ) } ) ;
vm . nodes = nodes ;
2017-12-14 08:38:10 +00:00
$ ( '.ui.checkbox' ) . checkbox ( ) ;
2017-01-21 10:16:45 +00:00
} ,
2017-02-16 03:57:58 +00:00
watch : {
'$route' : function ( ) {
2017-04-24 06:40:48 +00:00
this . fillParams ( ) ;
2017-02-16 03:57:58 +00:00
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 || '' ;
} ,
2017-01-22 07:18:08 +00:00
changeGroup : function ( val , text ) {
var vm = this ;
this . group = val ;
2017-02-16 03:57:58 +00:00
this . $router . push ( 'job?' + this . buildQuery ( ) ) ;
2017-01-22 07:18:08 +00:00
} ,
2017-03-16 10:27:26 +00:00
changeNode : function ( val , text ) {
var vm = this ;
this . node = val ;
this . $router . push ( 'job?' + this . buildQuery ( ) ) ;
} ,
2017-02-16 03:57:58 +00:00
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 ) ;
2017-02-16 03:57:58 +00:00
return params . join ( '&' ) ;
} ,
fetchList : function ( query ) {
2017-01-22 07:18:08 +00:00
var vm = this ;
2017-02-16 03:57:58 +00:00
this . $rest . GET ( 'jobs?' + query ) . onsucceed ( 200 , ( resp ) => {
2017-01-22 07:18:08 +00:00
vm . jobs = resp ;
vm . $nextTick ( ( ) => {
$ ( vm . $el ) . find ( 'table .ui.dropdown' ) . dropdown ( ) ;
} ) ;
} ) . do ( ) ;
} ,
2017-02-16 03:57:58 +00:00
refresh : function ( ) {
this . fetchList ( this . buildQuery ( ) ) ;
} ,
2017-01-22 07:18:08 +00:00
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 ( ) ;
2017-01-22 07:18:08 +00:00
} ) . do ( ) ;
2017-02-14 10:42:41 +00:00
} ,
formatExecResult : function ( st ) {
if ( ! st ) return '-' ;
return
} ,
2017-02-21 02:18:39 +00:00
formatLatest : function ( latest ) {
2018-03-19 07:36:10 +00:00
return this . $L ( 'on {node} took {times}, {begin ~ end}' , this . $store . getters . hostshowsWithoutTip ( latest . node ) , formatDuration ( latest . beginTime , latest . endTime ) , formatTime ( latest . beginTime , latest . endTime ) ) ;
2017-03-10 08:36:44 +00:00
} ,
2018-10-09 11:22:31 +00:00
formatNextRunTime : function ( nextRunTime ) {
return this . $L ( 'next will run on {nextTime}' , nextRunTime ) ;
} ,
2017-03-10 08:36:44 +00:00
showExecuteJobModal : function ( jobName , jobGroup , jobId ) {
this . $refs . executeJobModal . show ( jobName , jobGroup , jobId ) ;
2017-12-14 08:38:10 +00:00
} ,
batch : function ( op ) {
switch ( op ) {
case 'start' : break ;
case 'pause' : break ;
default : return ;
}
var vm = this ;
this . $rest . POST ( 'jobs/' + op , this . batchIds ) . onsucceed ( 200 , ( resp ) => {
vm . refresh ( ) ;
vm . $bus . $emit ( 'warning' , resp ) ;
} ) . do ( ) ;
2017-01-22 07:18:08 +00:00
}
2017-01-21 10:16:45 +00:00
} ,
2017-01-18 09:08:07 +00:00
components : {
2017-02-14 10:42:41 +00:00
Dropdown ,
2017-03-10 08:36:44 +00:00
ExecuteJob
2017-01-18 09:08:07 +00:00
}
}
2017-10-24 02:35:22 +00:00
< / script >