gocron/templates/task/index.html

243 lines
9.5 KiB
Go

{{{ template "common/header" . }}}
<div class="ui grid">
{{{template "task/menu" .}}}
<div class="twelve wide column">
{{{if .IsAdmin}}}
<div class="pageHeader">
<div class="segment">
<h3 class="ui dividing header">
<a href="/task/create">
<i class="large add icon"></i>
<div class="content">
</div>
</a>
</h3>
</div>
</div>
{{{end}}}
<form class="ui form">
<div class="six fields search">
<div class="one wide field">
<input type="text" placeholder="任务ID" name="id" value="{{{if gt .Params.Id 0}}}{{{.Params.Id}}}{{{end}}}">
</div>
<div class="field">
<input type="text" placeholder="任务名称" name="name" value="{{{.Params.Name}}}">
</div>
<div class="field">
<input type="text" placeholder="标签名称" name="tag" value="{{{.Params.Tag}}}">
</div>
</div>
<div class="six fields search">
<div class="field">
<select name="host_id" id="hostId">
<option value=""></option>
{{{range $i, $v := .Hosts}}}
<option value="{{{.Id}}}" {{{if eq $.Params.HostId .Id }}} selected {{{end}}} >{{{.Alias}}}-{{{.Name}}}</option>
{{{end}}}
</select>
</div>
<div class="field">
<select name="protocol" id="protocol">
<option value="0"></option>
<option value="2" {{{if eq .Params.Protocol 2}}}selected{{{end}}} data-match="host_id" data-validate-type="selectProtocol">SHELL</option>
<option value="1" {{{if eq .Params.Protocol 1}}}selected{{{end}}}>HTTP</option>
</select>
</div>
<div class="field">
<select name="status">
<option value="0"></option>
<option value="1" {{{if eq .Params.Status 0}}}selected{{{end}}} ></option>
<option value="2" {{{if eq .Params.Status 1}}}selected{{{end}}}></option>
</select>
</div>
<div class="field">
<button class="ui linkedin submit button"></button>
</div>
</div>
</form>
{{{if .IsAdmin}}}
<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>
{{{end}}}
<br>
<table class="ui celled table task-list">
<thead>
<tr>
{{{if .IsAdmin}}}
<th>
<input type="checkbox" onclick="checkAll(this)" style="width:25px;height: 25px;">
</th>
{{{end}}}
<th>ID</th>
<th></th>
<th></th>
<th></th>
<th>cron</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{{{range $i, $v := .Tasks}}}
<tr>
{{{if $.IsAdmin}}}
<td>
<input type="checkbox"
class="sub-check"
data-id="{{{.Id}}}"
style="width:25px;height: 25px;">
</td>
{{{end}}}
<td>{{{.Id}}}</td>
<td>{{{.Name}}}</td>
<td>{{{if eq .Level 1}}}{{{else}}}{{{end}}}</td>
<td>{{{.Tag}}}</td>
<td>{{{.Spec}}}</td>
<td>{{{if eq .Protocol 1}}} HTTP {{{else if eq .Protocol 2}}} SHELL {{{end}}}</td>
<td>{{{if eq .Timeout -1}}}{{{else if gt .Timeout 0}}}{{{.Timeout}}}{{{else}}}{{{end}}}</td>
<td>{{{.RetryTimes}}}</td>
<td>{{{if gt .Multi 0}}}{{{else}}}{{{end}}}</td>
<td>
{{{range $k, $h := .Hosts}}}
{{{$h.Alias}}}<br>
{{{end}}}
</td>
<td>
{{{if eq .Level 1}}}
{{{if eq .Status 1}}}<span><i class="checkmark big icon"></i></span>{{{else}}}<span><i class="minus big icon"></i><span>{{{end}}}
{{{end}}}
</td>
<td>
<div class="ui buttons operation">
{{{if $.IsAdmin}}}
<a href="/task/edit/{{{.Id}}}" ><i class="edit big icon" title="编辑"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;
{{{if eq .Level 1}}}
{{{if eq .Status 1}}}
<a href="javascript:void(0);" @click="changeStatus({{{.Id}}},{{{.Status}}})"><i class="pause circle big icon" title="停止"></i></a>&nbsp;&nbsp;
{{{else}}}
<a href="javascript:void(0);" @click="changeStatus({{{.Id}}},{{{.Status}}})"><i class="play big icon" title="激活"></i></a>&nbsp;&nbsp;
{{{end}}}
{{{end}}}
<a href="javascript:void(0);" @click="remove({{{.Id}}})"><i class="remove big icon" title="删除"></i></a>
<a href="javascript:void(0);" @click="run({{{.Id}}})"><i class="rocket big icon" title="手动执行"></i></a>&nbsp;&nbsp;
{{{end}}}
<a href="/task/log?task_id={{{.Id}}}"><i class="bar chart icon big" title="查看日志"></i></a>
</div>
</td>
</tr>
{{{end}}}
</tbody>
</table>
{{{ template "common/pagination" .}}}
</div>
</div>
<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: changeStatus,
remove: remove,
run: function(id) {
util.get("/task/run/" + id, function(code, message) {
swal('', message, 'success');
})
}
}
}
);
function checkAll(ele) {
if ($(ele).is(":checked")) {
$('.sub-check').prop("checked", true);
} else {
$('.sub-check').prop("checked", false);
}
}
function remove(id, stopReload) {
var url = '/task/remove/' + id;
if (stopReload === undefined) {
util.removeConfirm(url);
return;
}
util.post(url, {}, 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" . }}}