Sfoglia il codice sorgente

HUE-889 [oozie] Smarter file chooser in Workflow editor

jHueFileChooser defaults to workflow workspace if path is invalid or empty
Support for relative paths
Added onError and errorRedirectPath to jHueFileChooser
Added jHueFileChooser to Job XML on edit workflow action
Enrico Berti 13 anni fa
parent
commit
8c3abcd3e6

+ 2 - 2
apps/oozie/src/oozie/templates/editor/edit_workflow.mako

@@ -301,8 +301,8 @@ modal-window .modal-content {
       });
     });
 
-     ko.applyBindings(window.viewModelparameters, $("#parameters")[0]);
-     ko.applyBindings(window.viewModeljob_properties, $("#job_properties")[0]);
+    ko.applyBindings(window.viewModelparameters, $("#parameters")[0]);
+    ko.applyBindings(window.viewModeljob_properties, $("#job_properties")[0]);
 
     $('#jobForm').submit(function() {
       window.viewModelparameters.pre_submit();

+ 37 - 22
apps/oozie/src/oozie/templates/editor/edit_workflow_action.mako

@@ -90,7 +90,7 @@ ${ layout.menubar(section='workflows') }
                     <span class="span4 required" data-bind="text: type" />
                   </td>
                   <td>
-                    <input type="text" class="input span4 required" data-bind="fileChooser: $data, value: value, uniqueName: false" />
+                    <input type="text" class="input span4 required pathChooser" data-bind="fileChooser: $data, value: value, uniqueName: false" />
                   </td>
                   <td><a class="btn" href="#" data-bind="click: $root.removePrepare">${ _('Delete') }</a></td>
                 </tr>
@@ -128,7 +128,7 @@ ${ layout.menubar(section='workflows') }
                     <span class="span4 required" data-bind="text: type" />
                   </td>
                   <td>
-                    <input type="text" class="input span4 required" data-bind="fileChooser: $data, value: value, uniqueName: false" />
+                    <input type="text" class="input span4 required pathChooser" data-bind="fileChooser: $data, value: value, uniqueName: false" />
                   </td>
                   <td><a class="btn" href="#" data-bind="click: $root.removeParam">${ _('Delete') }</a></td>
                 </tr>
@@ -173,7 +173,7 @@ ${ layout.menubar(section='workflows') }
             <tbody data-bind="foreach: properties">
               <tr>
                 <td><input type="text" class="span4 required propKey" data-bind="value: name, uniqueName: false" /></td>
-                <td><input type="text" class="span4 required" data-bind="fileChooser: $data, value: value, uniqueName: false" /></td>
+                <td><input type="text" class="span4 required pathChooser" data-bind="fileChooser: $data, value: value, uniqueName: false" /></td>
                 <td><a class="btn" href="#" data-bind="click: $root.removeProp">${ _('Delete') }</a></td>
               </tr>
             </tbody>
@@ -199,7 +199,7 @@ ${ layout.menubar(section='workflows') }
               <table class="table-condensed designTable" data-bind="visible: files().length > 0">
                 <tbody data-bind="foreach: files">
                   <tr>
-                    <td><input type="text" class="span5 required"
+                    <td><input type="text" class="span5 required pathChooser"
                             data-bind="fileChooser: $data, value: name, uniqueName: false" />
                     </td>
                     <td><a class="btn" href="#" data-bind="click: $root.removeFile">${ _('Delete') }</a></td>
@@ -226,7 +226,7 @@ ${ layout.menubar(section='workflows') }
             <tbody data-bind="foreach: archives">
               <tr>
                 <td>
-                  <input type="text" class="span5 required"
+                  <input type="text" class="span5 required pathChooser"
                       data-bind="fileChooser: $data, value: name, uniqueName: false" />
                 </td>
                 <td><a class="btn" href="#" data-bind="click: $root.removeArchive">${ _('Delete') }</a></td>
@@ -273,16 +273,11 @@ ${ layout.menubar(section='workflows') }
   <div class="modal-footer"></div>
 </div>
 
-
 <link rel="stylesheet" href="/static/ext/css/jquery-ui-autocomplete-1.8.18.css" type="text/css" media="screen" title="no title" charset="utf-8" />
 <script src="/static/ext/js/knockout-2.1.0.js" type="text/javascript" charset="utf-8"></script>
 <script src="/static/ext/js/jquery/plugins/jquery-ui-autocomplete-1.8.18.min.js" type="text/javascript" charset="utf-8"></script>
 
 <style>
-  td.pathChooserKo {
-    min-width: 404px;
-  }
-
   #fileChooserModal {
     padding:14px;
     height:270px;
@@ -455,25 +450,45 @@ ${ layout.menubar(section='workflows') }
 
     ko.applyBindings(viewModel);
 
-    $(".pathChooser").each(function(){
-      var self = $(this);
-      self.after(getFileBrowseButton(self));
-    });
+    $("input[name='job_xml']").addClass("pathChooser").after(getFileBrowseButton($("input[name='job_xml']")));
 
     function getFileBrowseButton(inputElement) {
       return $("<button>").addClass("btn").addClass("fileChooserBtn").text("..").click(function(e){
         e.preventDefault();
-        $("#fileChooserModal").jHueFileChooser({
-          onFileChoose: function(filePath) {
+        // check if it's a relative path
+        var pathAddition = "";
+        if ($.trim(inputElement.val()) != ""){
+          $.getJSON("/filebrowser/chooser${ workflow.deployment_dir }" + inputElement.val(), function (data) {
+            pathAddition = "${ workflow.deployment_dir }";
+            callFileChooser();
+          }).error(function(){
+            callFileChooser();
+          });
+        }
+        else {
+          callFileChooser();
+        }
+
+        function callFileChooser() {
+          $("#fileChooserModal").jHueFileChooser({
+            onFileChoose: function(filePath) {
+              if (filePath.indexOf("${ workflow.deployment_dir }") > -1){
+                filePath = filePath.substring("${ workflow.deployment_dir }".length);
+                if (filePath == ""){
+                  filePath = "/";
+                }
+              }
               inputElement.val(filePath);
               inputElement.change();
               $("#chooseFile").modal("hide");
-          },
-          createFolder: false,
-          initialPath: "${ workflow.deployment_dir }"
-        });
-        $("#chooseFile").modal("show");
-      })
+            },
+            createFolder: false,
+            initialPath: $.trim(inputElement.val()) != "" ? pathAddition + inputElement.val() : "${ workflow.deployment_dir }",
+            errorRedirectPath: "${ workflow.deployment_dir }"
+          });
+          $("#chooseFile").modal("show");
+        }
+      });
     }
 
     $(".propKey").each(addAutoComplete);

