Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master 915ca9463 -> f4ff1c5f6


cors: Fix timing issue for slow connections

If the conenction was slow you could enabble cors and change
options, but cors was not enabled yet in the backend

PR: #578
PR-URL: https://github.com/apache/couchdb-fauxton/pull/578
Reviewed-By: Michelle Phung <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/f4ff1c5f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/f4ff1c5f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/f4ff1c5f

Branch: refs/heads/master
Commit: f4ff1c5f6a79c532e4d1479d50a21982c62aa0d0
Parents: 0500da8
Author: Robert Kowalski <[email protected]>
Authored: Wed Nov 18 13:51:26 2015 +0100
Committer: Robert Kowalski <[email protected]>
Committed: Fri Nov 20 14:55:46 2015 +0100

----------------------------------------------------------------------
 app/addons/cors/actions.js                     | 16 ++++++++++++++--
 app/addons/cors/actiontypes.js                 |  3 ++-
 app/addons/cors/components.react.jsx           | 13 ++++++++++---
 app/addons/cors/stores.js                      | 14 ++++++++++++++
 app/addons/cors/tests/componentsSpec.react.jsx | 18 +++++++++++++++++-
 5 files changed, 57 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f4ff1c5f/app/addons/cors/actions.js
----------------------------------------------------------------------
diff --git a/app/addons/cors/actions.js b/app/addons/cors/actions.js
index 1a35f78..22e2188 100644
--- a/app/addons/cors/actions.js
+++ b/app/addons/cors/actions.js
@@ -140,7 +140,16 @@ define([
         return origins.join(',');
       },
 
+      toggleLoadingBarsToEnabled: function (state) {
+        FauxtonAPI.dispatch({
+          type: ActionTypes.CORS_SET_IS_LOADING,
+          isLoading: state
+        });
+      },
+
       saveCors: function (options) {
+        this.toggleLoadingBarsToEnabled(true);
+
         var promises = [];
         promises.push(this.saveEnableCorsToHttpd(options.enableCors, 
options.node));
 
@@ -158,13 +167,16 @@ define([
             clear: true
           });
 
-        }, function () {
+          this.toggleLoadingBarsToEnabled(false);
+
+        }.bind(this), function () {
           FauxtonAPI.addNotification({
             msg: 'Error! Could not save your CORS settings. Please try again.',
             type: 'error',
             clear: true
           });
-        });
+          this.toggleLoadingBarsToEnabled(false);
+        }.bind(this));
       }
     };
   });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f4ff1c5f/app/addons/cors/actiontypes.js
----------------------------------------------------------------------
diff --git a/app/addons/cors/actiontypes.js b/app/addons/cors/actiontypes.js
index 7182624..215dbff 100644
--- a/app/addons/cors/actiontypes.js
+++ b/app/addons/cors/actiontypes.js
@@ -17,6 +17,7 @@ define([], function () {
     CORS_IS_ALL_ORIGINS: 'CORS_IS_ALL_ORIGINS',
     CORS_DELETE_ORIGIN: 'CORS_DELETE_ORIGIN',
     CORS_UPDATE_ORIGIN: 'CORS_UPDATE_ORIGIN',
-    CORS_METHOD_CHANGE: 'CORS_METHOD_CHANGE'
+    CORS_METHOD_CHANGE: 'CORS_METHOD_CHANGE',
+    CORS_SET_IS_LOADING: 'CORS_SET_IS_LOADING'
   };
 });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f4ff1c5f/app/addons/cors/components.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/cors/components.react.jsx 
