joblog.index.1.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. $(function() {
  2. // jobGroup change, job list init and select
  3. $("#jobGroup").on("change", function () {
  4. var jobGroup = $(this).children('option:selected').val();
  5. $.ajax({
  6. type : 'POST',
  7. async: false, // async, avoid js invoke pagelist before jobId data init
  8. url : base_url + '/joblog/getJobsByGroup',
  9. data : {"jobGroup":jobGroup},
  10. dataType : "json",
  11. success : function(data){
  12. if (data.code == 200) {
  13. $("#jobId").html( '<option value="0" >'+ I18n.system_all +'</option>' );
  14. $.each(data.content, function (n, value) {
  15. $("#jobId").append('<option value="' + value.id + '" >' + value.jobDesc + '</option>');
  16. });
  17. if ($("#jobId").attr("paramVal")){
  18. $("#jobId").find("option[value='" + $("#jobId").attr("paramVal") + "']").attr("selected",true);
  19. }
  20. } else {
  21. layer.open({
  22. title: I18n.system_tips ,
  23. btn: [ I18n.system_ok ],
  24. content: (data.msg || I18n.system_api_error ),
  25. icon: '2'
  26. });
  27. }
  28. },
  29. });
  30. });
  31. if ($("#jobGroup").attr("paramVal")){
  32. $("#jobGroup").find("option[value='" + $("#jobGroup").attr("paramVal") + "']").attr("selected",true);
  33. $("#jobGroup").change();
  34. }
  35. // filter Time
  36. var rangesConf = {};
  37. rangesConf[I18n.daterangepicker_ranges_recent_hour] = [moment().subtract(1, 'hours'), moment()];
  38. rangesConf[I18n.daterangepicker_ranges_today] = [moment().startOf('day'), moment().endOf('day')];
  39. rangesConf[I18n.daterangepicker_ranges_yesterday] = [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')];
  40. rangesConf[I18n.daterangepicker_ranges_this_month] = [moment().startOf('month'), moment().endOf('month')];
  41. rangesConf[I18n.daterangepicker_ranges_last_month] = [moment().subtract(1, 'months').startOf('month'), moment().subtract(1, 'months').endOf('month')];
  42. rangesConf[I18n.daterangepicker_ranges_recent_week] = [moment().subtract(1, 'weeks').startOf('day'), moment().endOf('day')];
  43. rangesConf[I18n.daterangepicker_ranges_recent_month] = [moment().subtract(1, 'months').startOf('day'), moment().endOf('day')];
  44. $('#filterTime').daterangepicker({
  45. autoApply:false,
  46. singleDatePicker:false,
  47. showDropdowns:false, // 是否显示年月选择条件
  48. timePicker: true, // 是否显示小时和分钟选择条件
  49. timePickerIncrement: 10, // 时间的增量,单位为分钟
  50. timePicker24Hour : true,
  51. opens : 'left', //日期选择框的弹出位置
  52. ranges: rangesConf,
  53. locale : {
  54. format: 'YYYY-MM-DD HH:mm:ss',
  55. separator : ' - ',
  56. customRangeLabel : I18n.daterangepicker_custom_name ,
  57. applyLabel : I18n.system_ok ,
  58. cancelLabel : I18n.system_cancel ,
  59. fromLabel : I18n.daterangepicker_custom_starttime ,
  60. toLabel : I18n.daterangepicker_custom_endtime ,
  61. daysOfWeek : I18n.daterangepicker_custom_daysofweek.split(',') , // '日', '一', '二', '三', '四', '五', '六'
  62. monthNames : I18n.daterangepicker_custom_monthnames.split(',') , // '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'
  63. firstDay : 1
  64. },
  65. startDate: rangesConf[I18n.daterangepicker_ranges_today][0],
  66. endDate: rangesConf[I18n.daterangepicker_ranges_today][1]
  67. });
  68. // init date tables
  69. var logTable = $("#joblog_list").dataTable({
  70. "deferRender": true,
  71. "processing" : true,
  72. "serverSide": true,
  73. "ajax": {
  74. url: base_url + "/joblog/pageList" ,
  75. type:"post",
  76. data : function ( d ) {
  77. var obj = {};
  78. obj.jobGroup = $('#jobGroup').val();
  79. obj.jobId = $('#jobId').val();
  80. obj.logStatus = $('#logStatus').val();
  81. obj.filterTime = $('#filterTime').val();
  82. obj.start = d.start;
  83. obj.length = d.length;
  84. return obj;
  85. }
  86. },
  87. "searching": false,
  88. "ordering": false,
  89. //"scrollX": false,
  90. "columns": [
  91. {
  92. "data": 'jobId',
  93. "visible" : true,
  94. "width":'10%',
  95. "render": function ( data, type, row ) {
  96. var glueTypeTitle = GlueTypeEnum[row.glueType];
  97. if (row.executorHandler) {
  98. glueTypeTitle = glueTypeTitle +":" + row.executorHandler;
  99. }
  100. var temp = '';
  101. temp += I18n.joblog_field_executorAddress + ':' + (row.executorAddress?row.executorAddress:'');
  102. temp += '<br>'+ I18n.jobinfo_field_gluetype +':' + glueTypeTitle;
  103. temp += '<br>'+ I18n.jobinfo_field_executorparam +':' + row.executorParam;
  104. return '<a class="logTips" href="javascript:;" >'+ row.jobId +'<span style="display:none;">'+ temp +'</span></a>';
  105. }
  106. },
  107. { "data": 'jobGroup', "visible" : false},
  108. {
  109. "data": 'triggerTime',
  110. "width":'16%',
  111. "render": function ( data, type, row ) {
  112. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  113. }
  114. },
  115. {
  116. "data": 'triggerCode',
  117. "width":'12%',
  118. "render": function ( data, type, row ) {
  119. var html = data;
  120. if (data == 200) {
  121. html = '<span style="color: green">'+ I18n.system_success +'</span>';
  122. } else if (data == 500) {
  123. html = '<span style="color: red">'+ I18n.system_fail +'</span>';
  124. } else if (data == 0) {
  125. html = '';
  126. }
  127. return html;
  128. }
  129. },
  130. {
  131. "data": 'triggerMsg',
  132. "width":'12%',
  133. "render": function ( data, type, row ) {
  134. return data?'<a class="logTips" href="javascript:;" >'+ I18n.system_show +'<span style="display:none;">'+ data +'</span></a>':I18n.system_empty;
  135. }
  136. },
  137. {
  138. "data": 'handleTime',
  139. "width":'16%',
  140. "render": function ( data, type, row ) {
  141. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  142. }
  143. },
  144. {
  145. "data": 'handleCode',
  146. "width":'12%',
  147. "render": function ( data, type, row ) {
  148. var html = data;
  149. if (data == 200) {
  150. html = '<span style="color: green">'+ I18n.joblog_handleCode_200 +'</span>';
  151. } else if (data == 500) {
  152. html = '<span style="color: red">'+ I18n.joblog_handleCode_500 +'</span>';
  153. } else if (data == 501) {
  154. html = '<span style="color: red">'+ I18n.joblog_handleCode_501 +'</span>';
  155. } else if (data == 502) {
  156. html = '<span style="color: red">'+ I18n.joblog_handleCode_502 +'</span>';
  157. } else if (data == 0) {
  158. html = '';
  159. }
  160. return html;
  161. }
  162. },
  163. {
  164. "data": 'handleMsg',
  165. "width":'12%',
  166. "render": function ( data, type, row ) {
  167. return data?'<a class="logTips" href="javascript:;" >'+ I18n.system_show +'<span style="display:none;">'+ data +'</span></a>':I18n.system_empty;
  168. }
  169. },
  170. {
  171. "data": 'handleMsg' ,
  172. "bSortable": false,
  173. "width":'10%',
  174. "render": function ( data, type, row ) {
  175. // better support expression or string, not function
  176. return function () {
  177. if (row.triggerCode == 200){
  178. var temp = '<a href="javascript:;" class="logDetail" _id="'+ row.id +'">'+ I18n.joblog_rolling_log +'</a>';
  179. if(row.handleCode == 0){
  180. temp += '<br><a href="javascript:;" class="logKill" _id="'+ row.id +'" style="color: red;" >'+ I18n.joblog_kill_log +'</a>';
  181. }
  182. return temp;
  183. }
  184. return null;
  185. }
  186. }
  187. }
  188. ],
  189. "language" : {
  190. "sProcessing" : I18n.dataTable_sProcessing ,
  191. "sLengthMenu" : I18n.dataTable_sLengthMenu ,
  192. "sZeroRecords" : I18n.dataTable_sZeroRecords ,
  193. "sInfo" : I18n.dataTable_sInfo ,
  194. "sInfoEmpty" : I18n.dataTable_sInfoEmpty ,
  195. "sInfoFiltered" : I18n.dataTable_sInfoFiltered ,
  196. "sInfoPostFix" : "",
  197. "sSearch" : I18n.dataTable_sSearch ,
  198. "sUrl" : "",
  199. "sEmptyTable" : I18n.dataTable_sEmptyTable ,
  200. "sLoadingRecords" : I18n.dataTable_sLoadingRecords ,
  201. "sInfoThousands" : ",",
  202. "oPaginate" : {
  203. "sFirst" : I18n.dataTable_sFirst ,
  204. "sPrevious" : I18n.dataTable_sPrevious ,
  205. "sNext" : I18n.dataTable_sNext ,
  206. "sLast" : I18n.dataTable_sLast
  207. },
  208. "oAria" : {
  209. "sSortAscending" : I18n.dataTable_sSortAscending ,
  210. "sSortDescending" : I18n.dataTable_sSortDescending
  211. }
  212. }
  213. });
  214. // logTips alert
  215. $('#joblog_list').on('click', '.logTips', function(){
  216. var msg = $(this).find('span').html();
  217. ComAlertTec.show(msg);
  218. });
  219. // search Btn
  220. $('#searchBtn').on('click', function(){
  221. logTable.fnDraw();
  222. });
  223. // logDetail look
  224. $('#joblog_list').on('click', '.logDetail', function(){
  225. var _id = $(this).attr('_id');
  226. window.open(base_url + '/joblog/logDetailPage?id=' + _id);
  227. return;
  228. });
  229. /**
  230. * log Kill
  231. */
  232. $('#joblog_list').on('click', '.logKill', function(){
  233. var _id = $(this).attr('_id');
  234. layer.confirm( (I18n.system_ok + I18n.joblog_kill_log + '?'), {
  235. icon: 3,
  236. title: I18n.system_tips ,
  237. btn: [ I18n.system_ok, I18n.system_cancel ]
  238. }, function(index){
  239. layer.close(index);
  240. $.ajax({
  241. type : 'POST',
  242. url : base_url + '/joblog/logKill',
  243. data : {"id":_id},
  244. dataType : "json",
  245. success : function(data){
  246. if (data.code == 200) {
  247. layer.open({
  248. title: I18n.system_tips,
  249. btn: [ I18n.system_ok ],
  250. content: I18n.system_opt_suc ,
  251. icon: '1',
  252. end: function(layero, index){
  253. logTable.fnDraw();
  254. }
  255. });
  256. } else {
  257. layer.open({
  258. title: I18n.system_tips,
  259. btn: [ I18n.system_ok ],
  260. content: (data.msg || I18n.system_opt_fail ),
  261. icon: '2'
  262. });
  263. }
  264. },
  265. });
  266. });
  267. });
  268. /**
  269. * clear Log
  270. */
  271. $('#clearLog').on('click', function(){
  272. var jobGroup = $('#jobGroup').val();
  273. var jobId = $('#jobId').val();
  274. var jobGroupText = $("#jobGroup").find("option:selected").text();
  275. var jobIdText = $("#jobId").find("option:selected").text();
  276. $('#clearLogModal input[name=jobGroup]').val(jobGroup);
  277. $('#clearLogModal input[name=jobId]').val(jobId);
  278. $('#clearLogModal .jobGroupText').val(jobGroupText);
  279. $('#clearLogModal .jobIdText').val(jobIdText);
  280. $('#clearLogModal').modal('show');
  281. });
  282. $("#clearLogModal .ok").on('click', function(){
  283. $.post(base_url + "/joblog/clearLog", $("#clearLogModal .form").serialize(), function(data, status) {
  284. if (data.code == "200") {
  285. $('#clearLogModal').modal('hide');
  286. layer.open({
  287. title: I18n.system_tips ,
  288. btn: [ I18n.system_ok ],
  289. content: (I18n.joblog_clean_log + I18n.system_success) ,
  290. icon: '1',
  291. end: function(layero, index){
  292. logTable.fnDraw();
  293. }
  294. });
  295. } else {
  296. layer.open({
  297. title: I18n.system_tips ,
  298. btn: [ I18n.system_ok ],
  299. content: (data.msg || (I18n.joblog_clean_log + I18n.system_fail) ),
  300. icon: '2'
  301. });
  302. }
  303. });
  304. });
  305. $("#clearLogModal").on('hide.bs.modal', function () {
  306. $("#clearLogModal .form")[0].reset();
  307. });
  308. });
  309. // Com Alert by Tec theme
  310. var ComAlertTec = {
  311. html:function(){
  312. var html =
  313. '<div class="modal fade" id="ComAlertTec" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
  314. '<div class="modal-dialog">' +
  315. '<div class="modal-content-tec">' +
  316. '<div class="modal-body"><div class="alert" style="color:#fff;"></div></div>' +
  317. '<div class="modal-footer">' +
  318. '<div class="text-center" >' +
  319. '<button type="button" class="btn btn-info ok" data-dismiss="modal" >'+ I18n.system_ok +'</button>' +
  320. '</div>' +
  321. '</div>' +
  322. '</div>' +
  323. '</div>' +
  324. '</div>';
  325. return html;
  326. },
  327. show:function(msg, callback){
  328. // dom init
  329. if ($('#ComAlertTec').length == 0){
  330. $('body').append(ComAlertTec.html());
  331. }
  332. // init com alert
  333. $('#ComAlertTec .alert').html(msg);
  334. $('#ComAlertTec').modal('show');
  335. $('#ComAlertTec .ok').click(function(){
  336. $('#ComAlertTec').modal('hide');
  337. if(typeof callback == 'function') {
  338. callback();
  339. }
  340. });
  341. }
  342. };