jobinfo.index.1.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. $(function () {
  2. // init date tables
  3. var jobTable = $("#job_list").dataTable({
  4. "deferRender": true,
  5. "processing": true,
  6. "serverSide": true,
  7. "ajax": {
  8. url: base_url + "/jobinfo/pageList",
  9. type: "post",
  10. data: function (d) {
  11. var obj = {};
  12. obj.jobGroup = $('#jobGroup').val();
  13. obj.jobDesc = $('#jobDesc').val();
  14. obj.executorHandler = $('#executorHandler').val();
  15. obj.start = d.start;
  16. obj.length = d.length;
  17. obj.type = 1;//corn
  18. return obj;
  19. }
  20. },
  21. "searching": false,
  22. "ordering": false,
  23. //"scrollX": true, // scroll x,close self-adaption
  24. "columns": [
  25. {
  26. "data": 'id',
  27. "bSortable": false,
  28. "visible": true,
  29. "width": '10%'
  30. },
  31. {
  32. "data": 'jobGroup',
  33. "visible": false,
  34. "width": '20%',
  35. "render": function (data, type, row) {
  36. var groupMenu = $("#jobGroup").find("option");
  37. for (var index in $("#jobGroup").find("option")) {
  38. if ($(groupMenu[index]).attr('value') == data) {
  39. return $(groupMenu[index]).html();
  40. }
  41. }
  42. return data;
  43. }
  44. },
  45. {
  46. "data": 'jobDesc',
  47. "visible": true,
  48. "width": '20%'
  49. },
  50. {
  51. "data": 'glueType',
  52. "width": '20%',
  53. "visible": true,
  54. "render": function (data, type, row) {
  55. var glueTypeTitle = findGlueTypeTitle(row.glueType);
  56. if (row.executorHandler) {
  57. return glueTypeTitle + ":" + row.executorHandler;
  58. } else {
  59. return glueTypeTitle;
  60. }
  61. }
  62. },
  63. {"data": 'executorParam', "visible": false},
  64. {
  65. "data": 'jobCron',
  66. "visible": true,
  67. "width": '10%'
  68. },
  69. {
  70. "data": 'addTime',
  71. "visible": false,
  72. "render": function (data, type, row) {
  73. return data ? moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss") : "";
  74. }
  75. },
  76. {
  77. "data": 'updateTime',
  78. "visible": false,
  79. "render": function (data, type, row) {
  80. return data ? moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss") : "";
  81. }
  82. },
  83. {"data": 'author', "visible": true, "width": '10%'},
  84. {"data": 'alarmEmail', "visible": false},
  85. {
  86. "data": 'jobStatus',
  87. "width": '10%',
  88. "visible": true,
  89. "render": function (data, type, row) {
  90. // status
  91. if (data && data != 'NONE') {
  92. if ('NORMAL' == data) {
  93. return '<small class="label label-success" ><i class="fa fa-clock-o"></i>RUNNING</small>';
  94. } else {
  95. return '<small class="label label-warning" >ERROR(' + data + ')</small>';
  96. }
  97. } else {
  98. return '<small class="label label-default" ><i class="fa fa-clock-o"></i>STOP</small>';
  99. }
  100. }
  101. },
  102. {
  103. "data": I18n.system_opt,
  104. "width": '15%',
  105. "render": function (data, type, row) {
  106. return function () {
  107. // status
  108. var start_stop = "";
  109. if (row.jobStatus && row.jobStatus != 'NONE') {
  110. if ('NORMAL' == row.jobStatus) {
  111. start_stop = '<button class="btn btn-primary btn-xs job_operate" _type="job_pause" type="button">' + I18n.jobinfo_opt_stop + '</button> ';
  112. } else {
  113. start_stop = '<button class="btn btn-primary btn-xs job_operate" _type="job_pause" type="button">' + I18n.jobinfo_opt_stop + '</button> ';
  114. }
  115. } else {
  116. start_stop = '<button class="btn btn-primary btn-xs job_operate" _type="job_resume" type="button">' + I18n.jobinfo_opt_start + '</button> ';
  117. }
  118. // log url
  119. var logUrl = base_url + '/joblog?jobId=' + row.id;
  120. // log url
  121. var codeBtn = "";
  122. if ('BEAN' != row.glueType) {
  123. var codeUrl = base_url + '/jobcode?jobId=' + row.id;
  124. codeBtn = '<button class="btn btn-warning btn-xs" type="button" onclick="javascript:window.open(\'' + codeUrl + '\')" >GLUE</button> '
  125. }
  126. // html
  127. tableData['key' + row.id] = row;
  128. var html = '<p id="' + row.id + '" >' +
  129. '<button class="btn btn-primary btn-xs job_trigger" type="button">' + I18n.jobinfo_opt_run + '</button> ' +
  130. start_stop +
  131. '<button class="btn btn-primary btn-xs" type="job_del" type="button" onclick="javascript:window.open(\'' + logUrl + '\')" >' + I18n.jobinfo_opt_log + '</button><br> ' +
  132. '<button class="btn btn-warning btn-xs update" type="button">' + I18n.system_opt_edit + '</button> ' +
  133. codeBtn +
  134. '<button class="btn btn-danger btn-xs job_operate" _type="job_del" type="button">' + I18n.system_opt_del + '</button> ' +
  135. '</p>';
  136. return html;
  137. };
  138. }
  139. }
  140. ],
  141. "language": {
  142. "sProcessing": I18n.dataTable_sProcessing,
  143. "sLengthMenu": I18n.dataTable_sLengthMenu,
  144. "sZeroRecords": I18n.dataTable_sZeroRecords,
  145. "sInfo": I18n.dataTable_sInfo,
  146. "sInfoEmpty": I18n.dataTable_sInfoEmpty,
  147. "sInfoFiltered": I18n.dataTable_sInfoFiltered,
  148. "sInfoPostFix": "",
  149. "sSearch": I18n.dataTable_sSearch,
  150. "sUrl": "",
  151. "sEmptyTable": I18n.dataTable_sEmptyTable,
  152. "sLoadingRecords": I18n.dataTable_sLoadingRecords,
  153. "sInfoThousands": ",",
  154. "oPaginate": {
  155. "sFirst": I18n.dataTable_sFirst,
  156. "sPrevious": I18n.dataTable_sPrevious,
  157. "sNext": I18n.dataTable_sNext,
  158. "sLast": I18n.dataTable_sLast
  159. },
  160. "oAria": {
  161. "sSortAscending": I18n.dataTable_sSortAscending,
  162. "sSortDescending": I18n.dataTable_sSortDescending
  163. }
  164. }
  165. });
  166. // table data
  167. var tableData = {};
  168. // search btn
  169. $('#searchBtn').on('click', function () {
  170. jobTable.fnDraw();
  171. });
  172. // jobGroup change
  173. $('#jobGroup').on('change', function () {
  174. //reload
  175. var jobGroup = $('#jobGroup').val();
  176. window.location.href = base_url + "/jobinfo/index1?jobGroup=" + jobGroup;
  177. });
  178. // job operate
  179. $("#job_list").on('click', '.job_operate', function () {
  180. var typeName;
  181. var url;
  182. var needFresh = false;
  183. var type = $(this).attr("_type");
  184. if ("job_pause" == type) {
  185. typeName = I18n.jobinfo_opt_stop;
  186. url = base_url + "/jobinfo/stop";
  187. needFresh = true;
  188. } else if ("job_resume" == type) {
  189. typeName = I18n.jobinfo_opt_start;
  190. url = base_url + "/jobinfo/start";
  191. needFresh = true;
  192. } else if ("job_del" == type) {
  193. typeName = I18n.system_opt_del;
  194. url = base_url + "/jobinfo/remove";
  195. needFresh = true;
  196. } else {
  197. return;
  198. }
  199. var id = $(this).parent('p').attr("id");
  200. layer.confirm(I18n.system_ok + typeName + '?', {
  201. icon: 3,
  202. title: I18n.system_tips,
  203. btn: [I18n.system_ok, I18n.system_cancel]
  204. }, function (index) {
  205. layer.close(index);
  206. $.ajax({
  207. type: 'POST',
  208. url: url,
  209. data: {
  210. "id": id
  211. },
  212. dataType: "json",
  213. success: function (data) {
  214. if (data.code == 200) {
  215. layer.open({
  216. title: I18n.system_tips,
  217. btn: [I18n.system_ok],
  218. content: typeName + I18n.system_success,
  219. icon: '1',
  220. end: function (layero, index) {
  221. if (needFresh) {
  222. //window.location.reload();
  223. jobTable.fnDraw(false);
  224. }
  225. }
  226. });
  227. } else {
  228. layer.open({
  229. title: I18n.system_tips,
  230. btn: [I18n.system_ok],
  231. content: (data.msg || typeName + I18n.system_fail),
  232. icon: '2'
  233. });
  234. }
  235. },
  236. });
  237. });
  238. });
  239. // job trigger
  240. $("#job_list").on('click', '.job_trigger', function () {
  241. var id = $(this).parent('p').attr("id");
  242. var row = tableData['key' + id];
  243. $("#jobTriggerModal .form input[name='id']").val(row.id);
  244. $("#jobTriggerModal .form textarea[name='executorParam']").val(row.executorParam);
  245. $('#jobTriggerModal').modal({backdrop: false, keyboard: false}).modal('show');
  246. });
  247. $("#jobTriggerModal .ok").on('click', function () {
  248. $.ajax({
  249. type: 'POST',
  250. url: base_url + "/jobinfo/trigger",
  251. data: {
  252. "id": $("#jobTriggerModal .form input[name='id']").val(),
  253. "executorParam": $("#jobTriggerModal .textarea[name='executorParam']").val()
  254. },
  255. dataType: "json",
  256. success: function (data) {
  257. if (data.code == 200) {
  258. $('#jobTriggerModal').modal('hide');
  259. layer.open({
  260. title: I18n.system_tips,
  261. btn: [I18n.system_ok],
  262. content: I18n.jobinfo_opt_run + I18n.system_success,
  263. icon: '1'
  264. });
  265. } else {
  266. layer.open({
  267. title: I18n.system_tips,
  268. btn: [I18n.system_ok],
  269. content: (data.msg || I18n.jobinfo_opt_run + I18n.system_fail),
  270. icon: '2'
  271. });
  272. }
  273. }
  274. });
  275. });
  276. $("#jobTriggerModal").on('hide.bs.modal', function () {
  277. $("#jobTriggerModal .form")[0].reset();
  278. });
  279. // helpDoc
  280. $(".helpDoc").click(function () {
  281. $('#helpDocModal').modal({backdrop: false, keyboard: false}).modal('show');
  282. });
  283. // add
  284. $(".add").click(function () {
  285. $('#addModal').modal({backdrop: false, keyboard: false}).modal('show');
  286. });
  287. var addModalValidate = $("#addModal .form").validate({
  288. errorElement: 'span',
  289. errorClass: 'help-block',
  290. focusInvalid: true,
  291. rules: {
  292. jobDesc: {
  293. required: true,
  294. maxlength: 50
  295. },
  296. jobCron: {
  297. required: true
  298. },
  299. author: {
  300. required: true
  301. },
  302. executorTimeout: {
  303. digits: true
  304. },
  305. executorFailRetryCount: {
  306. digits: true
  307. }
  308. },
  309. messages: {
  310. jobDesc: {
  311. required: I18n.system_please_input + I18n.jobinfo_field_jobdesc
  312. },
  313. jobCron: {
  314. required: I18n.system_please_input + "Cron"
  315. },
  316. author: {
  317. required: I18n.system_please_input + I18n.jobinfo_field_author
  318. },
  319. executorTimeout: {
  320. digits: I18n.system_please_input + I18n.system_digits
  321. },
  322. executorFailRetryCount: {
  323. digits: I18n.system_please_input + I18n.system_digits
  324. }
  325. },
  326. highlight: function (element) {
  327. $(element).closest('.form-group').addClass('has-error');
  328. },
  329. success: function (label) {
  330. label.closest('.form-group').removeClass('has-error');
  331. label.remove();
  332. },
  333. errorPlacement: function (error, element) {
  334. element.parent('div').append(error);
  335. },
  336. submitHandler: function (form) {
  337. // process
  338. var executorTimeout = $("#addModal .form input[name='executorTimeout']").val();
  339. if (!/^\d+$/.test(executorTimeout)) {
  340. executorTimeout = 0;
  341. }
  342. $("#addModal .form input[name='executorTimeout']").val(executorTimeout);
  343. var executorFailRetryCount = $("#addModal .form input[name='executorFailRetryCount']").val();
  344. if (!/^\d+$/.test(executorFailRetryCount)) {
  345. executorFailRetryCount = 0;
  346. }
  347. $("#addModal .form input[name='executorFailRetryCount']").val(executorFailRetryCount);
  348. $.post(base_url + "/jobinfo/add", $("#addModal .form").serialize(), function (data, status) {
  349. if (data.code == "200") {
  350. $('#addModal').modal('hide');
  351. layer.open({
  352. title: I18n.system_tips,
  353. btn: [I18n.system_ok],
  354. content: I18n.system_add_suc,
  355. icon: '1',
  356. end: function (layero, index) {
  357. jobTable.fnDraw();
  358. //window.location.reload();
  359. }
  360. });
  361. } else {
  362. layer.open({
  363. title: I18n.system_tips,
  364. btn: [I18n.system_ok],
  365. content: (data.msg || I18n.system_add_fail),
  366. icon: '2'
  367. });
  368. }
  369. });
  370. }
  371. });
  372. $("#addModal").on('hide.bs.modal', function () {
  373. $("#addModal .form")[0].reset();
  374. addModalValidate.resetForm();
  375. $("#addModal .form .form-group").removeClass("has-error");
  376. $(".remote_panel").show(); // remote
  377. $("#addModal .form input[name='executorHandler']").removeAttr("readonly");
  378. });
  379. // glueType change
  380. $(".glueType").change(function () {
  381. // executorHandler
  382. var $executorHandler = $(this).parents("form").find("input[name='executorHandler']");
  383. var glueType = $(this).val();
  384. if ('BEAN' != glueType) {
  385. $executorHandler.val("");
  386. $executorHandler.attr("readonly", "readonly");
  387. } else {
  388. $executorHandler.removeAttr("readonly");
  389. }
  390. });
  391. $("#addModal .glueType").change(function () {
  392. // glueSource
  393. var glueType = $(this).val();
  394. if ('GLUE_GROOVY' == glueType) {
  395. $("#addModal .form textarea[name='glueSource']").val($("#addModal .form .glueSource_java").val());
  396. } else if ('GLUE_SHELL' == glueType) {
  397. $("#addModal .form textarea[name='glueSource']").val($("#addModal .form .glueSource_shell").val());
  398. } else if ('GLUE_PYTHON' == glueType) {
  399. $("#addModal .form textarea[name='glueSource']").val($("#addModal .form .glueSource_python").val());
  400. } else if ('GLUE_PHP' == glueType) {
  401. $("#addModal .form textarea[name='glueSource']").val($("#addModal .form .glueSource_php").val());
  402. } else if ('GLUE_NODEJS' == glueType) {
  403. $("#addModal .form textarea[name='glueSource']").val($("#addModal .form .glueSource_nodejs").val());
  404. } else if ('GLUE_POWERSHELL' == glueType) {
  405. $("#addModal .form textarea[name='glueSource']").val($("#addModal .form .glueSource_powershell").val());
  406. } else {
  407. $("#addModal .form textarea[name='glueSource']").val("");
  408. }
  409. });
  410. // update
  411. $("#job_list").on('click', '.update', function () {
  412. var id = $(this).parent('p').attr("id");
  413. var row = tableData['key' + id];
  414. // base data
  415. $("#updateModal .form input[name='id']").val(row.id);
  416. $('#updateModal .form select[name=jobGroup] option[value=' + row.jobGroup + ']').prop('selected', true);
  417. $("#updateModal .form input[name='jobDesc']").val(row.jobDesc);
  418. $("#updateModal .form input[name='jobCron']").val(row.jobCron);
  419. $("#updateModal .form input[name='author']").val(row.author);
  420. $("#updateModal .form input[name='alarmEmail']").val(row.alarmEmail);
  421. $("#updateModal .form input[name='executorTimeout']").val(row.executorTimeout);
  422. $("#updateModal .form input[name='executorFailRetryCount']").val(row.executorFailRetryCount);
  423. $('#updateModal .form select[name=executorRouteStrategy] option[value=' + row.executorRouteStrategy + ']').prop('selected', true);
  424. $("#updateModal .form input[name='executorHandler']").val(row.executorHandler);
  425. $("#updateModal .form textarea[name='executorParam']").val(row.executorParam);
  426. $("#updateModal .form input[name='childJobId']").val(row.childJobId);
  427. $('#updateModal .form select[name=executorBlockStrategy] option[value=' + row.executorBlockStrategy + ']').prop('selected', true);
  428. $('#updateModal .form select[name=glueType] option[value=' + row.glueType + ']').prop('selected', true);
  429. $("#updateModal .form select[name=glueType]").change();
  430. // show
  431. $('#updateModal').modal({backdrop: false, keyboard: false}).modal('show');
  432. });
  433. var updateModalValidate = $("#updateModal .form").validate({
  434. errorElement: 'span',
  435. errorClass: 'help-block',
  436. focusInvalid: true,
  437. rules: {
  438. jobDesc: {
  439. required: true,
  440. maxlength: 50
  441. },
  442. jobCron: {
  443. required: true
  444. },
  445. author: {
  446. required: true
  447. },
  448. executorTimeout: {
  449. digits: true
  450. },
  451. executorFailRetryCount: {
  452. digits: true
  453. }
  454. },
  455. messages: {
  456. jobDesc: {
  457. required: I18n.system_please_input + I18n.jobinfo_field_jobdesc
  458. },
  459. jobCron: {
  460. required: I18n.system_please_input + "Cron"
  461. },
  462. author: {
  463. required: I18n.system_please_input + I18n.jobinfo_field_author
  464. },
  465. executorTimeout: {
  466. digits: I18n.system_please_input + I18n.system_digits
  467. },
  468. executorFailRetryCount: {
  469. digits: I18n.system_please_input + I18n.system_digits
  470. }
  471. },
  472. highlight: function (element) {
  473. $(element).closest('.form-group').addClass('has-error');
  474. },
  475. success: function (label) {
  476. label.closest('.form-group').removeClass('has-error');
  477. label.remove();
  478. },
  479. errorPlacement: function (error, element) {
  480. element.parent('div').append(error);
  481. },
  482. submitHandler: function (form) {
  483. // process
  484. var executorTimeout = $("#updateModal .form input[name='executorTimeout']").val();
  485. if (!/^\d+$/.test(executorTimeout)) {
  486. executorTimeout = 0;
  487. }
  488. $("#updateModal .form input[name='executorTimeout']").val(executorTimeout);
  489. var executorFailRetryCount = $("#updateModal .form input[name='executorFailRetryCount']").val();
  490. if (!/^\d+$/.test(executorFailRetryCount)) {
  491. executorFailRetryCount = 0;
  492. }
  493. $("#updateModal .form input[name='executorFailRetryCount']").val(executorFailRetryCount);
  494. // post
  495. $.post(base_url + "/jobinfo/update", $("#updateModal .form").serialize(), function (data, status) {
  496. if (data.code == "200") {
  497. $('#updateModal').modal('hide');
  498. layer.open({
  499. title: I18n.system_tips,
  500. btn: [I18n.system_ok],
  501. content: I18n.system_update_suc,
  502. icon: '1',
  503. end: function (layero, index) {
  504. //window.location.reload();
  505. jobTable.fnDraw();
  506. }
  507. });
  508. } else {
  509. layer.open({
  510. title: I18n.system_tips,
  511. btn: [I18n.system_ok],
  512. content: (data.msg || I18n.system_update_fail),
  513. icon: '2'
  514. });
  515. }
  516. });
  517. }
  518. });
  519. $("#updateModal").on('hide.bs.modal', function () {
  520. $("#updateModal .form")[0].reset()
  521. });
  522. /**
  523. * find title by name, GlueType
  524. */
  525. function findGlueTypeTitle(glueType) {
  526. var glueTypeTitle;
  527. $("#addModal .form select[name=glueType] option").each(function () {
  528. var name = $(this).val();
  529. var title = $(this).text();
  530. if (glueType == name) {
  531. glueTypeTitle = title;
  532. return false
  533. }
  534. });
  535. return glueTypeTitle;
  536. }
  537. });