ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From onechipore...@apache.org
Subject git commit: AMBARI-5962. Implement slider app flex action. (onechiporenko)
Date Fri, 30 May 2014 15:13:03 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-1.6.0.slider fd1b54a8b -> 39bf3de55


AMBARI-5962. Implement slider app flex action. (onechiporenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/39bf3de5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/39bf3de5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/39bf3de5

Branch: refs/heads/branch-1.6.0.slider
Commit: 39bf3de5583e84726d8fd19b395d8b69eef67255
Parents: fd1b54a
Author: Oleg Nechiporenko <onechiporenko@apache.org>
Authored: Fri May 30 18:07:50 2014 +0300
Committer: Oleg Nechiporenko <onechiporenko@apache.org>
Committed: Fri May 30 18:07:50 2014 +0300

----------------------------------------------------------------------
 .../ui/app/controllers/slider_app_controller.js | 115 +++++++++++++++++--
 .../src/main/resources/ui/app/helpers/helper.js |  12 ++
 .../resources/ui/app/models/slider_app_type.js  |   2 +-
 .../ui/app/templates/slider_app/flex_popup.hbs  |  42 +++++++
 4 files changed, 159 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/39bf3de5/contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js
b/contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js
index 77bf0a0..a29b46c 100644
--- a/contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js
+++ b/contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js
@@ -42,11 +42,19 @@ App.SliderAppController = Ember.ObjectController.extend({
         confirm: true
       });
     }
