Browse Source

AMBARI-7908. Have error message after clicking Start (or Stop) button second time (Buzhor Denys via alexantonenko)

Alex Antonenko 10 years ago
parent
commit
69f6fd4e89

+ 21 - 3
contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js

@@ -115,6 +115,7 @@ App.SliderAppController = Ember.ObjectController.extend(App.AjaxErrorHandler, {
       statusActionsMap = this.get('statusActionsMap'),
       statusActionsMap = this.get('statusActionsMap'),
       status = this.get('model.status');
       status = this.get('model.status');
 
 
+    this.get('model').set('isActionPerformed', false);
     statusActionsMap[status].forEach(function(action) {
     statusActionsMap[status].forEach(function(action) {
       if ('destroy' === action) {
       if ('destroy' === action) {
         advanced.pushObject(appActions[action]);
         advanced.pushObject(appActions[action]);
@@ -165,6 +166,12 @@ App.SliderAppController = Ember.ObjectController.extend(App.AjaxErrorHandler, {
    */
    */
   groupedComponentsHaveErrors: false,
   groupedComponentsHaveErrors: false,
 
 
+  /**
+   * Action is performed.
+   * @type {Bool}
+   **/
+  isActionRunning: false,
+
   /**
   /**
    * Custom popup for "Destroy"-action
    * Custom popup for "Destroy"-action
    * @method destroyConfirm
    * @method destroyConfirm
@@ -202,6 +209,7 @@ App.SliderAppController = Ember.ObjectController.extend(App.AjaxErrorHandler, {
    */
    */
   thaw: function() {
   thaw: function() {
     var model = this.get('model');
     var model = this.get('model');
+    this.get('model').set('isActionPerformed', true);
     return App.ajax.send({
     return App.ajax.send({
       name: 'changeAppState',
       name: 'changeAppState',
       sender: this,
       sender: this,
@@ -213,7 +221,8 @@ App.SliderAppController = Ember.ObjectController.extend(App.AjaxErrorHandler, {
           state: "RUNNING"
           state: "RUNNING"
         }
         }
       },
       },
-      success: 'thawSuccessCallback'
+      success: 'thawSuccessCallback',
+      error: 'actionErrorCallback'
     });
     });
   },
   },
 
 
@@ -232,6 +241,7 @@ App.SliderAppController = Ember.ObjectController.extend(App.AjaxErrorHandler, {
    */
    */
   freeze: function() {
   freeze: function() {
     var model = this.get('model');
     var model = this.get('model');
+    this.get('model').set('isActionPerformed', true);
     return App.ajax.send({
     return App.ajax.send({
       name: 'changeAppState',
       name: 'changeAppState',
       sender: this,
       sender: this,
@@ -242,7 +252,8 @@ App.SliderAppController = Ember.ObjectController.extend(App.AjaxErrorHandler, {
           name: model.get('name'),
           name: model.get('name'),
           state: "FROZEN"
           state: "FROZEN"
         }
         }
-      }
+      },
+      error: 'actionErrorCallback'
     });
     });
   },
   },
 
 
@@ -340,13 +351,15 @@ App.SliderAppController = Ember.ObjectController.extend(App.AjaxErrorHandler, {
    * @method destroy
    * @method destroy
    */
    */
   destroy: function() {
   destroy: function() {
+    this.get('model').set('isActionPerformed', true);
     return App.ajax.send({
     return App.ajax.send({
       name: 'destroyApp',
       name: 'destroyApp',
       sender: this,
       sender: this,
       data: {
       data: {
         id: this.get('model.id')
         id: this.get('model.id')
       },
       },
-      complete: 'destroyCompleteCallback'
+      complete: 'destroyCompleteCallback',
+      error: 'actionErrorCallback'
     });
     });
   },
   },
 
 
@@ -358,6 +371,11 @@ App.SliderAppController = Ember.ObjectController.extend(App.AjaxErrorHandler, {
     this.transitionToRoute('slider_apps');
     this.transitionToRoute('slider_apps');
   },
   },
 
 
+  actionErrorCallback: function() {
+    this.defaultErrorHandler(arguments[0], arguments[3].url, arguments[3].type, true);
+    this.get('model').set('isActionPerformed', false);
+  },
+
   actions: {
   actions: {
 
 
     /**
     /**

+ 5 - 0
contrib/views/slider/src/main/resources/ui/app/models/slider_app.js

@@ -48,6 +48,11 @@ App.SliderApp = DS.Model.extend({
    */
    */
   started: DS.attr('number'),
   started: DS.attr('number'),
 
 
+  /**
+   * @type {boolean}
+   */
+  isActionPerformed: DS.attr('boolean'),
+
   /**
   /**
    * @type {String}
    * @type {String}
    */
    */

+ 2 - 2
contrib/views/slider/src/main/resources/ui/app/templates/slider_app.hbs

@@ -26,10 +26,10 @@
   <p></p>
   <p></p>
   <div class="col-md-5 pull-right">
   <div class="col-md-5 pull-right">
     <div class="btn-group display-inline-block pull-right">
     <div class="btn-group display-inline-block pull-right">
-      <a class="btn dropdown-toggle btn-primary " data-toggle="dropdown" href="#">
+      <button class="btn dropdown-toggle btn-primary " data-toggle="dropdown" {{bind-attr disabled=model.isActionPerformed}}>
         {{t common.actions}}
         {{t common.actions}}
         <span class="caret"></span>
         <span class="caret"></span>
-      </a>
+      </button>
       <ul class="dropdown-menu">
       <ul class="dropdown-menu">
         {{#each option in controller.availableActions}}
         {{#each option in controller.availableActions}}
           <li {{bind-attr class="option.submenu.length:dropdown-submenu"}}>
           <li {{bind-attr class="option.submenu.length:dropdown-submenu"}}>

+ 52 - 0
contrib/views/slider/src/main/resources/ui/test/unit/controllers/slider_app_controller_test.js

@@ -87,3 +87,55 @@ test('quickLinksOrdered', function() {
   equal(controller.get('quickLinksOrdered').objectAt(4).get('label'), 'Metrics UI', 'Metrics UI link should be before Metrics API');
   equal(controller.get('quickLinksOrdered').objectAt(4).get('label'), 'Metrics UI', 'Metrics UI link should be before Metrics API');
   equal(controller.get('quickLinksOrdered').objectAt(5).get('label'), 'Metrics API', 'Metrics API link should be last');
   equal(controller.get('quickLinksOrdered').objectAt(5).get('label'), 'Metrics API', 'Metrics API link should be last');
 });
 });
+
+
+test('Disable Action Button', function() {
+  expect(6);
+
+  var controller = this.subject({
+    model: Em.Object.create({
+      id: 'someId',
+      name: 'SomeName',
+      status: 'ACCEPTED'
+    }),
+    defaultErrorHandler: function() { return true; }
+  });
+
+  Em.run(function() {
+    controller.thaw();
+  });
+
+  equal(controller.get('model').get('isActionPerformed'), true, 'Perform start action');
+
+  Em.run(function() {
+    controller.set('model.status', 'RUNNING');
+    controller.get('availableActions');
+  });
+
+  equal(controller.get('model').get('isActionPerformed'), false, 'Start is done.');
+
+  Em.run(function() {
+    controller.freeze();
+  });
+
+  equal(controller.get('model').get('isActionPerformed'), true, 'Perform freeze action')
+
+  Em.run(function() {
+    controller.set('model.status', 'FROZEN');
+    controller.get('availableActions');
+  });
+
+  equal(controller.get('model').get('isActionPerformed'), false, 'Freeze is done.');
+
+  Em.run(function() {
+    controller.thaw();
+  });
+
+  equal(controller.get('model').get('isActionPerformed'), true, 'Start action performed expect for error.');
+
+  Em.run(function() {
+    controller.actionErrorCallback({requestText: 'some text'}, {url: '/some/url'}, {type: 'PUT'}, true);
+  });
+
+  equal(controller.get('model').get('isActionPerformed'), false, 'Error catched button should be enabled');
+});