joblog.index.1.js 8.6 KB
Newer Older
X
xueli.xue 已提交
1
$(function() {
X
xueli.xue 已提交
2

X
fresh  
xueli.xue 已提交
3
	// 任务组列表选中, 任务列表初始化和选中
X
xueli.xue 已提交
4 5 6 7
	$("#jobGroup").on("change", function () {
		var jobGroup = $(this).children('option:selected').val();
		$.ajax({
			type : 'POST',
8
            async: false,   // async, avoid js invoke pagelist before jobId data init
X
xueli.xue 已提交
9 10 11 12 13
			url : base_url + '/joblog/getJobsByGroup',
			data : {"jobGroup":jobGroup},
			dataType : "json",
			success : function(data){
				if (data.code == 200) {
X
fix  
xueli.xue 已提交
14
					$("#jobId").html('<option value="0" >请选择</option>');
15 16
					$.each(data.content, function (n, value) {
                        $("#jobId").append('<option value="' + value.id + '" >' + value.jobDesc + '</option>');
X
xueli.xue 已提交
17
                    });
18 19
                    if ($("#jobId").attr("paramVal")){
                        $("#jobId").find("option[value='" + $("#jobId").attr("paramVal") + "']").attr("selected",true);
X
xueli.xue 已提交
20 21 22 23 24 25 26 27 28 29 30 31
                    }
				} else {
					ComAlertTec.show(data.msg);
				}
			},
		});
	});
	if ($("#jobGroup").attr("paramVal")){
		$("#jobGroup").find("option[value='" + $("#jobGroup").attr("paramVal") + "']").attr("selected",true);
        $("#jobGroup").change();
	}

32 33
	// 过滤时间
	$('#filterTime').daterangepicker({
X
xueli.xue 已提交
34 35 36 37 38 39 40
        autoApply:false,
        singleDatePicker:false,
        showDropdowns:false,        // 是否显示年月选择条件
		timePicker: true, 			// 是否显示小时和分钟选择条件
		timePickerIncrement: 10, 	// 时间的增量,单位为分钟
        timePicker24Hour : true,
        opens : 'left', //日期选择框的弹出位置
X
xueli.xue 已提交
41 42
		ranges: {
			'最近1小时': [moment().subtract(1, 'hours'), moment()],
X
xueli.xue 已提交
43 44
			'今日': [moment().startOf('day'), moment().endOf('day')],
			'昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
X
xueli.xue 已提交
45 46 47 48 49
			'最近7日': [moment().subtract(6, 'days'), moment()],
			'最近30日': [moment().subtract(29, 'days'), moment()],
			'本月': [moment().startOf('month'), moment().endOf('month')],
			'上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
		},
50
        locale : {
X
xueli.xue 已提交
51 52
            format: 'YYYY-MM-DD HH:mm:ss',
            separator : ' - ',
53 54 55 56 57 58 59
        	customRangeLabel : '自定义',
            applyLabel : '确定',
            cancelLabel : '取消',
            fromLabel : '起始时间',
            toLabel : '结束时间',
            daysOfWeek : [ '', '', '', '', '', '', '' ],
            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
X
xueli.xue 已提交
60 61 62
            firstDay : 1,
            startDate: moment().startOf('day'),
            endDate: moment().endOf('day')
63 64
        }
	});
X
xueli.xue 已提交
65

X
xueli.xue 已提交
66
	// init date tables
X
xueli.xue 已提交
67 68 69 70
	var logTable = $("#joblog_list").dataTable({
		"deferRender": true,
		"processing" : true, 
	    "serverSide": true,
X
xueli.xue 已提交
71
		"ajax": {
X
xueli.xue 已提交
72 73
	        url: base_url + "/joblog/pageList" ,
	        data : function ( d ) {
X
xueli.xue 已提交
74 75
	        	var obj = {};
	        	obj.jobGroup = $('#jobGroup').val();
76
	        	obj.jobId = $('#jobId').val();
X
init  
xueli.xue 已提交
77
				obj.filterTime = $('#filterTime').val();
X
xueli.xue 已提交
78 79
	        	obj.start = d.start;
	        	obj.length = d.length;
X
xueli.xue 已提交
80
                return obj;
X
xueli.xue 已提交
81
            }
X
xueli.xue 已提交
82
	    },
X
xueli.xue 已提交
83 84 85
	    "searching": false,
	    "ordering": false,
	    //"scrollX": false,
X
xueli.xue 已提交
86
	    "columns": [
X
xueli.xue 已提交
87
	                { "data": 'id', "bSortable": false, "visible" : false},
88 89
					{ "data": 'jobGroup', "visible" : false},
	                { "data": 'jobId', "visible" : false},
X
xueli.xue 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
					{
						"data": 'triggerTime',
						"render": function ( data, type, row ) {
							return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
						}
					},
					{
						"data": 'triggerCode',
						"render": function ( data, type, row ) {
							return (data==200)?'<span style="color: green">成功</span>':(data==500)?'<span style="color: red">失败</span>':(data==0)?'':data;
						}

					},
					{
						"data": 'triggerMsg',
						"render": function ( data, type, row ) {
							return data?'<a class="logTips" href="javascript:;" >查看<span style="display:none;">'+ data +'</span></a>':"";
						}
					},
109
	                { "data": 'executorAddress', "visible" : true},
X
coding  
xueli.xue 已提交
110
					{
X
xueli.xue 已提交
111
						"data": 'glueType',
X
coding  
xueli.xue 已提交
112 113
						"visible" : true,
						"render": function ( data, type, row ) {
X
xueli.xue 已提交
114 115 116 117 118 119 120 121 122 123
							if ('GLUE_GROOVY'==row.glueType) {
								return "GLUE模式(Java)";
							} else if ('GLUE_SHELL'==row.glueType) {
								return "GLUE模式(Shell)";
							} else if ('GLUE_PYTHON'==row.glueType) {
								return "GLUE模式(Python)";
							} else if ('BEAN'==row.glueType) {
								return "BEAN模式:" + row.executorHandler;
							}
							return row.executorHandler;
X
coding  
xueli.xue 已提交
124 125
						}
					},
126
	                { "data": 'executorParam', "visible" : true},
X
Coding  
xueli.xue 已提交
127

X
xueli.xue 已提交
128 129 130 131 132 133
	                { 
	                	"data": 'handleTime',
	                	"render": function ( data, type, row ) {
	                		return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
	                	}
	                },
X
Coding  
xueli.xue 已提交
134 135 136 137 138 139
	                {
						"data": 'handleCode',
						"render": function ( data, type, row ) {
							return (data==200)?'<span style="color: green">成功</span>':(data==500)?'<span style="color: red">失败</span>':(data==0)?'':data;
						}
	                },
X
xueli.xue 已提交
140 141
	                { 
	                	"data": 'handleMsg',
X
xueli.xue 已提交
142
	                	"render": function ( data, type, row ) {
X
xueli.xue 已提交
143
	                		return data?'<a class="logTips" href="javascript:;" >查看<span style="display:none;">'+ data +'</span></a>':"";
X
xueli.xue 已提交
144
	                	}
145
	                },
146 147 148 149
	                {
						"data": 'handleMsg' ,
						"bSortable": false,
						"width": "8%" ,
150 151 152
	                	"render": function ( data, type, row ) {
	                		// better support expression or string, not function
	                		return function () {
X
Coding  
xueli.xue 已提交
153
		                		if (row.triggerCode == 200){
X
xueli.xue 已提交
154
		                			var temp = '<a href="javascript:;" class="logDetail" _id="'+ row.id +'">执行日志</a>';
X
Coding  
xueli.xue 已提交
155
		                			if(row.handleCode == 0){
156 157 158 159 160 161 162
		                				temp += '<br><a href="javascript:;" class="logKill" _id="'+ row.id +'">终止任务</a>';
		                			}
		                			return temp;
		                		}
		                		return null;	
	                		}
	                	}
X
xueli.xue 已提交
163
	                }
X
xueli.xue 已提交
164 165 166 167 168
	            ],
		"language" : {
			"sProcessing" : "处理中...",
			"sLengthMenu" : "每页 _MENU_ 条记录",
			"sZeroRecords" : "没有匹配结果",
X
xueli.xue 已提交
169
			"sInfo" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页,_TOTAL_ 条记录 )",
X
xueli.xue 已提交
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
			"sInfoEmpty" : "无记录",
			"sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
			"sInfoPostFix" : "",
			"sSearch" : "搜索:",
			"sUrl" : "",
			"sEmptyTable" : "表中数据为空",
			"sLoadingRecords" : "载入中...",
			"sInfoThousands" : ",",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "上页",
				"sNext" : "下页",
				"sLast" : "末页"
			},
			"oAria" : {
				"sSortAscending" : ": 以升序排列此列",
				"sSortDescending" : ": 以降序排列此列"
			}
		}
	});
	