+    else {
+      actions.pushObject({
+        title: 'Destroy',
+        action: 'destroy',
+        confirm: true
+      });
+    }
     if ('FINISHED' !== status) {
       actions.push({
         title: 'Flex',
         action: 'flex',
-        confirm: true
+        confirm: false,
+        customAction: 'showFlexModal'
       });
     }
     if ('FROZEN' === status) {
@@ -54,11 +62,6 @@ App.SliderAppController = Ember.ObjectController.extend({
         {
           title: 'Thaw',
           action: 'thaw',
-          confirm: false
-        },
-        {
-          title: 'Destroy',
-          action: 'destroy',
           confirm: true
         }
       ]);
@@ -73,6 +76,48 @@ App.SliderAppController = Ember.ObjectController.extend({
   currentAction: null,
 
   /**
+   * Buttons for custom modal popup action
+   * @type {Ember.Object[]}
+   */
+  customActionPopupButtons: [
+    Ember.Object.create({title: Ember.I18n.t('common.finish'), clicked:"submitCustom"}),
+    Ember.Object.create({title: Ember.I18n.t('common.cancel'), clicked:"restoreUpdates",
dismiss: 'modal'})
+  ],
+
+  /**
+   * Enable/disable updating <code>componentsForFlex</code>
+   * Used when Flex Modal Popup is open
+   * @type {bool}
+   */
+  updateFlexComponents: true,
+
+  /**
+   * Did user do mistake while input fields
+   * @type {bool}
+   */
+  componentsForFlexContainsError: false,
+
+  /**
+   * List of components to Flex
+   * @type {Ember.Object[]}
+   */
+  componentsForFlex: [],
+
+  /**
+   * Update <code>componentsForFlex</code> if <code>updateFlexComponents</code>
is true
+   * @method componentsForFlexObs
+   */
+  componentsForFlexObs: function() {
+    if (!this.get('updateFlexComponents')) return;
+    this.set('componentsForFlex', this.get('model.appType.components').map(function(c) {
+      return Ember.Object.create({
+        name: c.get('displayName'),
+        count: c.get('defaultNumInstances')
+      });
+    }));
+  }.observes('model.appType.components.@each'),
+
+  /**
    * Try call controller's method with name stored in <code>currentAction</code>
    * @method tryDoAction
    */
@@ -147,7 +192,7 @@ App.SliderAppController = Ember.ObjectController.extend({
   },
 
   /**
-   * Map <code>model.components</code> for Flex request
+   * Map <code>appTypeComponents</code> for Flex request
    * Output format:
    * <code>
    *   {
@@ -165,9 +210,9 @@ App.SliderAppController = Ember.ObjectController.extend({
    */
   mapComponentsForFlexRequest: function() {
     var components = {};
-    this.get('model.components').forEach(function(component) {
+    this.get('componentsForFlex').forEach(function(component) {
       components[component.get('name')] = {
-        instanceCount: component.get('defaultNumInstances')
+        instanceCount: component.get('count')
       }
     });
     return components;
@@ -197,6 +242,21 @@ App.SliderAppController = Ember.ObjectController.extend({
     this.transitionToRoute('slider_apps');
   },
 
+  /**
+   * Create Modal Popup with data for Flex action
+   * @method showFlexModal
+   */
+  showFlexModal: function() {
+    this.set('updateFlexComponents', false);
+    Bootstrap.ModalManager.open(
+      'flexModal',
+      Ember.I18n.t('slider.app.flexPopup.title'),
+      'slider_app/flex_popup',
+      this.get('customActionPopupButtons'),
+      this
+    );
+  },
+
   actions: {
 
     /**
@@ -220,7 +280,7 @@ App.SliderAppController = Ember.ObjectController.extend({
 
     /**
      * Handler for Actions menu elements click
-     * @param {{title: string, action: string, confirm: bool}} option
+     * @param {{title: string, action: string, confirm: bool, customAction: string}} option
      * @method openModal
      */
     openModal: function(option) {
@@ -235,8 +295,41 @@ App.SliderAppController = Ember.ObjectController.extend({
         );
       }
       else {
-        this.tryDoAction();
+        if (option.customAction) {
+          this[option.customAction]();
+        }
+        else {
+          this.tryDoAction();
+        }
       }
+    },
+
+    /**
+     * Close popup and restore <code>componentsForFlex</code> updating
+     * @returns {*}
+     * @method submitCustom
+     */
+    submitCustom: function() {
+      var error = false;
+      this.get('componentsForFlex').forEach(function(c) {
+        var count = c.get('count').toString();
+        if(!(count.trim().length && (count % 1 == 0))) {
+          error = true;
+        }
+      });
+      this.set('componentsForFlexContainsError', error);
+      if (error) return;
+      this.flex();
+      this.set('updateFlexComponents', true);
+      return Bootstrap.ModalManager.close('flexModal');
+    },
+
+    /**
+     * Turn on <code>updateFlexComponents</code>
+     * @method restoreUpdates
+     */
+    restoreUpdates: function() {
+      this.set('updateFlexComponents', true);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/39bf3de5/contrib/views/slider/src/main/resources/ui/app/helpers/helper.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/helpers/helper.js b/contrib/views/slider/src/main/resources/ui/app/helpers/helper.js
index bfa0a68..63a0b39 100644
--- a/contrib/views/slider/src/main/resources/ui/app/helpers/helper.js
+++ b/contrib/views/slider/src/main/resources/ui/app/helpers/helper.js
@@ -17,6 +17,18 @@
  */
 
 
+/**
+ * Remove spaces at beginning and ending of line.
+ * @example
+ *  var str = "  I'm a string  "
+ *  str.trim() // return "I'm a string"
+ * @method trim
+ * @return {string}
+ */
+String.prototype.trim = function () {
+  return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
+};
+
 String.prototype.format = function () {
   var args = arguments;
   return this.replace(/{(\d+)}/g, function (match, number) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/39bf3de5/contrib/views/slider/src/main/resources/ui/app/models/slider_app_type.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/models/slider_app_type.js b/contrib/views/slider/src/main/resources/ui/app/models/slider_app_type.js
index fd58384..d161037 100644
--- a/contrib/views/slider/src/main/resources/ui/app/models/slider_app_type.js
+++ b/contrib/views/slider/src/main/resources/ui/app/models/slider_app_type.js
@@ -31,7 +31,7 @@ App.SliderAppType = DS.Model.extend({
   /**
    * @type {App.SliderAppTypeComponent[]}
    */
-  components: DS.hasMany('sliderAppTypeComponent', {async:true}),
+  components: DS.hasMany('sliderAppTypeComponent'),
 
   /**
    * @type {string}

http://git-wip-us.apache.org/repos/asf/ambari/blob/39bf3de5/contrib/views/slider/src/main/resources/ui/app/templates/slider_app/flex_popup.hbs
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/templates/slider_app/flex_popup.hbs
b/contrib/views/slider/src/main/resources/ui/app/templates/slider_app/flex_popup.hbs
new file mode 100644
index 0000000..0d3845a
--- /dev/null
+++ b/contrib/views/slider/src/main/resources/ui/app/templates/slider_app/flex_popup.hbs
@@ -0,0 +1,42 @@
+{{!
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+}}
+
+
+<table class="table table-condensed">
+  <thead>
+  <tr>
+    <th>
+      {{t common.components}}
+    </th>
+    <th>
+      {{t wizard.step2.table.instances}}
+    </th>
+  </tr>
+  </thead>
+  <tbody>
+    {{#each component in controller.componentsForFlex}}
+    <tr>
+      <td>{{component.name}}</td>
+      <td>{{input valueBinding="component.count"}}</td>
+    </tr>
+    {{/each}}
+  </tbody>
+</table>
+{{#if controller.componentsForFlexContainsError}}
+  <div class="alert alert-danger">{{t wizard.step2.error.numbers}}</div>
+{{/if}}
\ No newline at end of file


Mime
View raw message