瀏覽代碼

[spark] Show grid and chart buttons for table result

Romain Rigaux 10 年之前
父節點
當前提交
b9b02469df
共有 3 個文件被更改,包括 14 次插入5 次删除
  1. 6 2
      apps/spark/src/spark/models.py
  2. 6 3
      apps/spark/src/spark/templates/editor.mako
  3. 2 0
      apps/spark/static/js/spark.ko.js

+ 6 - 2
apps/spark/src/spark/models.py

@@ -194,7 +194,8 @@ class HS2Api():
           'name': column.name,
           'type': column.type,
           'comment': column.comment
-        } for column in results.data_table.cols()]
+        } for column in results.data_table.cols()],
+        'type': 'table'
     }
 
   @query_error_handler
@@ -337,11 +338,13 @@ class SparkApi():
         table = data['application/vnd.livy.table.v1+json']
       except KeyError:
         data = [[data['text/plain']]]
-        meta = [{'name': 'Header', 'type': 'String', 'comment': ''}]
+        meta = [{'name': 'Header', 'type': 'STRING_TYPE', 'comment': ''}]
+        type = 'text'        
       else:
         data = table['data']
         headers = table['headers']
         meta = [{'name': h['name'], 'type': h['type'], 'comment': ''} for h in headers]
+        type = 'table'
 
       # start_over not supported
       if not start_over:
@@ -350,6 +353,7 @@ class SparkApi():
       return {
           'data': data,
           'meta': meta,
+          'type': type
       }
     elif content['status'] == 'error':
       tb = content.get('traceback', None)

+ 6 - 3
apps/spark/src/spark/templates/editor.mako

@@ -319,6 +319,9 @@ ${ commonheader(_('Query'), app_name, user, "68px") | n,unicode }
             </div>
             <textarea data-bind="value: statement_raw, codemirror: { 'id': id(), 'viewportMargin': Infinity, 'lineNumbers': true, 'matchBrackets': true, 'mode': editorMode(), 'enter': execute }">
             </textarea>
+            <span data-bind="visible: status() == 'loading'" class="codeMirror-overlaybtn pointer">
+              <i class='fa fa-spinner fa-spin fa-2x'></i>
+            </span>
             <a title="${ _('CTRL + ENTER') }" data-bind="click: execute, visible: status() != 'running' && status() != 'loading'" class="btn codeMirror-overlaybtn pointer">
               ${ _('Go!') }
             </a>
@@ -331,10 +334,10 @@ ${ commonheader(_('Query'), app_name, user, "68px") | n,unicode }
         </div>
 
         <div style="padding-top: 10px;">
-          <button data-bind="visible: result.hasSomeResults(), click: function() { $data.showGrid(true); }, css: {'active': $data.showGrid}" href="javascript:void(0)" class="btn" title="${ _('Grid') }">
+          <button data-bind="visible: result.type() == 'table' && result.hasSomeResults(), click: function() { $data.showGrid(true); }, css: {'active': $data.showGrid}" href="javascript:void(0)" class="btn" title="${ _('Grid') }">
             <i class="fa fa-th"></i>
           </button>
-          <div class="btn-group" data-bind="visible: type() != 'scala' && type() != 'python' && result.hasSomeResults()">
+          <div class="btn-group" data-bind="visible: result.type() == 'table' && result.hasSomeResults()">
             <button class="btn" data-bind="css: {'active': $data.showChart}, click: function(){ $data.showChart(true); }">
               <i class="hcha hcha-bar-chart" data-bind="visible: chartType() == ko.HUE_CHARTS.TYPES.BARCHART"></i>
               <i class="hcha hcha-line-chart" data-bind="visible: chartType() == ko.HUE_CHARTS.TYPES.LINECHART"></i>
@@ -343,7 +346,7 @@ ${ commonheader(_('Query'), app_name, user, "68px") | n,unicode }
               <i class="fa fa-fw fa-map-marker" data-bind="visible: chartType() == ko.HUE_CHARTS.TYPES.MAP"></i>
               <i class="hcha hcha-map-chart" data-bind="visible: chartType() == ko.HUE_CHARTS.TYPES.GRADIENTMAP"></i>
             </button>
-            <button class="btn dropdown-toggle" data-bind="css: {'active': $data.showChart}" data-toggle="dropdown">
+            <button class="btn dropdown-toggle" data-bind="visible: result.type() == 'table', css: {'active': $data.showChart}" data-toggle="dropdown">
               <i class="fa fa-caret-down"></i>
             </button>
             <ul class="dropdown-menu">

+ 2 - 0
apps/spark/static/js/spark.ko.js

@@ -34,6 +34,7 @@ var Result = function (snippet, result) {
   self.executionTime = ko.computed(function() {
     return self.endTime().getTime() - self.startTime().getTime();
   });
+  self.type = ko.observable(typeof result.type != "undefined" && result.type != null ? result.type : 'plain');
   
   
   function isNumericColumn(type) {
@@ -349,6 +350,7 @@ var Snippet = function (vm, notebook, snippet) {
         if (self.result.meta().length == 0) {
    	      data.result.meta.unshift({type: "INT_TYPE", name: "", comment: null});
    	      self.result.meta(data.result.meta);
+   	      self.result.type(data.result.type);
         }
 
         var _initialIndex = self.result.data().length;