节点新增分组属性

This commit is contained in:
bwcx_jzy 2019-09-10 12:43:46 +08:00
parent 68ced39f42
commit 9ab6eebb32
24 changed files with 154 additions and 49 deletions

View File

@ -8,6 +8,7 @@
2. 【Server】新增构建触发器感谢@java 麦田英雄)
3. 【Server】新增自动清理过量的构建历史记录和文件感谢@Sawyer、@Jvmlz
4. 【Server】构建支持ssh发布感谢@£天空之城~龙)
5. 【Server】节点新增分组属性方便多节点快速筛选感谢@£天空之城~龙)
### 解决BUG、优化功能

View File

@ -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<String> allGroup = nodeService.getAllGroup();
setAttribute("groups", allGroup);
// 查询ssh
List<SshModel> sshModels = sshService.list();
List<NodeModel> 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, "该节点存在分发项目,不能删除");

View File

@ -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<NodeModel> 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<String> allGroup = nodeService.getAllGroup();
setAttribute("groups", allGroup);
return "node/list";
}

View File

@ -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) {

View File

@ -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<NodeModel> implements BaseDynam
super(ServerConfigBean.NODE);
}
public HashSet<String> getAllGroup() {
//获取所有分组
List<NodeModel> nodeModels = list();
HashSet<String> hashSet = new HashSet<>();
if (nodeModels == null) {
return hashSet;
}
for (NodeModel nodeModel : nodeModels) {
hashSet.add(nodeModel.getGroup());
}
return hashSet;
}
/**
* 获取所有节点 和节点下面的项目
*

View File

@ -71,7 +71,7 @@
var releaseMethods = [[${releaseMethods}]];
function openLog(id, buildId) {
layer.open({
layerOpen({
type: 2,
title: '构建日志',
content: './logPage.html?id=' + id + "&buildId=" + buildId,

View File

@ -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,

View File

@ -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;
}

View File

@ -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: ['确认'],

View File

@ -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',

View File

@ -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,

View File

@ -5,7 +5,7 @@
</head>
<body>
<div class="layui-container">
<form action="./save.json" class="layui-form" id="form_node">
<form action="./save.json" class="layui-form" id="form" lay-filter="form">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">节点ID</label>
@ -27,6 +27,17 @@
lay-verify="required">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">分组名称</label>
<div class="layui-input-block">
<select name="group" lay-filter="group">
<option th:each="i : ${groups}" th:value="${i}" th:selected="${item?.group==$i}"
th:text="${i}"></option>
<option value="">选择手动添加</option>
</select>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
@ -42,7 +53,6 @@
<label class="layui-form-label">节点状态</label>
<div class="layui-input-block">
<input type="checkbox" value="true"
th:checked="${item==null || item?.openStatus}"
name="openStatus"
lay-skin="switch"
@ -123,7 +133,7 @@
data: data.field,
success: function (data) {
layer.msg(data.msg);
if (200 == data.code) {
if (200 === data.code) {
autoClose();
}
}
@ -145,13 +155,33 @@
},
success: function (data) {
layer.msg(data.msg);
if (200 == data.code) {
if (200 === data.code) {
autoClose();
}
}
});
});
});
var selectGroup = $("select[name='group']");
form.on('select(group)', function (data) {
if (data.value === "") {
layer.prompt({
title: '输入分组名,并确认',
formType: 0
}, function (text, index) {
layer.close(index);
var ext = $("select[name='group'] option[value='" + text + "']");
if (ext.length <= 0) {
selectGroup.find("option").first().before("<option value='" + text + "'>" + text + "</option>");
}
form.val("form", {
"group": text
});
form.render('select');
});
}
});
}
</script>
</html>

View File

@ -11,12 +11,24 @@
<a onclick="editProject('');" class="layui-btn layui-btn-sm">创建节点</a>
</div>
<div class="layui-inline" th:unless="${#lists.isEmpty(array)}">
<label class="layui-form-label">筛选</label>
<div class="layui-input-block">
<select name="nodeSelect" multiple="multiple" lay-filter="nodeSelect" lay-search="">
<option value=""></option>
<option th:value="${item.id}" th:each="item : ${array}" th:text="${item.name}"></option>
</select>
<div class="layui-inline">
<label class="layui-form-label">分组</label>
<div class="layui-input-inline">
<select name="selectGroup" id="selectGroup" lay-verify="required" lay-filter="groupName"
lay-search="">
<option value="">请选择</option>
<option th:each="item : ${groups}" th:value="${item}" th:text="${item}"></option>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">筛选</label>
<div class="layui-input-inline">
<select name="nodeSelect" multiple="multiple" lay-filter="nodeSelect" lay-search="">
<option value=""></option>
<option th:value="${item.id}" th:each="item : ${array}" th:text="${item.name}"></option>
</select>
</div>
</div>
</div>
</div>
@ -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,

View File

@ -124,7 +124,7 @@
success: function (data) {
if (200 == data.code) {
attrProject(data.data);
layer.open({
layerOpen({
type: 1,
title: '查看项目',
content: $('#div-project'),

View File

@ -131,7 +131,7 @@
clickData = data;
var btnDiv = $("#btnDiv");
btnDiv.show();
openLayuiIndex = layer.open({
openLayuiIndex = layerOpen({
type: 1,
shade: [0.3, '#393D49'],
title: false,

View File

@ -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,

View File

@ -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'),

View File

@ -170,7 +170,7 @@
$("#add_selectNode").click(function () {
layer.open({
layerOpen({
type: 1,
title: '选择节点',
content: $('#selectNode'),

View File

@ -319,7 +319,7 @@
whitelistDirectorySelect = $("select[name='whitelistDirectory']");
$("#add_selectNode").click(function () {
layer.open({
layerOpen({
type: 1,
title: '选择节点',
content: $('#selectNode'),

View File

@ -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,

View File

@ -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,

View File

@ -100,7 +100,7 @@
layer.msg("请先创建角色");
return;
}
layer.open({
layerOpen({
type: 2,
title: '编辑用户',
content: './edit?id=' + id,

View File

@ -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,

View File

@ -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,