From d44f4745b4a186dd06dd6837a85ad90a237d7d97 Mon Sep 17 00:00:00 2001 From: Allen Wittenauer Date: Fri, 10 Jun 2016 09:02:28 -0700 Subject: [PATCH] HDFS-7987. Allow files / directories to be moved (Ravi Prakash via aw) --- .../src/main/webapps/hdfs/explorer.html | 9 ++ .../src/main/webapps/hdfs/explorer.js | 83 +++++++++++++++---- .../src/main/webapps/static/hadoop.css | 7 ++ 3 files changed, 83 insertions(+), 16 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.html b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.html index 51f72e574c8..ad8c3740ea9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.html +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.html @@ -179,6 +179,13 @@ data-target="#modal-upload-file" title="Upload Files"> + + @@ -236,6 +243,7 @@ + @@ -251,6 +259,7 @@ {#FileStatus} +
Permission Owner Group
{type|helper_to_directory}{permission|helper_to_permission} {aclBit|helper_to_acl_bit} diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js index 6fa5f195f8b..1739db2b7c1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js @@ -310,22 +310,28 @@ var absolute_file_path = append_path(current_directory, inode_name); delete_path(inode_name, absolute_file_path); }); - - $('#table-explorer').dataTable( { - 'lengthMenu': [ [25, 50, 100, -1], [25, 50, 100, "All"] ], - 'columns': [ - {'searchable': false }, //Permissions - null, //Owner - null, //Group - { 'searchable': false, 'render': func_size_render}, //Size - { 'searchable': false, 'render': func_time_render}, //Last Modified - { 'searchable': false }, //Replication - null, //Block Size - null, //Name - { 'sortable' : false } //Trash - ], - "deferRender": true - }); + + $('#file-selector-all').click(function() { + $('.file_selector').prop('checked', $('#file-selector-all')[0].checked ); + }); + + //This needs to be last because it repaints the table + $('#table-explorer').dataTable( { + 'lengthMenu': [ [25, 50, 100, -1], [25, 50, 100, "All"] ], + 'columns': [ + { 'orderable' : false }, //select + {'searchable': false }, //Permissions + null, //Owner + null, //Group + { 'searchable': false, 'render': func_size_render}, //Size + { '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)); } @@ -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(); })(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/hadoop.css b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/hadoop.css index 2ed5f294373..5021fb52e43 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/hadoop.css +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/hadoop.css @@ -285,4 +285,11 @@ header.bs-docs-nav, header.bs-docs-nav .navbar-brand { margin-bottom: 0; font-weight: normal; cursor: pointer; +} + +.cut-paste { + width: 75px; + min-width: 75px; + float: right; + left: 75px; } \ No newline at end of file