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

HUE-4954 [editor] Edit and save the coordinator

Romain Rigaux 9 роки тому
батько
коміт
13f4e0308c

+ 4 - 0
apps/oozie/src/oozie/models2.py

@@ -3031,6 +3031,7 @@ class Coordinator(Job):
               'start': '${start_date}',
               'end': '${end_date}',
               'workflow': None,
+              'document': None,
               'timeout': None,
               'concurrency': None,
               'execution': None,
@@ -3084,6 +3085,9 @@ class Coordinator(Job):
     if self.document is not None:
       self._data['id'] = self.document.id
 
+    if 'document' not in self._data['properties']:
+      self._data['properties']['document'] = None
+
     return self._data
 
   @property

+ 1 - 0
apps/oozie/src/oozie/static/oozie/js/coordinator-editor.ko.js

@@ -97,6 +97,7 @@ var Coordinator = function (vm, coordinator) {
   self.refreshParameters = function() {
     $.get("/oozie/editor/workflow/parameters/", {
       "uuid": self.properties.workflow(),
+      "document": self.properties.document(),
     }, function (data) {
       self.workflowParameters(data.parameters);
 

+ 2 - 2
apps/oozie/src/oozie/templates/editor2/common_scheduler.inc.mako

@@ -58,7 +58,7 @@ from django.utils.translation import ugettext as _
       </div>
       %endif
 
-      <div class="card card-home" data-bind="visible: coordinator.properties.workflow" style="margin-top: 20px">
+      <div class="card card-home" data-bind="visible: coordinator.properties.workflow() || coordinator.properties.document()" style="margin-top: 20px">
         <h1 class="card-heading simple">${ _('How often?') }
         </h1>
 
@@ -169,7 +169,7 @@ from django.utils.translation import ugettext as _
       </div>
 
 
-      <div class="card card-home" data-bind="visible: coordinator.properties.workflow()" style="margin-top: 20px; margin-bottom: 20px">
+      <div class="card card-home" data-bind="visible: coordinator.properties.workflow() || coordinator.properties.document()" style="margin-top: 20px; margin-bottom: 20px">
         <h1 class="card-heading simple">${ _('Parameters') }</h1>
 
         <div class="card-body">

+ 13 - 11
apps/oozie/src/oozie/views/editor2.py

@@ -520,14 +520,15 @@ def edit_coordinator(request):
     LOG.error(smart_str(e))
 
   if USE_NEW_EDITOR.get():
-    workflows = [dict([('uuid', d.uuid), ('name', d.name)])
-                      for d in Document2.objects.documents(request.user, include_managed=True).search_documents(types=['oozie-workflow2'])]
+    document = Document2.objects.get(uuid=coordinator.data['properties']['workflow'] or coordinator.data['properties']['document'])
+    if not document.can_read(request.user):
+      raise PopupException(_('You don\'t have access to the workflow or document of this coordinator.'))
   else:
     workflows = [dict([('uuid', d.content_object.uuid), ('name', d.content_object.name)])
                       for d in Document.objects.available_docs(Document2, request.user).filter(extra='workflow2')]
 
-  if coordinator_id and not filter(lambda a: a['uuid'] == coordinator.data['properties']['workflow'], workflows): # In Hue 4, use dependencies instead
-    raise PopupException(_('You don\'t have access to the workflow of this coordinator.'))
+    if coordinator_id and not filter(lambda a: a['uuid'] == coordinator.data['properties']['workflow'], workflows):
+      raise PopupException(_('You don\'t have access to the workflow of this coordinator.'))
 
   if USE_NEW_EDITOR.get(): # In Hue 4, merge with above
     workflows = [dict([('uuid', d.uuid), ('name', d.name)])
@@ -624,13 +625,14 @@ def save_coordinator(request):
 #     workflow_uuid = workflow_doc.uuid
 #     coordinator.data['name'] = _('Schedule of %s') % workflow_doc.name
 
-  if coordinator_data['properties']['workflow']:
-    workflow_doc = Document2.objects.get(type='oozie-workflow2', uuid=coordinator_data['properties']['workflow'])
-    workflow_doc.doc.get().can_read_or_exception(request.user)
-    coordinator_doc.dependencies = [workflow_doc]
-    scheduled_doc = workflow_doc.dependencies.filter(type__startswith='query-', owner=request.user, is_managed=False)
-    for action in scheduled_doc.all():
-      coordinator_doc.dependencies.add(action)
+  scheduled_id = coordinator_data['properties']['workflow'] or coordinator_data['properties']['document']
+  if scheduled_id:
+    scheduled_doc = Document2.objects.get(uuid=scheduled_id)
+    scheduled_doc.can_read_or_exception(request.user)
+    coordinator_doc.dependencies = [scheduled_doc]
+#     scheduled_doc = workflow_doc.dependencies.filter(type__startswith='query-', owner=request.user, is_managed=False)
+#     for action in scheduled_doc.all():
+#       coordinator_doc.dependencies.add(action)
 
   coordinator_doc1 = coordinator_doc.doc.get()
   coordinator_doc.update_data(coordinator_data)

+ 2 - 4
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1828,10 +1828,8 @@
             if (_action == 'new') {
               self.coordinatorUuid(UUID());
               self.schedulerViewModel.coordinator.uuid(self.coordinatorUuid());             
-      		//self.schedulerViewModel.coordinator.properties.workflow('aa');
+      		  self.schedulerViewModel.coordinator.properties.document(self.uuid());
             }
-
-
           }
         }).fail(function (xhr) {
           $(document).trigger("error", xhr.responseText);
@@ -1859,7 +1857,7 @@
       if (self.isBatchable() && (! self.coordinatorUuid() || self.schedulerViewModel.coordinator.isDirty())) {
         self.schedulerViewModel.coordinator.isManaged(true);
         self.schedulerViewModel.save(function(data) {
-          self.coordinatorUuid(data.uuid); // bewarre
+          self.coordinatorUuid(data.uuid);
         });
       }
     };