HDFS-7987. Allow files / directories to be moved (Ravi Prakash via aw)

(cherry picked from commit d44f4745b4)
This commit is contained in:
Allen Wittenauer 2016-06-10 09:02:28 -07:00 committed by Ravi Prakash
parent 743c0ebd67
commit b9eedc24a6
3 changed files with 83 additions and 16 deletions

View File

@ -179,6 +179,13 @@
data-target="#modal-upload-file" title="Upload Files"> data-target="#modal-upload-file" title="Upload Files">
<span class="glyphicon glyphicon-cloud-upload"></span> <span class="glyphicon glyphicon-cloud-upload"></span>
</button> </button>
<button class="btn btn-default dropdown-toggle" type="button"
data-toggle="dropdown" title="Cut & Paste">
<span class="glyphicon glyphicon-list-alt"></span></button>
<ul class="dropdown-menu cut-paste">
<li><a id="explorer-cut">Cut</a></li>
<li><a id="explorer-paste">Paste</a></li>
</ul>
</div> </div>
</div> </div>
@ -236,6 +243,7 @@
<table class="table" id="table-explorer"> <table class="table" id="table-explorer">
<thead> <thead>
<tr> <tr>
<th><input type="checkbox" id="file-selector-all"></th>
<th title="Permissions">Permission</th> <th title="Permissions">Permission</th>
<th>Owner</th> <th>Owner</th>
<th>Group</th> <th>Group</th>
@ -251,6 +259,7 @@
{#FileStatus} {#FileStatus}
<tr inode-path="{pathSuffix}" data-permission="{permission}" <tr inode-path="{pathSuffix}" data-permission="{permission}"
class="explorer-entry"> class="explorer-entry">
<td><input type="checkbox" class="file_selector"> </td>
<td><span class="explorer-perm-links editable-click"> <td><span class="explorer-perm-links editable-click">
{type|helper_to_directory}{permission|helper_to_permission} {type|helper_to_directory}{permission|helper_to_permission}
{aclBit|helper_to_acl_bit} {aclBit|helper_to_acl_bit}

View File

@ -311,21 +311,27 @@
delete_path(inode_name, absolute_file_path); delete_path(inode_name, absolute_file_path);
}); });
$('#table-explorer').dataTable( { $('#file-selector-all').click(function() {
'lengthMenu': [ [25, 50, 100, -1], [25, 50, 100, "All"] ], $('.file_selector').prop('checked', $('#file-selector-all')[0].checked );
'columns': [ });
{'searchable': false }, //Permissions
null, //Owner //This needs to be last because it repaints the table
null, //Group $('#table-explorer').dataTable( {
{ 'searchable': false, 'render': func_size_render}, //Size 'lengthMenu': [ [25, 50, 100, -1], [25, 50, 100, "All"] ],
{ 'searchable': false, 'render': func_time_render}, //Last Modified 'columns': [
{ 'searchable': false }, //Replication { 'orderable' : false }, //select
null, //Block Size {'searchable': false }, //Permissions
null, //Name null, //Owner
{ 'sortable' : false } //Trash null, //Group
], { 'searchable': false, 'render': func_size_render}, //Size
"deferRender": true { 'searchable': false, 'render': func_time_render}, //Last Modified
}); { 'searchable': false }, //Replication
null, //Block Size
null, //Name
{ 'orderable' : false } //Trash
],
"deferRender": true
});
}); });
}).error(network_error_handler(url)); }).error(network_error_handler(url));
} }
@ -417,5 +423,50 @@
} }
}); });
//Store the list of files which have been checked into session storage
function store_selected_files(current_directory) {
sessionStorage.setItem("source_directory", current_directory);
var selected_files = $("input:checked.file_selector");
var selected_file_names = new Array();
selected_files.each(function(index) {
selected_file_names[index] = $(this).closest('tr').attr('inode-path');
})
sessionStorage.setItem("selected_file_names", JSON.stringify(selected_file_names));
alert("Cut " + selected_file_names.length + " files/directories");
}
//Retrieve the list of files from session storage and rename them to the current
//directory
function paste_selected_files() {
var files = JSON.parse(sessionStorage.getItem("selected_file_names"));
var source_directory = sessionStorage.getItem("source_directory");
$.each(files, function(index, value) {
var url = "/webhdfs/v1"
+ encode_path(append_path(source_directory, value))
+ '?op=RENAME&destination='
+ encode_path(append_path(current_directory, value));
$.ajax({
type: 'PUT',
url: url
}).done(function(data) {
if(index == files.length - 1) {
browse_directory(current_directory);
}
}).error(function(jqXHR, textStatus, errorThrown) {
show_err_msg("Couldn't move file " + value + ". " + errorThrown);
});
})
}
$('#explorer-cut').click(function() {
store_selected_files(current_directory);
});
$('#explorer-paste').click(function() {
paste_selected_files();
});
init(); init();
})(); })();

View File

@ -286,3 +286,10 @@ header.bs-docs-nav, header.bs-docs-nav .navbar-brand {
font-weight: normal; font-weight: normal;
cursor: pointer; cursor: pointer;
} }
.cut-paste {
width: 75px;
min-width: 75px;
float: right;
left: 75px;
}