joblog.index.1.js 13 KB

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