showjobs.html
10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<div id="jobInfoDiv">
<div id="jobInfoListTable"></div>
<div id="jobCreateJobBtm">
<button id="crtbtn" onclick="showCreatePage()">创建任务</button>
</div>
<div id="jobCreateJobDiv"></div>
</div>
<meta charset="utf-8">
<link href="../css/bootstrap.css" rel="stylesheet">
<script src="../js/jquery-1.12.0.min.js" charset="UTF-8"
type="text/javascript"></script>
<script src="../js/bootstrap.table.js" charset="UTF-8"
type="text/javascript"></script>
<script src="../js/bootstrap.dialog.js" charset="UTF-8"
type="text/javascript"></script>
<script src="../js/bootstrap.pagination.js" charset="UTF-8"
type="text/javascript"></script>
<script src="../js/bootstrap.js" charset="UTF-8" type="text/javascript"></script>
<script src="../js/bootstrap.panel.js" charset="UTF-8"
type="text/javascript"></script>
<script>
$(function() {
//设置路径导航
//全局用来html传递参数使用
//var paramObj = {};
$("#jobCreateJobDiv").hide();
var currentPage = 1;
//全局的panel的样式
var panelStyle = "panel-primary";
$("#jobInfoDiv #jobInfoListTable").table(
{
url : "/jobs/jobmanager/showalljob.do",
queryParams : {
},
currentPage : currentPage,
title : "任务列表",
panelClass : panelStyle,
striped : true,
pagination : true,
pageSize : 10,
loadFilter : function(data) {
return data.data;
},
columns : [
{
title : "任务名称",
field : "jobName"
},
{
title : "任务所属组",
field : "jobGroup"
},
{
title : "任务所属模块",
field : "module"
},
{
title : "任务执行表达式",
field : "cronExpression"
},
{
title : "任务执行器",
field : "processor"
},
{
title : "任务执行入参",
field : "context"
},
{
title : "方式",
field : "activeMode",
formatter : function(value, rowData, rowIndex) {
if (value == 0)
return "单次";
else if (value == 1)
return "循环";
else
return "";
}
},
{
title : "执行IP",
field : "processIp"
},
{
title : "执行状态",
field : "status",
formatter : function(value, rowData, RowIndex) {
if (value == 1)
return "执行中";
else if (value == 0)
return "停止";
else
return "";
}
},
{
title : "操作",
formatter : function(value, rowData, rowIndex) {
var div = $("<div>");
if (rowData.status == 0) {//已暂停,可以开启
var openBtn = $("<button>").addClass(
"btn btn-xs btn-success").html(
"开启").appendTo(div);
div.append(" ");
openBtn.click(function() {//开启变为待执行状态
changeState(rowData, 1, this,
"确定开启吗", "确定开启改任务么");
});
var editBtn = $("<button>").addClass(
"btn btn-xs btn-success").html(
"编辑").appendTo(div);
editBtn.click(function() {
editJob(rowData);
});
div.append(" ");
div.append(" ");
}
if (rowData.status == 1) {//执行状态,可以停止
var stopBtn = $("<button>").addClass(
"btn btn-xs btn-success").html(
"停止").appendTo(div);
stopBtn.click(function() {
changeState(rowData, 0, this,
"确定停止吗", "确认停止该任务么");
});
div.append(" ");
}
var editBtn = $("<button>").addClass(
"btn btn-xs btn-success")
.html("查看").appendTo(div);
editBtn.click(function() {
showDetailJob(rowData);
});
return div;
}
} ]
});
//加载创建
$("#jobInfoDiv #jobCreateJobDiv").panel({
className : panelStyle,
title : "创建任务",
url : "/jobs/html/createjob.html",
showFooter : false
});
});
function changeState(job, newstate, obj, title, meg) {
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title : title,
backdrop : "static",
content : meg,
buttons : [ {
text : "否",
className : "btn-danger",
onclick : function() {
$(dialog).dialog("hide");
}
}, {
text : "是",
className : "btn-success",
onclick : function() {
$(dialog).dialog("hide");
$.ajax({
url : geturl(),
type : 'post',
contentType : "application/json; charset=utf-8",
data : JSON.stringify(job),
dataType : "json",
success : function(data) {
if (!data || data.code != 200) {
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title : "开启失败",
backdrop : "static",
content : "该活动已过期",
buttons : [ {
text : "确定",
className : "btn-danger",
onclick : function() {
$(dialog).dialog("hide");
}
} ]
});
}
$("#jobInfoDiv #jobInfoListTable").table("load");
}
});
}
} ]
});
function geturl() {
if (newstate == 0) {
return "/jobs/jobmanager/stopjob.do";
} else if (newstate == 1) {
return "/jobs/jobmanager/startjob.do";
}
}
}
function showCreatePage() {
$("#jobCreateJobDiv").show();
}
function editJob(job) {
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title : "创建任务",
backdrop : "static",
content : buildCnt(job)
});
function buildCnt(job) {
var cnt = "<form class=\"form col-md-12 center-block\" name=\"form\" id=\"editjobinfo\">";
cnt += "<div class=\"form-group\">";
cnt = cnt
+ "任务名称:<input type=\"text\" class=\"form-control input-lg\" id=\"editjobName\" name=\"editjobName\" placeholder=\"任务名称\" value=";
cnt =cnt+job.jobName;
cnt += " disabled=\"true\">";
cnt += "</div>";
cnt += "<div class=\"form-group\">";
cnt = cnt
+ "任务分组:<input type=\"text\" class=\"form-control input-lg\" id=\"editjobGroup\" name=\"editjobGroup\" placeholder=\"分组名称\" value=";
cnt =cnt+job.jobGroup;
cnt += " disabled=\"true\">";
cnt += "</div>";
cnt += "<div class=\"form-group\">";
cnt = cnt
+ "所属模块:<input type=\"text\" class=\"form-control input-lg\" id=\"editmodule\" name=\"editmodule\" placeholder=\"所属模块\" value=";
cnt =cnt+job.module;
cnt += " disabled=\"true\">";
cnt += "</div>";
cnt += "<div class=\"form-group\">";
cnt = cnt
+ "任务执行器:<input type=\"text\" class=\"form-control input-lg\" id=\"editprocessor\" name=\"editprocessor\" placeholder=\"任务执行器\" value=";
cnt =cnt+job.processor;
cnt += ">";
cnt += "</div>";
cnt += "<div class=\"form-group\">";
cnt = cnt
+ "任务执行IP:<input type=\"text\" class=\"form-control input-lg\" id=\"editprocessip\" name=\"editprocessip\" placeholder=\"任务执行IP\" value=";
cnt =cnt+job.processIp;
cnt += ">";
cnt += "</div>";
cnt += "<div class=\"form-group\">";
cnt = cnt + "任务类型:<select name=\"editjobtype\" id=\"editjobtype\">";
var tmp = "<option value=\"0\" selected = \"selected\">单节点执行</option>";
var tmpsec = "<option value=\"1\" >多节点执行</option>";
if (job.jobType == 1) {
tmp = "<option value=\"0\" >单节点执行</option>";
tmpsec = "<option value=\"1\" selected = \"selected\">多节点执行</option>";
}
cnt = cnt + tmp;
cnt = cnt + tmpsec;
cnt += "</select>";
cnt += "</div>";
cnt += "<div class=\"form-group\">";
cnt = cnt
+ "执行周期:<input type=\"text\" class=\"form-control input-lg\" id=\"editcronexception\" name=\"editcronexception\" placeholder=\"任务执行周期\" value=\"";
cnt =cnt+job.cronExpression;
cnt += "\">";
cnt += "</div>";
cnt += "<div class=\"form-group\">";
cnt = cnt
+ "任务入参:<input type=\"text\" class=\"form-control input-lg\" id=\"editcontext\" name=\"editcontext\" placeholder=\"任务入参\" value=";
if (typeof (job.context) == "undefined") {
cnt = cnt + "";
} else {
cnt = cnt + job.context;
}
cnt += ">";
cnt += "</div>";
cnt += "<div class=\"form-group\">";
cnt = cnt
+ "任务触发类型:<select name=\"editactivemode\" id=\"editactivemode\">";
var tmp = "<option value=\"0\" selected = \"selected\">单次任务</option>";
var tmpsec = "<option value=\"1\" >周期任务</option>";
if (job.activeMode == 1) {
tmp = "<option value=\"0\" >单次任务</option>";
tmpsec = "<option value=\"1\" selected = \"selected\">周期任务</option>";
}
cnt = cnt + tmp;
cnt = cnt + tmpsec;
cnt += "</select>";
cnt += "</div>";
cnt += "<div class=\"form-group\">";
cnt += "<input type=\"button\" value=\"更新\" id=\"editJobBtn\" class=\"btn btn-primary btn-lg btn-block\" name=\"editJobBtn\" onclick=\"updatejob()\" />";
cnt += "</div>";
cnt += "</form>";
return cnt;
}
}
function updatejob() {
var jobName = $("#editjobName");
var jobGroup = $("#editjobGroup");
var module = $("#editmodule");
var processor = $("#editprocessor");
var processip = $("#editprocessip");
var jobtype = $("#editjobtype");
var cronexception = $("#editcronexception");
var context = $("#editcontext");
var activemode = $("#editactivemode");
var jobinfo = {
"activeMode" : activemode.val(),
"cronExpression" : cronexception.val(),
"jobGroup" : jobGroup.val(),
"jobName" : jobName.val(),
"jobType" : jobtype.val(),
"module" : module.val(),
"processIp" : processip.val(),
"processor" : processor.val(),
"context" : context.val()
};
$.ajax({
url : "/jobs/jobmanager/updatejob.do",
contentType : "application/json; charset=utf-8",
data : JSON.stringify(jobinfo),
dataType : "json",
type : "POST",
success : function(data) {
if (!data) {
$("#messageAlert").alerts({
content : "创建任务失败",
type : "danger"
});
$("#createJobBtn").removeAttr("disabled");
return;
}
if (data.code != 200) {
$("#messageAlert").alerts({
content : data.message,
type : "danger"
});
$("#createJobBtn").removeAttr("disabled");
return;
}
location.href = "/jobs/html/showjobs.html";
}
});
}
function showDetailJob(job) {
window.open("/jobs/html/showdetailjob.html?jobname=" + job.jobName
+ "&module=" + job.module);
}
</script>