Просмотр исходного кода

HUE-3591 [oozie] Autocomplete list of possible hive queries in the hive doc action

Enrico Berti 9 лет назад
Родитель
Сommit
ca2dbd3

+ 7 - 3
apps/oozie/src/oozie/static/oozie/js/workflow-editor.ko.js

@@ -493,9 +493,13 @@ var WorkflowEditorViewModel = function (layout_json, workflow_json, credentials_
     self.workflow.loadNodes(workflow_json);
 
     $.get('/desktop/api2/docs/?type=query-hive&sort=last_modified&limit=100', function(data) {
-      $.each(data.documents, function(index, query) {
-        self.hiveQueries.push(ko.mapping.fromJS(query));
-      });
+      if (data && data.documents) {
+        var queries = [];
+        $.each(data.documents, function(index, query) {
+          queries.push(ko.mapping.fromJS(query));
+        });
+        self.hiveQueries(queries);
+      }
     });
   };
 

+ 3 - 6
apps/oozie/src/oozie/templates/editor2/common_workflow.mako

@@ -941,7 +941,7 @@
       <!-- ko with: $root.getHiveQueryById(properties.uuid()) -->
         <a data-bind="attr: {href: absoluteUrl()}" target="_blank"><span data-bind='text: name'></span></a>
         <br/>
-        <span data-bind='text: description'></span>
+        <span data-bind='text: description' class="muted"></span>
       <!-- /ko -->
       <!-- /ko -->
     </div>
@@ -950,9 +950,8 @@
       <div data-bind="visible: ! $parent.ooziePropertiesExpanded()" class="nowrap">
         <!-- ko if: $root.getHiveQueryById(properties.uuid()) -->
         <!-- ko with: $root.getHiveQueryById(properties.uuid()) -->
-          <span data-bind='text: name'></span>
-          <br/>
-          <span data-bind='text: description'></span>
+          <select data-bind="options: $root.hiveQueries, optionsText: 'name', optionsValue: 'uuid', value: $parent.properties.uuid, select2Version4:{ placeholder: '${ _ko('Hive query name...')}'}"></select>
+          <div data-bind='text: description' style="padding: 3px; margin-top: 2px" class="muted"></div>
         <!-- /ko -->
         <!-- /ko -->
 
@@ -1888,5 +1887,3 @@
 </script>
 
 </%def>
-
-

+ 3 - 1
apps/oozie/src/oozie/templates/editor2/workflow_editor.mako

@@ -270,7 +270,7 @@ ${ workflow.render() }
           <select data-bind="options: $root.subworkflows, optionsText: 'name', optionsValue: 'value', value: value"></select>
           <!-- /ko -->
           <!-- ko if: type() == 'hive' -->
-          <select data-bind="options: $root.hiveQueries, optionsText: 'name', optionsValue: 'uuid', value: value"></select>
+         <select data-bind="options: $root.hiveQueries, optionsText: 'name', optionsValue: 'uuid', value: value, select2Version4:{ placeholder: '${ _ko('Hive query name...')}'}"></select>
           <!-- /ko -->
 
           <!-- ko if: type() == 'distcp' -->
@@ -430,6 +430,7 @@ ${ workflow.render() }
 <link rel="stylesheet" href="${ static('desktop/ext/css/hue-filetypes.css') }">
 <link rel="stylesheet" href="${ static('desktop/ext/css/hue-charts.css') }">
 <link rel="stylesheet" href="${ static('desktop/ext/chosen/chosen.min.css') }">
+<link rel="stylesheet" href="${ static('desktop/ext/css/select2.min.css') }">
 <link rel="stylesheet" href="${ static('oozie/css/common-editor.css') }">
 <link rel="stylesheet" href="${ static('oozie/css/workflow-editor.css') }">
 
@@ -442,6 +443,7 @@ ${ commonshare() | n,unicode }
 <script src="${ static('desktop/js/hue.utils.js') }"></script>
 <script src="${ static('desktop/js/ko.editable.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/ext/chosen/chosen.jquery.min.js') }" type="text/javascript" charset="utf-8"></script>
+<script src="${ static('desktop/ext/js/select2.full.min.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/js/share.vm.js') }"></script>
 <script src="${ static('desktop/js/jquery.hdfsautocomplete.js') }" type="text/javascript" charset="utf-8"></script>
 

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
desktop/core/src/desktop/static/desktop/ext/css/select2.min.css


Разница между файлами не показана из-за своего большого размера
+ 0 - 0
desktop/core/src/desktop/static/desktop/ext/js/select2.full.min.js


+ 60 - 1
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -1789,6 +1789,12 @@
         return _source;
       }
 
+      if (valueAccessor.nonBindableSource && valueAccessor.displayProperty) {
+        source = ko.utils.arrayMap(valueAccessor.nonBindableSource(), function(item) {
+          return item[valueAccessor.displayProperty]();
+        });
+      }
+
       var _options = {
         source: source,
         onselect: function (val) {
@@ -3865,6 +3871,59 @@
         $element.text(text);
       }
     }
-};
+  };
+
+  ko.bindingHandlers.select2Version4 = {
+    init: function (el, valueAccessor, allBindingsAccessor, viewModel) {
+      ko.utils.domNodeDisposal.addDisposeCallback(el, function () {
+        $(el).select2('destroy');
+      });
+
+      var allBindings = allBindingsAccessor(),
+        select2 = ko.utils.unwrapObservable(allBindings.select2Version4);
+
+      $(el).select2(select2);
+    },
+    update: function (el, valueAccessor, allBindingsAccessor, viewModel) {
+      var allBindings = allBindingsAccessor();
+
+      if ("value" in allBindings) {
+        if ((allBindings.select2Version4.multiple || el.multiple) && allBindings.value().constructor != Array) {
+          $(el).val(allBindings.value().split(',')).trigger('change');
+        }
+        else {
+          $(el).val(allBindings.value()).trigger('change');
+        }
+      } else if ("selectedOptions" in allBindings) {
+        var converted = [];
+        var textAccessor = function (value) {
+          return value;
+        };
+        if ("optionsText" in allBindings) {
+          textAccessor = function (value) {
+            var valueAccessor = function (item) {
+              return item;
+            }
+            if ("optionsValue" in allBindings) {
+              valueAccessor = function (item) {
+                return item[allBindings.optionsValue];
+              }
+            }
+            var items = $.grep(allBindings.options(), function (e) {
+              return valueAccessor(e) == value
+            });
+            if (items.length == 0 || items.length > 1) {
+              return "UNKNOWN";
+            }
+            return items[0][allBindings.optionsText];
+          }
+        }
+        $.each(allBindings.selectedOptions(), function (key, value) {
+          converted.push({id: value, text: textAccessor(value)});
+        });
+        $(el).select2("data", converted);
+      }
+    }
+  };
 
 }));

+ 0 - 1
desktop/core/src/desktop/templates/common_dashboard.mako

@@ -297,4 +297,3 @@
   <script src="${ static('desktop/js/ko.charts.js') }" type="text/javascript" charset="utf-8"></script>
 
 </%def>
-

+ 0 - 1
desktop/core/src/desktop/templates/common_header.mako

@@ -687,4 +687,3 @@ if USE_NEW_EDITOR.get():
     <button class="close">&times;</button>
     <span class="message"></span>
 </div>
-

Некоторые файлы не были показаны из-за большого количества измененных файлов