From d100e47a640149756217111a4fc12b56f285efb2 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Sun, 16 Nov 2025 23:47:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor(biz):=20=E9=87=8D=E6=9E=84=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=8E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整任务代码页面返回路径至 biz/job.code - 修改任务信息页面返回路径至 biz/job.list - 更新任务新增接口地址为 /insert - 更改任务删除接口地址为 /delete 并支持批量操作 - 调整任务停止接口地址为 /pause 并支持批量操作 - 修改任务启动接口地址为 /start 并支持批量操作 - 增强调度时间计算接口参数校验 - 优化表格组件事件监听逻辑 - 新增任务代码编辑页面模板 - 新增任务列表展示页面模板 --- .../controller/biz/JobCodeController.java | 2 +- .../controller/biz/JobInfoController.java | 56 +- .../static/biz/common/admin.table.js | 2 +- .../main/resources/templates/biz/job.code.ftl | 280 ++++ .../main/resources/templates/biz/job.list.ftl | 1316 +++++++++++++++++ .../resources/templates/biz/log.detail.ftl | 10 +- .../main/resources/templates/biz/log.list.ftl | 17 +- .../resources/templates/v2/jobcode.index.ftl | 186 --- .../resources/templates/v2/jobinfo.index.ftl | 581 -------- .../v2/static2/js/jobcode.index.1.js | 97 -- .../v2/static2/js/jobinfo.index.1.js | 749 ---------- 11 files changed, 1657 insertions(+), 1639 deletions(-) create mode 100644 xxl-job-admin/src/main/resources/templates/biz/job.code.ftl create mode 100644 xxl-job-admin/src/main/resources/templates/biz/job.list.ftl delete mode 100644 xxl-job-admin/src/main/resources/templates/v2/jobcode.index.ftl delete mode 100644 xxl-job-admin/src/main/resources/templates/v2/jobinfo.index.ftl delete mode 100644 xxl-job-admin/src/main/resources/templates/v2/static2/js/jobcode.index.1.js delete mode 100644 xxl-job-admin/src/main/resources/templates/v2/static2/js/jobinfo.index.1.js diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobCodeController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobCodeController.java index ffb4b4f6..9b20604e 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobCodeController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobCodeController.java @@ -58,7 +58,7 @@ public class JobCodeController { model.addAttribute("jobInfo", jobInfo); model.addAttribute("jobLogGlues", jobLogGlues); - return "jobcode/jobcode.index"; + return "biz/job.code"; } @RequestMapping("/save") diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobInfoController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobInfoController.java index eb192438..d20929e3 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobInfoController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobInfoController.java @@ -16,8 +16,10 @@ import com.xxl.sso.core.helper.XxlSsoHelper; import com.xxl.sso.core.model.LoginInfo; import com.xxl.tool.core.CollectionTool; import com.xxl.tool.core.DateTool; +import com.xxl.tool.core.StringTool; import com.xxl.tool.response.PageModel; import com.xxl.tool.response.Response; +import com.xxl.tool.response.ResponseCode; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; import org.slf4j.Logger; @@ -65,10 +67,16 @@ public class JobInfoController { throw new XxlJobException(I18nUtil.getString("jobgroup_empty")); } + // parse jobGroup + if (!(CollectionTool.isNotEmpty(jobGroupList) + && jobGroupList.stream().map(XxlJobGroup::getId).toList().contains(jobGroup))) { + jobGroup = -1; + } + model.addAttribute("JobGroupList", jobGroupList); model.addAttribute("jobGroup", jobGroup); - return "jobinfo/jobinfo.index"; + return "biz/job.list"; } @RequestMapping("/pageList") @@ -89,7 +97,7 @@ public class JobInfoController { return xxlJobService.pageList(offset, pagesize, jobGroup, triggerStatus, jobDesc, executorHandler, author); } - @RequestMapping("/add") + @RequestMapping("/insert") @ResponseBody public Response add(HttpServletRequest request, XxlJobInfo jobInfo) { // valid permission @@ -109,25 +117,46 @@ public class JobInfoController { return xxlJobService.update(jobInfo, loginInfo); } - @RequestMapping("/remove") + @RequestMapping("/delete") @ResponseBody - public Response remove(HttpServletRequest request, @RequestParam("id") int id) { + public Response delete(HttpServletRequest request, @RequestParam("ids[]") List ids) { + + // valid + if (CollectionTool.isEmpty(ids) || ids.size()!=1) { + return Response.ofFail(I18nUtil.getString("system_please_choose") + I18nUtil.getString("system_one") + I18nUtil.getString("system_data")); + } + + // invoke Response loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request); - return xxlJobService.remove(id, loginInfoResponse.getData()); + return xxlJobService.remove(ids.get(0), loginInfoResponse.getData()); } @RequestMapping("/stop") @ResponseBody - public Response pause(HttpServletRequest request, @RequestParam("id") int id) { + public Response pause(HttpServletRequest request, @RequestParam("ids[]") List ids) { + + // valid + if (CollectionTool.isEmpty(ids) || ids.size()!=1) { + return Response.ofFail(I18nUtil.getString("system_please_choose") + I18nUtil.getString("system_one") + I18nUtil.getString("system_data")); + } + + // invoke Response loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request); - return xxlJobService.stop(id, loginInfoResponse.getData()); + return xxlJobService.stop(ids.get(0), loginInfoResponse.getData()); } @RequestMapping("/start") @ResponseBody - public Response start(HttpServletRequest request, @RequestParam("id") int id) { + public Response start(HttpServletRequest request, @RequestParam("ids[]") List ids) { + + // valid + if (CollectionTool.isEmpty(ids) || ids.size()!=1) { + return Response.ofFail(I18nUtil.getString("system_please_choose") + I18nUtil.getString("system_one") + I18nUtil.getString("system_data")); + } + + // invoke Response loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request); - return xxlJobService.start(id, loginInfoResponse.getData()); + return xxlJobService.start(ids.get(0), loginInfoResponse.getData()); } @RequestMapping("/trigger") @@ -145,10 +174,17 @@ public class JobInfoController { public Response> nextTriggerTime(@RequestParam("scheduleType") String scheduleType, @RequestParam("scheduleConf") String scheduleConf) { + // valid + if (StringTool.isBlank(scheduleType) || StringTool.isBlank(scheduleConf)) { + return Response.of(ResponseCode.FAILURE.getCode(), null, new ArrayList<>()); + } + + // param XxlJobInfo paramXxlJobInfo = new XxlJobInfo(); paramXxlJobInfo.setScheduleType(scheduleType); paramXxlJobInfo.setScheduleConf(scheduleConf); + // generate List result = new ArrayList<>(); try { Date lastTime = new Date(); @@ -166,7 +202,7 @@ public class JobInfoController { } } } catch (Exception e) { - logger.error(">>>>>>>>>>> nextTriggerTime error. scheduleType = {}, scheduleConf= {}", scheduleType, scheduleConf, e); + logger.error(">>>>>>>>>>> nextTriggerTime error. scheduleType = {}, scheduleConf= {}, error:{} ", scheduleType, scheduleConf, e.getMessage()); return Response.ofFail((I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) + e.getMessage()); } return Response.ofSuccess(result); diff --git a/xxl-job-admin/src/main/resources/static/biz/common/admin.table.js b/xxl-job-admin/src/main/resources/static/biz/common/admin.table.js index 91f9c07f..e1645fab 100644 --- a/xxl-job-admin/src/main/resources/static/biz/common/admin.table.js +++ b/xxl-job-admin/src/main/resources/static/biz/common/admin.table.js @@ -178,7 +178,7 @@ // onLoadSuccess: function(data) {} onAll: function(name, args) { // filter - if (!(['check.bs.table', "uncheck.bs.table", "check-all.bs.table", "uncheck-all.bs.table"].indexOf(name) > -1)) { + if (!(['check.bs.table', "uncheck.bs.table", "check-all.bs.table", "uncheck-all.bs.table", 'post-body.bs.table'].indexOf(name) > -1)) { return false; } var rows = $(table).bootstrapTable('getSelections'); diff --git a/xxl-job-admin/src/main/resources/templates/biz/job.code.ftl b/xxl-job-admin/src/main/resources/templates/biz/job.code.ftl new file mode 100644 index 00000000..4a0700e8 --- /dev/null +++ b/xxl-job-admin/src/main/resources/templates/biz/job.code.ftl @@ -0,0 +1,280 @@ + + + + <#-- import macro --> + <#import "../common/common.macro.ftl" as netCommon> + + + <@netCommon.commonStyle /> + + + ${I18n.admin_name} + + + + + +
+ + +
+ +
+ + + +
+
+ + + + + + +
+ Powered by XXL-JOB ${I18n.admin_version} + +
+ + +
+ + +<#-- glueModel --> +<#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js" /> +<#assign glueTypeIdeMode = "text/x-java" /> + +<#if jobInfo.glueType == "GLUE_GROOVY" > + <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js" /> + <#assign glueTypeIdeMode = "text/x-java" /> +<#elseif jobInfo.glueType == "GLUE_SHELL" > + <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/shell/shell.js" /> + <#assign glueTypeIdeMode = "text/x-sh" /> +<#elseif jobInfo.glueType == "GLUE_PYTHON" > + <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/python/python.js" /> + <#assign glueTypeIdeMode = "text/x-python" /> +<#elseif jobInfo.glueType == "GLUE_PYTHON2" > + <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/python/python.js" /> + <#assign glueTypeIdeMode = "text/x-python" /> +<#elseif jobInfo.glueType == "GLUE_PHP" > + <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/php/php.js" /> + <#assign glueTypeIdeMode = "text/x-php" /> + <#assign glueTypeModeSrc02 = "${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js" /> +<#elseif jobInfo.glueType == "GLUE_NODEJS" > + <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/javascript/javascript.js" /> + <#assign glueTypeIdeMode = "text/javascript" /> +<#elseif jobInfo.glueType == "GLUE_POWERSHELL" > + <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/powershell/powershell.js" /> + <#assign glueTypeIdeMode = "powershell" /> + + +<#-- script --> +<@netCommon.commonScript /> + +<#-- glue ide --> + + +<#if glueTypeModeSrc02?exists> + + + + + + + + + \ No newline at end of file diff --git a/xxl-job-admin/src/main/resources/templates/biz/job.list.ftl b/xxl-job-admin/src/main/resources/templates/biz/job.list.ftl new file mode 100644 index 00000000..b9729ca6 --- /dev/null +++ b/xxl-job-admin/src/main/resources/templates/biz/job.list.ftl @@ -0,0 +1,1316 @@ + + + + <#-- import macro --> + <#import "../common/common.macro.ftl" as netCommon> + + + <@netCommon.commonStyle /> + + + + + +
+
+ + + + <#-- 查询区域 --> +
+
+
+ +
+
+ ${I18n.jobinfo_field_jobgroup} + +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+ +
+ +
+
+ +
+
+
+
+ + <#-- 数据表格区域 --> +
+
+
+
+ + + + | + + <#-- GLUE IDE:'BEAN' != row.glueType --> + <#-- 启动 --> + <#-- 停止 --> + | + <#-- 执行一次 --> + <#-- 执行日志:base_url +'/joblog?jobId='+ row.id --> + <#-- 注册节点 --> + <#-- 下次执行时间:row.scheduleType == 'CRON' || row.scheduleType == 'FIX_RATE' --> +
+
+ + + + +
+
+
+
+
+ + + + + + + + <#-- trigger --> + + + + +
+
+ + +<@netCommon.commonScript /> + + +<#-- admin table --> + +<#-- admin util --> + +<#-- moment --> + +<#-- cronGen --> + + + + + + \ No newline at end of file diff --git a/xxl-job-admin/src/main/resources/templates/biz/log.detail.ftl b/xxl-job-admin/src/main/resources/templates/biz/log.detail.ftl index b1b60d1e..92e2e416 100644 --- a/xxl-job-admin/src/main/resources/templates/biz/log.detail.ftl +++ b/xxl-job-admin/src/main/resources/templates/biz/log.detail.ftl @@ -27,7 +27,9 @@ <#-- left nav --> @@ -40,6 +42,12 @@ ${I18n.joblog_rolling_log_refresh} +
  • + + + ${I18n.system_close} + +
  • diff --git a/xxl-job-admin/src/main/resources/templates/biz/log.list.ftl b/xxl-job-admin/src/main/resources/templates/biz/log.list.ftl index f2ac4e1d..6646c59b 100644 --- a/xxl-job-admin/src/main/resources/templates/biz/log.list.ftl +++ b/xxl-job-admin/src/main/resources/templates/biz/log.list.ftl @@ -82,14 +82,10 @@
    - - | - <#--warning - danger - info - default--> + | +
    @@ -226,13 +222,8 @@ var jobGroup = '${jobGroup}'; var jobId = '${jobId}'; function resetFilter(){ - $('#filterTime').data("daterangepicker").setStartDate( rangesConf[I18n.daterangepicker_ranges_today][0] ); - $('#filterTime').data("daterangepicker").setEndDate( rangesConf[I18n.daterangepicker_ranges_today][1] ); - - // todo - $('#filterTime').data("daterangepicker").setStartDate( rangesConf[I18n.daterangepicker_ranges_recent_month][0] ); - $('#filterTime').data("daterangepicker").setEndDate( rangesConf[I18n.daterangepicker_ranges_recent_month][1] ); - + $('#filterTime').data("daterangepicker").setStartDate( rangesConf[I18n.daterangepicker_ranges_recent_week][0] ); + $('#filterTime').data("daterangepicker").setEndDate( rangesConf[I18n.daterangepicker_ranges_recent_week][1] ); $("#jobGroup").val( jobGroup ); $("#jobId").val( jobId ); diff --git a/xxl-job-admin/src/main/resources/templates/v2/jobcode.index.ftl b/xxl-job-admin/src/main/resources/templates/v2/jobcode.index.ftl deleted file mode 100644 index 894c49e0..00000000 --- a/xxl-job-admin/src/main/resources/templates/v2/jobcode.index.ftl +++ /dev/null @@ -1,186 +0,0 @@ - - - - <#-- import macro --> - <#import "../common/common.macro.ftl" as netCommon> - - <#-- commonStyle --> - <@netCommon.commonStyle /> - - <#-- biz start(1/5 style) --> - - - ${I18n.admin_name} - - <#-- biz end(1/5 end) --> - - - -
    - - - <#-- biz start(2/5 header) --> -
    - -
    - <#-- biz end(2/5 header) --> - - - - -
    - <#-- biz start(3/5 content-header) --> - <#-- biz start(4/5 content-main) --> - - - - - - - - <#--<@netCommon.commonFooter />--> -
    - - -<@netCommon.commonScript /> - -<#-- biz start(5/5 script) --> -<#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js" /> -<#assign glueTypeIdeMode = "text/x-java" /> - -<#if jobInfo.glueType == "GLUE_GROOVY" > - <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js" /> - <#assign glueTypeIdeMode = "text/x-java" /> -<#elseif jobInfo.glueType == "GLUE_SHELL" > - <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/shell/shell.js" /> - <#assign glueTypeIdeMode = "text/x-sh" /> -<#elseif jobInfo.glueType == "GLUE_PYTHON" > - <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/python/python.js" /> - <#assign glueTypeIdeMode = "text/x-python" /> -<#elseif jobInfo.glueType == "GLUE_PYTHON2" > - <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/python/python.js" /> - <#assign glueTypeIdeMode = "text/x-python" /> -<#elseif jobInfo.glueType == "GLUE_PHP" > - <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/php/php.js" /> - <#assign glueTypeIdeMode = "text/x-php" /> - <#assign glueTypeModeSrc02 = "${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js" /> -<#elseif jobInfo.glueType == "GLUE_NODEJS" > - <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/javascript/javascript.js" /> - <#assign glueTypeIdeMode = "text/javascript" /> -<#elseif jobInfo.glueType == "GLUE_POWERSHELL" > - <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/powershell/powershell.js" /> - <#assign glueTypeIdeMode = "powershell" /> - - - - - -<#if glueTypeModeSrc02?exists> - - - - - - - - -<#-- biz end(5/5 script) --> - - - diff --git a/xxl-job-admin/src/main/resources/templates/v2/jobinfo.index.ftl b/xxl-job-admin/src/main/resources/templates/v2/jobinfo.index.ftl deleted file mode 100644 index 66e38504..00000000 --- a/xxl-job-admin/src/main/resources/templates/v2/jobinfo.index.ftl +++ /dev/null @@ -1,581 +0,0 @@ - - - - <#-- import macro --> - <#import "../common/common.macro.ftl" as netCommon> - - <#-- commonStyle --> - <@netCommon.commonStyle /> - - <#-- biz start(1/5 style) --> - - - <#-- biz end(1/5 end) --> - - - -
    - - - <@netCommon.commonHeader /> - - - <#-- biz start(2/5 left) --> - <@netCommon.commonLeft "jobinfo" /> - <#-- biz end(2/5 left) --> - - -
    - - -
    - <#-- biz start(3/5 name) --> -

    ${I18n.jobinfo_name}

    - <#-- biz end(3/5 name) --> -
    - - -
    - - <#-- biz start(4/5 content) --> - - -
    -
    -
    - ${I18n.jobinfo_field_jobgroup} - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    - -
    -
    - -
    -
    - - -
    -
    -
    - <#--
    -

    调度列表

    -
    --> -
    -
    - - - - - - - - - - - - - - - - - - -
    ${I18n.jobinfo_field_id}${I18n.jobinfo_field_jobgroup}${I18n.jobinfo_field_jobdesc}${I18n.schedule_type}${I18n.jobinfo_field_gluetype}${I18n.jobinfo_field_executorparam}addTimeupdateTime${I18n.jobinfo_field_author}${I18n.jobinfo_field_alarmemail}${I18n.system_status}${I18n.system_opt}
    -
    -
    -
    - - - - - - <#-- biz end(4/5 content) --> - - - - - <@netCommon.commonFooter /> - - - - - - - - -<#-- trigger --> - - -<@netCommon.commonScript /> - -<#-- biz start(5/5 script) --> - - - - - -<#-- cronGen --> - - -<#-- biz end(5/5 script) --> - - - diff --git a/xxl-job-admin/src/main/resources/templates/v2/static2/js/jobcode.index.1.js b/xxl-job-admin/src/main/resources/templates/v2/static2/js/jobcode.index.1.js deleted file mode 100644 index 668d6347..00000000 --- a/xxl-job-admin/src/main/resources/templates/v2/static2/js/jobcode.index.1.js +++ /dev/null @@ -1,97 +0,0 @@ -$(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编辑器?'; - });*/ - -}); diff --git a/xxl-job-admin/src/main/resources/templates/v2/static2/js/jobinfo.index.1.js b/xxl-job-admin/src/main/resources/templates/v2/static2/js/jobinfo.index.1.js deleted file mode 100644 index e16638d2..00000000 --- a/xxl-job-admin/src/main/resources/templates/v2/static2/js/jobinfo.index.1.js +++ /dev/null @@ -1,749 +0,0 @@ -$(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.offset = d.start; - obj.pagesize = d.length; - obj.jobGroup = $('#jobGroup').val(); - obj.triggerStatus = $('#triggerStatus').val(); - obj.jobDesc = $('#jobDesc').val(); - obj.executorHandler = $('#executorHandler').val(); - obj.author = $('#author').val(); - return obj; - }, - dataFilter: function (json ) { - var result = JSON.parse(json); - return JSON.stringify({ - "recordsTotal": result.data.total, - "recordsFiltered": result.data.total, - "data": result.data.data - }); - } - }, - "searching": false, - "ordering": false, - //"scrollX": true, // scroll x,close 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 'RUNNING'; - } else { - return 'STOP'; - } - 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 = '
  • '+ I18n.jobinfo_opt_stop +'
  • \n'; - } else { - start_stop_div = '
  • '+ I18n.jobinfo_opt_start +'
  • \n'; - } - - // job_next_time_html - var job_next_time_html = ''; - if (row.scheduleType == 'CRON' || row.scheduleType == 'FIX_RATE') { - job_next_time_html = '
  • ' + I18n.jobinfo_opt_next_time + '
  • \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 = '
  • GLUE IDE
  • \n'; - codeBtn += '
  • \n'; - } - - // data - tableData['key'+row.id] = row; - - // opt - var html = '
    \n' + - ' \n' + - ' \n' + - ' \n' + - '
    '; - - 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 = '
    '; - if (data.code == 200 && data.data.registryList) { - for (var index in data.data.registryList) { - html += (parseInt(index)+1) + '. ' + data.data.registryList[index] + '
    '; - } - } - html += '
    '; - - 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 = '
    '; - if (data.code == 200 && data.data) { - for (var index in data.data) { - html += '' + data.data[index] + '
    '; - } - } - html += '
    '; - - 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_PYTHON2'==glueType){ - $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_python2").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'); - }); - -});