jobinfo.index.1.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. return obj;
  18. }
  19. },
  20. "searching": false,
  21. "ordering": false,
  22. //"scrollX": true, // scroll x,close self-adaption
  23. "columns": [
  24. {
  25. "data": 'id',
  26. "bSortable": false,
  27. "visible" : true,
  28. "width":'10%'
  29. },
  30. {
  31. "data": 'jobGroup',
  32. "visible" : false,
  33. "width":'20%',
  34. "render": function ( data, type, row ) {
  35. var groupMenu = $("#jobGroup").find("option");
  36. for ( var index in $("#jobGroup").find("option")) {
  37. if ($(groupMenu[index]).attr('value') == data) {
  38. return $(groupMenu[index]).html();
  39. }
  40. }
  41. return data;
  42. }
  43. },
  44. {
  45. "data": 'jobDesc',
  46. "visible" : true,
  47. "width":'20%'
  48. },
  49. {
  50. "data": 'glueType',
  51. "width":'20%',
  52. "visible" : true,
  53. "render": function ( data, type, row ) {
  54. var glueTypeTitle = findGlueTypeTitle(row.glueType);
  55. if (row.executorHandler) {
  56. return glueTypeTitle +":" + row.executorHandler;
  57. } else {
  58. return glueTypeTitle;
  59. }
  60. }
  61. },
  62. { "data": 'executorParam', "visible" : false},
  63. {
  64. "data": 'jobCron',
  65. "visible" : true,
  66. "width":'10%'
  67. },
  68. {
  69. "data": 'addTime',
  70. "visible" : false,
  71. "render": function ( data, type, row ) {
  72. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  73. }
  74. },
  75. {
  76. "data": 'updateTime',
  77. "visible" : false,
  78. "render": function ( data, type, row ) {
  79. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  80. }
  81. },
  82. { "data": 'author', "visible" : true, "width":'10%'},
  83. { "data": 'alarmEmail', "visible" : false},
  84. {
  85. "data": 'jobStatus',
  86. "width":'10%',
  87. "visible" : true,
  88. "render": function ( data, type, row ) {
  89. // status
  90. if (data && data != 'NONE') {
  91. if ('NORMAL' == data) {
  92. return '<small class="label label-success" ><i class="fa fa-clock-o"></i>RUNNING</small>';
  93. } else {
  94. return '<small class="label label-warning" >ERROR('+ data +')</small>';
  95. }
  96. } else {
  97. return '<small class="label label-default" ><i class="fa fa-clock-o"></i>STOP</small>';
  98. }
  99. return data;
  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 = '<a href="'+ codeUrl +'" target="_blank" > <button class="btn btn-warning btn-xs" type="button" >GLUE</button> </a> '
  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. '<a href="'+ logUrl +'"> <button class="btn btn-primary btn-xs" type="job_del" type="button" >'+ I18n.jobinfo_opt_log +'</button> </a> <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?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. // add
  280. $(".add").click(function(){
  281. $('#addModal').modal({backdrop: false, keyboard: false}).modal('show');
  282. });
  283. var addModalValidate = $("#addModal .form").validate({
  284. errorElement : 'span',
  285. errorClass : 'help-block',
  286. focusInvalid : true,
  287. rules : {
  288. jobDesc : {
  289. required : true,
  290. maxlength: 50
  291. },
  292. jobCron : {
  293. required : true
  294. },
  295. author : {
  296. required : true
  297. },
  298. executorTimeout : {
  299. digits:true
  300. },
  301. executorFailRetryCount : {
  302. digits:true
  303. }
  304. },
  305. messages : {
  306. jobDesc : {
  307. required : I18n.system_please_input + I18n.jobinfo_field_jobdesc
  308. },
  309. jobCron : {
  310. required : I18n.system_please_input + "Cron"
  311. },
  312. author : {
  313. required : I18n.system_please_input + I18n.jobinfo_field_author
  314. },
  315. executorTimeout : {
  316. digits: I18n.system_please_input + I18n.system_digits
  317. },
  318. executorFailRetryCount : {
  319. digits: I18n.system_please_input + I18n.system_digits
  320. }
  321. },
  322. highlight : function(element) {
  323. $(element).closest('.form-group').addClass('has-error');
  324. },
  325. success : function(label) {
  326. label.closest('.form-group').removeClass('has-error');
  327. label.remove();
  328. },
  329. errorPlacement : function(error, element) {
  330. element.parent('div').append(error);
  331. },
  332. submitHandler : function(form) {
  333. // process
  334. var executorTimeout = $("#addModal .form input[name='executorTimeout']").val();
  335. if(!/^\d+$/.test(executorTimeout)) {
  336. executorTimeout = 0;
  337. }
  338. $("#addModal .form input[name='executorTimeout']").val(executorTimeout);
  339. var executorFailRetryCount = $("#addModal .form input[name='executorFailRetryCount']").val();
  340. if(!/^\d+$/.test(executorFailRetryCount)) {
  341. executorFailRetryCount = 0;
  342. }
  343. $("#addModal .form input[name='executorFailRetryCount']").val(executorFailRetryCount);
  344. $.post(base_url + "/jobinfo/add", $("#addModal .form").serialize(), function(data, status) {
  345. if (data.code == "200") {
  346. $('#addModal').modal('hide');
  347. layer.open({
  348. title: I18n.system_tips ,
  349. btn: [ I18n.system_ok ],
  350. content: I18n.system_add_suc ,
  351. icon: '1',
  352. end: function(layero, index){
  353. jobTable.fnDraw();
  354. //window.location.reload();
  355. }
  356. });
  357. } else {
  358. layer.open({
  359. title: I18n.system_tips ,
  360. btn: [ I18n.system_ok ],
  361. content: (data.msg || I18n.system_add_fail),
  362. icon: '2'
  363. });
  364. }
  365. });
  366. }
  367. });
  368. $("#addModal").on('hide.bs.modal', function () {
  369. $("#addModal .form")[0].reset();
  370. addModalValidate.resetForm();
  371. $("#addModal .form .form-group").removeClass("has-error");
  372. $(".remote_panel").show(); // remote
  373. $("#addModal .form input[name='executorHandler']").removeAttr("readonly");
  374. });
  375. // glueType change
  376. $(".glueType").change(function(){
  377. // executorHandler
  378. var $executorHandler = $(this).parents("form").find("input[name='executorHandler']");
  379. var glueType = $(this).val();
  380. if ('BEAN' != glueType) {
  381. $executorHandler.val("");
  382. $executorHandler.attr("readonly","readonly");
  383. } else {
  384. $executorHandler.removeAttr("readonly");
  385. }
  386. });
  387. $("#addModal .glueType").change(function(){
  388. // glueSource
  389. var glueType = $(this).val();
  390. if ('GLUE_GROOVY'==glueType){
  391. $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_java").val() );
  392. } else if ('GLUE_SHELL'==glueType){
  393. $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_shell").val() );
  394. } else if ('GLUE_PYTHON'==glueType){
  395. $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_python").val() );
  396. } else if ('GLUE_PHP'==glueType){
  397. $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_php").val() );
  398. } else if ('GLUE_NODEJS'==glueType){
  399. $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_nodejs").val() );
  400. } else if ('GLUE_POWERSHELL'==glueType){
  401. $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_powershell").val() );
  402. } else {
  403. $("#addModal .form textarea[name='glueSource']").val("");
  404. }
  405. });
  406. // update
  407. $("#job_list").on('click', '.update',function() {
  408. var id = $(this).parent('p').attr("id");
  409. var row = tableData['key'+id];
  410. // base data
  411. $("#updateModal .form input[name='id']").val( row.id );
  412. $('#updateModal .form select[name=jobGroup] option[value='+ row.jobGroup +']').prop('selected', true);
  413. $("#updateModal .form input[name='jobDesc']").val( row.jobDesc );
  414. $("#updateModal .form input[name='jobCron']").val( row.jobCron );
  415. $("#updateModal .form input[name='author']").val( row.author );
  416. $("#updateModal .form input[name='alarmEmail']").val( row.alarmEmail );
  417. $("#updateModal .form input[name='executorTimeout']").val( row.executorTimeout );
  418. $("#updateModal .form input[name='executorFailRetryCount']").val( row.executorFailRetryCount );
  419. $('#updateModal .form select[name=executorRouteStrategy] option[value='+ row.executorRouteStrategy +']').prop('selected', true);
  420. $("#updateModal .form input[name='executorHandler']").val( row.executorHandler );
  421. $("#updateModal .form textarea[name='executorParam']").val( row.executorParam );
  422. $("#updateModal .form input[name='childJobId']").val( row.childJobId );
  423. $('#updateModal .form select[name=executorBlockStrategy] option[value='+ row.executorBlockStrategy +']').prop('selected', true);
  424. $('#updateModal .form select[name=glueType] option[value='+ row.glueType +']').prop('selected', true);
  425. $("#updateModal .form select[name=glueType]").change();
  426. // show
  427. $('#updateModal').modal({backdrop: false, keyboard: false}).modal('show');
  428. });
  429. var updateModalValidate = $("#updateModal .form").validate({
  430. errorElement : 'span',
  431. errorClass : 'help-block',
  432. focusInvalid : true,
  433. rules : {
  434. jobDesc : {
  435. required : true,
  436. maxlength: 50
  437. },
  438. jobCron : {
  439. required : true
  440. },
  441. author : {
  442. required : true
  443. },
  444. executorTimeout : {
  445. digits:true
  446. },
  447. executorFailRetryCount : {
  448. digits:true
  449. }
  450. },
  451. messages : {
  452. jobDesc : {
  453. required : I18n.system_please_input + I18n.jobinfo_field_jobdesc
  454. },
  455. jobCron : {
  456. required : I18n.system_please_input + "Cron"
  457. },
  458. author : {
  459. required : I18n.system_please_input + I18n.jobinfo_field_author
  460. },
  461. executorTimeout : {
  462. digits: I18n.system_please_input + I18n.system_digits
  463. },
  464. executorFailRetryCount : {
  465. digits: I18n.system_please_input + I18n.system_digits
  466. }
  467. },
  468. highlight : function(element) {
  469. $(element).closest('.form-group').addClass('has-error');
  470. },
  471. success : function(label) {
  472. label.closest('.form-group').removeClass('has-error');
  473. label.remove();
  474. },
  475. errorPlacement : function(error, element) {
  476. element.parent('div').append(error);
  477. },
  478. submitHandler : function(form) {
  479. // process
  480. var executorTimeout = $("#updateModal .form input[name='executorTimeout']").val();
  481. if(!/^\d+$/.test(executorTimeout)) {
  482. executorTimeout = 0;
  483. }
  484. $("#updateModal .form input[name='executorTimeout']").val(executorTimeout);
  485. var executorFailRetryCount = $("#updateModal .form input[name='executorFailRetryCount']").val();
  486. if(!/^\d+$/.test(executorFailRetryCount)) {
  487. executorFailRetryCount = 0;
  488. }
  489. $("#updateModal .form input[name='executorFailRetryCount']").val(executorFailRetryCount);
  490. // post
  491. $.post(base_url + "/jobinfo/update", $("#updateModal .form").serialize(), function(data, status) {
  492. if (data.code == "200") {
  493. $('#updateModal').modal('hide');
  494. layer.open({
  495. title: I18n.system_tips ,
  496. btn: [ I18n.system_ok ],
  497. content: I18n.system_update_suc ,
  498. icon: '1',
  499. end: function(layero, index){
  500. //window.location.reload();
  501. jobTable.fnDraw();
  502. }
  503. });
  504. } else {
  505. layer.open({
  506. title: I18n.system_tips ,
  507. btn: [ I18n.system_ok ],
  508. content: (data.msg || I18n.system_update_fail ),
  509. icon: '2'
  510. });
  511. }
  512. });
  513. }
  514. });
  515. $("#updateModal").on('hide.bs.modal', function () {
  516. $("#updateModal .form")[0].reset()
  517. });
  518. /**
  519. * find title by name, GlueType
  520. */
  521. function findGlueTypeTitle(glueType) {
  522. var glueTypeTitle;
  523. $("#addModal .form select[name=glueType] option").each(function () {
  524. var name = $(this).val();
  525. var title = $(this).text();
  526. if (glueType == name) {
  527. glueTypeTitle = title;
  528. return false
  529. }
  530. });
  531. return glueTypeTitle;
  532. }
  533. });