Skip to content

Commit

Permalink
feat: get keys list drop key value
Browse files Browse the repository at this point in the history
  • Loading branch information
welllog committed Sep 12, 2024
1 parent e8c389f commit 41433f5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pkg
bin
release
*.tmp
.vscode

# Architecture specific extensions/prefixes
*.[568vq]
Expand All @@ -19,4 +20,4 @@ release

# Package Files
*.war
*.ear
*.ear
86 changes: 43 additions & 43 deletions assets/etcdkeeper/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
<div id="value"></div>
</div>
</div>

<div id="footer" style="padding:5px;color:#777;">&nbsp;</div>
<div id="westTools">
<a href="javascript:void(0)" class="icon-path" style="margin-right:4px;" onclick="changeTreeMode();" title="Tree mode"></a>
Expand All @@ -61,7 +61,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
<div id="treeNodeMenu" class="easyui-menu" style="width:150px;">
<div onclick="removeNode()" data-options="iconCls:'icon-remove'">Remove Node</div>
</div>

<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">
Expand Down Expand Up @@ -94,7 +94,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
</div>
</div>
</div>

<div id="userinfo" class="easyui-window" title="Authentication" data-options="modal:true,closed:true" style="width:350px;height:220px;padding:10px;">
<div style="padding:10px 40px 20px 40px">
<table cellpadding="10">
Expand All @@ -119,7 +119,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
<span id="statusMember" style="margin-left: 10px;"></span>
<span style="margin-left: 10px;">ETCD Keeper 0.7.7</span>
</div>

<div id="modeMenu" style="">
<div id="mode_text" onclick="changeMode('text')">text</div>
<div id="mode_toml" onclick="changeMode('toml')">toml</div>
Expand All @@ -135,13 +135,13 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
<div id="version_3" onclick="selVersion('3')">version 3</div>
<div id="version_2" onclick="selVersion('2')">version 2</div>
</div>

<script>
resizeWindow();
$(window).resize(function(){ // FIXME: invalid
resizeWindow();
});

function resizeWindow(){
$('#elayout').height(($(window).height() - 128) + 'px')
}
Expand Down Expand Up @@ -221,7 +221,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
//if(typeof(autoFormat) === 'undefined') {
//autoFormat = 'false';
//}

// get separator
$.ajax({
type: 'GET',
Expand All @@ -237,7 +237,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
$.messager.alert('Error', $.toJSON(err), 'error');
}
});

$(document).ready(function() {
editor.setTheme('ace/theme/github');
editor.getSession().setMode('ace/mode/' + aceMode);
Expand All @@ -248,7 +248,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
iconCls: 'icon-ok'
});
});

function init() {
$('#etcdAddr').textbox('setValue', etcdBase);
var t = $('#etree').tree({
Expand All @@ -258,7 +258,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
onContextMenu:showMenu
});
}

function changeHost(newValue, oldValue) {
if (newValue === '') {
$.messager.alert('Error','ETCD address is empty.','error');
Expand All @@ -268,7 +268,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
connect();
}
}

function connect() {
var status = 'ok';
var uname = $('#uname').textbox('getValue');
Expand Down Expand Up @@ -310,7 +310,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
$.messager.alert('Error', $.toJSON(err), 'error');
}
});

if (status === 'ok') {
reload();
} else if (status === 'login') {
Expand All @@ -323,7 +323,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
$('#etree').tree('loadData', []);
}
}

function reload() {
var rootNode = {
id : getId(),
Expand All @@ -339,14 +339,14 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
showNode($('#etree').tree('getRoot'));
resetValue();
}

function resetValue() {
$('#elayout').layout('panel','center').panel('setTitle', separator);
editor.getSession().setValue('');
editor.setReadOnly(false);
$('#footer').html('&nbsp;');
}

function showNode(node) {
$('#elayout').layout('panel','center').panel('setTitle', node.path);
editor.getSession().setValue('');
Expand Down Expand Up @@ -396,7 +396,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
// clear child node
var children = $('#etree').tree('getChildren', node.target);
//if (node.state === 'closed' || children.length === 0) {

//}
var url = '';
if (treeMode === 'list') {
Expand All @@ -421,11 +421,11 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
changeModeBySuffix(node.path);
}
var arr = [];
if (data.node.nodes) {

if (data.node.nodes) {
// refresh child node
for (var i in data.node.nodes) {
var newData = getNode(data.node.nodes[i]);
var newData = getNode(data.node.nodes[i]);
arr.push(newData);
}
$('#etree').tree('append', {
Expand All @@ -437,15 +437,15 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
for(var n in children) {
$('#etree').tree('remove', children[n].target);
}
}
}
},
error: function(err) {
$.messager.alert('Error',$.toJSON(err),'error');
}
});
}
}

function getNode(n) {
var text = '';
if (treeMode === 'list') {
Expand Down Expand Up @@ -475,7 +475,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
}
return obj
}

function showMenu(e, node) {
e.preventDefault();
$('#etree').tree('select',node.target);
Expand All @@ -497,7 +497,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
top: e.pageY
});
}

function saveValue() {
var node = $('#etree').tree('getSelected');
$.ajax({
Expand Down Expand Up @@ -525,19 +525,19 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
}
});
}