b/app/addons/cors/components.react.jsx
index 71f9382..6f6bf9f 100644
--- a/app/addons/cors/components.react.jsx
+++ b/app/addons/cors/components.react.jsx
@@ -16,8 +16,10 @@ define([
   "react",
   "addons/cors/stores",
   "addons/cors/resources",
-  "addons/cors/actions"
-], function (app, FauxtonAPI, React, Stores, Resources, Actions) {
+  "addons/cors/actions",
+  'addons/components/react-components.react'
+
+], function (app, FauxtonAPI, React, Stores, Resources, Actions, 
ReactComponents) {
   var corsStore = Stores.corsStore;
 
   var validateOrigin = function (origin) {
@@ -232,7 +234,8 @@ define([
         isAllOrigins: corsStore.isAllOrigins(),
         configChanged: corsStore.hasConfigChanged(),
         shouldSaveChange: corsStore.shouldSaveChange(),
-        node: corsStore.getNode()
+        node: corsStore.getNode(),
+        isLoading: corsStore.getIsLoading()
       };
     },
 
@@ -304,6 +307,10 @@ define([
       var isVisible = _.all([this.state.corsEnabled, 
!this.state.isAllOrigins]);
       var className = this.state.corsEnabled ? 'collapsing-container' : '';
 
+      if (this.state.isLoading) {
+        return (<ReactComponents.LoadLines />);
+      }
+
       return (
         <div className="cors-page">
           <header id="cors-header">

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f4ff1c5f/app/addons/cors/stores.js
----------------------------------------------------------------------
diff --git a/app/addons/cors/stores.js b/app/addons/cors/stores.js
index bd33447..0d083cc 100644
--- a/app/addons/cors/stores.js
+++ b/app/addons/cors/stores.js
@@ -23,6 +23,7 @@ define([
       this._configChanged = false;
       this._shouldSaveChange = false;
       this._node = options.node;
+      this._isLoading = false;
     },
 
     shouldSaveChange: function () {
@@ -41,6 +42,15 @@ define([
       this._configChanged = false;
     },
 
+    setIsLoading: function (state) {
+      this._isLoading = state;
+      this._shouldSaveChange = false;
+    },
+
+    getIsLoading: function () {
+      return this._isLoading;
+    },
+
     isEnabled: function () {
       return this._isEnabled;
     },
@@ -127,6 +137,10 @@ define([
           this.setConfigChanged();
         break;
 
+        case ActionTypes.CORS_SET_IS_LOADING:
+          this.setIsLoading(action.isLoading);
+        break;
+
         default:
         return;
       }

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f4ff1c5f/app/addons/cors/tests/componentsSpec.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/cors/tests/componentsSpec.react.jsx 
b/app/addons/cors/tests/componentsSpec.react.jsx
index c2f3cdd..68dd301 100644
--- a/app/addons/cors/tests/componentsSpec.react.jsx
+++ b/app/addons/cors/tests/componentsSpec.react.jsx
@@ -42,7 +42,9 @@ define([
       });
 
       afterEach(function () {
-        corsEl.save.restore();
+        utils.restore(Actions.toggleLoadingBarsToEnabled);
+        utils.restore(corsEl.save);
+
         React.unmountComponentAtNode(container);
         window.confirm.restore && window.confirm.restore();
       });
@@ -58,6 +60,7 @@ define([
 
       it('does not confirm for selected origins are emtpy for disabled cors 
change', function () {
         var spy = sinon.stub(window, 'confirm');
+        sinon.stub(Actions, 'toggleLoadingBarsToEnabled');
         spy.returns(false);
         corsEl.state.corsEnabled = true;
         corsEl.state.isAllOrigins = false;
@@ -77,13 +80,26 @@ define([
 
       it('does not confirm all origins change if selected origins are emtpy', 
function () {
         var spy = sinon.stub(window, 'confirm');
+        sinon.stub(Actions, 'toggleLoadingBarsToEnabled');
         spy.returns(false);
         corsEl.state.corsEnabled = true;
         corsEl.state.isAllOrigins = false;
         corsEl.state.origins = [];
         corsEl.originChange(true);
+
         assert.notOk(spy.calledOnce);
       });
+
+      it('shows loading bars', function () {
+        Actions.toggleLoadingBarsToEnabled(true);
+        assert.ok($(corsEl.getDOMNode()).hasClass('loading-lines'));
+      });
+
+      it('hides loading bars', function () {
+        Actions.toggleLoadingBarsToEnabled(false);
+
+        assert.notOk($(corsEl.getDOMNode()).hasClass('loading-lines'));
+      });
     });
 
     describe('OriginInput', function () {

Reply via email to