Browse Source

AMBARI-4951. Mirroring: ability to add Target Clusters from Create Dataset popup. (akovalenko)

Aleksandr Kovalenko 11 years ago
parent
commit
bcc8aad56c

+ 10 - 8
ambari-web/app/controllers/main/mirroring/edit_dataset_controller.js

@@ -47,7 +47,8 @@ App.MainMirroringEditDataSetController = Ember.Controller.extend({
     targetDir: '',
     startDate: '',
     endDate: '',
-    frequency: ''
+    frequency: '',
+    targetClusterName: ''
   }),
 
   errors: Ember.Object.create({
@@ -56,7 +57,8 @@ App.MainMirroringEditDataSetController = Ember.Controller.extend({
     isTargetDirError: false,
     isStartDateError: false,
     isEndDateError: false,
-    isFrequencyError: false
+    isFrequencyError: false,
+    isTargetClusterNameError: false
   }),
 
   clearStep: function () {
@@ -97,20 +99,20 @@ App.MainMirroringEditDataSetController = Ember.Controller.extend({
       secondary: Em.I18n.t('common.cancel'),
       showCloseButton: false,
       saveDisabled: function () {
-        return !self.get('saveDisabled');
+        return self.get('saveDisabled');
       }.property('App.router.' + self.get('name') + '.saveDisabled'),
       enablePrimary: function () {
-        return this.get('saveDisabled');
+        return !this.get('saveDisabled');
       }.property('saveDisabled'),
       onPrimary: function () {
-        if (!this.get('saveDisabled')) {
+        if (this.get('saveDisabled')) {
           return false;
         }
         // Apply form validation for first click
         if (!this.get('primaryWasClicked')) {
           this.toggleProperty('primaryWasClicked');
           self.applyValidation();
-          if (!this.get('saveDisabled')) {
+          if (this.get('saveDisabled')) {
             return false;
           }
         }
@@ -274,6 +276,6 @@ App.MainMirroringEditDataSetController = Ember.Controller.extend({
 
   saveDisabled: function () {
     var errors = this.get('errors');
-    return errors.get('isNameError') || errors.get('isSourceDirError') || errors.get('isTargetDirError') || errors.get('isStartDateError') || errors.get('isEndDateError') || errors.get('isFrequencyError');
-  }.property('errors.isNameError', 'errors.isSourceDirError', 'errors.isTargetDirError', 'errors.isStartDateError', 'errors.isEndDateError', 'errors.isFrequencyError')
+    return errors.get('isNameError') || errors.get('isSourceDirError') || errors.get('isTargetDirError') || errors.get('isStartDateError') || errors.get('isEndDateError') || errors.get('isFrequencyError') || errors.get('isTargetClusterNameError');
+  }.property('errors.isNameError', 'errors.isSourceDirError', 'errors.isTargetDirError', 'errors.isStartDateError', 'errors.isEndDateError', 'errors.isFrequencyError', 'errors.isTargetClusterNameError')
 });

+ 7 - 3
ambari-web/app/templates/main/mirroring/edit_dataset.hbs

@@ -69,13 +69,17 @@
         <tr>
           <td class="spacer" colspan="3"></td>
         </tr>
-        <tr {{bindAttr class="errors.isTargetClusterError:error"}}>
+        <tr {{bindAttr class="errors.isTargetClusterNameError:error"}}>
           <td colspan="1">
             {{t mirroring.dataset.targetCluster}}
           </td>
           <td colspan="2" style="text-align: left">
-            {{view view.targetClusterSelect selectionBinding="formFields.datasetTargetClusterName"}}
-            <span class="help-inline">{{errorMessages.targetCluster}}</span>
+            {{#if view.hasTargetClusters}}
+              {{view view.targetClusterSelect selectionBinding="formFields.datasetTargetClusterName"}}
+            {{else}}
+              <button class="btn" {{action manageClusters target="view"}}>{{t mirroring.dataset.addTargetCluster}}</button>
+            {{/if}}
+            <span class="help-inline">{{errorMessages.targetClusterName}}</span>
           </td>
         </tr>
         <tr>

+ 21 - 3
ambari-web/app/views/main/mirroring/edit_dataset_view.js

@@ -25,25 +25,38 @@ App.MainMirroringEditDataSetView = Em.View.extend({
   name: 'mainMirroringEditDataSetView',
   templateName: require('templates/main/mirroring/edit_dataset'),
 
+  hasTargetClusters: false,
+
   datasetTypeOptions: [Em.I18n.t('mirroring.dataset.type.HDFS'), Em.I18n.t('mirroring.dataset.type.Hive')],
 
+  targetClusters: App.TargetCluster.find(),
+
   targetClusterSelect: Em.Select.extend({
     classNames: ['target-cluster-select'],
 
     content: function () {
       if (!this.get('parentView.isLoaded')) return [];
-      return App.TargetCluster.find().mapProperty('name').without(App.get('clusterName')).concat(Em.I18n.t('mirroring.dataset.addTargetCluster'));
-    }.property('parentView.isLoaded'),
+      return this.get('parentView.targetClusters').mapProperty('name').without(App.get('clusterName')).concat(Em.I18n.t('mirroring.dataset.addTargetCluster'));
+    }.property('parentView.isLoaded', 'parentView.targetClusters.length'),
 
     change: function () {
       if (this.get('selection') === Em.I18n.t('mirroring.dataset.addTargetCluster')) {
         this.set('selection', this.get('content')[0]);
-        App.router.get('mainMirroringController').manageClusters();
+        this.get('parentView').manageClusters();
       }
       this.set('parentView.controller.formFields.datasetTargetClusterName', this.get('selection'))
     }
   }),
 
+  onTargetClustersChange: function () {
+    if (this.get('isLoaded') && this.get('targetClusters.length') > 1) {
+      this.set('hasTargetClusters', true);
+    } else {
+      this.set('hasTargetClusters', false);
+      this.set('controller.formFields.datasetTargetClusterName', null);
+    }
+  }.observes('isLoaded', 'targetClusters.length'),
+
   repeatOptions: [Em.I18n.t('mirroring.dataset.repeat.minutes'), Em.I18n.t('mirroring.dataset.repeat.hours'), Em.I18n.t('mirroring.dataset.repeat.days'), Em.I18n.t('mirroring.dataset.repeat.months')],
 
   middayPeriodOptions: [Em.I18n.t('mirroring.dataset.middayPeriod.am'), Em.I18n.t('mirroring.dataset.middayPeriod.pm')],
@@ -56,6 +69,10 @@ App.MainMirroringEditDataSetView = Em.View.extend({
     return App.router.get('mainMirroringController.isLoaded');
   }.property('App.router.mainMirroringController.isLoaded'),
 
+  manageClusters: function () {
+    App.router.get('mainMirroringController').manageClusters();
+  },
+
   fillForm: function () {
     var isEdit = this.get('controller.isEdit');
     var selectedDataset = App.router.get('mainMirroringController.selectedDataset');
@@ -92,6 +109,7 @@ App.MainMirroringEditDataSetView = Em.View.extend({
       format: 'mm/dd/yyyy'
     });
     this.fillForm();
+    this.onTargetClustersChange();
   },
 
   willDestroyElement: function () {