function createNode() {
var node = $('#etree').tree('getSelected');
var nodePath = node.path;
if (nodePath === separator) {
nodePath = ''
}

if (treeMode == 'list') { // list mode
if ($('#cnodeForm').form('validate')) {
var createNodePath = $('#name').textbox('getValue');
var createNodePath = $('#name').textbox('getValue').trim();
if (!createNodePath.startsWith(separator)) {
createNodePath= separator + $('#name').textbox('getValue');
createNodePath= separator + $('#name').textbox('getValue').trim();
}
$.ajax({
type: 'PUT',
Expand Down Expand Up @@ -566,7 +566,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
var objNode = nodeExist(obj.path);
if (objNode === null) {
newData.push(obj);

$('#etree').tree('append', {
parent: node.target,
data: newData
Expand All @@ -585,13 +585,13 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
} else { // dir mode
if ($('#cnodeForm').form('validate')) {
var pathArr = [];
var inputArr = $('#name').textbox('getValue').split(separator);
var inputArr = $('#name').textbox('getValue').trim().split(separator);
for (var i in inputArr) {
if ($.trim(inputArr[i]) != '') {
pathArr.push(inputArr[i]);
}
}

$.ajax({
type: 'PUT',
timeout: timeout,
Expand Down Expand Up @@ -657,7 +657,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
data: newData
});
}

$('#cvalue').textbox('enable','none');
$('#cnodeForm').form('reset');
$('#ttl').numberbox('setValue', '');
Expand All @@ -669,7 +669,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
}
}
}

function nodeExist(p) {
for (var i=0;i<=idCount;i++) {
var node = $('#etree').tree('find', i);
Expand All @@ -679,7 +679,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
}
return null;
}

function removeNode() {
var node = $('#etree').tree('getSelected');
$.messager.confirm('Confirm', 'Remove ' + node.text + '?', function(r){
Expand All @@ -695,9 +695,9 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
resetValue();
if (data === 'ok') {
alertMessage('Delete success.');

var pnode = $('#etree').tree('getParent', node.target);

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

if (version === '3') {
Expand All @@ -720,15 +720,15 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
}
});
}

function selDir(item) {
if (item.value === 'true') {
$('#cvalue').textbox('disable','none');
}else {
$('#cvalue').textbox('enable','none');
}
}

function alertMessage(msg) {
$.messager.show({
title:'Message',
Expand All @@ -741,11 +741,11 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
}
});
}

function getId() {
return idCount++;
}

function changeMode(mode) {
aceMode = mode;
Cookies.set('ace-mode', aceMode, {expires: 30});
Expand All @@ -755,7 +755,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
$('#mode_' + mode).append('<div id="' + curIconMode + '" class="menu-icon icon-ok"></div>');
$('#showMode').html(aceMode);
}

function changeFooter(ttl, cIndex, mIndex) {
$('#footer').html('<span>TTL&nbsp;:&nbsp;' + ttl + '&nbsp;&nbsp;&nbsp;&nbsp;CreateRevision&nbsp;:&nbsp;' + cIndex + '&nbsp;&nbsp;&nbsp;&nbsp;ModRevision&nbsp;:&nbsp;' + mIndex + '</span><span id="showMode" style="position: absolute;right: 10px;color: #777;">' + aceMode + '</span>');
}
Expand All @@ -769,7 +769,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
editor.navigateFileStart();
}
}

function changeTreeMode() {
if (version === '2') {
treeMode = 'path';
Expand All @@ -784,7 +784,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
connect();
}
}

function changeModeBySuffix(path) {
var a = path.split(separator);
var tokens = a.slice(a.length-1,a.lenght)[0].split('.');
Expand All @@ -801,7 +801,7 @@ <h2><img src="../etcdkeeper/framework/logo.png" width="20" style="position:relat
}
}
}

function userOK() {
$('#userinfo').window('close');
connect();
Expand Down
8 changes: 4 additions & 4 deletions src/etcdkeeper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,9 @@ func get(w http.ResponseWriter, r *http.Request) {
if p[0] == "/" {
prefixKey = ""
}
resp, err = cli.Get(context.Background(), prefixKey, clientv3.WithPrefix())
resp, err = cli.Get(context.Background(), prefixKey, clientv3.WithPrefix(), clientv3.WithKeysOnly())
} else {
resp, err = cli.Get(context.Background(), p[0])
resp, err = cli.Get(context.Background(), p[0], clientv3.WithKeysOnly())
}
if err != nil {
data["errorCode"] = 500
Expand Down Expand Up @@ -840,9 +840,9 @@ func getPath(w http.ResponseWriter, r *http.Request) {
//child
var resp *clientv3.GetResponse
if rangeEnd != "" {
resp, err = cli.Get(context.Background(), key, clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend))
resp, err = cli.Get(context.Background(), key, clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend), clientv3.WithKeysOnly())
} else {
resp, err = cli.Get(context.Background(), key, clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend))
resp, err = cli.Get(context.Background(), key, clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend), clientv3.WithKeysOnly())
}
if err != nil {
data["errorCode"] = 500
Expand Down
Loading

0 comments on commit 41433f5

Please sign in to comment.