Authored by mlge

监控对象模块修改--1)前端区分叶子and 非叶子节点;2)节点类型可修改

... ... @@ -7,7 +7,9 @@ import com.ui.model.req.MObjectHostInfoReq;
import com.ui.model.req.MObjectInfoReq;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
... ... @@ -110,4 +112,18 @@ public class MObjectInfoCtrl {
BaseResponse response = httpRestClient.defaultPost("/mobject/updateBindDependency", request, BaseResponse.class);
return response;
}
/**
* 查询 当前 typeId 是否可以修改类型(叶子,非叶子)
* 1)是否存在主机
* 2)是否包括子节点
* @param typeIdStr "node_id"
* @return true or false(不能更改类型)
*/
@GetMapping("/queryTypeInfoById")
public BaseResponse queryTypeInfoById(String typeIdStr){
String typeId = StringUtils.split(typeIdStr, "_")[1];
BaseResponse response = httpRestClient.defaultGet("/mobject/queryTypeInfoById?typeId=" + typeId,BaseResponse.class );
return response;
}
}
... ...
... ... @@ -61,13 +61,14 @@ public class TypeCtrl {
@RequestMapping("/update")
@ResponseBody
public String updateType(@RequestParam int id, @RequestParam String name) {
log.info("update type id {} ,name {}", id, name);
public String updateType(@RequestParam int id, @RequestParam String name,@RequestParam int isLeaf) {
log.info("update type id {} ,name {}, isLeaf {}", id, name, isLeaf);
JSONObject req=new JSONObject();
req.put("typeId",id);
req.put("typeName",name);
req.put("typeIsLeaf",isLeaf);
BaseResponse rtn = httpClient.defaultPost(HttpUriContants.TYPE_UPDATE, req,BaseResponse.class);
String rel= JSON.toJSONString(rtn);
... ...
... ... @@ -949,7 +949,7 @@
nodeTags.id=ids[i];
var treenode = $('#jstree').jstree("get_node","node_"+ids[i]);
if(treenode!=null&&treenode){
nodeTags.name=treenode.text;
nodeTags.name=treenode.data.typeName;
nodeTags.tags=treenode.data.tags;
nodeTags.descr=treenode.data.descr;
nodeTags.cloudTags=treenode.data.cloudTags;
... ... @@ -1011,7 +1011,7 @@
<div class="modal-dialog" style="width: 300px">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">
<h4 class="modal-title" id="myModalLabel2">
添加类型
</h4>
</div>
... ... @@ -1042,6 +1042,11 @@
<span class="input-group-addon" style="width: 100px">新名称:</span>
<input type="text" id="tx_update_type_name_new" class="form-control" placeholder=""/>
</div>
<div class="input-group" style="padding-bottom: 5px">
<span class="input-group-addon" style="width: 100px">叶子节点:</span>
<input type="checkbox" id="tx_update_type_isleaf" style="margin-left: 30px" disabled>
</div>
</div>
<div id="modal_type_del">
确认删除该类型节点?
... ...
... ... @@ -16,7 +16,7 @@ var getPath = function (nodeid) {
var currentId = nodeid;
while (currentId != "#") {
var node = $("#jstree").jstree().get_node(currentId);
paths.push(node.text);
paths.push(node.data.typeName);
num++;
currentId = node.parent;
}
... ... @@ -55,7 +55,7 @@ var addType = function (node) {
$('#modal_type_update').hide();
$('#modal_type_del').hide();
$('#modal_type_add').show();
$('#myModalLabel').html("添加类型");
$('#myModalLabel2').html("添加类型");
//$('#cb_new_type_isleaf').prop("checked", true);// 默认为子节点
$('#tx_new_type_name').val("");
$('#tx_type_id').val(nodeId2id(node.id));
... ... @@ -69,7 +69,7 @@ var addType = function (node) {
};
var delType = function (id) {
var rel = 0;
$('#myModalLabel').html("确认删除?");
$('#myModalLabel2').html("确认删除?");
$('#tx_type_action').val("del");
$('#modal_type_update').hide();
$('#modal_type_add').hide();
... ... @@ -78,18 +78,49 @@ var delType = function (id) {
$('#myModal').modal({keyboard: true});
return rel;
};
var updateType = function (id, oldName) {
var updateType = function (id, oldName, isLeaf) {
var rel = 0;
$('#myModalLabel').html("更新类型");
$('#myModalLabel2').html("修改类型");
$('#tx_type_action').val("update");
$('#tx_type_id').val(nodeId2id(id));
$('#tx_update_type_name_old').val(oldName);
$('#tx_update_type_name_new').val();
$('#tx_update_type_name_new').val("");
$('#modal_type_update').show();
$('#modal_type_add').hide();
$('#modal_type_del').hide();
$('#tx_update_type_isleaf') .prop("checked", false);
if(isLeaf == 1){//叶子节点--选中状态
$('#tx_update_type_isleaf') .prop("checked", true);
}
$('#myModal').modal({keyboard: true});
//默认不可以修改类型
$('#tx_update_type_isleaf') .attr('disabled',true);
//发送ajax请求,查看当前节点--是否可以修改类型
//1)不包含主机;2)不存在子节点;--则可以修改类型(叶子 vs 非 叶子)
$.ajax({
url: contextPath + "/mobject/queryTypeInfoById?typeIdStr="+id,
type: "get",
success: function (response) {
if(response.code != 200){
console.log("queryHostsByType response error!");
return;
}else{
if(response.data){//可以修改叶子节点的类型
$('#tx_update_type_isleaf') .attr('disabled',false);
}
}
},
error: function (e) {
console.log("queryHostsByType error!");
}
});
return rel;
};
... ... @@ -398,25 +429,32 @@ var doAddType = function () {
$.toaster('添加成功', '提示', 'info');
console.log(repjson.data);
var newNode = repjson.data;
var show_text = newNode.typeName;
if( newNode.typeIsLeaf == 1){
show_text = '<span class="glyphicon glyphicon-leaf" style="color: green"></span> &nbsp' + newNode.typeName;
}
$('#jstree').jstree().create_node("#node_" + newNode.typeParentId,
{
'id': "node_" + newNode.typeId,
'text': newNode.typeName,
'text': show_text,
'parent': "#node_" + newNode.typeParentId,
//'data': newNode.typeIsLeaf
'data':{
isLeaf:newNode.typeIsLeaf,
descr:newNode.descr,
cloudTags:newNode.cloudTags,
tags:newNode.tags
tags:newNode.tags,
typeName: newNode.typeName
}
}, 'last');
$('#jstree').jstree().get_node("node_" + newNode.typeId).data = {
/* $('#jstree').jstree().get_node("node_" + newNode.typeId).data = {
isLeaf:newNode.typeIsLeaf,
descr:newNode.descr,
cloudTags:newNode.cloudTags,
tags:newNode.tags
};
};*/
} else
$.toaster('添加失败' + repjson.code + " " + repjson.message, '提示', 'warning');
}
... ... @@ -432,13 +470,24 @@ var doUpdateType = function () {
$.toaster('输入类型名', '提示', 'warning');
return;
}
console.log("update " + id + " name " + name);
$.get(contextPath+"/type/update", {"id": id, "name": name},
var isLeaf = $('#tx_update_type_isleaf').prop("checked") == true ? 1 : 0;
$.get(contextPath+"/type/update", {"id": id, "name": name, "isLeaf": isLeaf},
function (data, state) {
var repjson = JSON.parse(data);
if (state == "success" && repjson.code == 200) {
$.toaster('更新成功', '更新', 'info');
//显示的名字
$("#jstree").jstree('set_text', '#node_' + id, name);
if(isLeaf == 1){
var new_name = '<span class="glyphicon glyphicon-leaf" style="color: green"></span> &nbsp' + name;
$("#jstree").jstree('set_text', '#node_' + id, new_name);
}
//isLeaf
$('#jstree').jstree().get_node("node_" + id).data.isLeaf = isLeaf;
//节点的名字
$('#jstree').jstree().get_node("node_" + id).data.typeName = name;
} else
$.toaster('更新失败:' + repjson.code + " " + repjson.message, '提示', 'warning');
}
... ... @@ -526,12 +575,16 @@ var refreshTypeTree = function () {
treeNode.id = "node_" + val.typeId;
treeNode.parent = (val.typeParentId == 0 ? "#" : "node_" + val.typeParentId);
treeNode.text = val.typeName;
if(val.typeIsLeaf == 1){//叶子节点多加一个图标
treeNode.text = '<span class="glyphicon glyphicon-leaf" style="color: green"></span> &nbsp' + val.typeName;
}
treeNode.data ={
isLeaf:val.typeIsLeaf,
descr:val.descr,
cloudTags:val.cloudTags,
tags:val.tags
tags:val.tags,
typeName: val.typeName
};
//console.log("treenode is "+JSON.stringify(treeNode));
//treeNode.data = val.typeIsLeaf;
... ... @@ -579,7 +632,7 @@ $('#jstree').jstree({
"action": function (obj) {
var inst = jQuery.jstree.reference(obj.reference);
var clickedNode = inst.get_node(obj.reference);
updateType(clickedNode.id, clickedNode.text);
updateType(clickedNode.id, clickedNode.data.typeName,clickedNode.data.isLeaf);
}
}, "DEL": {
"label": "删除类型",
... ... @@ -604,7 +657,7 @@ $('#jstree').jstree({
$.toaster('非叶子节点无法添加子类型', '提示', 'info');
return;
}
addMObjType(clickedNode.id, clickedNode.text);
addMObjType(clickedNode.id, clickedNode.data.typeName);
}
}, "ADDDepend": {
"label": "添加依赖服务",
... ... @@ -616,7 +669,7 @@ $('#jstree').jstree({
$.toaster('非叶子节点无法添加子类型', '提示', 'info');
return;
}
AddDepend(clickedNode.id, clickedNode.text);
AddDepend(clickedNode.id, clickedNode.data.typeName);
}
}
}
... ...