diff options
author | 一颗红心 <thinkwei2012@gmail.com> | 2019-08-19 11:41:27 +0300 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2019-08-19 11:41:27 +0300 |
commit | 913fac2159b922f0a9e335916fc6fa57606acd5d (patch) | |
tree | 522ab2acf7b1bc56dabdb795e051baf78ea603b0 | |
parent | 4c0c99cd8d1289b389d9b9a4cc3dbdba2d75acc7 (diff) |
Add features: batch delete (#145)
* Add features: batch delete
-rw-r--r-- | delete.php | 13 | ||||
-rw-r--r-- | index.php | 6 | ||||
-rw-r--r-- | js/index.js | 36 |
3 files changed, 53 insertions, 2 deletions
@@ -60,4 +60,17 @@ if (isset($_GET['tree'])) { die('?view&s='.$server['id'].'&d='.$server['db']); } +if (isset($_GET['batch_del'])) { + $keys = $_POST['selected_keys']; + $keys = trim($keys, ','); + if (empty($keys)) die('No keys to delete'); + + $keys = explode(',', $keys); + foreach ($keys as $key) { + $redis->del($key); + } + + die('?view&s=' . $server['id'] . '&d=' . $server['db'] . '&key=' . urlencode($keys[0])); +} + ?> @@ -102,6 +102,7 @@ if($redis) { ?> <li<?php echo empty($class) ? '' : ' class="'.implode(' ', $class).'"'?>> + <input type="checkbox" name="checked_keys" value="<?php echo $fullkey?>"/> <a href="?view&s=<?php echo $server['id']?>&d=<?php echo $server['db']?>&key=<?php echo urlencode($fullkey)?>"><?php echo format_html($name)?><?php if ($len !== false) { ?><span class="info">(<?php echo $len?>)</span><?php } ?></a> </li> <?php @@ -215,7 +216,10 @@ if ($databases > 1) { ?> <p> <input type="text" id="filter" size="24" value="type here to filter" placeholder="type here to filter" class="info"> </p> - +<button id="selected_all_keys">Select all</button> +<button id="operations"> +<a href="delete.php?s=<?php echo $server['id']?>&d=<?php echo $server['db']?>&batch_del=1" class="batch_del">Delete selected<img src="images/delete.png" style="width: 1em;height: 1em;vertical-align: middle;" title="Delete selected" alt="[X]"></a> +</button> <div id="keys"> <ul> <?php print_namespace($namespaces, 'Keys', '', empty($namespaces))?> diff --git a/js/index.js b/js/index.js index b440a77..de45790 100644 --- a/js/index.js +++ b/js/index.js @@ -1,6 +1,40 @@ $(function() { + $('#selected_all_keys').on('click', function () { + if ($(this).html()=='Select all'){ + $('input[name=checked_keys]').each(function () { + $(this).attr('checked', 'checked'); + }); + $(this).html('Select none'); + }else { + $('input[name=checked_keys]').each(function () { + $(this).removeAttr('checked'); + }); + $(this).html('Select all'); + } + }) + $('#sidebar').on('click', 'a', function(e) { - if (e.currentTarget.className.indexOf('deltree') !== -1) { + if (e.currentTarget.className.indexOf('batch_del') !== -1){ + e.preventDefault(); + var selected_keys = ''; + $('input[name=checked_keys]:checked').each(function () { + selected_keys += $(this).val() + ','; + }); + if (!selected_keys) { + alert('Please select the keys you want to delete.'); + return; + } + if (confirm('Are you sure you want to delete all selected keys?')) { + $.ajax({ + type: "POST", + url: this.href, + data: 'post=1&selected_keys=' + selected_keys, + success: function(url) { + top.location.href = top.location.pathname+url; + } + }); + } + }else if (e.currentTarget.className.indexOf('deltree') !== -1) { e.preventDefault(); if (confirm('Are you sure you want to delete this whole tree and all it\'s keys?')) { |