Skip to content

Commit

Permalink
Fix some displayed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
evildecay committed Aug 31, 2018
1 parent bded50e commit 9efebbd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 65 deletions.
72 changes: 37 additions & 35 deletions assets/etcdkeeper/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5

<div id="cnode" class="easyui-window" title="Create node" data-options="modal:true,closed:true" style="width:650px;height:480px;padding:10px;">
<div style="padding:10px 40px 20px 40px">
<form id="cnodeForm" method="put">
<form id="cnodeForm">
<table cellpadding="10">
<tr>
<td>Name:</td>
Expand Down Expand Up @@ -309,9 +309,9 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
success: function(data) {
if (data.errorCode) {
$('#etree').tree('remove', node.target);
console.log(data.errorCode);
console.log(data.message);
resetValue()
}else {
} else {
editor.getSession().setValue(data.node.value);
//if (autoFormat === 'true') {
//format(aceMode);
Expand Down Expand Up @@ -357,8 +357,8 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
dataType: 'json',
success: function(data) {
if (data.errorCode) {
$.messager.alert('Error',data.errorCode,'error');
}else {
$.messager.alert('Error', data.message, 'error');
} else {
if (data.node.value) {
editor.getSession().setValue(data.node.value);
changeFooter(data.node.ttl, data.node.createdIndex, data.node.modifiedIndex);
Expand Down Expand Up @@ -473,7 +473,7 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
nodePath = ''
}

if (treeMode == 'list') {
if (treeMode == 'list') { // list mode
if ($('#cnodeForm').form('validate')) {
var createNodePath = $('#name').textbox('getValue');
if (!createNodePath.startsWith(separator)) {
Expand All @@ -490,7 +490,7 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
$('#cnode').window('close');
var ret = $.evalJSON(data);
if (ret.errorCode) {
$.messager.alert('Error', ret.cause + " " + ret.message, 'error');
$.messager.alert('Error', ret.message, 'error');
}else {
alertMessage('Create success.');
var newData = [];
Expand All @@ -512,7 +512,6 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
data: newData
});
}

}
$('#cvalue').textbox('enable','none');
$('#cnodeForm').form('reset');
Expand All @@ -523,13 +522,13 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
}
});
}
} else {
} else { // dir mode
if ($('#cnodeForm').form('validate')) {
var pathArr = [];
var inputArr = $('#name').textbox('getValue').split(separator);
for (var i in inputArr) {
if ($.trim(inputArr[i]) != '') {
pathArr.push(inputArr[i])
pathArr.push(inputArr[i]);
}
}

Expand All @@ -544,7 +543,7 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
$('#cnode').window('close');
var ret = $.evalJSON(data);
if (ret.errorCode) {
$.messager.alert('Error', ret.cause + ' ' + ret.message, 'error');
$.messager.alert('Error', ret.message, 'error');
}else {
alertMessage('Create success.');
var newData = [];
Expand All @@ -556,13 +555,13 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
obj = {
id : getId(),
text: pathArr[k],
state: $('#dir').combobox('getValue') == 'true'?'closed':'',
state: $('#dir').combobox('getValue') == 'true'?'open':'',
dir: $('#dir').combobox('getValue') == 'true'?true:false,
iconCls: $('#dir').combobox('getValue') == 'true'?'icon-dir':'icon-text',
path: (prePath==separator?(prePath + ''):(prePath + separator)) + pathArr[k],
children:[]
};
}else {
} else {
obj = {
id : getId(),
text: pathArr[k],
Expand All @@ -574,25 +573,26 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
};
}
var objNode = nodeExist(obj.path);
if (objNode != null) {
node = objNode;
prePath = node.path;
continue;
}
if (newData.length == 0) {
if (objNode != null) {
node = objNode;
prePath = node.path;
continue;
}
if (newData.length === 0) {
newData.push(obj);
}else {
} else {
preObj.children.push(obj);
}
preObj = obj;
prePath = obj.path;
}

$('#etree').tree('update', {
target: node.target,
iconCls: 'icon-dir'
});
$('#etree').tree('append', {
if (version === '3') {
$('#etree').tree('update', {
target: node.target,
iconCls: 'icon-dir'
});
}
$('#etree').tree('append', {
parent: node.target,
data: newData
});
Expand Down Expand Up @@ -639,15 +639,17 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
var pnode = $('#etree').tree('getParent', node.target);

$('#etree').tree('remove', node.target);

var isLeaf = $('#etree').tree('isLeaf', pnode.target);
if (isLeaf) {
$('#etree').tree('update', {
target: pnode.target,
iconCls: 'icon-text'
});

if (version === '3') {
var isLeaf = $('#etree').tree('isLeaf', pnode.target);
if (isLeaf && pnode.text !== separator) {
$('#etree').tree('update', {
target: pnode.target,
iconCls: 'icon-text'
});
}
}
}else {
} else {
$.messager.alert('Error', data, 'error');
}
},
Expand Down Expand Up @@ -729,7 +731,7 @@ <h2>ETCD Keeper <span id="ver" style="border: 1px solid #D4D4D4;border-radius: 5
if (tokens.length < 2) {
return
}
var mode = tokens[tokens.length-1]
var mode = tokens[tokens.length-1];
var modes = $('#modeMenu').children();
for (var i=0;i<modes.length;i++) {
m = modes[i].innerText;
Expand Down
64 changes: 34 additions & 30 deletions src/etcdkeeper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func putV2(w http.ResponseWriter, r *http.Request) {
_, err = kapi.Set(context.Background(), key, value, &client.SetOptions{Dir:isDir})
}
if err != nil {
io.WriteString(w, string(err.Error()))
data["errorCode"] = 500
data["message"] = err.Error()
} else {
if resp, err := kapi.Get(context.Background(), key, &client.GetOptions{Recursive:true, Sort:true}); err != nil {
data["errorCode"] = err.Error()
Expand All @@ -164,12 +165,13 @@ func putV2(w http.ResponseWriter, r *http.Request) {
data["node"] = node
}
}
var dataByte []byte
if dataByte, err = json.Marshal(data);err != nil {
io.WriteString(w, err.Error())
} else {
io.WriteString(w, string(dataByte))
}
}

var dataByte []byte
if dataByte, err = json.Marshal(data);err != nil {
io.WriteString(w, err.Error())
} else {
io.WriteString(w, string(dataByte))
}
}

Expand All @@ -179,10 +181,12 @@ func getV2(w http.ResponseWriter, r *http.Request) {
log.Println("GET", "v2", key)

if resp, err := kapi.Get(context.Background(), key, &client.GetOptions{Recursive:true, Sort:true}); err != nil {
data["errorCode"] = err.Error()
data["errorCode"] = 500
data["message"] = err.Error()
} else {
if resp.Node == nil {
data["errorCode"] = "The node does not exist."
data["errorCode"] = 500
data["message"] = "The node does not exist."
} else {
data["node"] = getNode(resp.Node)
}
Expand Down Expand Up @@ -310,7 +314,8 @@ func put(w http.ResponseWriter, r *http.Request) {
_, err = cli.Put(context.Background(), key, value)
}
if err != nil {
io.WriteString(w, string(err.Error()))
data["errorCode"] = 500
data["message"] = err.Error()
} else {
if resp, err := cli.Get(context.Background(), key, clientv3.WithPrefix());err != nil {
data["errorCode"] = err.Error()
Expand All @@ -327,12 +332,13 @@ func put(w http.ResponseWriter, r *http.Request) {
data["node"] = node
}
}
var dataByte []byte
if dataByte, err = json.Marshal(data);err != nil {
io.WriteString(w, err.Error())
} else {
io.WriteString(w, string(dataByte))
}
}

var dataByte []byte
if dataByte, err = json.Marshal(data);err != nil {
io.WriteString(w, err.Error())
} else {
io.WriteString(w, string(dataByte))
}
}

Expand All @@ -342,7 +348,8 @@ func get(w http.ResponseWriter, r *http.Request) {
log.Println("GET", "v3", key)

if resp, err := cli.Get(context.Background(), key, clientv3.WithPrefix());err != nil {
data["errorCode"] = err.Error()
data["errorCode"] = 500
data["message"] = err.Error()
} else {
if r.FormValue("prefix") == "true" {
pnode := make(map[string]interface{})
Expand Down Expand Up @@ -376,7 +383,8 @@ func get(w http.ResponseWriter, r *http.Request) {
node["modifiedIndex"] = kv.ModRevision
data["node"] = node
} else {
data["errorCode"] = "The node does not exist."
data["errorCode"] = 500
data["message"] = "The node does not exist."
}
}
}
Expand Down Expand Up @@ -405,12 +413,10 @@ func getPath(w http.ResponseWriter, r *http.Request) {
// parent
presp, err := cli.Get(context.Background(), key)
if err != nil {
data["errorCode"] = err.Error()
if dataByte, err := json.Marshal(data);err != nil {
io.WriteString(w, err.Error())
} else {
io.WriteString(w, string(dataByte))
}
data["errorCode"] = 500
data["message"] = err.Error()
dataByte, _ := json.Marshal(data)
io.WriteString(w, string(dataByte))
return
}
if key == separator {
Expand All @@ -433,12 +439,10 @@ func getPath(w http.ResponseWriter, r *http.Request) {
//child
resp, err := cli.Get(context.Background(), prefixKey, clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend))
if err != nil {
data["errorCode"] = err.Error()
if dataByte, err := json.Marshal(data);err != nil {
io.WriteString(w, err.Error())
} else {
io.WriteString(w, string(dataByte))
}
data["errorCode"] = 500
data["message"] = err.Error()
dataByte, _ := json.Marshal(data)
io.WriteString(w, string(dataByte))
return
}

Expand Down

0 comments on commit 9efebbd

Please sign in to comment.