Forráskód Böngészése

AMBARI-18638. Include an option to upload query in hive-view (alexantonenko)

Alex Antonenko 8 éve
szülő
commit
e93c13d0de

+ 31 - 0
contrib/views/hive-next/src/main/resources/ui/hive-web/app/components/upload-query.js

@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import EmberUploader from 'ember-uploader';
+
+export default EmberUploader.FileField.extend({
+
+  attributeBindings: ['id', 'style'],
+  id: 'upload',
+  style: 'display:none',
+  initialize: function() {
+    this.$().on('change', function(e) {
+		this.sendAction('filesUploaded', e.currentTarget.files);
+		}.bind(this));
+    }.on('didInsertElement')
+  });

+ 41 - 2
contrib/views/hive-next/src/main/resources/ui/hive-web/app/controllers/index.js

@@ -1,4 +1,4 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one
+/* * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
  * distributed with this work for additional information
  * regarding copyright ownership.  The ASF licenses this file
  * regarding copyright ownership.  The ASF licenses this file
@@ -39,7 +39,6 @@ export default Ember.Controller.extend({
   selectedDatabase: Ember.computed.alias('databaseService.selectedDatabase'),
   selectedDatabase: Ember.computed.alias('databaseService.selectedDatabase'),
   isDatabaseExplorerVisible: true,
   isDatabaseExplorerVisible: true,
   canKillSession: Ember.computed.and('model.sessionTag', 'model.sessionActive'),
   canKillSession: Ember.computed.and('model.sessionTag', 'model.sessionActive'),
-
   queryProcessTabs: [
   queryProcessTabs: [
     Ember.Object.create({
     Ember.Object.create({
       name: Ember.I18n.t('menus.logs'),
       name: Ember.I18n.t('menus.logs'),
@@ -208,6 +207,7 @@ export default Ember.Controller.extend({
     return this.createJob(job, originalModel);
     return this.createJob(job, originalModel);
   },
   },
 
 
+
   getVisualExplainJson: function (job, originalModel) {
   getVisualExplainJson: function (job, originalModel) {
     var self = this;
     var self = this;
     var defer = Ember.RSVP.defer();
     var defer = Ember.RSVP.defer();
@@ -622,6 +622,45 @@ export default Ember.Controller.extend({
       query.set('fileContent', updatedContent);
       query.set('fileContent', updatedContent);
     },
     },
 
 
+    filesUploaded: (function(files) {
+      var idCounter = 0;
+      return function (files) {
+        var self=this;
+        var name = files[0].name;
+        var i = name.indexOf(".");
+        var title = name.substr(0, i);
+        idCounter++;
+        var defer = Ember.RSVP.defer()
+        var reader = new FileReader();
+
+        reader.onloadstart = function(e) {
+          Ember.$("#uploadProgressModal").modal("show");
+        }
+        reader.onloadend = function(e) {
+          defer.resolve(e.target.result);
+        }
+        reader.onerror = function(e) {
+          self.get('notifyService').error("Upload failed");
+          Ember.$("#uploadProgressModal").modal("hide");
+        }
+        reader.readAsText(files[0]);
+        defer.promise.then(function(data) {
+        var model = self.store.createRecord(constants.namingConventions.savedQuery, {
+          dataBase: self.get('selectedDatabase.name'),
+          title: title,
+          id: 'fixture_upload' + idCounter
+          });
+        return Ember.RSVP.resolve(self.transitionToRoute(constants.namingConventions.subroutes.savedQuery, model)).then(function() {
+          return data;
+        });
+        }). then(function(data) {
+          self.set('openQueries.currentQuery.fileContent',data);
+          Ember.$("#uploadProgressModal").modal("hide");
+        });
+        };
+    }()),
+
+
     addQuery: (function () {
     addQuery: (function () {
       var idCounter = 0;
       var idCounter = 0;
 
 

+ 2 - 0
contrib/views/hive-next/src/main/resources/ui/hive-web/app/initializers/i18n.js

@@ -195,6 +195,7 @@ TRANSLATIONS = {
     save: 'Save',
     save: 'Save',
     downloadQuery: 'Download',
     downloadQuery: 'Download',
     newQuery: 'New Worksheet',
     newQuery: 'New Worksheet',
+    uploadQuery: 'Upload',
     newUdf: 'New UDF',
     newUdf: 'New UDF',
     history: 'History',
     history: 'History',
     ok: 'OK',
     ok: 'OK',
@@ -297,6 +298,7 @@ TRANSLATIONS = {
     },
     },
     ui : {
     ui : {
       'uploadProgress' : "Upload Progress",
       'uploadProgress' : "Upload Progress",
+      'uploading': "Uploading..",
       'uploadFromLocal':"Upload from Local",
       'uploadFromLocal':"Upload from Local",
       'uploadFromHdfs':"Upload from HDFS",
       'uploadFromHdfs':"Upload from HDFS",
       'selectFileType':"Select File Type",
       'selectFileType':"Select File Type",

+ 29 - 2
contrib/views/hive-next/src/main/resources/ui/hive-web/app/templates/index.hbs

@@ -15,6 +15,27 @@
 * See the License for the specific language governing permissions and
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * limitations under the License.
 }}
 }}
+<div id="uploadProgressModal" class="modal fade" role="dialog" data-backdrop="static">
+  <div class="modal-dialog">
+
+    <!-- Modal content-->
+    <div class="modal-content">
+      <div class="modal-header">
+        <h4 class="modal-title">{{t "hive.ui.uploadProgress"}}</h4>
+      </div>
+      <div class="modal-body">
+        <p>
+        <ul>
+          {{t "hive.ui.uploading"}}
+        </ul>
+        </p>
+      </div>
+    </div>
+
+  </div>
+</div>
+
+
 
 
 <div id="index-content">
 <div id="index-content">
   <div class="main-content">
   <div class="main-content">
@@ -46,6 +67,11 @@
             {{t "buttons.explain"}}
             {{t "buttons.explain"}}
           </button>
           </button>
 
 
+          <label for="upload">
+            <span {{bind-attr class=":btn :btn-sm :btn-default"}}>{{t "buttons.uploadQuery"}}</span>
+            {{upload-query filesUploaded="filesUploaded"}}
+          </label>
+
           <button type="button" class="btn btn-sm btn-default save-query-as" {{action "saveQuery"}}>{{t "buttons.saveAs"}}</button>
           <button type="button" class="btn btn-sm btn-default save-query-as" {{action "saveQuery"}}>{{t "buttons.saveAs"}}</button>
 
 
           {{render 'insert-udfs'}}
           {{render 'insert-udfs'}}
@@ -54,8 +80,9 @@
             <button type="button" class="btn btn-sm btn-danger kill-session" {{action "killSession"}}>{{t "buttons.killSession"}}</button>
             <button type="button" class="btn btn-sm btn-danger kill-session" {{action "killSession"}}>{{t "buttons.killSession"}}</button>
           {{/if}}
           {{/if}}
 
 
-          <button type="button" class="btn btn-sm btn-primary  pull-right" {{action "addQuery"}}>{{t "buttons.newQuery"}}</button>
-        </div>
+          <button type="button" class="btn btn-sm btn-primary  pull-right" {{action "addQuery"}}> {{t "buttons.newQuery"}}</button>
+         
+         </div>
       {{/panel-widget}}
       {{/panel-widget}}
 
 
       {{#if displayJobTabs}}
       {{#if displayJobTabs}}

+ 32 - 0
contrib/views/hive/src/main/resources/ui/hive-web/app/components/upload-query.js

@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import EmberUploader from 'ember-uploader';
+
+export default EmberUploader.FileField.extend({
+
+  attributeBindings: ['id', 'style'],
+  id: 'upload',
+  style: 'display:none',
+  initialize: function() {
+    this.$().on('change', function(e) {
+                this.sendAction('filesUploaded', e.currentTarget.files);
+                }.bind(this));
+    }.on('didInsertElement')
+  });
+

+ 38 - 0
contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js

@@ -599,6 +599,44 @@ export default Ember.Controller.extend({
       query.set('fileContent', updatedContent);
       query.set('fileContent', updatedContent);
     },
     },
 
 
+    filesUploaded: (function(files) {
+      var idCounter = 0;
+      return function (files) {
+        var self=this;
+        var name = files[0].name;
+        var i = name.indexOf(".");
+        var title = name.substr(0, i);
+        idCounter++;
+        var defer = Ember.RSVP.defer()
+        var reader = new FileReader();
+
+        reader.onloadstart = function(e) {
+          Ember.$("#uploadProgressModal").modal("show");
+        }
+        reader.onloadend = function(e) {
+          defer.resolve(e.target.result);
+        }
+        reader.onerror = function(e) {
+          self.get('notifyService').error("Upload failed");
+          Ember.$("#uploadProgressModal").modal("hide");
+        }
+        reader.readAsText(files[0]);
+        defer.promise.then(function(data) {
+        var model = self.store.createRecord(constants.namingConventions.savedQuery, {
+          dataBase: self.get('selectedDatabase.name'),
+          title: title,
+          id: 'fixture_upload' + idCounter
+          });
+        return Ember.RSVP.resolve(self.transitionToRoute(constants.namingConventions.subroutes.savedQuery, model)).then(function() {
+          return data;
+        });
+        }). then(function(data) {
+          self.set('openQueries.currentQuery.fileContent',data);
+          Ember.$("#uploadProgressModal").modal("hide");
+        });
+        };
+    }()),
+
     addQuery: (function () {
     addQuery: (function () {
       var idCounter = 0;
       var idCounter = 0;
 
 

+ 2 - 0
contrib/views/hive/src/main/resources/ui/hive-web/app/initializers/i18n.js

@@ -193,6 +193,7 @@ TRANSLATIONS = {
     save: 'Save',
     save: 'Save',
     downloadQuery: 'Download',
     downloadQuery: 'Download',
     newQuery: 'New Worksheet',
     newQuery: 'New Worksheet',
+    uploadQuery: 'Upload',
     newUdf: 'New UDF',
     newUdf: 'New UDF',
     history: 'History',
     history: 'History',
     ok: 'OK',
     ok: 'OK',
@@ -295,6 +296,7 @@ TRANSLATIONS = {
     },
     },
     ui : {
     ui : {
       'uploadProgress' : "Upload Progress",
       'uploadProgress' : "Upload Progress",
+      'uploading': "Uploading..",
       'uploadFromLocal':"Upload from Local",
       'uploadFromLocal':"Upload from Local",
       'uploadFromHdfs':"Upload from HDFS",
       'uploadFromHdfs':"Upload from HDFS",
       'selectFileType':"Select File Type",
       'selectFileType':"Select File Type",

+ 24 - 0
contrib/views/hive/src/main/resources/ui/hive-web/app/templates/index.hbs

@@ -15,6 +15,25 @@
 * See the License for the specific language governing permissions and
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * limitations under the License.
 }}
 }}
+<div id="uploadProgressModal" class="modal fade" role="dialog" data-backdrop="static">
+  <div class="modal-dialog">
+
+    <!-- Modal content-->
+    <div class="modal-content">
+      <div class="modal-header">
+        <h4 class="modal-title">{{t "hive.ui.uploadProgress"}}</h4>
+      </div>
+      <div class="modal-body">
+        <p>
+        <ul>
+          {{t "hive.ui.uploading"}}
+        </ul>
+        </p>
+      </div>
+    </div>
+
+  </div>
+</div>
 
 
 <div id="index-content">
 <div id="index-content">
   <div class="main-content">
   <div class="main-content">
@@ -46,6 +65,11 @@
             {{t "buttons.explain"}}
             {{t "buttons.explain"}}
           </button>
           </button>
 
 
+          <label for="upload">
+            <span {{bind-attr class=":btn :btn-sm :btn-default"}}>{{t "buttons.uploadQuery"}}</span>
+            {{upload-query filesUploaded="filesUploaded"}}
+          </label>
+
           <button type="button" class="btn btn-sm btn-default save-query-as" {{action "saveQuery"}}>{{t "buttons.saveAs"}}</button>
           <button type="button" class="btn btn-sm btn-default save-query-as" {{action "saveQuery"}}>{{t "buttons.saveAs"}}</button>
 
 
           {{render 'insert-udfs'}}
           {{render 'insert-udfs'}}