ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbhowm...@apache.org
Subject ambari git commit: AMBARI-15347. New Files View: Add a notice to upload modal stating that it only supports single file upload. (dipayanb)
Date Tue, 15 Mar 2016 12:03:05 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 1d1620a32 -> 226143a5b


AMBARI-15347. New Files View: Add a notice to upload modal stating that it only supports single
file upload. (dipayanb)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/226143a5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/226143a5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/226143a5

Branch: refs/heads/trunk
Commit: 226143a5b8df4e44611672f540d09b9e8f6f4389
Parents: 1d1620a
Author: Dipayan Bhowmick <dipayan.bhowmick@gmail.com>
Authored: Tue Mar 15 17:32:45 2016 +0530
Committer: Dipayan Bhowmick <dipayan.bhowmick@gmail.com>
Committed: Tue Mar 15 17:32:45 2016 +0530

----------------------------------------------------------------------
 .../resources/ui/app/components/upload-file.js  | 74 ++++++++++++++------
 .../src/main/resources/ui/app/styles/app.less   |  5 ++
 .../ui/app/templates/components/upload-file.hbs |  3 +
 3 files changed, 61 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/226143a5/contrib/views/files/src/main/resources/ui/app/components/upload-file.js
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/components/upload-file.js b/contrib/views/files/src/main/resources/ui/app/components/upload-file.js
index e50dec8..96686db 100644
--- a/contrib/views/files/src/main/resources/ui/app/components/upload-file.js
+++ b/contrib/views/files/src/main/resources/ui/app/components/upload-file.js
@@ -52,6 +52,31 @@ export default Ember.Component.extend(OperationModal, {
     this.set('closeOnEscape', false);
   },
 
+  // Returns a promise which resolves if the entry is a file else it rejects if it is a directory.
+  // This tries to read entry and FileReader fails if the entry points to a directory. The
file is
+  // only opened and the reader is aborted when the loading starts.
+  _checkIfFileIsNotDirectory: function(file) {
+    return new Ember.RSVP.Promise((resolve, reject) => {
+
+      if (!Ember.isNone(file.size) && file.size <= 4096) { // Directories generally
have less equal to 4096 bytes as size
+        var reader = new FileReader();
+        reader.onerror = function() {
+          return reject();
+        };
+
+        reader.onloadstart = function() {
+          reader.abort();
+          return resolve();
+        };
+
+        reader.readAsArrayBuffer(file);
+
+      } else {
+        return resolve();
+      }
+    })
+  },
+
   actions: {
     openModal : function() {
       this.get('modalEventBus').showModal('ctx-uploader');
@@ -67,28 +92,35 @@ export default Ember.Component.extend(OperationModal, {
     },
 
     fileLoaded: function(file) {
-      var url = this.get('fileOperationService').getUploadUrl();
-      var uploader = FileUploader.create({
-        url: url
-      });
-      this.set('uploader', uploader);
-      if(!Ember.isEmpty(file)) {
-        uploader.upload(file, {path: this.get('path')});
-        this.setUploading(file.name);
-        uploader.on('progress', (e) => {
-          this.setUploadPercent(e.percent);
-        });
-        uploader.on('didUpload', (e) => {
-          this.send('close');
-          this.sendAction('refreshAction');
-        });
-        uploader.on('didError', (jqXHR, textStatus, errorThrown) => {
-          var error = Ember.$.parseJSON(jqXHR.responseText);
-          this.get('logger').danger(`Failed to upload ${file.name} to ${this.get('path')}`,
error);
-          this.send('close');
-          return false;
+
+      this._checkIfFileIsNotDirectory(file).then(() => {
+        var url = this.get('fileOperationService').getUploadUrl();
+        var uploader = FileUploader.create({
+          url: url
         });
-      }
+        this.set('uploader', uploader);
+        if(!Ember.isEmpty(file)) {
+          uploader.upload(file, {path: this.get('path')});
+          this.setUploading(file.name);
+          uploader.on('progress', (e) => {
+            this.setUploadPercent(e.percent);
+          });
+          uploader.on('didUpload', (e) => {
+            this.set('uploader');
+            this.send('close');
+            this.sendAction('refreshAction');
+          });
+          uploader.on('didError', (jqXHR, textStatus, errorThrown) => {
+            var error = Ember.$.parseJSON(jqXHR.responseText);
+            this.set('uploader');
+            this.get('logger').danger(`Failed to upload ${file.name} to ${this.get('path')}`,
error);
+            this.send('close');
+            return false;
+          });
+        }
+      }, () => {
+        console.error("Cannot add a directory.");
+      });
 
     },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/226143a5/contrib/views/files/src/main/resources/ui/app/styles/app.less
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/styles/app.less b/contrib/views/files/src/main/resources/ui/app/styles/app.less
index a0355c7..bc83db6 100644
--- a/contrib/views/files/src/main/resources/ui/app/styles/app.less
+++ b/contrib/views/files/src/main/resources/ui/app/styles/app.less
@@ -213,3 +213,8 @@ div.text-danger pre{
   font-size: 14px;
   font-weight: normal;
 }
+
+.upload-notice {
+  margin-top: 5px;
+  margin-bottom: -10px;
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/226143a5/contrib/views/files/src/main/resources/ui/app/templates/components/upload-file.hbs
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/templates/components/upload-file.hbs
b/contrib/views/files/src/main/resources/ui/app/templates/components/upload-file.hbs
index 9563406..62714f9 100644
--- a/contrib/views/files/src/main/resources/ui/app/templates/components/upload-file.hbs
+++ b/contrib/views/files/src/main/resources/ui/app/templates/components/upload-file.hbs
@@ -36,6 +36,9 @@
                 <h4> Drag file to upload or click to browse</h4>
               </div>
             {{/file-picker}}
+            <div class="upload-notice text-right">
+              <em class="text-danger">Currently support single file upload</em>
+            </div>
           {{else}}
             <div class="progress file-picker-progress">
               <div class="progress-bar" role="progressbar" aria-valuenow="{{uploadPercent}}"
aria-valuemin="0"


Mime
View raw message