Эх сурвалжийг харах

HUE-6012 [metastore] Support dropping tables in responsive

Romain Rigaux 8 жил өмнө
parent
commit
fea2477

+ 3 - 5
apps/metastore/src/metastore/static/metastore/js/metastore.ko.js

@@ -544,11 +544,9 @@ var MetastoreViewModel = (function () {
     	table_selection: ko.mapping.toJSON([self.name]),
     	skip_trash: 'off',
     	is_embeddable: true
-      }, function(data) {
-        if (data && data.status == 0) {
-          self.navigatorStats().tags.push(self.addTagName());
-          self.addTagName('');
-          self.showAddTagName(false);
+      }, function(resp) {
+        if (resp.history_uuid) {
+          huePubSub.publish('notebook.task.submitted', resp.history_uuid);
         } else {
           $(document).trigger("error", data.message);
         }

+ 22 - 15
apps/metastore/src/metastore/templates/metastore.mako

@@ -382,7 +382,6 @@ ${ components.menubar() }
         span12
       %endif
        tile">
-
           <div class="span6 tile">
             <h4>${ _('Properties') }</h4>
             <div title="${ _('Comment') }"><i class="fa fa-fw fa-comment muted"></i>
@@ -509,7 +508,12 @@ ${ components.menubar() }
 
   % if has_write_access:
     <div id="dropTable" class="modal hide fade">
-      <form data-bind="attr: { 'action': '/metastore/tables/drop/' + name }" method="POST">
+      % if is_embeddable:
+        <form data-bind="attr: { 'action': '/metastore/tables/drop/' + name }, submit: dropTables" method="POST">
+          <input type="hidden" name="is_embeddable" value="true"/>
+      % else:
+        <form data-bind="attr: { 'action': '/metastore/tables/drop/' + name }" method="POST">
+      % endif
         ${ csrf_token(request) | n,unicode }
         <div class="modal-header">
           <a href="#" class="close" data-dismiss="modal">&times;</a>
@@ -1114,24 +1118,27 @@ ${ components.menubar() }
   <div id="import-data-modal" class="modal hide fade" style="display: block;width: 640px;margin-left: -320px!important;"></div>
 </div>
 </span>
+
 <script type="text/javascript" charset="utf-8">
 
-  function pieChartDataTransformer(rawDatum) {
-    var _data = [];
-    $(rawDatum.counts).each(function (cnt, item) {
-      _data.push({
-        label: item.name,
-        value: item.popularity,
-        obj: item
-      });
-    });
-    _data.sort(function (a, b) {
-      return a.value - b.value
+  function dropTables(formElement) {
+    $(formElement).ajaxSubmit({
+      dataType: 'json',
+      success: function(resp) {
+        if (resp.history_uuid) {
+          huePubSub.publish('notebook.task.submitted', resp.history_uuid);
+        } else {
+          $(document).trigger("error", data.message);
+        }
+        $("#dropTable").modal('hide');
+      },
+      error: function (xhr, textStatus, errorThrown) {
+        $(document).trigger("error", xhr.responseText);
+      }
     });
-
-    return _data;
   }
 
+
   (function () {
 
     ko.options.deferUpdates = true;

+ 21 - 20
apps/metastore/src/metastore/views.py

@@ -370,31 +370,32 @@ def drop_table(request, database):
   db = dbms.get(request.user)
 
   if request.method == 'POST':
-    tables = request.POST.getlist('table_selection')
-    tables_objects = [db.get_table(database, table) for table in tables]
-    skip_trash = request.POST.get('skip_trash') == 'on'
-    
-    if request.POST.get('is_embeddable'):
-      sql = db.drop_tables(database, tables_objects, design=None, skip_trash=skip_trash, generate_ddl_only=True)
-      return make_notebook(
-          name='Execute and watch',
-          editor_type='hive',
-          statement=sql.strip(),
-          status='ready',
-          database=database,
-          on_success_url=json.dumps({'app': 'metastore', 'path': 'table/%(database)s' % {'database': database}})
-      )
-    else:    
-      try:
+    try:
+      tables = request.POST.getlist('table_selection')
+      tables_objects = [db.get_table(database, table) for table in tables]
+      skip_trash = request.POST.get('skip_trash') == 'on'
+
+      if request.POST.get('is_embeddable'):
+        sql = db.drop_tables(database, tables_objects, design=None, skip_trash=skip_trash, generate_ddl_only=True).hql_query
+        job = make_notebook(
+            name='Execute and watch',
+            editor_type='hive',
+            statement=sql.strip(),
+            status='ready',
+            database=database,
+            on_success_url='assist.db.refresh'
+        )
+        return JsonResponse(job.execute(request, batch=False))
+      else:
         # Can't be simpler without an important refactoring
         design = SavedQuery.create_empty(app_name='beeswax', owner=request.user, data=hql_query('').dumps())
         query_history = db.drop_tables(database, tables_objects, design, skip_trash=skip_trash)
         url = reverse('beeswax:watch_query_history', kwargs={'query_history_id': query_history.id}) + '?on_success_url=' + reverse('metastore:show_tables', kwargs={'database': database})
         return redirect(url)
-      except Exception, ex:
-        error_message, log = dbms.expand_exception(ex, db)
-        error = _("Failed to remove %(tables)s.  Error: %(error)s") % {'tables': ','.join(tables), 'error': error_message}
-        raise PopupException(error, title=_("Hive Error"), detail=log)
+    except Exception, ex:
+      error_message, log = dbms.expand_exception(ex, db)
+      error = _("Failed to remove %(tables)s.  Error: %(error)s") % {'tables': ','.join(tables), 'error': error_message}
+      raise PopupException(error, title=_("Hive Error"), detail=log)
   else:
     title = _("Do you really want to delete the table(s)?")
     return render('confirm.mako', request, {'url': request.path, 'title': title})

+ 1 - 1
desktop/core/src/desktop/templates/assist.mako

@@ -906,7 +906,7 @@ from notebook.conf import get_ordered_interpreters
         if (typeof options.sourceTypes === 'undefined') {
           options.sourceTypes = [];
           % for interpreter in get_ordered_interpreters(request.user):
-            % if interpreter["interface"] in ["hiveserver2", "rdbms", "jdbc"]:
+            % if interpreter["interface"] in ["hiveserver2", "rdbms", "jdbc", "solr"]:
               options.sourceTypes.push({
                 type: '${ interpreter["type"] }',
                 name: '${ interpreter["name"] }'

+ 5 - 6
desktop/core/src/desktop/templates/responsive.mako

@@ -1052,7 +1052,6 @@ ${ assist.assistPanel() }
       self.editorVM.newNotebook();
 
       huePubSub.subscribe("notebook.task.submitted", function (history_id) {
-        // Load
         self.editorVM.openNotebook(history_id, null, true, function(){
           var notebook = self.editorVM.selectedNotebook();
           notebook.snippets()[0].progress.subscribe(function(val){
@@ -1073,11 +1072,11 @@ ${ assist.assistPanel() }
                 // TODO: Show finish notification and clicking on it does onSuccessUrl
                 // or if still on initial spinner we redirect automatically to onSuccessUrl
                 if (notebook.onSuccessUrl()) {
-                  // TODO: If we are in FB directory, also refresh FB dir
-                  window.location.href = notebook.onSuccessUrl();
-                  // TODO: switch to something like params = ko.mapping.fromJSON(notebook.onSuccessUrl())
-                  // {'app': 'metastore', 'path': 'table/%(database)s' % {'database': database}}
-                  // huePubSub.publish('open.app', {'app': 'importer', 'prefill': {'source_type: 'all', 'target_type': 'table'}, 'database': 'huedb'})
+                  if (notebook.onSuccessUrl() == 'assist.db.refresh') { // TODO: Similar if in in FB directory, also refresh FB dir
+                    huePubSub.publish('assist.db.refresh', { sourceType: 'hive' });
+                  } else {  
+                    huePubSub.publish('open.link', notebook.onSuccessUrl());
+                  }
                 }
               } else { // Perform last DROP statement execute
                 snippet.execute();

+ 4 - 4
desktop/libs/indexer/src/indexer/api3.py

@@ -358,10 +358,10 @@ def _create_table_from_a_file(request, source, destination):
 
   editor_type = 'impala' if table_format == 'kudu' else 'hive'
   
-  if request.POST.get('is_embeddable'):
-    on_success_url = json.dumps({'app': 'metastore', 'path': 'table/%(database)s/%(table)s' % {'database': database, 'table': table_name}})
-  else:
-    on_success_url = reverse('metastore:describe_table', kwargs={'database': database, 'table': table_name})
+#   if request.POST.get('is_embeddable'):
+#     on_success_url = json.dumps({'app': 'metastore', 'path': 'table/%(database)s/%(table)s' % {'database': database, 'table': table_name}})
+#   else:
+  on_success_url = reverse('metastore:describe_table', kwargs={'database': database, 'table': table_name})
 
   return make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql.strip(), status='ready', database=database, on_success_url=on_success_url)
 

+ 1 - 2
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -1680,8 +1680,7 @@ ${ assist.assistPanel() }
 % else:
         $.post("${ url('indexer:importer_submit') }", {
           "source": ko.mapping.toJSON(self.source),
-          "destination": ko.mapping.toJSON(self.destination),
-          "is_embeddable": 'true'
+          "destination": ko.mapping.toJSON(self.destination)
         }, function (resp) {
           if (resp.history_uuid) {
             $.jHueNotify.info("${ _('Task ') }" + resp.history_uuid + "${_(' submitted.') }");

+ 5 - 2
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -599,7 +599,10 @@ var EditorViewModel = (function() {
     self.jobs = ko.observableArray(typeof snippet.jobs != "undefined" && snippet.jobs != null ? snippet.jobs : []);
 
     self.ddlNotification = ko.observable();
-    self.delayedDDLNotification = ko.pureComputed(self.ddlNotification).extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 5000 } });
+    self.delayedDDLNotification = ko.pureComputed(self.ddlNotification);
+    if (! vm.isNotificationManager()) {
+      self.delayedDDLNotification.extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 5000 } });
+    }
     window.setTimeout(function () {
       self.delayedDDLNotification.subscribe(function (val) {
         huePubSub.publish('assist.db.refresh', { sourceType: self.type() });
@@ -1410,7 +1413,7 @@ var EditorViewModel = (function() {
                 }
               }
               if (! self.result.handle().has_more_statements && vm.successUrl()) {
-                window.location.href = vm.successUrl(); // Not used anymore in responsive 
+                window.location.href = vm.successUrl(); // Not used anymore in Hue 4 
               }
             }
             else if (self.status() == 'success') {