Переглянути джерело

HUE-946 [oozie] Fix property name autocomplete on the edit workflow page

Removed references to jQuery UI autocomplete
Added Bootstrap JS typeahead
Added test for typeahead JSON autocomplete API call
Enrico Berti 13 роки тому
батько
коміт
cdf3c07705

+ 7 - 14
apps/oozie/src/oozie/templates/editor/edit_workflow.mako

@@ -282,7 +282,6 @@ ${ layout.menubar(section='workflows') }
 
 <script src="/static/ext/js/knockout-2.1.0.js" type="text/javascript" charset="utf-8"></script>
 <script src="/static/ext/js/knockout.mapping-2.3.2.js" type="text/javascript" charset="utf-8"></script>
-<script src="/static/ext/js/jquery/plugins/jquery-ui-autocomplete-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
 <script src="/static/ext/js/jquery/plugins/jquery-ui-draggable-droppable-sortable-1.8.23.min.js" type="text/javascript" charset="utf-8"></script>
 <script src="/static/ext/js/routie-0.3.0.min.js" type="text/javascript" charset="utf-8"></script>
 
@@ -718,19 +717,6 @@ ko.bindingHandlers.fileChooser = {
 
 ko.applyBindings(workflow, $('#workflow')[0]);
 
-// Handles adding autocomplete to job properties.
-// We need to propagate the selected value to knockoutjs.
-var addAutoComplete = function(i, elem) {
-  var propertiesHint = '';
-  $(elem).autocomplete({
-    source: propertiesHint,
-    select: function(event, ui) {
-      var context = ko.contextFor(this);
-      context.$data.name = ui.item.value;
-    }
-  });
-};
-
 window.onbeforeunload = function (e) {
   if (workflow.is_dirty()) {
     var message = "${ _('You have unsaved changes in this workflow.') }";
@@ -753,6 +739,8 @@ window.onresize = function () {
   }
 };
 
+var AUTOCOMPLETE_PROPERTIES;
+
 $(document).ready(function () {
 
   routie('editWorkflow');
@@ -834,6 +822,11 @@ $(document).ready(function () {
       }
     }
   }
+
+  // load the autocomplete properties
+  $.getJSON("${ url('oozie:autocomplete_properties') }", function (properties) {
+    AUTOCOMPLETE_PROPERTIES = properties;
+  });
 });
 
 function checkModelDirtiness() {

+ 5 - 0
apps/oozie/src/oozie/tests.py

@@ -453,6 +453,11 @@ class TestAPI(OozieMockBase):
     assert_true('archives' in test_response_json_object['data'], test_response_json_object['data'])
     assert_equal(0, len(test_response_json_object['data']['archives']), test_response_json_object['data'])
 
+  def test_autocomplete(self):
+    response = self.c.get(reverse('oozie:autocomplete_properties'))
+    test_response_json = response.content
+    assert_true('mapred.input.dir' in test_response_json)
+
 
 class TestAPIWithOozie(OozieBase):
   def setUp(self):

+ 1 - 0
apps/oozie/src/oozie/urls.py

@@ -58,6 +58,7 @@ urlpatterns += patterns(
   url(r'^workflows/(?P<workflow>\d+)/save$', 'workflow_save', name='workflow_save'),
   url(r'^workflows/(?P<workflow>\d+)/nodes/(?P<node_type>\w+)/validate$', 'workflow_validate_node', name='workflow_validate_node'),
   url(r'^workflows/(?P<workflow>\d+)/jobsub/actions$', 'workflow_jobsub_actions', name='workflow_jobsub_actions'),
+  url(r'^workflows/autocomplete_properties/$', 'autocomplete_properties', name='autocomplete_properties'),
 )
 
 

+ 4 - 1
apps/oozie/src/oozie/views/api.py

@@ -32,7 +32,7 @@ from oozie.forms import WorkflowForm, ImportJobsubDesignForm, NodeForm, design_f
 from oozie.import_jobsub import convert_jobsub_design
 from oozie.models import Workflow, Node, Start, End, Kill, Mapreduce, Java, Streaming,\
                          Link, Decision, Fork, DecisionEnd, Join,\
-                         NODE_TYPES, ACTION_TYPES, CONTROL_TYPES
+                         NODE_TYPES, ACTION_TYPES, CONTROL_TYPES, _STD_PROPERTIES_JSON
 from oozie.decorators import check_job_access_permission, check_job_edition_permission
 from oozie.utils import model_to_dict
 
@@ -389,3 +389,6 @@ def workflow_jobsub_actions(request, workflow):
     }
     return HttpResponse(json.dumps(response), mimetype="application/json")
 
+def autocomplete_properties(request):
+  return HttpResponse(_STD_PROPERTIES_JSON, mimetype="application/json")
+

+ 1 - 1
apps/oozie/src/oozie/views/editor.py

@@ -43,7 +43,7 @@ from oozie.import_workflow import import_workflow as _import_workflow
 from oozie.management.commands import oozie_setup
 from oozie.models import Job, Workflow, History, Coordinator,\
                          Dataset, DataInput, DataOutput,\
-                         ACTION_TYPES
+                         ACTION_TYPES, _STD_PROPERTIES_JSON
 from oozie.forms import WorkflowForm, CoordinatorForm, DatasetForm,\
   DataInputForm, DataOutputForm, LinkForm,\
   DefaultLinkForm, design_form_by_type, ParameterForm,\

+ 4 - 0
apps/oozie/static/css/workflow.css

@@ -199,4 +199,8 @@ ul {
 
 .draggable-button a {
   padding: 8px;
+}
+
+.typeahead {
+  z-index: 2000;
 }

+ 6 - 1
apps/oozie/static/js/workflow.js

@@ -222,6 +222,9 @@ var ModalModule = function($, ko) {
         });
       }
     });
+    $(".propKey").typeahead({
+      source:(typeof AUTOCOMPLETE_PROPERTIES != 'undefined') ? AUTOCOMPLETE_PROPERTIES : []
+    });
   }
 
   return module;
@@ -753,7 +756,9 @@ var NodeModule = function($, IdGeneratorTable) {
           self.job_properties.valueHasMutated();
         });
         self.job_properties.push(prop);
-        // $(".propKey:last").each(addAutoComplete);
+        $(".propKey:last").typeahead({
+          source:(typeof AUTOCOMPLETE_PROPERTIES != 'undefined') ? AUTOCOMPLETE_PROPERTIES : []
+        });
       };
 
       self.removeProp = function(val) {