修复编辑定时器的bug

pull/1/head
Doflatango 2017-02-13 15:15:16 +08:00 committed by miraclesu
parent eefba51edc
commit c270762d95
7 changed files with 60 additions and 20 deletions

View File

@ -62,7 +62,7 @@ func (n *Node) Exist() (pid int, err error) {
} }
func GetActivityNodeList() (nodes []string, 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 { if err != nil {
return return
} }

View File

@ -37,6 +37,11 @@ func (jl *JobLog) GetDetail(w http.ResponseWriter, r *http.Request) {
} }
func (jl *JobLog) GetList(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{ list := []*models.JobLog{
&models.JobLog{ &models.JobLog{
Id: bson.NewObjectId(), Id: bson.NewObjectId(),
@ -68,3 +73,12 @@ func (jl *JobLog) GetList(w http.ResponseWriter, r *http.Request) {
} }
outJSON(w, list) 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)
}

View File

@ -2,7 +2,7 @@
<div v-if="error != ''" class="ui negative message"> <div v-if="error != ''" class="ui negative message">
<div class="header"><i class="attention icon"></i> {{error}}</div> <div class="header"><i class="attention icon"></i> {{error}}</div>
</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' ? '添加' : '更新'}}任务&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <h3 class="ui header">{{action == 'CREATE' ? '添加' : '更新'}}任务&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div class="ui toggle checkbox"> <div class="ui toggle checkbox">
<input type="checkbox" class="hidden" v-bind:checked="!job.pause"> <input type="checkbox" class="hidden" v-bind:checked="!job.pause">
@ -26,7 +26,7 @@
<div class="field"> <div class="field">
<span v-if="!job.rules || job.rules.length == 0"><i class="warning circle icon"></i></span> <span v-if="!job.rules || job.rules.length == 0"><i class="warning circle icon"></i></span>
</div> </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="two fields">
<div class="field"> <div class="field">
<button class="fluid ui button" v-on:click="addNewTimer" type="button"><i class="history icon"></i> 添加定时器</button> <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(){ addNewTimer: function(){
if (!this.job.rules) this.job.rules = []; if (!this.job.rules) this.job.rules = [];
this.job.rules.push({}); this.job.rules.push({id: this.randomRuleId()});
}, },
changeGroup: function(val, text){ changeGroup: function(val, text){
@ -94,6 +94,10 @@ export default {
.onfailed((resp)=>{console.log(resp)}) .onfailed((resp)=>{console.log(resp)})
.onend(()=>{vm.loading=false}) .onend(()=>{vm.loading=false})
.do(); .do();
},
randomRuleId: function(){
return Math.random().toString();
} }
}, },
@ -105,15 +109,22 @@ export default {
} else { } else {
this.action = 'UPDATE'; this.action = 'UPDATE';
this.$rest.GET('job/'+this.$route.params.group+'-'+this.$route.params.id). 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}). onfailed((data)=>{vm.error = data.error}).
do(); do();
} }
this.$rest.GET('job/groups').onsucceed(200, (resp)=>{ this.$rest.GET('job/groups').onsucceed(200, (resp)=>{
!resp.includes('default') && resp.unshift('default'); !resp.includes('default') && resp.unshift('default');
vm.groups = resp; vm.groups = resp;
}).do(); }).do();
$(this.$el).find('.checkbox').checkbox({ $(this.$el).find('.checkbox').checkbox({
onChange: function(){ onChange: function(){
@ -126,7 +137,7 @@ export default {
onChange: function(value, text, $choice){ onChange: function(value, text, $choice){
vm.job.group = value; vm.job.group = value;
} }
}).dropdown('set selected', this.job.group); }).dropdown('set exactly', this.job.group);
}, },
components: { components: {

View File

@ -11,11 +11,11 @@
</div> </div>
<div class="field"> <div class="field">
<label>同时在这些节点上面运行任务</label> <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>
<div class="field"> <div class="field">
<label>不在这些节点上面运行任务</label> <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>
</div> </div>
</template> </template>
@ -25,7 +25,7 @@ import Dropdown from './basic/Dropdown.vue';
export default { export default {
name: 'job-edit-rule', name: 'job-edit-rule',
props: ['rule', 'index'], props: ['index', 'rule'],
data: function(){ data: function(){
return { return {
nodeGroups: [], nodeGroups: [],
@ -51,6 +51,14 @@ export default {
}, },
change: function(key, val){ change: function(key, val){
this.$emit('change', this.index, 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);
} }
}, },

View File

@ -1,6 +1,6 @@
<template> <template>
<div> <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"> <div class="field">
<label>任务名称</label> <label>任务名称</label>
<input type="text" ref="name" v-model="names" placeholder="多个名称用英文逗号分隔"> <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> <button class="fluid ui button" type="button" v-on:click="submit">查询</button>
</div> </div>
</form> </form>
<table class="ui selectable green table"> <table class="ui selectable green table" v-if="list && list.length > 0">
<thead> <thead>
<tr> <tr>
<th class="center aligned">任务名称</th> <th class="center aligned">任务名称</th>

View File

@ -5,7 +5,7 @@
<div v-else> <div v-else>
<div class="ui segments"> <div class="ui segments">
<div class="ui segment"> <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>
<div class="ui segment"> <div class="ui segment">
<p>节点{{log.node}}</p> <p>节点{{log.node}}</p>

View File

@ -12,7 +12,11 @@
<script> <script>
export default { export default {
name: 'dropdown', name: 'dropdown',
props: ['title', 'items', 'selected', 'allowAdditions', 'multiple'], props: ['title', 'items', 'allowAdditions', 'multiple', 'selected'],
data: function(){
return {}
},
mounted: function() { mounted: function() {
if (this.title.length === 0) this.title = '选择分组'; if (this.title.length === 0) this.title = '选择分组';
@ -26,10 +30,13 @@ export default {
vm.$emit('change', value, text); vm.$emit('change', value, text);
} }
}); });
setTimeout(()=>{
if (this.selected !== null) { $(vm.$el).dropdown('set exactly', vm.selected).dropdown('refresh');
$(this.$el).dropdown('set selected', this.selected); }, 200);
} },
updated: function(){
$(this.$el).dropdown('set exactly', this.selected);
} }
} }
</script> </script>