+ 37 - 13
apps/oozie/src/oozie/templates/utils.inc.mako

@@ -214,22 +214,46 @@
       function getFileBrowseButton(inputElement) {
         return $("<button>").addClass("btn").addClass("fileChooserBtn").text("..").click(function(e){
           e.preventDefault();
-          $("#fileChooserModal").jHueFileChooser({
-            % if select_folder:
+          // check if it's a relative path
+          var pathAddition = "";
+          if ($.trim(inputElement.val()) != ""){
+            $.getJSON("/filebrowser/chooser${ workflow.deployment_dir }" + inputElement.val(), function (data) {
+              pathAddition = "${ workflow.deployment_dir }";
+              callFileChooser();
+            }).error(function(){
+              callFileChooser();
+            });
+          }
+          else {
+            callFileChooser();
+          }
+
+          function callFileChooser() {
+            $("#fileChooserModal").jHueFileChooser({
+              % if select_folder:
               selectFolder: true,
               onFolderChoose: function(filePath) {
-            % else:
+              % else:
               onFileChoose: function(filePath) {
-            % endif
-              inputElement.val(filePath);
-              $("#chooseFile").modal("hide");
-            },
-            createFolder: true,
-            uploadFile: false,
-            initialPath: inputElement.val()
-          });
-          $("#chooseFile").modal("show");
-        })
+              % endif
+                if (filePath.indexOf("${ workflow.deployment_dir }") > -1){
+                  filePath = filePath.substring("${ workflow.deployment_dir }".length);
+                  if (filePath == ""){
+                    filePath = "/";
+                  }
+                }
+                inputElement.val(filePath);
+                inputElement.change();
+                $("#chooseFile").modal("hide");
+              },
+              createFolder: false,
+              uploadFile: false,
+              initialPath: $.trim(inputElement.val()) != "" ? pathAddition + inputElement.val() : "${ workflow.deployment_dir }",
+              errorRedirectPath: "${ workflow.deployment_dir }"
+            });
+            $("#chooseFile").modal("show");
+          }
+        });
       }
     });
   </script>

+ 5 - 1
desktop/core/static/js/Source/jHue/jquery.filechooser.js

@@ -9,6 +9,7 @@
         // desktop/templates/common_header.mako
         defaults = {
             initialPath:"",
+            errorRedirectPath:"",
             createFolder:true,
             uploadFile:true,
             selectFolder:false,
@@ -27,6 +28,8 @@
             onFolderChoose:function () {
             },
             onFolderChange:function () {
+            },
+            onError:function () {
             }
         };
 
@@ -216,7 +219,8 @@
                 }
             }
         }).error(function(){
-            _parent.navigateTo("/?default_to_home");
+            _parent.options.onError();
+            _parent.navigateTo(_parent.options.errorRedirectPath != "" ? _parent.options.errorRedirectPath : "/?default_to_home");
             if ($.jHueNotify) {
                 $.jHueNotify.info(_parent.options.labels.FILE_NOT_FOUND);
             }