feat($task): 任务批量开启、关闭、删除

pull/21/merge
ouqiang 2017-09-05 22:31:16 +08:00
parent 2ba8cb67c8
commit d642c9641d
5 changed files with 90 additions and 23 deletions

View File

@ -71,10 +71,10 @@
## To Do List
- [x] 版本升级
- [x] 批量开启、关闭、删除任务
- [ ] 任务分组
- [ ] 多用户
- [ ] 权限控制
- [ ] 批量开启、关闭、删除任务
- [ ] 调度器与任务节点通信支持https
- [ ] 新增任务API接口

View File

@ -60,7 +60,7 @@ function Util() {
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: '',
confirmButtonText: '',
cancelButtonColor: '#d33',
cancelButtonText: "取消",
closeOnConfirm: false,

View File

@ -66,7 +66,7 @@
<script type="text/javascript">
var Vue = new Vue({
el: '.ui.striped.table',
el: '.ui.celled.table',
methods: {
ping: function(id) {
util.get("/host/ping/" + id, function(code, message) {

View File

@ -49,9 +49,21 @@
</div>
</div>
</form>
<div class="field">
<select id="batch-operation">
<option value="0"></option>
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
</select>
</div>
<br>
<table class="ui celled table task-list">
<thead>
<tr>
<th>
<input type="checkbox" onclick="checkAll(this)" style="width:25px;height: 25px;">
</th>
<th>ID</th>
<th></th>
<th></th>
@ -68,6 +80,12 @@
<tbody>
{{{range $i, $v := .Tasks}}}
<tr>
<td>
<input type="checkbox"
class="sub-check"
data-id="{{{.Id}}}"
style="width:25px;height: 25px;">
</td>
<td>{{{.Id}}}</td>
<td>{{{.Name}}}</td>
<td>{{{if eq .Level 1}}}{{{else}}}{{{end}}}</td>
@ -112,25 +130,51 @@
<script type="text/javascript">
$('.ui.checkbox').checkbox();
$('#batch-operation').change(function() {
var type = $(this).val();
if (type == 0) {
return;
}
var ids = [];
$('.sub-check:checked').each(function() {
ids.push($(this).data('id'));
});
if (ids.length == 0) {
swal('', '', 'warning');
return;
}
util.confirm("确定要执行此操作吗", function () {
$.ajaxSetup({
async: false
});
switch (type) {
case "1":
for (i in ids) {
changeStatus(ids[i], false, true);
}
break;
case "2":
for (i in ids) {
changeStatus(ids[i], true, true);
}
break;
case "3":
for (i in ids) {
remove(ids[i], true);
}
break;
}
location.reload();
});
});
var vue = new Vue(
{
el: '.task-list',
methods: {
changeStatus: function (id ,status) {
var url = '';
if (status) {
url = '/task/disable';
} else {
url = '/task/enable';
}
url += '/' + id;
util.post(url,{}, function() {
location.reload();
});
},
remove: function(id) {
util.removeConfirm('/task/remove/' + id);
},
changeStatus: changeStatus,
remove: remove,
run: function(id) {
util.get("/task/run/" + id, function(code, message) {
swal('', message, 'success');
@ -140,9 +184,36 @@
}
);
function checkAll(ele) {
if ($(ele).is(":checked")) {
$('.sub-check').prop("checked", true);
} else {
$('.sub-check').prop("checked", false);
}
}
function remove(id, stopReload) {
util.post('/task/remove/' + id, {}, function () {
if (stopReload === undefined) {
location.reload();
}
});
}
function changeStatus(id ,status, stopReload) {
var url = '';
if (status) {
url = '/task/disable';
} else {
url = '/task/enable';
}
url += '/' + id;
util.post(url,{}, function() {
if (stopReload === undefined) {
location.reload();
}
});
}
</script>
{{{ template "common/footer" . }}}

View File

@ -127,10 +127,6 @@
</script>
<script type="text/javascript">
function showTime(startTime, endTime, status) {
}
function showResult(name, command,result) {
$('.message').html($('#task-result').html());
new Vue(