浏览代码

HUE-1660 [oozie] Integrate the import/export of Workflows, Coordinators and Bundles

Romain Rigaux 10 年之前
父节点
当前提交
bc629f4

+ 14 - 1
apps/oozie/src/oozie/templates/editor2/list_editor_bundles.mako

@@ -15,7 +15,7 @@
 ## limitations under the License.
 
 <%!
-  from desktop.views import commonheader, commonfooter, commonshare
+  from desktop.views import commonheader, commonfooter, commonshare, commonimportexport
   from django.utils.translation import ugettext as _
 %>
 <%namespace name="actionbar" file="../actionbar.mako" />
@@ -58,11 +58,18 @@ ${ layout.menubar(section='bundles', is_editor=True) }
           <i class="fa fa-times"></i> ${ _('Delete') }
         </a>
 
+        <a data-bind="click: function() { atLeastOneSelected() ? exportDocuments() : void(0) }, css: {'btn': true, 'disabled': ! atLeastOneSelected() }">
+          <i class="fa fa-download"></i> ${ _('Export') }
+        </a>
       </div>
     </%def>
 
     <%def name="creation()">
       <a href="${ url('oozie:new_bundle') }" class="btn"><i class="fa fa-plus-circle"></i> ${ _('Create') }</a>
+
+      <a data-bind="click: function() { $('#import-documents').modal('show'); }" class="btn">
+        <i class="fa fa-upload"></i> ${ _('Import') }
+      </a>
     </%def>
   </%actionbar:render>
 
@@ -129,6 +136,7 @@ ${ layout.menubar(section='bundles', is_editor=True) }
 
 
 ${ commonshare() | n,unicode }
+${ commonimportexport(request) | n,unicode }
 
 
 <script src="${ static('desktop/ext/js/datatables-paging-0.1.js') }" type="text/javascript" charset="utf-8"></script>
@@ -212,6 +220,11 @@ ${ commonshare() | n,unicode }
       });
     };
 
+    self.exportDocuments = function() {
+      $('#export-documents').find('input[name=\'documents\']').val(ko.mapping.toJSON($.map(viewModel.selectedJobs(), function(doc) { return doc.id(); })));
+      $('#export-documents').find('form').submit();
+    };
+
     self.prepareShareModal = function() {
      shareViewModel.setDocId(self.selectedJobs()[0].doc1_id());
       openShareModal();

+ 14 - 1
apps/oozie/src/oozie/templates/editor2/list_editor_coordinators.mako

@@ -15,7 +15,7 @@
 ## limitations under the License.
 
 <%!
-  from desktop.views import commonheader, commonfooter, commonshare
+  from desktop.views import commonheader, commonfooter, commonshare, commonimportexport
   from django.utils.translation import ugettext as _
 %>
 <%namespace name="actionbar" file="../actionbar.mako" />
@@ -58,11 +58,18 @@ ${ layout.menubar(section='coordinators', is_editor=True) }
           <i class="fa fa-times"></i> ${ _('Delete') }
         </a>
 
+        <a data-bind="click: function() { atLeastOneSelected() ? exportDocuments() : void(0) }, css: {'btn': true, 'disabled': ! atLeastOneSelected() }">
+          <i class="fa fa-download"></i> ${ _('Export') }
+        </a>
       </div>
     </%def>
 
     <%def name="creation()">
       <a href="${ url('oozie:new_coordinator') }" class="btn"><i class="fa fa-plus-circle"></i> ${ _('Create') }</a>
+
+      <a data-bind="click: function() { $('#import-documents').modal('show'); }" class="btn">
+        <i class="fa fa-upload"></i> ${ _('Import') }
+      </a>
     </%def>
   </%actionbar:render>
 
@@ -129,6 +136,7 @@ ${ layout.menubar(section='coordinators', is_editor=True) }
 
 
 ${ commonshare() | n,unicode }
+${ commonimportexport(request) | n,unicode }
 
 
 <script src="${ static('desktop/ext/js/datatables-paging-0.1.js') }" type="text/javascript" charset="utf-8"></script>
@@ -210,6 +218,11 @@ ${ commonshare() | n,unicode }
       });
     };
 
+    self.exportDocuments = function() {
+      $('#export-documents').find('input[name=\'documents\']').val(ko.mapping.toJSON($.map(viewModel.selectedJobs(), function(doc) { return doc.id(); })));
+      $('#export-documents').find('form').submit();
+    };
+
     self.prepareShareModal = function() {
      shareViewModel.setDocId(self.selectedJobs()[0].doc1_id());
       openShareModal();

+ 14 - 1
apps/oozie/src/oozie/templates/editor2/list_editor_workflows.mako

@@ -15,7 +15,7 @@
 ## limitations under the License.
 
 <%!
-  from desktop.views import commonheader, commonfooter, commonshare
+  from desktop.views import commonheader, commonfooter, commonshare, commonimportexport
   from django.utils.translation import ugettext as _
 %>
 <%namespace name="actionbar" file="../actionbar.mako" />
@@ -59,11 +59,18 @@ ${ layout.menubar(section='workflows', is_editor=True) }
           <i class="fa fa-times"></i> ${ _('Delete') }
         </a>
 
+        <a data-bind="click: function() { atLeastOneSelected() ? exportDocuments() : void(0) }, css: {'btn': true, 'disabled': ! atLeastOneSelected() }">
+          <i class="fa fa-download"></i> ${ _('Export') }
+        </a>
       </div>
     </%def>
 
     <%def name="creation()">
       <a href="${ url('oozie:new_workflow') }" class="btn"><i class="fa fa-plus-circle"></i> ${ _('Create') }</a>
+
+      <a data-bind="click: function() { $('#import-documents').modal('show'); }" class="btn">
+        <i class="fa fa-upload"></i> ${ _('Import') }
+      </a>
     </%def>
   </%actionbar:render>
 
@@ -130,6 +137,7 @@ ${ layout.menubar(section='workflows', is_editor=True) }
 
 
 ${ commonshare() | n,unicode }
+${ commonimportexport(request) | n,unicode }
 
 
 <script src="${ static('desktop/ext/js/datatables-paging-0.1.js') }" type="text/javascript" charset="utf-8"></script>
@@ -212,6 +220,11 @@ ${ commonshare() | n,unicode }
       });
     };
 
+    self.exportDocuments = function() {
+      $('#export-documents').find('input[name=\'documents\']').val(ko.mapping.toJSON($.map(viewModel.selectedJobs(), function(doc) { return doc.id(); })));
+      $('#export-documents').find('form').submit();
+    };
+
     self.prepareShareModal = function() {
       shareViewModel.setDocId(self.selectedJobs()[0].doc1_id());
       openShareModal();

+ 3 - 3
desktop/core/src/desktop/api2.py

@@ -82,7 +82,7 @@ def export_documents(request):
 
   # If non admin, only export documents the user owns
   docs = Document2.objects
-  if request.user.is_superuser:
+  if not request.user.is_superuser:
     docs = docs.filter(owner=request.user)
   docs = docs.filter(id__in=selection).order_by('-id')
   doc_ids = docs.values_list('id', flat=True)
@@ -109,11 +109,11 @@ def export_documents(request):
     zfile.close()
     response = HttpResponse(content_type="application/zip")
     response["Content-Length"] = len(f.getvalue())
-    response['Content-Disposition'] = 'attachment; filename="hue.zip"'
+    response['Content-Disposition'] = 'attachment; filename="hue-documents.zip"'
     response.write(f.getvalue())
     return response
   else:
-    return make_response(f.getvalue(), 'json', 'hue')
+    return make_response(f.getvalue(), 'json', 'hue-documents')