mirror of https://github.com/shunfei/cronsun
修复编辑定时器的bug
parent
eefba51edc
commit
c270762d95
|
@ -62,7 +62,7 @@ func (n *Node) Exist() (pid int, err error) {
|
|||
}
|
||||
|
||||
func GetActivityNodeList() (nodes []string, err error) {
|
||||
resp, err := DefalutClient.Get(conf.Config.Proc, client.WithPrefix(), client.WithKeysOnly())
|
||||
resp, err := DefalutClient.Get(conf.Config.Proc, client.WithPrefix(), client.WithKeysOnly(), client.WithSort(client.SortByKey, client.SortAscend))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -37,6 +37,11 @@ func (jl *JobLog) GetDetail(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (jl *JobLog) GetList(w http.ResponseWriter, r *http.Request) {
|
||||
// nodes := GetStringArrayFromQuery("nodes", ",", r)
|
||||
// names := GetStringArrayFromQuery("names", ",", r)
|
||||
// begin := r.FormValue("begin")
|
||||
// end := r.FormValue("end")
|
||||
|
||||
list := []*models.JobLog{
|
||||
&models.JobLog{
|
||||
Id: bson.NewObjectId(),
|
||||
|
@ -68,3 +73,12 @@ func (jl *JobLog) GetList(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
outJSON(w, list)
|
||||
}
|
||||
|
||||
func GetStringArrayFromQuery(name, sep string, r *http.Request) (arr []string) {
|
||||
val := strings.TrimSpace(r.FormValue(name))
|
||||
if len(val) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
return strings.Split(val, sep)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<div v-if="error != ''" class="ui negative message">
|
||||
<div class="header"><i class="attention icon"></i> {{error}}</div>
|
||||
</div>
|
||||
<form v-else class="ui form segment" v-bind:class="{loading:loading}" v-on:submit.prevent>
|
||||
<form v-else class="ui form" v-bind:class="{loading:loading}" v-on:submit.prevent>
|
||||
<h3 class="ui header">{{action == 'CREATE' ? '添加' : '更新'}}任务
|
||||
<div class="ui toggle checkbox">
|
||||
<input type="checkbox" class="hidden" v-bind:checked="!job.pause">
|
||||
|
@ -26,7 +26,7 @@
|
|||
<div class="field">
|
||||
<span v-if="!job.rules || job.rules.length == 0"><i class="warning circle icon"></i>当前任务没有定时器,点击下面按钮来添加定时器</span>
|
||||
</div>
|
||||
<JobEditRule v-for="(rule, index) in job.rules" :rule="rule" :index="index" v-on:remove="removeRule" v-on:change="changeRule"/>
|
||||
<JobEditRule v-for="(rule, index) in job.rules" :key="rule.id" v-bind:rule="rule" :index="index" v-on:remove="removeRule" v-on:change="changeRule"/>
|
||||
<div class="two fields">
|
||||
<div class="field">
|
||||
<button class="fluid ui button" v-on:click="addNewTimer" type="button"><i class="history icon"></i> 添加定时器</button>
|
||||
|
@ -72,7 +72,7 @@ export default {
|
|||
|
||||
addNewTimer: function(){
|
||||
if (!this.job.rules) this.job.rules = [];
|
||||
this.job.rules.push({});
|
||||
this.job.rules.push({id: this.randomRuleId()});
|
||||
},
|
||||
|
||||
changeGroup: function(val, text){
|
||||
|
@ -94,6 +94,10 @@ export default {
|
|||
.onfailed((resp)=>{console.log(resp)})
|
||||
.onend(()=>{vm.loading=false})
|
||||
.do();
|
||||
},
|
||||
|
||||
randomRuleId: function(){
|
||||
return Math.random().toString();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -105,15 +109,22 @@ export default {
|
|||
} else {
|
||||
this.action = 'UPDATE';
|
||||
this.$rest.GET('job/'+this.$route.params.group+'-'+this.$route.params.id).
|
||||
onsucceed(200, (resp)=>{vm.job = resp}).
|
||||
onsucceed(200, (resp)=>{
|
||||
vm.job = resp;
|
||||
if (vm.job.rules) {
|
||||
for (var i in vm.job.rules) {
|
||||
vm.job.rules[i].id = vm.randomRuleId();
|
||||
}
|
||||
}
|
||||
}).
|
||||
onfailed((data)=>{vm.error = data.error}).
|
||||
do();
|
||||
}
|
||||
|
||||
this.$rest.GET('job/groups').onsucceed(200, (resp)=>{
|
||||
!resp.includes('default') && resp.unshift('default');
|
||||
vm.groups = resp;
|
||||
}).do();
|
||||
!resp.includes('default') && resp.unshift('default');
|
||||
vm.groups = resp;
|
||||
}).do();
|
||||
|
||||
$(this.$el).find('.checkbox').checkbox({
|
||||
onChange: function(){
|
||||
|
@ -126,7 +137,7 @@ export default {
|
|||
onChange: function(value, text, $choice){
|
||||
vm.job.group = value;
|
||||
}
|
||||
}).dropdown('set selected', this.job.group);
|
||||
}).dropdown('set exactly', this.job.group);
|
||||
},
|
||||
|
||||
components: {
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
</div>
|
||||
<div class="field">
|
||||
<label>同时在这些节点上面运行任务</label>
|
||||
<Dropdown title="选择节点" v-bind:items="activityNodes" multiple="true"></Dropdown>
|
||||
<Dropdown title="选择节点" v-bind:items="activityNodes" v-bind:selected="rule.nids" v-on:change="changeIncludeNodes($event)" multiple="true"></Dropdown>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>不在这些节点上面运行任务</label>
|
||||
<Dropdown title="选择节点" v-bind:items="activityNodes" multiple="true"></Dropdown>
|
||||
<Dropdown title="选择节点" v-bind:items="activityNodes" v-on:change="changeExcludeNodes($event)" multiple="true"></Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -25,7 +25,7 @@ import Dropdown from './basic/Dropdown.vue';
|
|||
|
||||
export default {
|
||||
name: 'job-edit-rule',
|
||||
props: ['rule', 'index'],
|
||||
props: ['index', 'rule'],
|
||||
data: function(){
|
||||
return {
|
||||
nodeGroups: [],
|
||||
|
@ -51,6 +51,14 @@ export default {
|
|||
},
|
||||
change: function(key, val){
|
||||
this.$emit('change', this.index, key, val);
|
||||
},
|
||||
changeIncludeNodes: function(val){
|
||||
var nids = val.trim().length === 0 ? [] : val.split(',');
|
||||
this.change('nids', nids);
|
||||
},
|
||||
changeExcludeNodes: function(val){
|
||||
var exclude_nids = val.trim().length === 0 ? [] : val.split(',');
|
||||
this.change('exclude_nids', exclude_nids);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div>
|
||||
<form class="ui form segment fixed" v-bind:class="{loading:loading}" v-on:submit.prevent>
|
||||
<form class="ui form" v-bind:class="{loading:loading}" v-on:submit.prevent>
|
||||
<div class="field">
|
||||
<label>任务名称</label>
|
||||
<input type="text" ref="name" v-model="names" placeholder="多个名称用英文逗号分隔">
|
||||
|
@ -23,7 +23,7 @@
|
|||
<button class="fluid ui button" type="button" v-on:click="submit">查询</button>
|
||||
</div>
|
||||
</form>
|
||||
<table class="ui selectable green table">
|
||||
<table class="ui selectable green table" v-if="list && list.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="center aligned">任务名称</th>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<div v-else>
|
||||
<div class="ui segments">
|
||||
<div class="ui segment">
|
||||
<p>任务:<router-link class="item" :to="'/job/'+log.jobGroup+'/'+log.jobId">{{log.name}}</router-link></p>
|
||||
<p>任务:<router-link class="item" :to="'/job/edit/'+log.jobGroup+'/'+log.jobId">{{log.name}}</router-link></p>
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<p>节点:{{log.node}}</p>
|
||||
|
|
|
@ -12,7 +12,11 @@
|
|||
<script>
|
||||
export default {
|
||||
name: 'dropdown',
|
||||
props: ['title', 'items', 'selected', 'allowAdditions', 'multiple'],
|
||||
props: ['title', 'items', 'allowAdditions', 'multiple', 'selected'],
|
||||
|
||||
data: function(){
|
||||
return {}
|
||||
},
|
||||
|
||||
mounted: function() {
|
||||
if (this.title.length === 0) this.title = '选择分组';
|
||||
|
@ -26,10 +30,13 @@ export default {
|
|||
vm.$emit('change', value, text);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.selected !== null) {
|
||||
$(this.$el).dropdown('set selected', this.selected);
|
||||
}
|
||||
setTimeout(()=>{
|
||||
$(vm.$el).dropdown('set exactly', vm.selected).dropdown('refresh');
|
||||
}, 200);
|
||||
},
|
||||
|
||||
updated: function(){
|
||||
$(this.$el).dropdown('set exactly', this.selected);
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue