集成xxl-job-admin控制台。

This commit is contained in:
sxq
2021-10-20 11:32:31 +08:00
parent 8b6f7b4e4c
commit 3eeeb27d70
164 changed files with 38579 additions and 2 deletions

View File

@ -0,0 +1,156 @@
$(function(){
// logout
$("#logoutBtn").click(function(){
layer.confirm( I18n.logout_confirm , {
icon: 3,
title: I18n.system_tips ,
btn: [ I18n.system_ok, I18n.system_cancel ]
}, function(index){
layer.close(index);
$.post(base_url + "/logout", function(data, status) {
if (data.code == "200") {
layer.msg( I18n.logout_success );
setTimeout(function(){
window.location.href = base_url + "/";
}, 500);
} else {
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.logout_fail),
icon: '2'
});
}
});
});
});
// slideToTop
var slideToTop = $("<div />");
slideToTop.html('<i class="fa fa-chevron-up"></i>');
slideToTop.css({
position: 'fixed',
bottom: '20px',
right: '25px',
width: '40px',
height: '40px',
color: '#eee',
'font-size': '',
'line-height': '40px',
'text-align': 'center',
'background-color': '#222d32',
cursor: 'pointer',
'border-radius': '5px',
'z-index': '99999',
opacity: '.7',
'display': 'none'
});
slideToTop.on('mouseenter', function () {
$(this).css('opacity', '1');
});
slideToTop.on('mouseout', function () {
$(this).css('opacity', '.7');
});
$('.wrapper').append(slideToTop);
$(window).scroll(function () {
if ($(window).scrollTop() >= 150) {
if (!$(slideToTop).is(':visible')) {
$(slideToTop).fadeIn(500);
}
} else {
$(slideToTop).fadeOut(500);
}
});
$(slideToTop).click(function () {
$("html,body").animate({ // firefox ie not support body, chrome support body. but found that new version chrome not support body too.
scrollTop: 0
}, 100);
});
// left menu status v: js + server + cookie
$('.sidebar-toggle').click(function(){
var xxljob_adminlte_settings = $.cookie('xxljob_adminlte_settings'); // on=openoff=close
if ('off' == xxljob_adminlte_settings) {
xxljob_adminlte_settings = 'on';
} else {
xxljob_adminlte_settings = 'off';
}
$.cookie('xxljob_adminlte_settings', xxljob_adminlte_settings, { expires: 7 }); //$.cookie('the_cookie', '', { expires: -1 });
});
// left menu status v1: js + cookie
/*
var xxljob_adminlte_settings = $.cookie('xxljob_adminlte_settings');
if (xxljob_adminlte_settings == 'off') {
$('body').addClass('sidebar-collapse');
}
*/
// update pwd
$('#updatePwd').on('click', function(){
$('#updatePwdModal').modal({backdrop: false, keyboard: false}).modal('show');
});
var updatePwdModalValidate = $("#updatePwdModal .form").validate({
errorElement : 'span',
errorClass : 'help-block',
focusInvalid : true,
rules : {
password : {
required : true ,
rangelength:[4,50]
}
},
messages : {
password : {
required : '请输入密码' ,
rangelength : "密码长度限制为4~50"
}
},
highlight : function(element) {
$(element).closest('.form-group').addClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error');
label.remove();
},
errorPlacement : function(error, element) {
element.parent('div').append(error);
},
submitHandler : function(form) {
$.post(base_url + "/user/updatePwd", $("#updatePwdModal .form").serialize(), function(data, status) {
if (data.code == 200) {
$('#updatePwdModal').modal('hide');
layer.msg( I18n.change_pwd_suc_to_logout );
setTimeout(function(){
$.post(base_url + "/logout", function(data, status) {
if (data.code == 200) {
window.location.href = base_url + "/";
} else {
layer.open({
icon: '2',
content: (data.msg|| I18n.logout_fail)
});
}
});
}, 500);
} else {
layer.open({
icon: '2',
content: (data.msg|| I18n.change_pwd + I18n.system_fail )
});
}
});
}
});
$("#updatePwdModal").on('hide.bs.modal', function () {
$("#updatePwdModal .form")[0].reset();
updatePwdModalValidate.resetForm();
$("#updatePwdModal .form .form-group").removeClass("has-error");
});
});

View File

@ -0,0 +1,207 @@
/**
* Created by xuxueli on 17/4/24.
*/
$(function () {
// filter Time
var rangesConf = {};
rangesConf[I18n.daterangepicker_ranges_today] = [moment().startOf('day'), moment().endOf('day')];
rangesConf[I18n.daterangepicker_ranges_yesterday] = [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')];
rangesConf[I18n.daterangepicker_ranges_this_month] = [moment().startOf('month'), moment().endOf('month')];
rangesConf[I18n.daterangepicker_ranges_last_month] = [moment().subtract(1, 'months').startOf('month'), moment().subtract(1, 'months').endOf('month')];
rangesConf[I18n.daterangepicker_ranges_recent_week] = [moment().subtract(1, 'weeks').startOf('day'), moment().endOf('day')];
rangesConf[I18n.daterangepicker_ranges_recent_month] = [moment().subtract(1, 'months').startOf('day'), moment().endOf('day')];
$('#filterTime').daterangepicker({
autoApply:false,
singleDatePicker:false,
showDropdowns:false, // 是否显示年月选择条件
timePicker: true, // 是否显示小时和分钟选择条件
timePickerIncrement: 10, // 时间的增量,单位为分钟
timePicker24Hour : true,
opens : 'left', //日期选择框的弹出位置
ranges: rangesConf,
locale : {
format: 'YYYY-MM-DD HH:mm:ss',
separator : ' - ',
customRangeLabel : I18n.daterangepicker_custom_name ,
applyLabel : I18n.system_ok ,
cancelLabel : I18n.system_cancel ,
fromLabel : I18n.daterangepicker_custom_starttime ,
toLabel : I18n.daterangepicker_custom_endtime ,
daysOfWeek : I18n.daterangepicker_custom_daysofweek.split(',') , // '日', '一', '二', '三', '四', '五', '六'
monthNames : I18n.daterangepicker_custom_monthnames.split(',') , // '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'
firstDay : 1
},
startDate: rangesConf[I18n.daterangepicker_ranges_recent_week][0] ,
endDate: rangesConf[I18n.daterangepicker_ranges_recent_week][1]
}, function (start, end, label) {
freshChartDate(start, end);
});
freshChartDate(rangesConf[I18n.daterangepicker_ranges_recent_week][0], rangesConf[I18n.daterangepicker_ranges_recent_week][1]);
/**
* fresh Chart Date
*
* @param startDate
* @param endDate
*/
function freshChartDate(startDate, endDate) {
$.ajax({
type : 'POST',
url : base_url + '/chartInfo',
data : {
'startDate':startDate.format('YYYY-MM-DD HH:mm:ss'),
'endDate':endDate.format('YYYY-MM-DD HH:mm:ss')
},
dataType : "json",
success : function(data){
if (data.code == 200) {
lineChartInit(data)
pieChartInit(data);
} else {
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.job_dashboard_report_loaddata_fail ),
icon: '2'
});
}
}
});
}
/**
* line Chart Init
*/
function lineChartInit(data) {
var option = {
title: {
text: I18n.job_dashboard_date_report
},
tooltip : {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985'
}
}
},
legend: {
data:[I18n.joblog_status_suc, I18n.joblog_status_fail, I18n.joblog_status_running]
},
toolbox: {
feature: {
/*saveAsImage: {}*/
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis : [
{
type : 'category',
boundaryGap : false,
data : data.content.triggerDayList
}
],
yAxis : [
{
type : 'value'
}
],
series : [
{
name:I18n.joblog_status_suc,
type:'line',
stack: 'Total',
areaStyle: {normal: {}},
data: data.content.triggerDayCountSucList
},
{
name:I18n.joblog_status_fail,
type:'line',
stack: 'Total',
label: {
normal: {
show: true,
position: 'top'
}
},
areaStyle: {normal: {}},
data: data.content.triggerDayCountFailList
},
{
name:I18n.joblog_status_running,
type:'line',
stack: 'Total',
areaStyle: {normal: {}},
data: data.content.triggerDayCountRunningList
}
],
color:['#00A65A', '#c23632', '#F39C12']
};
var lineChart = echarts.init(document.getElementById('lineChart'));
lineChart.setOption(option);
}
/**
* pie Chart Init
*/
function pieChartInit(data) {
var option = {
title : {
text: I18n.job_dashboard_rate_report ,
/*subtext: 'subtext',*/
x:'center'
},
tooltip : {
trigger: 'item',
formatter: "{b} : {c} ({d}%)"
},
legend: {
orient: 'vertical',
left: 'left',
data: [I18n.joblog_status_suc, I18n.joblog_status_fail, I18n.joblog_status_running ]
},
series : [
{
//name: '分布比例',
type: 'pie',
radius : '55%',
center: ['50%', '60%'],
data:[
{
name:I18n.joblog_status_suc,
value:data.content.triggerCountSucTotal
},
{
name:I18n.joblog_status_fail,
value:data.content.triggerCountFailTotal
},
{
name:I18n.joblog_status_running,
value:data.content.triggerCountRunningTotal
}
],
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
],
color:['#00A65A', '#c23632', '#F39C12']
};
var pieChart = echarts.init(document.getElementById('pieChart'));
pieChart.setOption(option);
}
});

View File

@ -0,0 +1,97 @@
$(function() {
// init code editor
var codeEditor;
function initIde(glueSource) {
if (codeEditor == null) {
codeEditor = CodeMirror(document.getElementById("ideWindow"), {
mode : ideMode,
lineNumbers : true,
matchBrackets : true,
value: glueSource
});
} else {
codeEditor.setValue(glueSource);
}
}
initIde($("#version_now").val());
// code change
$(".source_version").click(function(){
var sourceId = $(this).attr('version');
var temp = $( "#" + sourceId ).val();
//codeEditor.setValue('');
initIde(temp);
});
// code source save
$("#save").click(function() {
$('#saveModal').modal({backdrop: false, keyboard: false}).modal('show');
});
$("#saveModal .ok").click(function() {
var glueSource = codeEditor.getValue();
var glueRemark = $("#glueRemark").val();
if (!glueRemark) {
layer.open({
title: I18n.system_tips,
btn: [ I18n.system_ok],
content: I18n.system_please_input + I18n.jobinfo_glue_remark ,
icon: '2'
});
return;
}
if (glueRemark.length <4 || glueRemark.length > 100) {
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: I18n.jobinfo_glue_remark_limit ,
icon: '2'
});
return;
}
$.ajax({
type : 'POST',
url : base_url + '/jobcode/save',
data : {
'id' : id,
'glueSource' : glueSource,
'glueRemark' : glueRemark
},
dataType : "json",
success : function(data){
if (data.code == 200) {
layer.open({
title: I18n.system_tips,
btn: [ I18n.system_ok ],
content: (I18n.system_save + I18n.system_success) ,
icon: '1',
end: function(layero, index){
//$(window).unbind('beforeunload');
window.location.reload();
}
});
} else {
layer.open({
title: I18n.system_tips,
btn: [ I18n.system_ok ],
content: (data.msg || (I18n.system_save + I18n.system_fail) ),
icon: '2'
});
}
}
});
});
// before upload
/*$(window).bind('beforeunload',function(){
return 'Glue尚未保存确定离开Glue编辑器';
});*/
});

View File

@ -0,0 +1,359 @@
$(function() {
// init date tables
var jobGroupTable = $("#jobgroup_list").dataTable({
"deferRender": true,
"processing" : true,
"serverSide": true,
"ajax": {
url: base_url + "/jobgroup/pageList",
type:"post",
data : function ( d ) {
var obj = {};
obj.appname = $('#appname').val();
obj.title = $('#title').val();
obj.start = d.start;
obj.length = d.length;
return obj;
}
},
"searching": false,
"ordering": false,
//"scrollX": true, // scroll xclose self-adaption
"columns": [
{
"data": 'id',
"visible" : false
},
{
"data": 'appname',
"visible" : true,
"width":'30%'
},
{
"data": 'title',
"visible" : true,
"width":'30%'
},
{
"data": 'addressType',
"width":'10%',
"visible" : true,
"render": function ( data, type, row ) {
if (row.addressType == 0) {
return I18n.jobgroup_field_addressType_0;
} else {
return I18n.jobgroup_field_addressType_1;
}
}
},
{
"data": 'registryList',
"width":'15%',
"visible" : true,
"render": function ( data, type, row ) {
return row.registryList
?'<a class="show_registryList" href="javascript:;" _id="'+ row.id +'" >'
+ I18n.system_show +' ( ' + row.registryList.length+ ' </a>'
:I18n.system_empty;
}
},
{
"data": I18n.system_opt ,
"width":'15%',
"render": function ( data, type, row ) {
return function(){
// data
tableData['key'+row.id] = row;
// opt
var html = '<div class="btn-group">\n' +
' <button type="button" class="btn btn-primary btn-sm">'+ I18n.system_opt +'</button>\n' +
' <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">\n' +
' <span class="caret"></span>\n' +
' <span class="sr-only">Toggle Dropdown</span>\n' +
' </button>\n' +
' <ul class="dropdown-menu" role="menu" _id="'+ row.id +'" >\n' +
' <li><a href="javascript:void(0);" class="opt_edit" >'+ I18n.system_opt_edit +'</a></li>\n' +
' <li><a href="javascript:void(0);" class="opt_del" >'+ I18n.system_opt_del +'</a></li>\n' +
' </ul>\n' +
' </div>';
return html;
};
}
}
],
"language" : {
"sProcessing" : I18n.dataTable_sProcessing ,
"sLengthMenu" : I18n.dataTable_sLengthMenu ,
"sZeroRecords" : I18n.dataTable_sZeroRecords ,
"sInfo" : I18n.dataTable_sInfo ,
"sInfoEmpty" : I18n.dataTable_sInfoEmpty ,
"sInfoFiltered" : I18n.dataTable_sInfoFiltered ,
"sInfoPostFix" : "",
"sSearch" : I18n.dataTable_sSearch ,
"sUrl" : "",
"sEmptyTable" : I18n.dataTable_sEmptyTable ,
"sLoadingRecords" : I18n.dataTable_sLoadingRecords ,
"sInfoThousands" : ",",
"oPaginate" : {
"sFirst" : I18n.dataTable_sFirst ,
"sPrevious" : I18n.dataTable_sPrevious ,
"sNext" : I18n.dataTable_sNext ,
"sLast" : I18n.dataTable_sLast
},
"oAria" : {
"sSortAscending" : I18n.dataTable_sSortAscending ,
"sSortDescending" : I18n.dataTable_sSortDescending
}
}
});
// table data
var tableData = {};
// search btn
$('#searchBtn').on('click', function(){
jobGroupTable.fnDraw();
});
// job registryinfo
$("#jobgroup_list").on('click', '.show_registryList',function() {
var id = $(this).attr("_id");
var row = tableData['key'+id];
var html = '<div>';
if (row.registryList) {
for (var index in row.registryList) {
html += (parseInt(index)+1) + '. <span class="badge bg-green" >' + row.registryList[index] + '</span><br>';
}
}
html += '</div>';
layer.open({
title: I18n.jobinfo_opt_registryinfo ,
btn: [ I18n.system_ok ],
content: html
});
});
// opt_del
$("#jobgroup_list").on('click', '.opt_del',function() {
var id = $(this).parents('ul').attr("_id");
layer.confirm( (I18n.system_ok + I18n.jobgroup_del + '') , {
icon: 3,
title: I18n.system_tips ,
btn: [ I18n.system_ok, I18n.system_cancel ]
}, function(index){
layer.close(index);
$.ajax({
type : 'POST',
url : base_url + '/jobgroup/remove',
data : {"id":id},
dataType : "json",
success : function(data){
if (data.code == 200) {
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: (I18n.jobgroup_del + I18n.system_success),
icon: '1',
end: function(layero, index){
jobGroupTable.fnDraw();
}
});
} else {
layer.open({
title: I18n.system_tips,
btn: [ I18n.system_ok ],
content: (data.msg || (I18n.jobgroup_del + I18n.system_fail)),
icon: '2'
});
}
},
});
});
});
// jquery.validate “low letters start, limit contants、 letters、numbers and line-through.”
jQuery.validator.addMethod("myValid01", function(value, element) {
var length = value.length;
var valid = /^[a-z][a-zA-Z0-9-]*$/;
return this.optional(element) || valid.test(value);
}, I18n.jobgroup_field_appname_limit );
$('.add').on('click', function(){
$('#addModal').modal({backdrop: false, keyboard: false}).modal('show');
});
var addModalValidate = $("#addModal .form").validate({
errorElement : 'span',
errorClass : 'help-block',
focusInvalid : true,
rules : {
appname : {
required : true,
rangelength:[4,64],
myValid01 : true
},
title : {
required : true,
rangelength:[4, 12]
}
},
messages : {
appname : {
required : I18n.system_please_input+"AppName",
rangelength: I18n.jobgroup_field_appname_length ,
myValid01: I18n.jobgroup_field_appname_limit
},
title : {
required : I18n.system_please_input + I18n.jobgroup_field_title ,
rangelength: I18n.jobgroup_field_title_length
}
},
highlight : function(element) {
$(element).closest('.form-group').addClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error');
label.remove();
},
errorPlacement : function(error, element) {
element.parent('div').append(error);
},
submitHandler : function(form) {
$.post(base_url + "/jobgroup/save", $("#addModal .form").serialize(), function(data, status) {
if (data.code == "200") {
$('#addModal').modal('hide');
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: I18n.system_add_suc ,
icon: '1',
end: function(layero, index){
jobGroupTable.fnDraw();
}
});
} else {
layer.open({
title: I18n.system_tips,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.system_add_fail ),
icon: '2'
});
}
});
}
});
$("#addModal").on('hide.bs.modal', function () {
$("#addModal .form")[0].reset();
addModalValidate.resetForm();
$("#addModal .form .form-group").removeClass("has-error");
});
// addressType change
$("#addModal input[name=addressType], #updateModal input[name=addressType]").click(function(){
var addressType = $(this).val();
var $addressList = $(this).parents("form").find("textarea[name=addressList]");
if (addressType == 0) {
$addressList.css("background-color", "#eee"); // 自动注册
$addressList.attr("readonly","readonly");
$addressList.val("");
} else {
$addressList.css("background-color", "white");
$addressList.removeAttr("readonly");
}
});
// opt_edit
$("#jobgroup_list").on('click', '.opt_edit',function() {
var id = $(this).parents('ul').attr("_id");
var row = tableData['key'+id];
$("#updateModal .form input[name='id']").val( row.id );
$("#updateModal .form input[name='appname']").val( row.appname );
$("#updateModal .form input[name='title']").val( row.title );
// 注册方式
$("#updateModal .form input[name='addressType']").removeAttr('checked');
$("#updateModal .form input[name='addressType'][value='"+ row.addressType +"']").click();
// 机器地址
$("#updateModal .form textarea[name='addressList']").val( row.addressList );
$('#updateModal').modal({backdrop: false, keyboard: false}).modal('show');
});
var updateModalValidate = $("#updateModal .form").validate({
errorElement : 'span',
errorClass : 'help-block',
focusInvalid : true,
rules : {
appname : {
required : true,
rangelength:[4,64],
myValid01 : true
},
title : {
required : true,
rangelength:[4, 12]
}
},
messages : {
appname : {
required : I18n.system_please_input+"AppName",
rangelength: I18n.jobgroup_field_appname_length ,
myValid01: I18n.jobgroup_field_appname_limit
},
title : {
required : I18n.system_please_input + I18n.jobgroup_field_title ,
rangelength: I18n.jobgroup_field_title_length
}
},
highlight : function(element) {
$(element).closest('.form-group').addClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error');
label.remove();
},
errorPlacement : function(error, element) {
element.parent('div').append(error);
},
submitHandler : function(form) {
$.post(base_url + "/jobgroup/update", $("#updateModal .form").serialize(), function(data, status) {
if (data.code == "200") {
$('#updateModal').modal('hide');
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: I18n.system_update_suc ,
icon: '1',
end: function(layero, index){
jobGroupTable.fnDraw();
}
});
} else {
layer.open({
title: I18n.system_tips,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.system_update_fail ),
icon: '2'
});
}
});
}
});
$("#updateModal").on('hide.bs.modal', function () {
$("#updateModal .form")[0].reset();
addModalValidate.resetForm();
$("#updateModal .form .form-group").removeClass("has-error");
});
});

View File

@ -0,0 +1,739 @@
$(function() {
// init date tables
var jobTable = $("#job_list").dataTable({
"deferRender": true,
"processing" : true,
"serverSide": true,
"ajax": {
url: base_url + "/jobinfo/pageList",
type:"post",
data : function ( d ) {
var obj = {};
obj.jobGroup = $('#jobGroup').val();
obj.triggerStatus = $('#triggerStatus').val();
obj.jobDesc = $('#jobDesc').val();
obj.executorHandler = $('#executorHandler').val();
obj.author = $('#author').val();
obj.start = d.start;
obj.length = d.length;
return obj;
}
},
"searching": false,
"ordering": false,
//"scrollX": true, // scroll xclose self-adaption
"columns": [
{
"data": 'id',
"bSortable": false,
"visible" : true,
"width":'7%'
},
{
"data": 'jobGroup',
"visible" : false,
"render": function ( data, type, row ) {
var groupMenu = $("#jobGroup").find("option");
for ( var index in $("#jobGroup").find("option")) {
if ($(groupMenu[index]).attr('value') == data) {
return $(groupMenu[index]).html();
}
}
return data;
}
},
{
"data": 'jobDesc',
"visible" : true,
"width":'25%'
},
{
"data": 'scheduleType',
"visible" : true,
"width":'13%',
"render": function ( data, type, row ) {
if (row.scheduleConf) {
return row.scheduleType + ''+ row.scheduleConf;
} else {
return row.scheduleType;
}
}
},
{
"data": 'glueType',
"width":'25%',
"visible" : true,
"render": function ( data, type, row ) {
var glueTypeTitle = findGlueTypeTitle(row.glueType);
if (row.executorHandler) {
return glueTypeTitle +"" + row.executorHandler;
} else {
return glueTypeTitle;
}
}
},
{ "data": 'executorParam', "visible" : false},
{
"data": 'addTime',
"visible" : false,
"render": function ( data, type, row ) {
return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
}
},
{
"data": 'updateTime',
"visible" : false,
"render": function ( data, type, row ) {
return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
}
},
{ "data": 'author', "visible" : true, "width":'10%'},
{ "data": 'alarmEmail', "visible" : false},
{
"data": 'triggerStatus',
"width":'10%',
"visible" : true,
"render": function ( data, type, row ) {
// status
if (1 == data) {
return '<small class="label label-success" >RUNNING</small>';
} else {
return '<small class="label label-default" >STOP</small>';
}
return data;
}
},
{
"data": I18n.system_opt ,
"width":'10%',
"render": function ( data, type, row ) {
return function(){
// status
var start_stop_div = "";
if (1 == row.triggerStatus ) {
start_stop_div = '<li><a href="javascript:void(0);" class="job_operate" _type="job_pause" >'+ I18n.jobinfo_opt_stop +'</a></li>\n';
} else {
start_stop_div = '<li><a href="javascript:void(0);" class="job_operate" _type="job_resume" >'+ I18n.jobinfo_opt_start +'</a></li>\n';
}
// job_next_time_html
var job_next_time_html = '';
if (row.scheduleType == 'CRON' || row.scheduleType == 'FIX_RATE') {
job_next_time_html = '<li><a href="javascript:void(0);" class="job_next_time" >' + I18n.jobinfo_opt_next_time + '</a></li>\n';
}
// log url
var logHref = base_url +'/joblog?jobId='+ row.id;
// code url
var codeBtn = "";
if ('BEAN' != row.glueType) {
var codeUrl = base_url +'/jobcode?jobId='+ row.id;
codeBtn = '<li><a href="'+ codeUrl +'" target="_blank" >GLUE IDE</a></li>\n';
codeBtn += '<li class="divider"></li>\n';
}
// data
tableData['key'+row.id] = row;
// opt
var html = '<div class="btn-group">\n' +
' <button type="button" class="btn btn-primary btn-sm">'+ I18n.system_opt +'</button>\n' +
' <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">\n' +
' <span class="caret"></span>\n' +
' <span class="sr-only">Toggle Dropdown</span>\n' +
' </button>\n' +
' <ul class="dropdown-menu" role="menu" _id="'+ row.id +'" >\n' +
' <li><a href="javascript:void(0);" class="job_trigger" >'+ I18n.jobinfo_opt_run +'</a></li>\n' +
' <li><a href="'+ logHref +'">'+ I18n.jobinfo_opt_log +'</a></li>\n' +
' <li><a href="javascript:void(0);" class="job_registryinfo" >' + I18n.jobinfo_opt_registryinfo + '</a></li>\n' +
job_next_time_html +
' <li class="divider"></li>\n' +
codeBtn +
start_stop_div +
' <li><a href="javascript:void(0);" class="update" >'+ I18n.system_opt_edit +'</a></li>\n' +
' <li><a href="javascript:void(0);" class="job_operate" _type="job_del" >'+ I18n.system_opt_del +'</a></li>\n' +
' <li><a href="javascript:void(0);" class="job_copy" >'+ I18n.system_opt_copy +'</a></li>\n' +
' </ul>\n' +
' </div>';
return html;
};
}
}
],
"language" : {
"sProcessing" : I18n.dataTable_sProcessing ,
"sLengthMenu" : I18n.dataTable_sLengthMenu ,
"sZeroRecords" : I18n.dataTable_sZeroRecords ,
"sInfo" : I18n.dataTable_sInfo ,
"sInfoEmpty" : I18n.dataTable_sInfoEmpty ,
"sInfoFiltered" : I18n.dataTable_sInfoFiltered ,
"sInfoPostFix" : "",
"sSearch" : I18n.dataTable_sSearch ,
"sUrl" : "",
"sEmptyTable" : I18n.dataTable_sEmptyTable ,
"sLoadingRecords" : I18n.dataTable_sLoadingRecords ,
"sInfoThousands" : ",",
"oPaginate" : {
"sFirst" : I18n.dataTable_sFirst ,
"sPrevious" : I18n.dataTable_sPrevious ,
"sNext" : I18n.dataTable_sNext ,
"sLast" : I18n.dataTable_sLast
},
"oAria" : {
"sSortAscending" : I18n.dataTable_sSortAscending ,
"sSortDescending" : I18n.dataTable_sSortDescending
}
}
});
// table data
var tableData = {};
// search btn
$('#searchBtn').on('click', function(){
jobTable.fnDraw();
});
// jobGroup change
$('#jobGroup').on('change', function(){
//reload
var jobGroup = $('#jobGroup').val();
window.location.href = base_url + "/jobinfo?jobGroup=" + jobGroup;
});
// job operate
$("#job_list").on('click', '.job_operate',function() {
var typeName;
var url;
var needFresh = false;
var type = $(this).attr("_type");
if ("job_pause" == type) {
typeName = I18n.jobinfo_opt_stop ;
url = base_url + "/jobinfo/stop";
needFresh = true;
} else if ("job_resume" == type) {
typeName = I18n.jobinfo_opt_start ;
url = base_url + "/jobinfo/start";
needFresh = true;
} else if ("job_del" == type) {
typeName = I18n.system_opt_del ;
url = base_url + "/jobinfo/remove";
needFresh = true;
} else {
return;
}
var id = $(this).parents('ul').attr("_id");
layer.confirm( I18n.system_ok + typeName + '?', {
icon: 3,
title: I18n.system_tips ,
btn: [ I18n.system_ok, I18n.system_cancel ]
}, function(index){
layer.close(index);
$.ajax({
type : 'POST',
url : url,
data : {
"id" : id
},
dataType : "json",
success : function(data){
if (data.code == 200) {
layer.msg( typeName + I18n.system_success );
if (needFresh) {
//window.location.reload();
jobTable.fnDraw(false);
}
} else {
layer.msg( data.msg || typeName + I18n.system_fail );
}
}
});
});
});
// job trigger
$("#job_list").on('click', '.job_trigger',function() {
var id = $(this).parents('ul').attr("_id");
var row = tableData['key'+id];
$("#jobTriggerModal .form input[name='id']").val( row.id );
$("#jobTriggerModal .form textarea[name='executorParam']").val( row.executorParam );
$('#jobTriggerModal').modal({backdrop: false, keyboard: false}).modal('show');
});
$("#jobTriggerModal .ok").on('click',function() {
$.ajax({
type : 'POST',
url : base_url + "/jobinfo/trigger",
data : {
"id" : $("#jobTriggerModal .form input[name='id']").val(),
"executorParam" : $("#jobTriggerModal .textarea[name='executorParam']").val(),
"addressList" : $("#jobTriggerModal .textarea[name='addressList']").val()
},
dataType : "json",
success : function(data){
if (data.code == 200) {
$('#jobTriggerModal').modal('hide');
layer.msg( I18n.jobinfo_opt_run + I18n.system_success );
} else {
layer.msg( data.msg || I18n.jobinfo_opt_run + I18n.system_fail );
}
}
});
});
$("#jobTriggerModal").on('hide.bs.modal', function () {
$("#jobTriggerModal .form")[0].reset();
});
// job registryinfo
$("#job_list").on('click', '.job_registryinfo',function() {
var id = $(this).parents('ul').attr("_id");
var row = tableData['key'+id];
var jobGroup = row.jobGroup;
$.ajax({
type : 'POST',
url : base_url + "/jobgroup/loadById",
data : {
"id" : jobGroup
},
dataType : "json",
success : function(data){
var html = '<div>';
if (data.code == 200 && data.content.registryList) {
for (var index in data.content.registryList) {
html += (parseInt(index)+1) + '. <span class="badge bg-green" >' + data.content.registryList[index] + '</span><br>';
}
}
html += '</div>';
layer.open({
title: I18n.jobinfo_opt_registryinfo ,
btn: [ I18n.system_ok ],
content: html
});
}
});
});
// job_next_time
$("#job_list").on('click', '.job_next_time',function() {
var id = $(this).parents('ul').attr("_id");
var row = tableData['key'+id];
$.ajax({
type : 'POST',
url : base_url + "/jobinfo/nextTriggerTime",
data : {
"scheduleType" : row.scheduleType,
"scheduleConf" : row.scheduleConf
},
dataType : "json",
success : function(data){
if (data.code != 200) {
layer.open({
title: I18n.jobinfo_opt_next_time ,
btn: [ I18n.system_ok ],
content: data.msg
});
} else {
var html = '<center>';
if (data.code == 200 && data.content) {
for (var index in data.content) {
html += '<span>' + data.content[index] + '</span><br>';
}
}
html += '</center>';
layer.open({
title: I18n.jobinfo_opt_next_time ,
btn: [ I18n.system_ok ],
content: html
});
}
}
});
});
// add
$(".add").click(function(){
// init-cronGen
$("#addModal .form input[name='schedule_conf_CRON']").show().siblings().remove();
$("#addModal .form input[name='schedule_conf_CRON']").cronGen({});
// 》init scheduleType
$("#updateModal .form select[name=scheduleType]").change();
// 》init glueType
$("#updateModal .form select[name=glueType]").change();
$('#addModal').modal({backdrop: false, keyboard: false}).modal('show');
});
var addModalValidate = $("#addModal .form").validate({
errorElement : 'span',
errorClass : 'help-block',
focusInvalid : true,
rules : {
jobDesc : {
required : true,
maxlength: 50
},
author : {
required : true
}/*,
executorTimeout : {
digits:true
},
executorFailRetryCount : {
digits:true
}*/
},
messages : {
jobDesc : {
required : I18n.system_please_input + I18n.jobinfo_field_jobdesc
},
author : {
required : I18n.system_please_input + I18n.jobinfo_field_author
}/*,
executorTimeout : {
digits: I18n.system_please_input + I18n.system_digits
},
executorFailRetryCount : {
digits: I18n.system_please_input + I18n.system_digits
}*/
},
highlight : function(element) {
$(element).closest('.form-group').addClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error');
label.remove();
},
errorPlacement : function(error, element) {
element.parent('div').append(error);
},
submitHandler : function(form) {
// process executorTimeout+executorFailRetryCount
var executorTimeout = $("#addModal .form input[name='executorTimeout']").val();
if(!/^\d+$/.test(executorTimeout)) {
executorTimeout = 0;
}
$("#addModal .form input[name='executorTimeout']").val(executorTimeout);
var executorFailRetryCount = $("#addModal .form input[name='executorFailRetryCount']").val();
if(!/^\d+$/.test(executorFailRetryCount)) {
executorFailRetryCount = 0;
}
$("#addModal .form input[name='executorFailRetryCount']").val(executorFailRetryCount);
// process schedule_conf
var scheduleType = $("#addModal .form select[name='scheduleType']").val();
var scheduleConf;
if (scheduleType == 'CRON') {
scheduleConf = $("#addModal .form input[name='cronGen_display']").val();
} else if (scheduleType == 'FIX_RATE') {
scheduleConf = $("#addModal .form input[name='schedule_conf_FIX_RATE']").val();
} else if (scheduleType == 'FIX_DELAY') {
scheduleConf = $("#addModal .form input[name='schedule_conf_FIX_DELAY']").val();
}
$("#addModal .form input[name='scheduleConf']").val( scheduleConf );
$.post(base_url + "/jobinfo/add", $("#addModal .form").serialize(), function(data, status) {
if (data.code == "200") {
$('#addModal').modal('hide');
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: I18n.system_add_suc ,
icon: '1',
end: function(layero, index){
jobTable.fnDraw();
//window.location.reload();
}
});
} else {
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.system_add_fail),
icon: '2'
});
}
});
}
});
$("#addModal").on('hide.bs.modal', function () {
addModalValidate.resetForm();
$("#addModal .form")[0].reset();
$("#addModal .form .form-group").removeClass("has-error");
$(".remote_panel").show(); // remote
$("#addModal .form input[name='executorHandler']").removeAttr("readonly");
});
// scheduleType change
$(".scheduleType").change(function(){
var scheduleType = $(this).val();
$(this).parents("form").find(".schedule_conf").hide();
$(this).parents("form").find(".schedule_conf_" + scheduleType).show();
});
// glueType change
$(".glueType").change(function(){
// executorHandler
var $executorHandler = $(this).parents("form").find("input[name='executorHandler']");
var glueType = $(this).val();
if ('BEAN' != glueType) {
$executorHandler.val("");
$executorHandler.attr("readonly","readonly");
} else {
$executorHandler.removeAttr("readonly");
}
});
$("#addModal .glueType").change(function(){
// glueSource
var glueType = $(this).val();
if ('GLUE_GROOVY'==glueType){
$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_java").val() );
} else if ('GLUE_SHELL'==glueType){
$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_shell").val() );
} else if ('GLUE_PYTHON'==glueType){
$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_python").val() );
} else if ('GLUE_PHP'==glueType){
$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_php").val() );
} else if ('GLUE_NODEJS'==glueType){
$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_nodejs").val() );
} else if ('GLUE_POWERSHELL'==glueType){
$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_powershell").val() );
} else {
$("#addModal .form textarea[name='glueSource']").val("");
}
});
// update
$("#job_list").on('click', '.update',function() {
var id = $(this).parents('ul').attr("_id");
var row = tableData['key'+id];
// fill base
$("#updateModal .form input[name='id']").val( row.id );
$('#updateModal .form select[name=jobGroup] option[value='+ row.jobGroup +']').prop('selected', true);
$("#updateModal .form input[name='jobDesc']").val( row.jobDesc );
$("#updateModal .form input[name='author']").val( row.author );
$("#updateModal .form input[name='alarmEmail']").val( row.alarmEmail );
// fill trigger
$('#updateModal .form select[name=scheduleType] option[value='+ row.scheduleType +']').prop('selected', true);
$("#updateModal .form input[name='scheduleConf']").val( row.scheduleConf );
if (row.scheduleType == 'CRON') {
$("#updateModal .form input[name='schedule_conf_CRON']").val( row.scheduleConf );
} else if (row.scheduleType == 'FIX_RATE') {
$("#updateModal .form input[name='schedule_conf_FIX_RATE']").val( row.scheduleConf );
} else if (row.scheduleType == 'FIX_DELAY') {
$("#updateModal .form input[name='schedule_conf_FIX_DELAY']").val( row.scheduleConf );
}
// 》init scheduleType
$("#updateModal .form select[name=scheduleType]").change();
// fill job
$('#updateModal .form select[name=glueType] option[value='+ row.glueType +']').prop('selected', true);
$("#updateModal .form input[name='executorHandler']").val( row.executorHandler );
$("#updateModal .form textarea[name='executorParam']").val( row.executorParam );
// 》init glueType
$("#updateModal .form select[name=glueType]").change();
// 》init-cronGen
$("#updateModal .form input[name='schedule_conf_CRON']").show().siblings().remove();
$("#updateModal .form input[name='schedule_conf_CRON']").cronGen({});
// fill advanced
$('#updateModal .form select[name=executorRouteStrategy] option[value='+ row.executorRouteStrategy +']').prop('selected', true);
$("#updateModal .form input[name='childJobId']").val( row.childJobId );
$('#updateModal .form select[name=misfireStrategy] option[value='+ row.misfireStrategy +']').prop('selected', true);
$('#updateModal .form select[name=executorBlockStrategy] option[value='+ row.executorBlockStrategy +']').prop('selected', true);
$("#updateModal .form input[name='executorTimeout']").val( row.executorTimeout );
$("#updateModal .form input[name='executorFailRetryCount']").val( row.executorFailRetryCount );
// show
$('#updateModal').modal({backdrop: false, keyboard: false}).modal('show');
});
var updateModalValidate = $("#updateModal .form").validate({
errorElement : 'span',
errorClass : 'help-block',
focusInvalid : true,
rules : {
jobDesc : {
required : true,
maxlength: 50
},
author : {
required : true
}
},
messages : {
jobDesc : {
required : I18n.system_please_input + I18n.jobinfo_field_jobdesc
},
author : {
required : I18n.system_please_input + I18n.jobinfo_field_author
}
},
highlight : function(element) {
$(element).closest('.form-group').addClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error');
label.remove();
},
errorPlacement : function(error, element) {
element.parent('div').append(error);
},
submitHandler : function(form) {
// process executorTimeout + executorFailRetryCount
var executorTimeout = $("#updateModal .form input[name='executorTimeout']").val();
if(!/^\d+$/.test(executorTimeout)) {
executorTimeout = 0;
}
$("#updateModal .form input[name='executorTimeout']").val(executorTimeout);
var executorFailRetryCount = $("#updateModal .form input[name='executorFailRetryCount']").val();
if(!/^\d+$/.test(executorFailRetryCount)) {
executorFailRetryCount = 0;
}
$("#updateModal .form input[name='executorFailRetryCount']").val(executorFailRetryCount);
// process schedule_conf
var scheduleType = $("#updateModal .form select[name='scheduleType']").val();
var scheduleConf;
if (scheduleType == 'CRON') {
scheduleConf = $("#updateModal .form input[name='cronGen_display']").val();
} else if (scheduleType == 'FIX_RATE') {
scheduleConf = $("#updateModal .form input[name='schedule_conf_FIX_RATE']").val();
} else if (scheduleType == 'FIX_DELAY') {
scheduleConf = $("#updateModal .form input[name='schedule_conf_FIX_DELAY']").val();
}
$("#updateModal .form input[name='scheduleConf']").val( scheduleConf );
// post
$.post(base_url + "/jobinfo/update", $("#updateModal .form").serialize(), function(data, status) {
if (data.code == "200") {
$('#updateModal').modal('hide');
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: I18n.system_update_suc ,
icon: '1',
end: function(layero, index){
//window.location.reload();
jobTable.fnDraw();
}
});
} else {
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.system_update_fail ),
icon: '2'
});
}
});
}
});
$("#updateModal").on('hide.bs.modal', function () {
updateModalValidate.resetForm();
$("#updateModal .form")[0].reset();
$("#updateModal .form .form-group").removeClass("has-error");
});
/**
* find title by name, GlueType
*/
function findGlueTypeTitle(glueType) {
var glueTypeTitle;
$("#addModal .form select[name=glueType] option").each(function () {
var name = $(this).val();
var title = $(this).text();
if (glueType == name) {
glueTypeTitle = title;
return false
}
});
return glueTypeTitle;
}
// job_copy
$("#job_list").on('click', '.job_copy',function() {
var id = $(this).parents('ul').attr("_id");
var row = tableData['key'+id];
// fill base
$('#addModal .form select[name=jobGroup] option[value='+ row.jobGroup +']').prop('selected', true);
$("#addModal .form input[name='jobDesc']").val( row.jobDesc );
$("#addModal .form input[name='author']").val( row.author );
$("#addModal .form input[name='alarmEmail']").val( row.alarmEmail );
// fill trigger
$('#addModal .form select[name=scheduleType] option[value='+ row.scheduleType +']').prop('selected', true);
$("#addModal .form input[name='scheduleConf']").val( row.scheduleConf );
if (row.scheduleType == 'CRON') {
$("#addModal .form input[name='schedule_conf_CRON']").val( row.scheduleConf );
} else if (row.scheduleType == 'FIX_RATE') {
$("#addModal .form input[name='schedule_conf_FIX_RATE']").val( row.scheduleConf );
} else if (row.scheduleType == 'FIX_DELAY') {
$("#addModal .form input[name='schedule_conf_FIX_DELAY']").val( row.scheduleConf );
}
// 》init scheduleType
$("#addModal .form select[name=scheduleType]").change();
// fill job
$('#addModal .form select[name=glueType] option[value='+ row.glueType +']').prop('selected', true);
$("#addModal .form input[name='executorHandler']").val( row.executorHandler );
$("#addModal .form textarea[name='executorParam']").val( row.executorParam );
// 》init glueType
$("#addModal .form select[name=glueType]").change();
// 》init-cronGen
$("#addModal .form input[name='schedule_conf_CRON']").show().siblings().remove();
$("#addModal .form input[name='schedule_conf_CRON']").cronGen({});
// fill advanced
$('#addModal .form select[name=executorRouteStrategy] option[value='+ row.executorRouteStrategy +']').prop('selected', true);
$("#addModal .form input[name='childJobId']").val( row.childJobId );
$('#addModal .form select[name=misfireStrategy] option[value='+ row.misfireStrategy +']').prop('selected', true);
$('#addModal .form select[name=executorBlockStrategy] option[value='+ row.executorBlockStrategy +']').prop('selected', true);
$("#addModal .form input[name='executorTimeout']").val( row.executorTimeout );
$("#addModal .form input[name='executorFailRetryCount']").val( row.executorFailRetryCount );
// show
$('#addModal').modal({backdrop: false, keyboard: false}).modal('show');
});
});

View File

@ -0,0 +1,91 @@
$(function() {
// trigger fail, end
if ( !(triggerCode == 200 || handleCode != 0) ) {
$('#logConsoleRunning').hide();
$('#logConsole').append('<span style="color: red;">'+ I18n.joblog_rolling_log_triggerfail +'</span>');
return;
}
// pull log
var fromLineNum = 1; // [from, to], start as 1
var pullFailCount = 0;
function pullLog() {
// pullFailCount, max=20
if (pullFailCount++ > 20) {
logRunStop('<span style="color: red;">'+ I18n.joblog_rolling_log_failoften +'</span>');
return;
}
// load
console.log("pullLog, fromLineNum:" + fromLineNum);
$.ajax({
type : 'POST',
async: false, // sync, make log ordered
url : base_url + '/joblog/logDetailCat',
data : {
"executorAddress":executorAddress,
"triggerTime":triggerTime,
"logId":logId,
"fromLineNum":fromLineNum
},
dataType : "json",
success : function(data){
if (data.code == 200) {
if (!data.content) {
console.log('pullLog fail');
return;
}
if (fromLineNum != data.content.fromLineNum) {
console.log('pullLog fromLineNum not match');
return;
}
if (fromLineNum > data.content.toLineNum ) {
console.log('pullLog already line-end');
// valid end
if (data.content.end) {
logRunStop('<br><span style="color: green;">[Rolling Log Finish]</span>');
return;
}
return;
}
// append content
fromLineNum = data.content.toLineNum + 1;
$('#logConsole').append(data.content.logContent);
pullFailCount = 0;
// scroll to bottom
scrollTo(0, document.body.scrollHeight); // $('#logConsolePre').scrollTop( document.body.scrollHeight + 300 );
} else {
console.log('pullLog fail:'+data.msg);
}
}
});
}
// pull first page
pullLog();
// handler already callback, end
if (handleCode > 0) {
logRunStop('<br><span style="color: green;">[Load Log Finish]</span>');
return;
}
// round until end
var logRun = setInterval(function () {
pullLog()
}, 3000);
function logRunStop(content){
$('#logConsoleRunning').hide();
logRun = window.clearInterval(logRun);
$('#logConsole').append(content);
}
});

View File

@ -0,0 +1,396 @@
$(function() {
// jobGroup change, job list init and select
$("#jobGroup").on("change", function () {
var jobGroup = $(this).children('option:selected').val();
$.ajax({
type : 'POST',
async: false, // async, avoid js invoke pagelist before jobId data init
url : base_url + '/joblog/getJobsByGroup',
data : {"jobGroup":jobGroup},
dataType : "json",
success : function(data){
if (data.code == 200) {
$("#jobId").html( '<option value="0" >'+ I18n.system_all +'</option>' );
$.each(data.content, function (n, value) {
$("#jobId").append('<option value="' + value.id + '" >' + value.jobDesc + '</option>');
});
if ($("#jobId").attr("paramVal")){
$("#jobId").find("option[value='" + $("#jobId").attr("paramVal") + "']").attr("selected",true);
}
} else {
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.system_api_error ),
icon: '2'
});
}
},
});
});
if ($("#jobGroup").attr("paramVal")){
$("#jobGroup").find("option[value='" + $("#jobGroup").attr("paramVal") + "']").attr("selected",true);
$("#jobGroup").change();
}
// filter Time
var rangesConf = {};
rangesConf[I18n.daterangepicker_ranges_recent_hour] = [moment().subtract(1, 'hours'), moment()];
rangesConf[I18n.daterangepicker_ranges_today] = [moment().startOf('day'), moment().endOf('day')];
rangesConf[I18n.daterangepicker_ranges_yesterday] = [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')];
rangesConf[I18n.daterangepicker_ranges_this_month] = [moment().startOf('month'), moment().endOf('month')];
rangesConf[I18n.daterangepicker_ranges_last_month] = [moment().subtract(1, 'months').startOf('month'), moment().subtract(1, 'months').endOf('month')];
rangesConf[I18n.daterangepicker_ranges_recent_week] = [moment().subtract(1, 'weeks').startOf('day'), moment().endOf('day')];
rangesConf[I18n.daterangepicker_ranges_recent_month] = [moment().subtract(1, 'months').startOf('day'), moment().endOf('day')];
$('#filterTime').daterangepicker({
autoApply:false,
singleDatePicker:false,
showDropdowns:false, // 是否显示年月选择条件
timePicker: true, // 是否显示小时和分钟选择条件
timePickerIncrement: 10, // 时间的增量,单位为分钟
timePicker24Hour : true,
opens : 'left', //日期选择框的弹出位置
ranges: rangesConf,
locale : {
format: 'YYYY-MM-DD HH:mm:ss',
separator : ' - ',
customRangeLabel : I18n.daterangepicker_custom_name ,
applyLabel : I18n.system_ok ,
cancelLabel : I18n.system_cancel ,
fromLabel : I18n.daterangepicker_custom_starttime ,
toLabel : I18n.daterangepicker_custom_endtime ,
daysOfWeek : I18n.daterangepicker_custom_daysofweek.split(',') , // '日', '一', '二', '三', '四', '五', '六'
monthNames : I18n.daterangepicker_custom_monthnames.split(',') , // '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'
firstDay : 1
},
startDate: rangesConf[I18n.daterangepicker_ranges_today][0],
endDate: rangesConf[I18n.daterangepicker_ranges_today][1]
});
// init date tables
var logTable = $("#joblog_list").dataTable({
"deferRender": true,
"processing" : true,
"serverSide": true,
"ajax": {
url: base_url + "/joblog/pageList" ,
type:"post",
data : function ( d ) {
var obj = {};
obj.jobGroup = $('#jobGroup').val();
obj.jobId = $('#jobId').val();
obj.logStatus = $('#logStatus').val();
obj.filterTime = $('#filterTime').val();
obj.start = d.start;
obj.length = d.length;
return obj;
}
},
"searching": false,
"ordering": false,
//"scrollX": false,
"columns": [
{
"data": 'jobId',
"visible" : true,
"width":'10%',
"render": function ( data, type, row ) {
var jobhandler = '';
if (row.executorHandler) {
jobhandler = "<br>JobHandler" + row.executorHandler;
}
var temp = '';
temp += I18n.joblog_field_executorAddress + '' + (row.executorAddress?row.executorAddress:'');
temp += jobhandler;
temp += '<br>'+ I18n.jobinfo_field_executorparam +'' + row.executorParam;
return '<a class="logTips" href="javascript:;" >'+ row.jobId +'<span style="display:none;">'+ temp +'</span></a>';
}
},
{ "data": 'jobGroup', "visible" : false},
{
"data": 'triggerTime',
"width":'20%',
"render": function ( data, type, row ) {
return data?moment(data).format("YYYY-MM-DD HH:mm:ss"):"";
}
},
{
"data": 'triggerCode',
"width":'10%',
"render": function ( data, type, row ) {
var html = data;
if (data == 200) {
html = '<span style="color: green">'+ I18n.system_success +'</span>';
} else if (data == 500) {
html = '<span style="color: red">'+ I18n.system_fail +'</span>';
} else if (data == 0) {
html = '';
}
return html;
}
},
{
"data": 'triggerMsg',
"width":'10%',
"render": function ( data, type, row ) {
return data?'<a class="logTips" href="javascript:;" >'+ I18n.system_show +'<span style="display:none;">'+ data +'</span></a>':I18n.system_empty;
}
},
{
"data": 'handleTime',
"width":'20%',
"render": function ( data, type, row ) {
return data?moment(data).format("YYYY-MM-DD HH:mm:ss"):"";
}
},
{
"data": 'handleCode',
"width":'10%',
"render": function ( data, type, row ) {
var html = data;
if (data == 200) {
html = '<span style="color: green">'+ I18n.joblog_handleCode_200 +'</span>';
} else if (data == 500) {
html = '<span style="color: red">'+ I18n.joblog_handleCode_500 +'</span>';
} else if (data == 502) {
html = '<span style="color: red">'+ I18n.joblog_handleCode_502 +'</span>';
} else if (data == 0) {
html = '';
}
return html;
}
},
{
"data": 'handleMsg',
"width":'10%',
"render": function ( data, type, row ) {
return data?'<a class="logTips" href="javascript:;" >'+ I18n.system_show +'<span style="display:none;">'+ data +'</span></a>':I18n.system_empty;
}
},
{
"data": 'handleMsg' ,
"bSortable": false,
"width":'10%',
"render": function ( data, type, row ) {
// better support expression or string, not function
return function () {
if (row.triggerCode == 200 || row.handleCode != 0){
/*var temp = '<a href="javascript:;" class="logDetail" _id="'+ row.id +'">'+ I18n.joblog_rolling_log +'</a>';
if(row.handleCode == 0){
temp += '<br><a href="javascript:;" class="logKill" _id="'+ row.id +'" style="color: red;" >'+ I18n.joblog_kill_log +'</a>';
}*/
//return temp;
var logKillDiv = '';
if(row.handleCode == 0){
logKillDiv = ' <li class="divider"></li>\n' +
' <li><a href="javascript:void(0);" class="logKill" _id="'+ row.id +'" >'+ I18n.joblog_kill_log +'</a></li>\n';
}
var html = '<div class="btn-group">\n' +
' <button type="button" class="btn btn-primary btn-sm">'+ I18n.system_opt +'</button>\n' +
' <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">\n' +
' <span class="caret"></span>\n' +
' <span class="sr-only">Toggle Dropdown</span>\n' +
' </button>\n' +
' <ul class="dropdown-menu" role="menu" _id="'+ row.id +'" >\n' +
' <li><a href="javascript:void(0);" class="logDetail" _id="'+ row.id +'" >'+ I18n.joblog_rolling_log +'</a></li>\n' +
logKillDiv +
' </ul>\n' +
' </div>';
return html;
}
return null;
}
}
}
],
"language" : {
"sProcessing" : I18n.dataTable_sProcessing ,
"sLengthMenu" : I18n.dataTable_sLengthMenu ,
"sZeroRecords" : I18n.dataTable_sZeroRecords ,
"sInfo" : I18n.dataTable_sInfo ,
"sInfoEmpty" : I18n.dataTable_sInfoEmpty ,
"sInfoFiltered" : I18n.dataTable_sInfoFiltered ,
"sInfoPostFix" : "",
"sSearch" : I18n.dataTable_sSearch ,
"sUrl" : "",
"sEmptyTable" : I18n.dataTable_sEmptyTable ,
"sLoadingRecords" : I18n.dataTable_sLoadingRecords ,
"sInfoThousands" : ",",
"oPaginate" : {
"sFirst" : I18n.dataTable_sFirst ,
"sPrevious" : I18n.dataTable_sPrevious ,
"sNext" : I18n.dataTable_sNext ,
"sLast" : I18n.dataTable_sLast
},
"oAria" : {
"sSortAscending" : I18n.dataTable_sSortAscending ,
"sSortDescending" : I18n.dataTable_sSortDescending
}
}
});
logTable.on('xhr.dt',function(e, settings, json, xhr) {
if (json.code && json.code != 200) {
layer.msg( json.msg || I18n.system_api_error );
}
});
// logTips alert
$('#joblog_list').on('click', '.logTips', function(){
var msg = $(this).find('span').html();
ComAlertTec.show(msg);
});
// search Btn
$('#searchBtn').on('click', function(){
logTable.fnDraw();
});
// logDetail look
$('#joblog_list').on('click', '.logDetail', function(){
var _id = $(this).attr('_id');
window.open(base_url + '/joblog/logDetailPage?id=' + _id);
return;
});
/**
* log Kill
*/
$('#joblog_list').on('click', '.logKill', function(){
var _id = $(this).attr('_id');
layer.confirm( (I18n.system_ok + I18n.joblog_kill_log + '?'), {
icon: 3,
title: I18n.system_tips ,
btn: [ I18n.system_ok, I18n.system_cancel ]
}, function(index){
layer.close(index);
$.ajax({
type : 'POST',
url : base_url + '/joblog/logKill',
data : {"id":_id},
dataType : "json",
success : function(data){
if (data.code == 200) {
layer.open({
title: I18n.system_tips,
btn: [ I18n.system_ok ],
content: I18n.system_opt_suc ,
icon: '1',
end: function(layero, index){
logTable.fnDraw();
}
});
} else {
layer.open({
title: I18n.system_tips,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.system_opt_fail ),
icon: '2'
});
}
},
});
});
});
/**
* clear Log
*/
$('#clearLog').on('click', function(){
var jobGroup = $('#jobGroup').val();
var jobId = $('#jobId').val();
var jobGroupText = $("#jobGroup").find("option:selected").text();
var jobIdText = $("#jobId").find("option:selected").text();
$('#clearLogModal input[name=jobGroup]').val(jobGroup);
$('#clearLogModal input[name=jobId]').val(jobId);
$('#clearLogModal .jobGroupText').val(jobGroupText);
$('#clearLogModal .jobIdText').val(jobIdText);
$('#clearLogModal').modal('show');
});
$("#clearLogModal .ok").on('click', function(){
$.post(base_url + "/joblog/clearLog", $("#clearLogModal .form").serialize(), function(data, status) {
if (data.code == "200") {
$('#clearLogModal').modal('hide');
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: (I18n.joblog_clean_log + I18n.system_success) ,
icon: '1',
end: function(layero, index){
logTable.fnDraw();
}
});
} else {
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: (data.msg || (I18n.joblog_clean_log + I18n.system_fail) ),
icon: '2'
});
}
});
});
$("#clearLogModal").on('hide.bs.modal', function () {
$("#clearLogModal .form")[0].reset();
});
});
// Com Alert by Tec theme
var ComAlertTec = {
html:function(){
var html =
'<div class="modal fade" id="ComAlertTec" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
' <div class="modal-dialog modal-lg-">' +
' <div class="modal-content-tec">' +
' <div class="modal-body">' +
' <div class="alert" style="color:#fff;word-wrap: break-word;">' +
' </div>' +
' </div>' +
' <div class="modal-footer">' +
' <div class="text-center" >' +
' <button type="button" class="btn btn-info ok" data-dismiss="modal" >'+ I18n.system_ok +'</button>' +
' </div>' +
' </div>' +
' </div>' +
' </div>' +
'</div>';
return html;
},
show:function(msg, callback){
// dom init
if ($('#ComAlertTec').length == 0){
$('body').append(ComAlertTec.html());
}
// init com alert
$('#ComAlertTec .alert').html(msg);
$('#ComAlertTec').modal('show');
$('#ComAlertTec .ok').click(function(){
$('#ComAlertTec').modal('hide');
if(typeof callback == 'function') {
callback();
}
});
}
};

View File

@ -0,0 +1,66 @@
$(function(){
// input iCheck
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' // optional
});
// login Form Valid
var loginFormValid = $("#loginForm").validate({
errorElement : 'span',
errorClass : 'help-block',
focusInvalid : true,
rules : {
userName : {
required : true ,
minlength: 4,
maxlength: 18
},
password : {
required : true ,
minlength: 4,
maxlength: 18
}
},
messages : {
userName : {
required : I18n.login_username_empty,
minlength : I18n.login_username_lt_4
},
password : {
required : I18n.login_password_empty ,
minlength : I18n.login_password_lt_4
/*,maxlength:"登录密码不应超过18位"*/
}
},
highlight : function(element) {
$(element).closest('.form-group').addClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error');
label.remove();
},
errorPlacement : function(error, element) {
element.parent('div').append(error);
},
submitHandler : function(form) {
$.post(base_url + "/login", $("#loginForm").serialize(), function(data, status) {
if (data.code == "200") {
layer.msg( I18n.login_success );
setTimeout(function(){
window.location.href = base_url + "/";
}, 500);
} else {
layer.open({
title: I18n.system_tips,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.login_fail ),
icon: '2'
});
}
});
}
});
});

View File

@ -0,0 +1,328 @@
$(function() {
// init date tables
var userListTable = $("#user_list").dataTable({
"deferRender": true,
"processing" : true,
"serverSide": true,
"ajax": {
url: base_url + "/user/pageList",
type:"post",
data : function ( d ) {
var obj = {};
obj.username = $('#username').val();
obj.role = $('#role').val();
obj.start = d.start;
obj.length = d.length;
return obj;
}
},
"searching": false,
"ordering": false,
//"scrollX": true, // scroll xclose self-adaption
"columns": [
{
"data": 'id',
"visible" : false,
"width":'10%'
},
{
"data": 'username',
"visible" : true,
"width":'20%'
},
{
"data": 'password',
"visible" : false,
"width":'20%',
"render": function ( data, type, row ) {
return '*********';
}
},
{
"data": 'role',
"visible" : true,
"width":'10%',
"render": function ( data, type, row ) {
if (data == 1) {
return I18n.user_role_admin
} else {
return I18n.user_role_normal
}
}
},
{
"data": 'permission',
"width":'10%',
"visible" : false
},
{
"data": I18n.system_opt ,
"width":'15%',
"render": function ( data, type, row ) {
return function(){
// html
tableData['key'+row.id] = row;
var html = '<p id="'+ row.id +'" >'+
'<button class="btn btn-warning btn-xs update" type="button">'+ I18n.system_opt_edit +'</button> '+
'<button class="btn btn-danger btn-xs delete" type="button">'+ I18n.system_opt_del +'</button> '+
'</p>';
return html;
};
}
}
],
"language" : {
"sProcessing" : I18n.dataTable_sProcessing ,
"sLengthMenu" : I18n.dataTable_sLengthMenu ,
"sZeroRecords" : I18n.dataTable_sZeroRecords ,
"sInfo" : I18n.dataTable_sInfo ,
"sInfoEmpty" : I18n.dataTable_sInfoEmpty ,
"sInfoFiltered" : I18n.dataTable_sInfoFiltered ,
"sInfoPostFix" : "",
"sSearch" : I18n.dataTable_sSearch ,
"sUrl" : "",
"sEmptyTable" : I18n.dataTable_sEmptyTable ,
"sLoadingRecords" : I18n.dataTable_sLoadingRecords ,
"sInfoThousands" : ",",
"oPaginate" : {
"sFirst" : I18n.dataTable_sFirst ,
"sPrevious" : I18n.dataTable_sPrevious ,
"sNext" : I18n.dataTable_sNext ,
"sLast" : I18n.dataTable_sLast
},
"oAria" : {
"sSortAscending" : I18n.dataTable_sSortAscending ,
"sSortDescending" : I18n.dataTable_sSortDescending
}
}
});
// table data
var tableData = {};
// search btn
$('#searchBtn').on('click', function(){
userListTable.fnDraw();
});
// job operate
$("#user_list").on('click', '.delete',function() {
var id = $(this).parent('p').attr("id");
layer.confirm( I18n.system_ok + I18n.system_opt_del + '?', {
icon: 3,
title: I18n.system_tips ,
btn: [ I18n.system_ok, I18n.system_cancel ]
}, function(index){
layer.close(index);
$.ajax({
type : 'POST',
url : base_url + "/user/remove",
data : {
"id" : id
},
dataType : "json",
success : function(data){
if (data.code == 200) {
layer.msg( I18n.system_success );
userListTable.fnDraw(false);
} else {
layer.msg( data.msg || I18n.system_opt_del + I18n.system_fail );
}
}
});
});
});
// add role
$("#addModal .form input[name=role]").change(function () {
var role = $(this).val();
if (role == 1) {
$("#addModal .form input[name=permission]").parents('.form-group').hide();
} else {
$("#addModal .form input[name=permission]").parents('.form-group').show();
}
$("#addModal .form input[name='permission']").prop("checked",false);
});
jQuery.validator.addMethod("myValid01", function(value, element) {
var length = value.length;
var valid = /^[a-z][a-z0-9]*$/;
return this.optional(element) || valid.test(value);
}, I18n.user_username_valid );
// add
$(".add").click(function(){
$('#addModal').modal({backdrop: false, keyboard: false}).modal('show');
});
var addModalValidate = $("#addModal .form").validate({
errorElement : 'span',
errorClass : 'help-block',
focusInvalid : true,
rules : {
username : {
required : true,
rangelength:[4, 20],
myValid01: true
},
password : {
required : true,
rangelength:[4, 20]
}
},
messages : {
username : {
required : I18n.system_please_input + I18n.user_username,
rangelength: I18n.system_lengh_limit + "[4-20]"
},
password : {
required : I18n.system_please_input + I18n.user_password,
rangelength: I18n.system_lengh_limit + "[4-20]"
}
},
highlight : function(element) {
$(element).closest('.form-group').addClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error');
label.remove();
},
errorPlacement : function(error, element) {
element.parent('div').append(error);
},
submitHandler : function(form) {
var permissionArr = [];
$("#addModal .form input[name=permission]:checked").each(function(){
permissionArr.push($(this).val());
});
var paramData = {
"username": $("#addModal .form input[name=username]").val(),
"password": $("#addModal .form input[name=password]").val(),
"role": $("#addModal .form input[name=role]:checked").val(),
"permission": permissionArr.join(',')
};
$.post(base_url + "/user/add", paramData, function(data, status) {
if (data.code == "200") {
$('#addModal').modal('hide');
layer.msg( I18n.system_add_suc );
userListTable.fnDraw();
} else {
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.system_add_fail),
icon: '2'
});
}
});
}
});
$("#addModal").on('hide.bs.modal', function () {
$("#addModal .form")[0].reset();
addModalValidate.resetForm();
$("#addModal .form .form-group").removeClass("has-error");
$(".remote_panel").show(); // remote
$("#addModal .form input[name=permission]").parents('.form-group').show();
});
// update role
$("#updateModal .form input[name=role]").change(function () {
var role = $(this).val();
if (role == 1) {
$("#updateModal .form input[name=permission]").parents('.form-group').hide();
} else {
$("#updateModal .form input[name=permission]").parents('.form-group').show();
}
$("#updateModal .form input[name='permission']").prop("checked",false);
});
// update
$("#user_list").on('click', '.update',function() {
var id = $(this).parent('p').attr("id");
var row = tableData['key'+id];
// base data
$("#updateModal .form input[name='id']").val( row.id );
$("#updateModal .form input[name='username']").val( row.username );
$("#updateModal .form input[name='password']").val( '' );
$("#updateModal .form input[name='role'][value='"+ row.role +"']").click();
var permissionArr = [];
if (row.permission) {
permissionArr = row.permission.split(",");
}
$("#updateModal .form input[name='permission']").each(function () {
if($.inArray($(this).val(), permissionArr) > -1) {
$(this).prop("checked",true);
} else {
$(this).prop("checked",false);
}
});
// show
$('#updateModal').modal({backdrop: false, keyboard: false}).modal('show');
});
var updateModalValidate = $("#updateModal .form").validate({
errorElement : 'span',
errorClass : 'help-block',
focusInvalid : true,
highlight : function(element) {
$(element).closest('.form-group').addClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error');
label.remove();
},
errorPlacement : function(error, element) {
element.parent('div').append(error);
},
submitHandler : function(form) {
var permissionArr =[];
$("#updateModal .form input[name=permission]:checked").each(function(){
permissionArr.push($(this).val());
});
var paramData = {
"id": $("#updateModal .form input[name=id]").val(),
"username": $("#updateModal .form input[name=username]").val(),
"password": $("#updateModal .form input[name=password]").val(),
"role": $("#updateModal .form input[name=role]:checked").val(),
"permission": permissionArr.join(',')
};
$.post(base_url + "/user/update", paramData, function(data, status) {
if (data.code == "200") {
$('#updateModal').modal('hide');
layer.msg( I18n.system_update_suc );
userListTable.fnDraw();
} else {
layer.open({
title: I18n.system_tips ,
btn: [ I18n.system_ok ],
content: (data.msg || I18n.system_update_fail),
icon: '2'
});
}
});
}
});
$("#updateModal").on('hide.bs.modal', function () {
$("#updateModal .form")[0].reset();
updateModalValidate.resetForm();
$("#updateModal .form .form-group").removeClass("has-error");
$(".remote_panel").show(); // remote
$("#updateModal .form input[name=permission]").parents('.form-group').show();
});
});