diff --git a/CHANGELOG.md b/CHANGELOG.md index 18e45e328..33730aa46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ 2. 【Server】新增构建触发器(感谢@java 麦田英雄) 3. 【Server】新增自动清理过量的构建历史记录和文件(感谢@Sawyer、@Jvmlz) 4. 【Server】构建支持ssh发布(感谢@£天空之城~龙) +5. 【Server】节点新增分组属性,方便多节点快速筛选(感谢@£天空之城~龙) ### 解决BUG、优化功能 diff --git a/modules/server/src/main/java/io/jpom/controller/node/NodeEditController.java b/modules/server/src/main/java/io/jpom/controller/node/NodeEditController.java index 7797cdc24..9e6f1072e 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/NodeEditController.java +++ b/modules/server/src/main/java/io/jpom/controller/node/NodeEditController.java @@ -16,7 +16,6 @@ import io.jpom.plugin.Feature; import io.jpom.plugin.MethodFeature; import io.jpom.service.build.BuildService; import io.jpom.service.monitor.MonitorService; -import io.jpom.service.node.NodeService; import io.jpom.service.node.OutGivingServer; import io.jpom.service.node.ssh.SshService; import io.jpom.service.user.UserService; @@ -27,7 +26,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; -import java.io.IOException; +import java.util.HashSet; import java.util.List; /** @@ -54,7 +53,7 @@ public class NodeEditController extends BaseServerController { @RequestMapping(value = "edit.html", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE) @Feature(method = MethodFeature.EDIT) - public String edit(String id) throws IOException { + public String edit(String id) { setAttribute("type", "add"); if (StrUtil.isNotEmpty(id)) { NodeModel nodeModel = nodeService.getItem(id); @@ -63,6 +62,9 @@ public class NodeEditController extends BaseServerController { setAttribute("type", "edit"); } } + // group + HashSet allGroup = nodeService.getAllGroup(); + setAttribute("groups", allGroup); // 查询ssh List sshModels = sshService.list(); List list = nodeService.list(); @@ -92,7 +94,7 @@ public class NodeEditController extends BaseServerController { @OptLog(UserOperateLogV1.OptType.EditNode) @ResponseBody @Feature(method = MethodFeature.EDIT) - public String save(String type) throws Exception { + public String save(String type) { NodeModel model = ServletUtil.toBean(getRequest(), NodeModel.class, true); if ("add".equalsIgnoreCase(type)) { return nodeService.addNode(model, getRequest()); @@ -112,7 +114,7 @@ public class NodeEditController extends BaseServerController { @OptLog(UserOperateLogV1.OptType.DelNode) @ResponseBody @Feature(method = MethodFeature.DEL) - public String del(String id) throws IOException { + public String del(String id) { // 判断分发 if (outGivingServer.checkNode(id)) { return JsonMessage.getString(400, "该节点存在分发项目,不能删除"); diff --git a/modules/server/src/main/java/io/jpom/controller/node/NodeIndexController.java b/modules/server/src/main/java/io/jpom/controller/node/NodeIndexController.java index ffa47ff6e..5db5c97b8 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/NodeIndexController.java +++ b/modules/server/src/main/java/io/jpom/controller/node/NodeIndexController.java @@ -14,7 +14,6 @@ import io.jpom.model.data.UserModel; import io.jpom.plugin.ClassFeature; import io.jpom.plugin.Feature; import io.jpom.plugin.MethodFeature; -import io.jpom.service.node.NodeService; import io.jpom.service.node.ssh.SshService; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -23,7 +22,9 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import java.util.HashSet; import java.util.List; +import java.util.stream.Collectors; /** * 节点管理 @@ -41,8 +42,13 @@ public class NodeIndexController extends BaseServerController { @RequestMapping(value = "list.html", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE) @Feature(method = MethodFeature.LIST) - public String list() { + public String list(String group) { List nodeModels = nodeService.list(); + // + if (nodeModels != null && StrUtil.isNotEmpty(group)) { + // 筛选 + nodeModels = nodeModels.stream().filter(nodeModel -> StrUtil.equals(group, nodeModel.getGroup())).collect(Collectors.toList()); + } setAttribute("array", nodeModels); // 获取所有的ssh 名称 JSONObject sshName = new JSONObject(); @@ -51,6 +57,9 @@ public class NodeIndexController extends BaseServerController { sshModels.forEach(sshModel -> sshName.put(sshModel.getId(), sshModel.getName())); } setAttribute("sshName", sshName); + // group + HashSet allGroup = nodeService.getAllGroup(); + setAttribute("groups", allGroup); return "node/list"; } diff --git a/modules/server/src/main/java/io/jpom/model/data/NodeModel.java b/modules/server/src/main/java/io/jpom/model/data/NodeModel.java index 410029af8..b0fd4ab5c 100644 --- a/modules/server/src/main/java/io/jpom/model/data/NodeModel.java +++ b/modules/server/src/main/java/io/jpom/model/data/NodeModel.java @@ -51,7 +51,7 @@ public class NodeModel extends BaseModel { private String group; public String getGroup() { - return group; + return StrUtil.emptyToDefault(group, "默认"); } public void setGroup(String group) { diff --git a/modules/server/src/main/java/io/jpom/service/node/NodeService.java b/modules/server/src/main/java/io/jpom/service/node/NodeService.java index c5338dfad..6c4463b5a 100644 --- a/modules/server/src/main/java/io/jpom/service/node/NodeService.java +++ b/modules/server/src/main/java/io/jpom/service/node/NodeService.java @@ -17,6 +17,7 @@ import io.jpom.util.StringUtil; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletRequest; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; @@ -37,6 +38,19 @@ public class NodeService extends BaseOperService implements BaseDynam super(ServerConfigBean.NODE); } + public HashSet getAllGroup() { + //获取所有分组 + List nodeModels = list(); + HashSet hashSet = new HashSet<>(); + if (nodeModels == null) { + return hashSet; + } + for (NodeModel nodeModel : nodeModels) { + hashSet.add(nodeModel.getGroup()); + } + return hashSet; + } + /** * 获取所有节点 和节点下面的项目 * diff --git a/modules/server/src/main/resources/templates/build/history.html b/modules/server/src/main/resources/templates/build/history.html index f2d3c9395..6742bf96e 100644 --- a/modules/server/src/main/resources/templates/build/history.html +++ b/modules/server/src/main/resources/templates/build/history.html @@ -71,7 +71,7 @@ var releaseMethods = [[${releaseMethods}]]; function openLog(id, buildId) { - layer.open({ + layerOpen({ type: 2, title: '构建日志', content: './logPage.html?id=' + id + "&buildId=" + buildId, diff --git a/modules/server/src/main/resources/templates/build/list.html b/modules/server/src/main/resources/templates/build/list.html index 37f4bf6a7..dbbcda71d 100644 --- a/modules/server/src/main/resources/templates/build/list.html +++ b/modules/server/src/main/resources/templates/build/list.html @@ -33,7 +33,7 @@ var statusArray = [[${statusArray}]]; function openLog(id, buildId) { - layer.open({ + layerOpen({ type: 2, title: '构建日志', content: './logPage.html?id=' + id + "&buildId=" + buildId, @@ -159,7 +159,7 @@ } }); } else if ('trigger' === event) { - layer.open({ + layerOpen({ type: 2, title: '查看触发器', content: './trigger.html?id=' + data.id, @@ -170,7 +170,7 @@ } function editData(id) { - layer.open({ + layerOpen({ type: 2, title: '编辑构建', content: './edit.html?id=' + id, diff --git a/modules/server/src/main/resources/templates/common/head.html b/modules/server/src/main/resources/templates/common/head.html index 06186930e..95cf9365e 100644 --- a/modules/server/src/main/resources/templates/common/head.html +++ b/modules/server/src/main/resources/templates/common/head.html @@ -140,10 +140,14 @@ } function layerOpen(options) { - if (options.type == 2) { + if (options.type === 2) { options.content = appendNodeId(options.content); } - layer.open(options); + var newData = { + maxmin: true, + }; + $.extend(newData, options); + layer.open(newData); } function getSocketHost() { @@ -166,7 +170,8 @@ function getQueryStringByUrl(url, name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = url.match(reg); - if (r != null) return unescape(r[2]); + if (r != null) + return decodeURI(r[2]); return null; } diff --git a/modules/server/src/main/resources/templates/common/userHead.html b/modules/server/src/main/resources/templates/common/userHead.html index 0e11d28d4..e30c43617 100644 --- a/modules/server/src/main/resources/templates/common/userHead.html +++ b/modules/server/src/main/resources/templates/common/userHead.html @@ -49,7 +49,7 @@ element.on('nav(userOperation)', function (elem) { var op = this.getAttribute('op'); if ('userInfo' == op) { - layer.open({ + layerOpen({ type: 2, title: '修改资料', content: inNode ? '../user/userInfo.html' : './user/userInfo.html', @@ -58,7 +58,7 @@ } else if ('updatePwd' == op) { // 修改密码 document.getElementById('form_updatePwd').reset(); - layer.open({ + layerOpen({ type: 1, title: '修改密码', btn: ['确认'], diff --git a/modules/server/src/main/resources/templates/monitor/list.html b/modules/server/src/main/resources/templates/monitor/list.html index 88e76e49b..f57d3c5a0 100644 --- a/modules/server/src/main/resources/templates/monitor/list.html +++ b/modules/server/src/main/resources/templates/monitor/list.html @@ -58,7 +58,7 @@ // '添加监控'点击事件 $('#addMonitor').on('click', function () { // 弹出 - layer.open({ + layerOpen({ type: 2, title: '新增监控', content: './edit.html', @@ -86,7 +86,7 @@ // 编辑监控 function updateApplication(data) { - layer.open({ + layerOpen({ type: 2, title: '修改监控', content: './edit.html?id=' + data.id, @@ -117,7 +117,7 @@ $('#monitorStatus').on('click', function () { // 弹出 - layer.open({ + layerOpen({ type: 2, title: '新增监控', content: './edit.html', diff --git a/modules/server/src/main/resources/templates/monitor/loglist.html b/modules/server/src/main/resources/templates/monitor/loglist.html index 4ffbf7e66..2c467f235 100644 --- a/modules/server/src/main/resources/templates/monitor/loglist.html +++ b/modules/server/src/main/resources/templates/monitor/loglist.html @@ -146,7 +146,7 @@ var event = obj.event; if ('view' === event) { laytpl(showBox).render(data, function (html) { - layer.open({ + layerOpen({ type: 1, content: html, scrollbar: false, diff --git a/modules/server/src/main/resources/templates/node/edit.html b/modules/server/src/main/resources/templates/node/edit.html index 4c014e0dd..b2ef65308 100644 --- a/modules/server/src/main/resources/templates/node/edit.html +++ b/modules/server/src/main/resources/templates/node/edit.html @@ -5,7 +5,7 @@
-
+
@@ -27,6 +27,17 @@ lay-verify="required">
+
+ +
+ +
+
@@ -42,7 +53,6 @@
" + text + ""); + } + form.val("form", { + "group": text + }); + form.render('select'); + }); + } + }); } diff --git a/modules/server/src/main/resources/templates/node/list.html b/modules/server/src/main/resources/templates/node/list.html index 995eecec4..d0597654a 100644 --- a/modules/server/src/main/resources/templates/node/list.html +++ b/modules/server/src/main/resources/templates/node/list.html @@ -11,12 +11,24 @@ 创建节点
- -
- +
+ +
+ +
+
+
+ +
+ +
@@ -140,6 +152,37 @@ multiSelect.render(); } }); + + form.on('select(groupName)', function (data) { + // + // 缓存选择 + layui.data('cache', { + key: "selectNodeGroup", + value: data.value + }); + // 防止错误选择 + layui.data('cache', { + key: "selectNodes", + remove: true + }); + var href = location.href; + href = urlUpdateParams(href, "group", data.value); + location.href = href; + return true; + }); + var queryGroup = getQueryString("group"); + if (queryGroup && queryGroup !== '') { + // 选中 + $("#selectGroup option[value='" + queryGroup + "']").attr("selected", "selected"); + form.render(); + } else { + const cache = layui.data('cache'); + if (cache.selectNodeGroup) { + var href = location.href; + href = urlUpdateParams(href, "group", cache.selectNodeGroup); + location.href = href; + } + } } function changeNodeSelect(vals) { @@ -158,7 +201,8 @@ } function editProject(id) { - layer.open({ + layerOpen({ + maxmin: true, type: 2, title: '管理节点配置信息', shade: 0.8, diff --git a/modules/server/src/main/resources/templates/node/manage/project_recover.html b/modules/server/src/main/resources/templates/node/manage/project_recover.html index b00a6d1d0..9e8df1efc 100644 --- a/modules/server/src/main/resources/templates/node/manage/project_recover.html +++ b/modules/server/src/main/resources/templates/node/manage/project_recover.html @@ -124,7 +124,7 @@ success: function (data) { if (200 == data.code) { attrProject(data.data); - layer.open({ + layerOpen({ type: 1, title: '查看项目', content: $('#div-project'), diff --git a/modules/server/src/main/resources/templates/node/ssh/file.html b/modules/server/src/main/resources/templates/node/ssh/file.html index 686c3d134..febfbb784 100644 --- a/modules/server/src/main/resources/templates/node/ssh/file.html +++ b/modules/server/src/main/resources/templates/node/ssh/file.html @@ -131,7 +131,7 @@ clickData = data; var btnDiv = $("#btnDiv"); btnDiv.show(); - openLayuiIndex = layer.open({ + openLayuiIndex = layerOpen({ type: 1, shade: [0.3, '#393D49'], title: false, diff --git a/modules/server/src/main/resources/templates/node/ssh/list.html b/modules/server/src/main/resources/templates/node/ssh/list.html index 3dee30c88..42f468cfa 100644 --- a/modules/server/src/main/resources/templates/node/ssh/list.html +++ b/modules/server/src/main/resources/templates/node/ssh/list.html @@ -88,7 +88,7 @@ // 编辑监控 function edit(id) { - layer.open({ + layerOpen({ type: 2, title: '编辑ssh', content: './edit.html?id=' + id, @@ -97,7 +97,7 @@ } function install(id) { - layer.open({ + layerOpen({ type: 2, title: '安装插件端', content: './installAgent.html?id=' + id, diff --git a/modules/server/src/main/resources/templates/node/system/certificate.html b/modules/server/src/main/resources/templates/node/system/certificate.html index 83eda2d86..8a39bbb21 100644 --- a/modules/server/src/main/resources/templates/node/system/certificate.html +++ b/modules/server/src/main/resources/templates/node/system/certificate.html @@ -199,7 +199,7 @@ $("input[name='type']").val("add"); $("#zipResult").html(""); form.render('select'); - layer.open({ + layerOpen({ type: 1, title: '新增证书', content: $('#div-certificate'), @@ -264,7 +264,7 @@ $("input[name='type']").val("edit"); form.render('select'); // 弹出 - layer.open({ + layerOpen({ type: 1, title: '编辑', content: $('#div-certificate'), @@ -337,7 +337,7 @@ laytpl(page).render(param, function (html) { view.innerHTML = html; }); - layer.open({ + layerOpen({ type: 1, title: '模板', content: $('#cert_template'), diff --git a/modules/server/src/main/resources/templates/outgiving/edit.html b/modules/server/src/main/resources/templates/outgiving/edit.html index 3c69ac42d..262e4329d 100644 --- a/modules/server/src/main/resources/templates/outgiving/edit.html +++ b/modules/server/src/main/resources/templates/outgiving/edit.html @@ -170,7 +170,7 @@ $("#add_selectNode").click(function () { - layer.open({ + layerOpen({ type: 1, title: '选择节点', content: $('#selectNode'), diff --git a/modules/server/src/main/resources/templates/outgiving/editProject.html b/modules/server/src/main/resources/templates/outgiving/editProject.html index 5855cb40b..a65ca382f 100644 --- a/modules/server/src/main/resources/templates/outgiving/editProject.html +++ b/modules/server/src/main/resources/templates/outgiving/editProject.html @@ -319,7 +319,7 @@ whitelistDirectorySelect = $("select[name='whitelistDirectory']"); $("#add_selectNode").click(function () { - layer.open({ + layerOpen({ type: 1, title: '选择节点', content: $('#selectNode'), diff --git a/modules/server/src/main/resources/templates/outgiving/list.html b/modules/server/src/main/resources/templates/outgiving/list.html index 52a931ed6..2f43d49d0 100644 --- a/modules/server/src/main/resources/templates/outgiving/list.html +++ b/modules/server/src/main/resources/templates/outgiving/list.html @@ -117,7 +117,7 @@ var url = "file" == op ? "/node/manage/file/list.html" : "/node/manage/console"; url = urlUpdateParams(url, "nodeId", nodeId); url = urlUpdateParams(url, "id", projectId); - var index = layer.open({ + var index = layerOpen({ type: 2, title: "file" == op ? '文件管理' : '控制台', shade: [0.4, '#fff'], @@ -168,7 +168,7 @@ } if ("add" == op) { var id = $(this).attr("id"); - layer.open({ + layerOpen({ type: 2, title: '添加分发文件', shade: 0.8, @@ -212,7 +212,7 @@ } function editProject(id) { - layer.open({ + layerOpen({ type: 2, title: '管理分发信息', shade: 0.8, diff --git a/modules/server/src/main/resources/templates/outgiving/loglist.html b/modules/server/src/main/resources/templates/outgiving/loglist.html index 28fe11549..51f7767cd 100644 --- a/modules/server/src/main/resources/templates/outgiving/loglist.html +++ b/modules/server/src/main/resources/templates/outgiving/loglist.html @@ -147,7 +147,7 @@ var event = obj.event; if ('view' === event) { laytpl(showBox).render(data, function (html) { - layer.open({ + layerOpen({ type: 1, content: html, scrollbar: false, diff --git a/modules/server/src/main/resources/templates/user/list.html b/modules/server/src/main/resources/templates/user/list.html index ddff23a4e..77018bee1 100644 --- a/modules/server/src/main/resources/templates/user/list.html +++ b/modules/server/src/main/resources/templates/user/list.html @@ -100,7 +100,7 @@ layer.msg("请先创建角色"); return; } - layer.open({ + layerOpen({ type: 2, title: '编辑用户', content: './edit?id=' + id, diff --git a/modules/server/src/main/resources/templates/user/log/list.html b/modules/server/src/main/resources/templates/user/log/list.html index 9ef6138e6..25e96f7d4 100644 --- a/modules/server/src/main/resources/templates/user/log/list.html +++ b/modules/server/src/main/resources/templates/user/log/list.html @@ -121,7 +121,7 @@ var event = obj.event; if ('view' === event) { laytpl(showBox).render(data, function (html) { - layer.open({ + layerOpen({ type: 1, content: html, scrollbar: false, diff --git a/modules/server/src/main/resources/templates/user/role/list.html b/modules/server/src/main/resources/templates/user/role/list.html index b2c00619b..1ccaf0466 100644 --- a/modules/server/src/main/resources/templates/user/role/list.html +++ b/modules/server/src/main/resources/templates/user/role/list.html @@ -36,7 +36,7 @@ // 修改 edit(data.id); } else if ('dynamic' === event) { - layer.open({ + layerOpen({ type: 2, title: '编辑角色', content: './dynamicData.html?id=' + data.id, @@ -69,7 +69,7 @@ } function edit(id) { - layer.open({ + layerOpen({ type: 2, title: '编辑角色', content: './edit.html?id=' + id,