191 192 193 194 195 196
	// 任务数据
	$('#joblog_list').on('click', '.logMsg', function(){
		var msg = $(this).find('span').html();
		ComAlert.show(2, msg);
	});
	
X
xueli.xue 已提交
197 198
	// 日志弹框提示
	$('#joblog_list').on('click', '.logTips', function(){
X
xueli.xue 已提交
199 200
		var msg = $(this).find('span').html();
		ComAlertTec.show(msg);
X
xueli.xue 已提交
201 202
	});
	
X
xueli.xue 已提交
203 204 205 206 207
	// 搜索按钮
	$('#searchBtn').on('click', function(){
		logTable.fnDraw();
	});
	
208 209 210 211
	// 查看执行器详细执行日志
	$('#joblog_list').on('click', '.logDetail', function(){
		var _id = $(this).attr('_id');
		
X
xueli.xue 已提交
212
		window.open(base_url + '/joblog/logDetailPage?id=' + _id);
213 214 215 216 217
		return;
		
		/*
		$.ajax({
			type : 'POST',
X
xueli.xue 已提交
218
			url : base_url + '/joblog/logDetail',
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
			data : {"id":_id},
			dataType : "json",
			success : function(data){
				if (data.code == 200) {
					ComAlertTec.show('<pre style="color: white;background-color: black;width2:'+ $(window).width()*2/3 +'px;" >'+ data.content +'</pre>');
				} else {
					ComAlertTec.show(data.msg);
				}
			},
		});
		*/
	});
	
	$('#joblog_list').on('click', '.logKill', function(){
		var _id = $(this).attr('_id');
		ComConfirm.show("确认主动终止任务?", function(){
			$.ajax({
				type : 'POST',
X
xueli.xue 已提交
237
				url : base_url + '/joblog/logKill',
238 239 240 241 242 243 244 245 246 247 248 249 250 251
				data : {"id":_id},
				dataType : "json",
				success : function(data){
					if (data.code == 200) {
						ComAlert.show(1, '操作成功');
						logTable.fnDraw();
					} else {
						ComAlert.show(2, data.msg);
					}
				},
			});
		});
	});
	
X
xueli.xue 已提交
252
});