Przeglądaj źródła

[impala] Added session link to the new tab

Enrico Berti 10 lat temu
rodzic
commit
68df0f2

+ 27 - 0
apps/beeswax/src/beeswax/static/beeswax/js/beeswax.vm.js

@@ -86,6 +86,8 @@ function BeeswaxViewModel(server) {
     });
   });
 
+  self.impalaSessionLink = ko.observable("");
+
   self.chartType = ko.observable("bars");
   self.chartSorting = ko.observable("none");
   self.chartData = ko.observableArray();
@@ -378,6 +380,31 @@ function BeeswaxViewModel(server) {
     }
   };
 
+  self.fetchingImpalaSession = ko.observable(false);
+  self.fetchImpalaSession = function () {
+    self.fetchingImpalaSession(true);
+    var request = {
+      url: '/impala/api/session/',
+      dataType: 'json',
+      type: 'GET',
+      success: function (data) {
+        if (data && data.properties && data.properties.http_addr) {
+          if (!data.properties.http_addr.match(/^(https?):\/\//)) {
+            data.properties.http_addr = window.location.protocol + "//" + data.properties.http_addr;
+          }
+          self.impalaSessionLink(data.properties.http_addr);
+        }
+        else {
+          self.impalaSessionLink("");
+        }
+        self.fetchingImpalaSession(false);
+      },
+      error: error_fn,
+      cache: false
+    };
+    $.ajax(request);
+  }
+
   self.fetchDesign = function() {
     $(document).trigger('fetch.design');
 

+ 28 - 6
apps/beeswax/src/beeswax/templates/execute.mako

@@ -206,13 +206,28 @@ ${layout.menubar(section='query')}
       <div class="tab-pane" id="sessionTab">
         <div class="card card-small card-tab">
           <div class="card-body">
-            <div id="advanced-settings">
-            <form id="advancedSettingsForm" action="" method="POST" class="form form-horizontal">
-
-              link
-
-            </form>
+            <!-- ko if: $root.fetchingImpalaSession() -->
+            <div style="margin: 5px">
+              <!--[if !IE]><!--><i class="fa fa-spinner fa-spin" style="font-size: 20px; color: #BBB"></i><!--<![endif]-->
+              <!--[if IE]><img src="${ static('desktop/art/spinner.gif') }"/><![endif]-->
             </div>
+            <!-- /ko -->
+
+            <!-- ko ifnot: $root.fetchingImpalaSession() -->
+              <!-- ko if: $root.impalaSessionLink() != '' -->
+              <ul class="nav nav-list" style="border: none; padding: 0;">
+                <li class="nav-header">${ _('address')}</li>
+              </ul>
+              <div style="margin: 2px">
+              <a data-bind="attr: {'href': $root.impalaSessionLink()}" target="_blank"><span data-bind="text: $root.impalaSessionLink().replace(/^(https?):\/\//, '')"></span> <i class="fa fa-external-link"></i></a>
+              </div>
+              <!-- /ko -->
+              <!-- ko if: $root.impalaSessionLink() == '' -->
+              <div style="margin: 5px">
+                ${ _("There's currently no valid session") }
+              </div>
+              <!-- /ko -->
+            <!-- /ko -->
           </div>
         </div>
       </div>
@@ -2082,6 +2097,13 @@ $(document).ready(function () {
     resizeLogs();
   });
 
+  % if app_name == 'impala':
+  $("a[href='#sessionTab']").on("shown", function () {
+    // get the impala session info
+    viewModel.fetchImpalaSession();
+  });
+  % endif
+
   $(".blueprintSelect").on("change", function () {
     generateGraph(getGraphType())
   });