瀏覽代碼

HUE-1723 [beeswax] Example SQL text should not be executable

Abraham Elmahrek 12 年之前
父節點
當前提交
81b4c6e60b
共有 2 個文件被更改,包括 10 次插入2 次删除
  1. 5 2
      apps/beeswax/src/beeswax/templates/execute.mako
  2. 5 0
      apps/beeswax/static/js/beeswax.vm.js

+ 5 - 2
apps/beeswax/src/beeswax/templates/execute.mako

@@ -242,10 +242,10 @@ ${layout.menubar(section='query')}
 
           <div class="actions">
             % if app_name == 'impala':
-            <button data-bind="click: tryExecuteQuery, visible: !$root.design.isRunning() && $root.design.isFinished()" type="button" id="executeQuery" class="btn btn-primary disable-feedback" tabindex="2">${_('Execute')}</button>
+            <button data-bind="click: tryExecuteQuery, visible: $root.canExecute, enable: $root.queryEditorBlank" type="button" id="executeQuery" class="btn btn-primary disable-feedback" tabindex="2">${_('Execute')}</button>
             <button data-bind="click: tryCancelQuery, visible: $root.design.isRunning()" class="btn btn-danger" data-loading-text="${ _('Canceling...') }" rel="tooltip" data-original-title="${ _('Cancel the query') }">${ _('Cancel') }</button>
             % else:
-            <button data-bind="click: tryExecuteQuery, enable: !$root.design.isRunning(), visible: $root.design.isFinished()" type="button" id="executeQuery" class="btn btn-primary disable-feedback" tabindex="2">${_('Execute')}</button>
+            <button data-bind="click: tryExecuteQuery, enable: $root.canExecute() && $root.queryEditorBlank()" type="button" id="executeQuery" class="btn btn-primary disable-feedback" tabindex="2">${_('Execute')}</button>
             % endif
             <button data-bind="click: executeNextStatement, visible: !$root.design.isFinished()" type="button" class="btn btn-primary disable-feedback" tabindex="2">${_('Next')}</button>
 
@@ -1143,6 +1143,9 @@ $(document).ready(function () {
   codeMirror.on("focus", function () {
     if (codeMirror.getValue() == queryPlaceholder) {
       codeMirror.setValue("");
+      // Use a view model attribute so that we don't have to override KO.
+      // This allows Hue to disable the execute button until the query placeholder dies.
+      viewModel.queryEditorBlank(true);
     }
     clearErrorWidgets();
     $("#validationResults").empty();

+ 5 - 0
apps/beeswax/static/js/beeswax.vm.js

@@ -73,8 +73,13 @@ function BeeswaxViewModel(server) {
   self.databases = ko.observableArray();
   self.selectedDatabase = ko.observable(0);
   self.isReady = ko.observable(false);
+  self.queryEditorBlank = ko.observable(false);
   self.design = ko.mapping.fromJS(DESIGN_DEFAULTS);
 
+  self.canExecute = ko.computed(function() {
+    return !self.design.isRunning() && self.design.isFinished();
+  });
+
   self.hasMoreResults = ko.computed(function() {
     return self.design.results.url() != null;
   });