couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [14/27] fauxton commit: updated refs/heads/master to 0ca35da
Date Tue, 31 May 2016 07:58:42 GMT
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/index-results/tests/index-results.storesSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/index-results/tests/index-results.storesSpec.js b/app/addons/documents/index-results/tests/index-results.storesSpec.js
index 940c388..5dd9c87 100644
--- a/app/addons/documents/index-results/tests/index-results.storesSpec.js
+++ b/app/addons/documents/index-results/tests/index-results.storesSpec.js
@@ -10,736 +10,733 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../../core/api',
-  '../stores',
-  '../actiontypes',
-  '../../resources',
-  '../../tests/document-test-helper',
-  '../../../../../test/mocha/testUtils',
-  'sinon'
-], function (FauxtonAPI, Stores, ActionTypes, Documents, documentTestHelper, testUtils, sinon) {
-  var assert = testUtils.assert;
-  var dispatchToken;
-  var store;
-  var opts;
-
-  var createDocColumn = documentTestHelper.createDocColumn;
-  var createMangoIndexDocColumn = documentTestHelper.createMangoIndexDocColumn;
-
-  describe('Index Results Store', function () {
-    beforeEach(function () {
-      store = new Stores.IndexResultsStore();
-      store.dispatchToken = FauxtonAPI.dispatcher.register(store.dispatch);
-      store.reset();
-      opts = {
-        params: {limit: 10, skip: 0},
-        database: {
-          safeID: function () { return '1';}
-        }
-      };
-
-      store.newResults({
-        collection: createDocColumn([
-          {_id: 'testId5', _rev: '1', 'value': 'one'},
-          {_id: 'testId6', _rev: '1', 'value': 'one'}
-        ]),
-        bulkCollection: new Documents.BulkDeleteDocCollection([], { databaseId: '1' })
-      });
-    });
+import FauxtonAPI from "../../../../core/api";
+import Stores from "../stores";
+import ActionTypes from "../actiontypes";
+import Documents from "../../resources";
+import documentTestHelper from "../../tests/document-test-helper";
+import testUtils from "../../../../../test/mocha/testUtils";
+import sinon from "sinon";
+var assert = testUtils.assert;
+var dispatchToken;
+var store;
+var opts;
+
+var createDocColumn = documentTestHelper.createDocColumn;
+var createMangoIndexDocColumn = documentTestHelper.createMangoIndexDocColumn;
+
+describe('Index Results Store', function () {
+  beforeEach(function () {
+    store = new Stores.IndexResultsStore();
+    store.dispatchToken = FauxtonAPI.dispatcher.register(store.dispatch);
+    store.reset();
+    opts = {
+      params: {limit: 10, skip: 0},
+      database: {
+        safeID: function () { return '1';}
+      }
+    };
 
-    afterEach(function () {
-      FauxtonAPI.dispatcher.unregister(store.dispatchToken);
+    store.newResults({
+      collection: createDocColumn([
+        {_id: 'testId5', _rev: '1', 'value': 'one'},
+        {_id: 'testId6', _rev: '1', 'value': 'one'}
+      ]),
+      bulkCollection: new Documents.BulkDeleteDocCollection([], { databaseId: '1' })
     });
+  });
 
+  afterEach(function () {
+    FauxtonAPI.dispatcher.unregister(store.dispatchToken);
+  });
 
-    it('hasResults returns true for collection', function () {
-      store.newResults({
-        collection: createDocColumn([
-          {_id: 'testId5', _rev: '1', 'value': 'one'},
-          {_id: 'testId6', _rev: '1', 'value': 'one'}
-        ]),
-        bulkCollection: new Documents.BulkDeleteDocCollection([], { databaseId: '1' })
-      });
 
-      assert.ok(store.hasResults());
+  it('hasResults returns true for collection', function () {
+    store.newResults({
+      collection: createDocColumn([
+        {_id: 'testId5', _rev: '1', 'value': 'one'},
+        {_id: 'testId6', _rev: '1', 'value': 'one'}
+      ]),
+      bulkCollection: new Documents.BulkDeleteDocCollection([], { databaseId: '1' })
     });
 
-    it('can sort 2 dimensional arrays by the first value', function () {
-      var a = [
-        [20, 5],
-        [1, 2],
-        [3, 4]
-      ];
-      var res = store.sortByTwoFields(a);
+    assert.ok(store.hasResults());
+  });
 
-      assert.equal(a[0][0], 20);
-      assert.equal(a[1][0], 3);
-      assert.equal(a[2][0], 1);
-    });
+  it('can sort 2 dimensional arrays by the first value', function () {
+    var a = [
+      [20, 5],
+      [1, 2],
+      [3, 4]
+    ];
+    var res = store.sortByTwoFields(a);
+
+    assert.equal(a[0][0], 20);
+    assert.equal(a[1][0], 3);
+    assert.equal(a[2][0], 1);
+  });
 
-    it('can sort 2 dimensional arrays by the second value if multiple appear', function () {
-      var a = [
-        [1, "z"],
-        [1, "g"],
-        [1, "a"]
-      ];
-      var res = store.sortByTwoFields(a);
+  it('can sort 2 dimensional arrays by the second value if multiple appear', function () {
+    var a = [
+      [1, "z"],
+      [1, "g"],
+      [1, "a"]
+    ];
+    var res = store.sortByTwoFields(a);
+
+    assert.equal(a[0][1], 'a');
+    assert.equal(a[1][1], 'g');
+    assert.equal(a[2][1], 'z');
+  });
 
-      assert.equal(a[0][1], 'a');
-      assert.equal(a[1][1], 'g');
-      assert.equal(a[2][1], 'z');
-    });
 
+  it('hasResults returns false for empty collection', function () {
+    store._collection = [];
 
-    it('hasResults returns false for empty collection', function () {
-      store._collection = [];
+    assert.notOk(store.hasResults());
+  });
 
-      assert.notOk(store.hasResults());
+  it('getResults has correct doc format', function () {
+    store.newResults({
+      collection: createDocColumn([
+        {_id: 'testId', _rev: '1', 'value': 'one'},
+      ])
     });
 
-    it('getResults has correct doc format', function () {
-      store.newResults({
-        collection: createDocColumn([
-          {_id: 'testId', _rev: '1', 'value': 'one'},
-        ])
-      });
+    var doc = store.getResults().results[0];
+    assert.equal(doc.id, 'testId');
+    assert.equal(doc.keylabel, 'id');
+  });
 
-      var doc = store.getResults().results[0];
-      assert.equal(doc.id, 'testId');
-      assert.equal(doc.keylabel, 'id');
-    });
+  it('tries to guess a pseudo schema for table views', function () {
+    var doclist = [
+      {_id: 'testId1', value: 'one'},
+      {_id: 'testId2', foo: 'one'},
+      {_id: 'testId3', bar: 'one'},
+    ];
 
-    it('tries to guess a pseudo schema for table views', function () {
-      var doclist = [
-        {_id: 'testId1', value: 'one'},
-        {_id: 'testId2', foo: 'one'},
-        {_id: 'testId3', bar: 'one'},
-      ];
+    var schema = store.getPseudoSchema(doclist);
 
-      var schema = store.getPseudoSchema(doclist);
+    assert.ok(schema.indexOf('_id') !== -1);
+    assert.ok(schema.indexOf('value') !== -1);
+    assert.ok(schema.indexOf('foo') !== -1);
+    assert.ok(schema.indexOf('bar') !== -1);
+  });
 
-      assert.ok(schema.indexOf('_id') !== -1);
-      assert.ok(schema.indexOf('value') !== -1);
-      assert.ok(schema.indexOf('foo') !== -1);
-      assert.ok(schema.indexOf('bar') !== -1);
-    });
+  it('uses unique values for the pseudo schema', function () {
+    var doclist = [
+      {_id: 'testId1', foo: 'one'},
+      {_id: 'testId2', foo: 'one'}
+    ];
 
-    it('uses unique values for the pseudo schema', function () {
-      var doclist = [
-        {_id: 'testId1', foo: 'one'},
-        {_id: 'testId2', foo: 'one'}
-      ];
+    var schema = store.getPseudoSchema(doclist);
 
-      var schema = store.getPseudoSchema(doclist);
+    assert.equal(schema.length, 2);
+    assert.equal(schema.length, 2);
+    assert.ok(schema.indexOf('foo') !== -1);
+    assert.ok(schema.indexOf('_id') !== -1);
+  });
 
-      assert.equal(schema.length, 2);
-      assert.equal(schema.length, 2);
-      assert.ok(schema.indexOf('foo') !== -1);
-      assert.ok(schema.indexOf('_id') !== -1);
-    });
+  it('puts the id into the array as first element', function () {
+    var doclist = [
+      {foo: 'one', _id: 'testId1'},
+      {foo: 'one', _id: 'testId2'}
+    ];
 
-    it('puts the id into the array as first element', function () {
-      var doclist = [
-        {foo: 'one', _id: 'testId1'},
-        {foo: 'one', _id: 'testId2'}
-      ];
+    var schema = store.getPseudoSchema(doclist);
 
-      var schema = store.getPseudoSchema(doclist);
+    assert.equal(schema.shift(), '_id');
+  });
 
-      assert.equal(schema.shift(), '_id');
-    });
+  it('normalizes different content from include_docs enabled', function () {
+    var doclist = [
+      {_id: 'testId2', foo: 'one', doc: {"_rev": "1", "ente": "gans", "fuchs": "hase"}},
+      {_id: 'testId3', foo: 'two', doc: {"_rev": "2", "haus": "blau", "tanne": "acht"}}
+    ];
 
-    it('normalizes different content from include_docs enabled', function () {
-      var doclist = [
-        {_id: 'testId2', foo: 'one', doc: {"_rev": "1", "ente": "gans", "fuchs": "hase"}},
-        {_id: 'testId3', foo: 'two', doc: {"_rev": "2", "haus": "blau", "tanne": "acht"}}
-      ];
+    var res = store.normalizeTableData(doclist);
+    assert.deepEqual(res[0], {"_rev": "1", "ente": "gans", "fuchs": "hase"});
+  });
 
-      var res = store.normalizeTableData(doclist);
-      assert.deepEqual(res[0], {"_rev": "1", "ente": "gans", "fuchs": "hase"});
-    });
+  it('returns the fields that occure the most without id and rev', function () {
+    var doclist = [
+      {_rev: '1', _id: '1', id: 'testId2', foo: 'one'},
+      {_rev: '1', _id: '1', id: 'testId3', foo: 'two'}
+    ];
 
-    it('returns the fields that occure the most without id and rev', function () {
-      var doclist = [
-        {_rev: '1', _id: '1', id: 'testId2', foo: 'one'},
-        {_rev: '1', _id: '1', id: 'testId3', foo: 'two'}
-      ];
+    var res = store.getPrioritizedFields(doclist, 10);
+    assert.deepEqual(res, ['foo']);
+  });
 
-      var res = store.getPrioritizedFields(doclist, 10);
-      assert.deepEqual(res, ['foo']);
-    });
+  it('sorts the fields that occure the most', function () {
+    var doclist = [
+      {id: 'testId2', foo: 'one'},
 
-    it('sorts the fields that occure the most', function () {
-      var doclist = [
-        {id: 'testId2', foo: 'one'},
+      {id: 'testId3', bar: 'two'},
+      {id: 'testId3', bar: 'two'},
+      {id: 'testId3', baz: 'two'},
+      {id: 'testId3', baz: 'two'}
+    ];
 
-        {id: 'testId3', bar: 'two'},
-        {id: 'testId3', bar: 'two'},
-        {id: 'testId3', baz: 'two'},
-        {id: 'testId3', baz: 'two'}
-      ];
+    var res = store.getPrioritizedFields(doclist, 10);
+    assert.deepEqual(res, ['bar', 'baz', 'foo']);
+  });
 
-      var res = store.getPrioritizedFields(doclist, 10);
-      assert.deepEqual(res, ['bar', 'baz', 'foo']);
-    });
+  it('limits the fields that occure the most', function () {
+    var doclist = [
+      {id: 'testId2', foo: 'one'},
 
-    it('limits the fields that occure the most', function () {
-      var doclist = [
-        {id: 'testId2', foo: 'one'},
+      {id: 'testId3', bar: 'two'},
+      {id: 'testId3', bar: 'two'},
+      {id: 'testId3', baz: 'two'},
+      {id: 'testId3', baz: 'two'}
+    ];
 
-        {id: 'testId3', bar: 'two'},
-        {id: 'testId3', bar: 'two'},
-        {id: 'testId3', baz: 'two'},
-        {id: 'testId3', baz: 'two'}
-      ];
+    var res = store.getPrioritizedFields(doclist, 2);
+    assert.deepEqual(res, ['bar', 'baz']);
+  });
 
-      var res = store.getPrioritizedFields(doclist, 2);
-      assert.deepEqual(res, ['bar', 'baz']);
-    });
+  it('if the collection is empty, no docs should be selected', function () {
+    store._collection = new Documents.AllDocs([], opts);
 
-    it('if the collection is empty, no docs should be selected', function () {
-      store._collection = new Documents.AllDocs([], opts);
+    assert.notOk(store.areAllDocumentsSelected());
+  });
 
-      assert.notOk(store.areAllDocumentsSelected());
-    });
+  it('if the collection changes, not all docs should be selected', function () {
+    store._collection = createDocColumn([
+      {_id: 'testId1', _rev: '1', 'value': 'one'},
+      {_id: 'testId2', _rev: '1', 'value': 'one'}
+    ]);
 
-    it('if the collection changes, not all docs should be selected', function () {
-      store._collection = createDocColumn([
-        {_id: 'testId1', _rev: '1', 'value': 'one'},
-        {_id: 'testId2', _rev: '1', 'value': 'one'}
-      ]);
+    store.selectAllDocuments();
 
-      store.selectAllDocuments();
+    store._collection = createDocColumn([
+      {_id: 'testId5', _rev: '1', 'value': 'one'},
+      {_id: 'testId6', _rev: '1', 'value': 'one'}
+    ]);
 
-      store._collection = createDocColumn([
-        {_id: 'testId5', _rev: '1', 'value': 'one'},
-        {_id: 'testId6', _rev: '1', 'value': 'one'}
-      ]);
+    assert.notOk(store.areAllDocumentsSelected());
+  });
 
-      assert.notOk(store.areAllDocumentsSelected());
-    });
+  it('special mango docs are not selectable, but all should be selected', function () {
+    store._collection = createMangoIndexDocColumn([
+      {ddoc: 'testId1', type: 'special', def: {fields: [{_id: 'desc'}]}},
+      {ddoc: 'testId2', blubb: 'ba', type: 'json', def: {fields: [{_id: 'desc'}]}}
+    ]);
 
-    it('special mango docs are not selectable, but all should be selected', function () {
-      store._collection = createMangoIndexDocColumn([
-        {ddoc: 'testId1', type: 'special', def: {fields: [{_id: 'desc'}]}},
-        {ddoc: 'testId2', blubb: 'ba', type: 'json', def: {fields: [{_id: 'desc'}]}}
-      ]);
+    store.selectAllDocuments();
 
-      store.selectAllDocuments();
+    assert.ok(store.areAllDocumentsSelected());
+  });
 
-      assert.ok(store.areAllDocumentsSelected());
-    });
+  it('returns true for selected docs less than collection', function () {
+    store._collection = createDocColumn([
+      {_id: 'testId1', _rev: 'foo'},
+      {_id: 'testId2', _rev: 'foo'}
+    ]);
 
-    it('returns true for selected docs less than collection', function () {
-      store._collection = createDocColumn([
-        {_id: 'testId1', _rev: 'foo'},
-        {_id: 'testId2', _rev: 'foo'}
-      ]);
+    store._selectedItems = {'testId1': true};
+    assert.notOk(store.areAllDocumentsSelected());
+  });
 
-      store._selectedItems = {'testId1': true};
-      assert.notOk(store.areAllDocumentsSelected());
-    });
+  it('returns true even with _all_docs (mango)', function () {
+    store._collection = new Documents.AllDocs([
+      {_id: 'testId1'},
+      {_id: 'testId2'},
+      {_id: '_all_docs'}
+    ], opts);
 
-    it('returns true even with _all_docs (mango)', function () {
-      store._collection = new Documents.AllDocs([
-        {_id: 'testId1'},
-        {_id: 'testId2'},
-        {_id: '_all_docs'}
-      ], opts);
+    store._selectedItems = {
+      'testId1': true,
+      'testId2': true
+    };
 
-      store._selectedItems = {
-        'testId1': true,
-        'testId2': true
-      };
+    assert.ok(store.areAllDocumentsSelected());
+  });
 
-      assert.ok(store.areAllDocumentsSelected());
+  it('does not count multiple fields in the prioritzed table', function () {
+    store.newResults({
+      collection: createDocColumn([
+        {a: '1', 'value': 'one', b: '1'},
+        {a: '1', 'value': 'one', b: '1'},
+        {a: '1', 'value': 'one', b: '1'}
+      ])
     });
 
-    it('does not count multiple fields in the prioritzed table', function () {
-      store.newResults({
-        collection: createDocColumn([
-          {a: '1', 'value': 'one', b: '1'},
-          {a: '1', 'value': 'one', b: '1'},
-          {a: '1', 'value': 'one', b: '1'}
-        ])
-      });
+    store.getResults();
 
-      store.getResults();
+    store.toggleTableView({enable: true});
+    store.getResults();
 
-      store.toggleTableView({enable: true});
-      store.getResults();
+    store.changeTableViewFields({index: 0, newSelectedRow: 'value'});
 
-      store.changeTableViewFields({index: 0, newSelectedRow: 'value'});
+    var stub = sinon.stub(store, 'isIncludeDocsEnabled');
+    stub.returns(true);
 
-      var stub = sinon.stub(store, 'isIncludeDocsEnabled');
-      stub.returns(true);
+    assert.deepEqual(store.getDisplayCountForTableView(), { shown: 2, allFieldCount: 3 });
+  });
 
-      assert.deepEqual(store.getDisplayCountForTableView(), { shown: 2, allFieldCount: 3 });
+  it('id and rev count as one field, because of the combined metadata field', function () {
+    store.newResults({
+      collection: createDocColumn([
+        {_id: 'foo1', _rev: 'bar', a: '1', 'value': 'one', b: '1'},
+        {_id: 'foo2', _rev: 'bar', a: '1', 'value': 'one', b: '1'},
+        {_id: 'foo3', _rev: 'bar', a: '1', 'value': 'one', b: '1'}
+      ]),
+      bulkCollection: new Documents.BulkDeleteDocCollection([], { databaseId: '1' })
     });
 
-    it('id and rev count as one field, because of the combined metadata field', function () {
-      store.newResults({
-        collection: createDocColumn([
-          {_id: 'foo1', _rev: 'bar', a: '1', 'value': 'one', b: '1'},
-          {_id: 'foo2', _rev: 'bar', a: '1', 'value': 'one', b: '1'},
-          {_id: 'foo3', _rev: 'bar', a: '1', 'value': 'one', b: '1'}
-        ]),
-        bulkCollection: new Documents.BulkDeleteDocCollection([], { databaseId: '1' })
-      });
+    store.toggleTableView({enable: true});
 
-      store.toggleTableView({enable: true});
+    var stub = sinon.stub(store, 'isIncludeDocsEnabled');
+    stub.returns(true);
+    store.getResults();
 
-      var stub = sinon.stub(store, 'isIncludeDocsEnabled');
-      stub.returns(true);
-      store.getResults();
+    assert.deepEqual(store.getDisplayCountForTableView(), { shown: 4, allFieldCount: 4 });
+  });
 
-      assert.deepEqual(store.getDisplayCountForTableView(), { shown: 4, allFieldCount: 4 });
-    });
+  it('selectDoc selects doc if not already selected', function () {
+    store._collection = new createDocColumn([
+      {_id: 'id', _rev: '1', 'value': 'one'},
+      {_id: 'testId6', _rev: '1', 'value': 'one'}
+    ]);
+    store.selectDoc({_id: 'id', _rev: '1'});
+    assert.equal(store.getSelectedItemsLength(), 1);
+  });
 
-    it('selectDoc selects doc if not already selected', function () {
-      store._collection = new createDocColumn([
-        {_id: 'id', _rev: '1', 'value': 'one'},
-        {_id: 'testId6', _rev: '1', 'value': 'one'}
-      ]);
-      store.selectDoc({_id: 'id', _rev: '1'});
-      assert.equal(store.getSelectedItemsLength(), 1);
-    });
+  it('selectDoc deselects doc if already selected', function () {
+    store.selectDoc({_id: 'id', _rev: '1'});
+    store._collection = new createDocColumn([
+      {_id: 'id', _rev: '1', 'value': 'one'},
+      {_id: 'testId6', _rev: '1', 'value': 'one'}
+    ]);
+    store.selectDoc({_id: 'id', _rev: '1'});
+    assert.equal(store.getSelectedItemsLength(), 0);
+  });
 
-    it('selectDoc deselects doc if already selected', function () {
-      store.selectDoc({_id: 'id', _rev: '1'});
-      store._collection = new createDocColumn([
-        {_id: 'id', _rev: '1', 'value': 'one'},
-        {_id: 'testId6', _rev: '1', 'value': 'one'}
-      ]);
-      store.selectDoc({_id: 'id', _rev: '1'});
-      assert.equal(store.getSelectedItemsLength(), 0);
-    });
+  it('selectDoc selects all documents', function () {
+    store._collection = createDocColumn([{_id: 'testId1', _rev: '1', 'value': 'one'}]);
 
-    it('selectDoc selects all documents', function () {
-      store._collection = createDocColumn([{_id: 'testId1', _rev: '1', 'value': 'one'}]);
+    store.selectAllDocuments();
+    assert.ok(store._bulkDeleteDocCollection.get('testId1'));
+  });
 
-      store.selectAllDocuments();
-      assert.ok(store._bulkDeleteDocCollection.get('testId1'));
-    });
+  it('selectDoc does not select all documents if rev is missing', function () {
+    store._collection = createDocColumn([{_id: 'testId1', 'value': 'one'}]);
 
-    it('selectDoc does not select all documents if rev is missing', function () {
-      store._collection = createDocColumn([{_id: 'testId1', 'value': 'one'}]);
+    store.selectAllDocuments();
+    assert.equal(store.getSelectedItemsLength(), 0);
+  });
 
-      store.selectAllDocuments();
-      assert.equal(store.getSelectedItemsLength(), 0);
-    });
+});
+describe('toggleSelectAllDocuments', function () {
+
+  it('deselects all documents', function () {
+    store._collection = new Documents.AllDocs([{_id: 'testId1', _rev: '1', 'value': 'one'}], opts);
 
+    store.selectAllDocuments();
+    assert.ok(store._bulkDeleteDocCollection.get('testId1'));
+    store.toggleSelectAllDocuments();
+    assert.equal(store.getSelectedItemsLength(), 0);
   });
-  describe('toggleSelectAllDocuments', function () {
 
-    it('deselects all documents', function () {
-      store._collection = new Documents.AllDocs([{_id: 'testId1', _rev: '1', 'value': 'one'}], opts);
+  it('deselects all documents with toggleSelectAllDocuments', function () {
+    store.reset();
+    store._collection = new Documents.AllDocs([{_id: 'testId1', _rev: '1', 'value': 'one'}], opts);
 
-      store.selectAllDocuments();
-      assert.ok(store._bulkDeleteDocCollection.get('testId1'));
-      store.toggleSelectAllDocuments();
-      assert.equal(store.getSelectedItemsLength(), 0);
-    });
+    assert.equal(store._bulkDeleteDocCollection.length, 0);
+    store.toggleSelectAllDocuments();
+    assert.equal(store.getSelectedItemsLength(), 1);
+  });
+});
 
-    it('deselects all documents with toggleSelectAllDocuments', function () {
-      store.reset();
-      store._collection = new Documents.AllDocs([{_id: 'testId1', _rev: '1', 'value': 'one'}], opts);
+describe('#getMangoDoc', function () {
+  beforeEach(function () {
+    store = new Stores.IndexResultsStore();
+    dispatchToken = FauxtonAPI.dispatcher.register(store.dispatch);
+    opts = {
+      params: {},
+      database: {
+        safeID: function () { return '1';}
+      }
+    };
+  });
 
-      assert.equal(store._bulkDeleteDocCollection.length, 0);
-      store.toggleSelectAllDocuments();
-      assert.equal(store.getSelectedItemsLength(), 1);
-    });
+  var fakeMango = {
+    ddoc: '_design/e4d338e5d6f047749f5399ab998b4fa04ba0c816',
+    def: {
+      fields: [
+        {'_id': 'asc'},
+        {'foo': 'bar'},
+        {'ente': 'gans'}
+      ]
+    },
+    name: 'e4d338e5d6f047749f5399ab998b4fa04ba0c816',
+    type: 'json'
+  };
+
+  it('creates a special id from the header fields', function () {
+    var doc = new Documents.MangoIndex(fakeMango, opts);
+    assert.equal(store.getMangoDoc(doc).header, 'json: _id, foo, ente');
   });
 
-  describe('#getMangoDoc', function () {
-    beforeEach(function () {
-      store = new Stores.IndexResultsStore();
-      dispatchToken = FauxtonAPI.dispatcher.register(store.dispatch);
-      opts = {
-        params: {},
-        database: {
-          safeID: function () { return '1';}
-        }
-      };
+  it('supports custom header fields', function () {
+    FauxtonAPI.registerExtension('mango:additionalIndexes', {
+      createHeader: function (doc) {
+        return ['foobar'];
+      }
     });
 
-    var fakeMango = {
+    var doc = new Documents.MangoIndex({
       ddoc: '_design/e4d338e5d6f047749f5399ab998b4fa04ba0c816',
       def: {
-        fields: [
-          {'_id': 'asc'},
-          {'foo': 'bar'},
-          {'ente': 'gans'}
-        ]
+        fields: []
       },
       name: 'e4d338e5d6f047749f5399ab998b4fa04ba0c816',
       type: 'json'
-    };
+    }, opts);
+    assert.equal(store.getMangoDoc(doc).header, 'foobar');
+  });
 
-    it('creates a special id from the header fields', function () {
-      var doc = new Documents.MangoIndex(fakeMango, opts);
-      assert.equal(store.getMangoDoc(doc).header, 'json: _id, foo, ente');
-    });
+  it('removes the name and ddoc field', function () {
+    var doc = new Documents.MangoIndex(fakeMango, opts);
+    assert.ok(doc.get('name'));
+    assert.ok(doc.get('ddoc'));
 
-    it('supports custom header fields', function () {
-      FauxtonAPI.registerExtension('mango:additionalIndexes', {
-        createHeader: function (doc) {
-          return ['foobar'];
-        }
-      });
+    store._allCollapsed = false;
+    var newDoc = store.getMangoDoc(doc);
+    assert.notOk(JSON.parse(newDoc.content).name);
+    assert.notOk(JSON.parse(newDoc.content).ddoc);
+    assert.ok(JSON.parse(newDoc.content).type);
+  });
+});
 
-      var doc = new Documents.MangoIndex({
-        ddoc: '_design/e4d338e5d6f047749f5399ab998b4fa04ba0c816',
-        def: {
-          fields: []
-        },
-        name: 'e4d338e5d6f047749f5399ab998b4fa04ba0c816',
-        type: 'json'
-      }, opts);
-      assert.equal(store.getMangoDoc(doc).header, 'foobar');
-    });
+describe('#getDocId', function () {
 
-    it('removes the name and ddoc field', function () {
-      var doc = new Documents.MangoIndex(fakeMango, opts);
-      assert.ok(doc.get('name'));
-      assert.ok(doc.get('ddoc'));
+  it('returns id if it exists', function () {
+    var doc = new Documents.Doc({
+      _id: 'doc-id'
+    }, opts);
+
+    assert.equal(store.getDocId(doc), 'doc-id');
 
-      store._allCollapsed = false;
-      var newDoc = store.getMangoDoc(doc);
-      assert.notOk(JSON.parse(newDoc.content).name);
-      assert.notOk(JSON.parse(newDoc.content).ddoc);
-      assert.ok(JSON.parse(newDoc.content).type);
-    });
   });
 
-  describe('#getDocId', function () {
+  it('returns key if it exists', function () {
+    var doc = new Documents.Doc({
+      key: 'doc-key'
+    }, opts);
 
-    it('returns id if it exists', function () {
-      var doc = new Documents.Doc({
-        _id: 'doc-id'
-      }, opts);
+    assert.equal(store.getDocId(doc), 'doc-key');
 
-      assert.equal(store.getDocId(doc), 'doc-id');
+  });
 
-    });
+  it('returns empty string if no key or id exists', function () {
+    var doc = new Documents.Doc({
+      key: null,
+      value: 'the-value'
+    }, opts);
 
-    it('returns key if it exists', function () {
-      var doc = new Documents.Doc({
-        key: 'doc-key'
-      }, opts);
+    assert.equal(store.getDocId(doc), '');
 
-      assert.equal(store.getDocId(doc), 'doc-key');
+  });
+});
 
-    });
+describe('isEditable', function () {
+  store = new Stores.IndexResultsStore();
 
-    it('returns empty string if no key or id exists', function () {
-      var doc = new Documents.Doc({
-        key: null,
-        value: 'the-value'
-      }, opts);
+  it('returns false for no collection', function () {
+    store._collection = null;
+    assert.notOk(store.isEditable());
+  });
 
-      assert.equal(store.getDocId(doc), '');
+  it('returns false for empty collection', function () {
+    store._collection = [];
+    assert.notOk(store.isEditable());
+  });
 
-    });
+  it('delegates to collection', function () {
+    store._collection = {
+      attributes: {
+        fields: ["foo"]
+      }
+    };
+    store._collection.isEditable = function () { return {'stub': true}; };
+    assert.deepEqual(store.isEditable(), {'stub': true});
+    store._collection = {};
   });
 
-  describe('isEditable', function () {
-    store = new Stores.IndexResultsStore();
+  it('retuns false for ghost-docs that are filtered away', function () {
+    store._collection = {};
+    assert.equal(store.isEditable({}), false);
+  });
+});
 
-    it('returns false for no collection', function () {
-      store._collection = null;
-      assert.notOk(store.isEditable());
-    });
+describe('isDeletable', function () {
+  store = new Stores.IndexResultsStore();
 
-    it('returns false for empty collection', function () {
-      store._collection = [];
-      assert.notOk(store.isEditable());
-    });
+  it('retuns false for ghost-docs that are filtered away', function () {
+    assert.equal(store.isDeletable({}), false);
+  });
+});
+
+describe('Index Pagination', function () {
+
+  beforeEach(function () {
+    store = new Stores.IndexResultsStore();
+    dispatchToken = FauxtonAPI.dispatcher.register(store.dispatch);
+  });
+
+  afterEach(function () {
+    FauxtonAPI.dispatcher.unregister(dispatchToken);
+  });
 
-    it('delegates to collection', function () {
-      store._collection = {
-        attributes: {
-          fields: ["foo"]
+  describe('#collectionChanged', function () {
+    var collection;
+    beforeEach(function () {
+      collection = new Documents.AllDocs([{id:1}, {id: 2}], {
+        params: {},
+        database: {
+          safeID: function () { return '1';}
         }
-      };
-      store._collection.isEditable = function () { return {'stub': true}; };
-      assert.deepEqual(store.isEditable(), {'stub': true});
-      store._collection = {};
+      });
+      store.reset();
+      store.newResults({
+        collection: collection
+      });
     });
 
-    it('retuns false for ghost-docs that are filtered away', function () {
-      store._collection = {};
-      assert.equal(store.isEditable({}), false);
+    it('sets total rows correctly', function () {
+      assert.equal(store.getTotalRows(), 2);
     });
   });
 
-  describe('isDeletable', function () {
-    store = new Stores.IndexResultsStore();
+  describe('canShowPrevious', function () {
+    it('cannot show previous if disabled', function () {
+      store._enabled = false;
+      assert.notOk(store.canShowPrevious());
+    });
 
-    it('retuns false for ghost-docs that are filtered away', function () {
-      assert.equal(store.isDeletable({}), false);
+    it('can show if collection can show', function () {
+      store._enabled = true;
+      store._collection = new Backbone.Collection();
+      store._collection.hasPrevious = function () { return true;};
+      assert.ok(store.canShowPrevious());
     });
+
   });
 
-  describe('Index Pagination', function () {
+  describe('canShowNext', function () {
+    it('cannot show next if disabled', function () {
+      store._enabled = false;
+      assert.notOk(store.canShowNext());
+    });
 
-    beforeEach(function () {
-      store = new Stores.IndexResultsStore();
-      dispatchToken = FauxtonAPI.dispatcher.register(store.dispatch);
+    it('cannot show if pageStart and perPage greater than docLimit', function () {
+      store._enabled = true;
+      store._docLimit = 10;
+      store._perPage = 20;
+
+      assert.notOk(store.canShowNext());
     });
 
-    afterEach(function () {
-      FauxtonAPI.dispatcher.unregister(dispatchToken);
+    it('can show if collection can show', function () {
+      store._enabled = true;
+      store._docLimit = 100000;
+      store.reset();
+      store._collection = new Backbone.Collection();
+      store._collection.hasNext = function () { return true;};
+      assert.ok(store.canShowNext());
     });
+  });
 
-    describe('#collectionChanged', function () {
-      var collection;
-      beforeEach(function () {
-        collection = new Documents.AllDocs([{id:1}, {id: 2}], {
+  describe('paginateNext', function () {
+    beforeEach(function () {
+      store.reset();
+
+      store.newResults({
+        collection: new Documents.AllDocs(null, {
           params: {},
           database: {
             safeID: function () { return '1';}
           }
-        });
-        store.reset();
-        store.newResults({
-          collection: collection
-        });
-      });
-
-      it('sets total rows correctly', function () {
-        assert.equal(store.getTotalRows(), 2);
+        })
       });
+      store.setPerPage(20);
     });
 
-    describe('canShowPrevious', function () {
-      it('cannot show previous if disabled', function () {
-        store._enabled = false;
-        assert.notOk(store.canShowPrevious());
-      });
-
-      it('can show if collection can show', function () {
-        store._enabled = true;
-        store._collection = new Backbone.Collection();
-        store._collection.hasPrevious = function () { return true;};
-        assert.ok(store.canShowPrevious());
-      });
+    it('should increment page number', function () {
+      store.paginateNext();
 
+      assert.equal(store.getCurrentPage(), 2);
     });
 
-    describe('canShowNext', function () {
-      it('cannot show next if disabled', function () {
-        store._enabled = false;
-        assert.notOk(store.canShowNext());
-      });
-
-      it('cannot show if pageStart and perPage greater than docLimit', function () {
-        store._enabled = true;
-        store._docLimit = 10;
-        store._perPage = 20;
+    it('should increment page start', function () {
+      store.paginateNext();
 
-        assert.notOk(store.canShowNext());
-      });
-
-      it('can show if collection can show', function () {
-        store._enabled = true;
-        store._docLimit = 100000;
-        store.reset();
-        store._collection = new Backbone.Collection();
-        store._collection.hasNext = function () { return true;};
-        assert.ok(store.canShowNext());
-      });
+      assert.equal(store.getPageStart(), 21);
     });
 
-    describe('paginateNext', function () {
-      beforeEach(function () {
-        store.reset();
-
-        store.newResults({
-          collection: new Documents.AllDocs(null, {
-            params: {},
-            database: {
-              safeID: function () { return '1';}
-            }
-          })
-        });
-        store.setPerPage(20);
-      });
-
-      it('should increment page number', function () {
-        store.paginateNext();
-
-        assert.equal(store.getCurrentPage(), 2);
-      });
+    it('should set correct page end', function () {
+      store._collection.length = 20;
+      store.paginateNext();
 
-      it('should increment page start', function () {
-        store.paginateNext();
+      assert.equal(store.getPageEnd(), 40);
+    });
 
-        assert.equal(store.getPageStart(), 21);
-      });
+    it('should set collection pageSize', function () {
+      store.paginateNext();
 
-      it('should set correct page end', function () {
-        store._collection.length = 20;
-        store.paginateNext();
+      assert.equal(store.getCollection().paging.pageSize, 20);
+    });
+  });
 
-        assert.equal(store.getPageEnd(), 40);
+  describe('paginatePrevious', function () {
+    beforeEach(function () {
+      store.resetPagination();
+      store._collection = new Documents.AllDocs(null, {
+        params: {},
+        database: {
+          safeID: function () { return '1';}
+        }
       });
+    });
 
-      it('should set collection pageSize', function () {
-        store.paginateNext();
+    it('should decrement page number', function () {
+      store.paginateNext();
+      store.paginatePrevious();
 
-        assert.equal(store.getCollection().paging.pageSize, 20);
-      });
+      assert.equal(store.getCurrentPage(), 1);
     });
 
-    describe('paginatePrevious', function () {
-      beforeEach(function () {
-        store.resetPagination();
-        store._collection = new Documents.AllDocs(null, {
-          params: {},
-          database: {
-            safeID: function () { return '1';}
-          }
-        });
-      });
-
-      it('should decrement page number', function () {
-        store.paginateNext();
-        store.paginatePrevious();
+    it('should decrement page start', function () {
+      store.paginateNext();
+      store.paginatePrevious();
 
-        assert.equal(store.getCurrentPage(), 1);
-      });
+      assert.equal(store.getPageStart(), 1);
+    });
 
-      it('should decrement page start', function () {
-        store.paginateNext();
-        store.paginatePrevious();
+    it('should decrement page end', function () {
+      store._collection.length = 20;
+      store.paginateNext();
+      store.paginatePrevious();
 
-        assert.equal(store.getPageStart(), 1);
-      });
+      assert.equal(store.getPageEnd(), 20);
+    });
 
-      it('should decrement page end', function () {
-        store._collection.length = 20;
-        store.paginateNext();
-        store.paginatePrevious();
+    it('should set collection pageSize', function () {
+      store.paginateNext();
+      store.paginatePrevious();
 
-        assert.equal(store.getPageEnd(), 20);
-      });
+      assert.equal(store.getCollection().paging.pageSize, 20);
+    });
 
-      it('should set collection pageSize', function () {
-        store.paginateNext();
-        store.paginatePrevious();
+  });
 
-        assert.equal(store.getCollection().paging.pageSize, 20);
-      });
+  describe('totalDocsViewed', function () {
+    beforeEach(function () {
+      store.reset();
+    });
 
+    it('returns correct count for page 1 and 20 docs per page', function () {
+      assert.equal(store.totalDocsViewed(), 20);
     });
 
-    describe('totalDocsViewed', function () {
-      beforeEach(function () {
-        store.reset();
-      });
+    it('returns correct count for page 3 and 10 docs per page', function () {
+      store._perPage = 10;
+      store._currentPage = 3;
 
-      it('returns correct count for page 1 and 20 docs per page', function () {
-        assert.equal(store.totalDocsViewed(), 20);
-      });
+      assert.equal(store.totalDocsViewed(), 30);
+    });
+  });
 
-      it('returns correct count for page 3 and 10 docs per page', function () {
-        store._perPage = 10;
-        store._currentPage = 3;
+  describe('documentsLeftToFetch', function () {
+    beforeEach(function () {
+      store.reset();
+    });
 
-        assert.equal(store.totalDocsViewed(), 30);
-      });
+    it('returns 20 documents left', function () {
+      assert.equal(store.documentsLeftToFetch(), 20);
     });
 
-    describe('documentsLeftToFetch', function () {
-      beforeEach(function () {
-        store.reset();
-      });
+    it('returns less if close to limit', function () {
+      store._docLimit = 35;
+      store._perPage = 10;
+      store._currentPage = 3;
+      assert.equal(store.documentsLeftToFetch(), 5);
+    });
 
-      it('returns 20 documents left', function () {
-        assert.equal(store.documentsLeftToFetch(), 20);
-      });
+  });
 
-      it('returns less if close to limit', function () {
-        store._docLimit = 35;
-        store._perPage = 10;
-        store._currentPage = 3;
-        assert.equal(store.documentsLeftToFetch(), 5);
-      });
+  describe('#initPerPage', function () {
 
+    it('uses default if no local storage set', function () {
+      window.localStorage.removeItem('fauxton:perpage');
+      store.initPerPage();
+      assert.equal(store.getPerPage(), 20);
     });
 
-    describe('#initPerPage', function () {
+    it('uses localstorage when available', function () {
+      window.localStorage.setItem('fauxton:perpage', 44);
+      store.initPerPage();
+      assert.equal(store.getPerPage(), 44);
+    });
 
-      it('uses default if no local storage set', function () {
-        window.localStorage.removeItem('fauxton:perpage');
-        store.initPerPage();
-        assert.equal(store.getPerPage(), 20);
-      });
+    it('uses doc limit when its less than perPage', function () {
+      window.localStorage.setItem('fauxton:perpage', 100);
+      store._docLimit = 6;
+      store.initPerPage();
+      assert.equal(store.getPerPage(), 6);
+    });
 
-      it('uses localstorage when available', function () {
-        window.localStorage.setItem('fauxton:perpage', 44);
-        store.initPerPage();
-        assert.equal(store.getPerPage(), 44);
-      });
+  });
 
-      it('uses doc limit when its less than perPage', function () {
-        window.localStorage.setItem('fauxton:perpage', 100);
-        store._docLimit = 6;
-        store.initPerPage();
-        assert.equal(store.getPerPage(), 6);
-      });
+  describe('#setDocumentLimit', function () {
 
+    it('sets document if exists', function () {
+      store.setDocumentLimit(10);
+      assert.equal(store._docLimit, 10);
     });
 
-    describe('#setDocumentLimit', function () {
+    it('sets perPage to doclimit if doclimit less than perPage', function () {
+      store.setPerPage(20);
+      store.setDocumentLimit(1);
+      assert.equal(store._docLimit, 1);
+    });
 
-      it('sets document if exists', function () {
-        store.setDocumentLimit(10);
-        assert.equal(store._docLimit, 10);
-      });
+    it('sets doclimit to 10000 if NaN', function () {
+      store.setDocumentLimit(NaN);
+      assert.equal(store._docLimit, 10000);
+    });
+  });
 
-      it('sets perPage to doclimit if doclimit less than perPage', function () {
-        store.setPerPage(20);
-        store.setDocumentLimit(1);
-        assert.equal(store._docLimit, 1);
+  describe('#setPerPage', function () {
+    beforeEach(function () {
+      store.reset();
+      store._collection = new Documents.AllDocs(null, {
+        params: {},
+        database: {
+          safeID: function () { return '1';}
+        }
       });
 
-      it('sets doclimit to 10000 if NaN', function () {
-        store.setDocumentLimit(NaN);
-        assert.equal(store._docLimit, 10000);
-      });
     });
 
-    describe('#setPerPage', function () {
-      beforeEach(function () {
-        store.reset();
-        store._collection = new Documents.AllDocs(null, {
-          params: {},
-          database: {
-            safeID: function () { return '1';}
-          }
-        });
-
-      });
-
-      it('stores per page in local storage', function () {
-        var testPerPage = 111;
-        store.setPerPage(testPerPage);
-        var perPage = window.localStorage.getItem('fauxton:perpage');
-        assert.equal(perPage, testPerPage );
-      });
+    it('stores per page in local storage', function () {
+      var testPerPage = 111;
+      store.setPerPage(testPerPage);
+      var perPage = window.localStorage.getItem('fauxton:perpage');
+      assert.equal(perPage, testPerPage );
+    });
 
-      it('sets collections perPage', function () {
-        var spy = sinon.spy(store._collection, 'pageSizeReset');
-        var testPerPage = 110;
+    it('sets collections perPage', function () {
+      var spy = sinon.spy(store._collection, 'pageSizeReset');
+      var testPerPage = 110;
 
-        store.setPerPage(testPerPage);
-        assert.equal(spy.getCall(0).args[0], testPerPage);
+      store.setPerPage(testPerPage);
+      assert.equal(spy.getCall(0).args[0], testPerPage);
 
 
-      });
     });
   });
 });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/jumptodoc.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/documents/jumptodoc.react.jsx b/app/addons/documents/jumptodoc.react.jsx
index 3b27b59..64b2691 100644
--- a/app/addons/documents/jumptodoc.react.jsx
+++ b/app/addons/documents/jumptodoc.react.jsx
@@ -10,48 +10,45 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../app',
-  '../../core/api',
-  'react',
-  'react-dom',
-  'react-select',
-  'lodash'
-], (app, FauxtonAPI, React, ReactDOM, ReactSelect, {debounce}) => {
+import app from "../../app";
+import FauxtonAPI from "../../core/api";
+import React from "react";
+import ReactDOM from "react-dom";
+import ReactSelect from "react-select";
+import "lodash";
 
-  const JumpToDoc = ({database, allDocs}) => {
-    const options = allDocs.map(doc => {
-      return {
-        value: doc.get('_id'),
-        label: doc.get('_id')
-      };
-    });
-    return (
-      <div id="jump-to-doc" class="input-append">
-        <ReactSelect
-          name="jump-to-doc"
-          placeholder="Document ID"
-          className="input-large jump-to-doc"
-          options={options}
-          clearable={false}
-          onChange={({value: docId}) => {
-            const url = FauxtonAPI.urls('document', 'app', app.utils.safeURLName(database.id), app.utils.safeURLName(docId) );
-            FauxtonAPI.navigate(url, {trigger: true});
-          }}
-        />
-      </div>
-    );
-  };
+const JumpToDoc = ({database, allDocs}) => {
+  const options = allDocs.map(doc => {
+    return {
+      value: doc.get('_id'),
+      label: doc.get('_id')
+    };
+  });
+  return (
+    <div id="jump-to-doc" class="input-append">
+      <ReactSelect
+        name="jump-to-doc"
+        placeholder="Document ID"
+        className="input-large jump-to-doc"
+        options={options}
+        clearable={false}
+        onChange={({value: docId}) => {
+          const url = FauxtonAPI.urls('document', 'app', app.utils.safeURLName(database.id), app.utils.safeURLName(docId) );
+          FauxtonAPI.navigate(url, {trigger: true});
+        }}
+      />
+    </div>
+  );
+};
 
-  JumpToDoc.propTypes = {
-    database: React.PropTypes.object.isRequired,
-    allDocs: React.PropTypes.object.isRequired,
-  };
+JumpToDoc.propTypes = {
+  database: React.PropTypes.object.isRequired,
+  allDocs: React.PropTypes.object.isRequired,
+};
 
-  return {
-    JumpToDoc,
-    render: (el, database, allDocs) => {
-      ReactDOM.render(<JumpToDoc database={database} allDocs={allDocs} />, $(el)[0]);
-    }
-  };
-});
+export default {
+  JumpToDoc,
+  render: (el, database, allDocs) => {
+    ReactDOM.render(<JumpToDoc database={database} allDocs={allDocs} />, $(el)[0]);
+  }
+};

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/mango/mango.actions.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/mango/mango.actions.js b/app/addons/documents/mango/mango.actions.js
index 56c5726..28cfd87 100644
--- a/app/addons/documents/mango/mango.actions.js
+++ b/app/addons/documents/mango/mango.actions.js
@@ -10,115 +10,111 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../app',
-  '../../../core/api',
-  '../resources',
-  './mango.actiontypes',
-  './mango.stores',
-  '../index-results/stores',
-  '../index-results/actions',
-],
-function (app, FauxtonAPI, Documents, ActionTypes, Stores, IndexResultsStores, IndexResultActions) {
-  var store = Stores.mangoStore;
-
-  return {
-
-    setDatabase: function (options) {
-      FauxtonAPI.dispatch({
-        type: ActionTypes.MANGO_SET_DB,
-        options: options
-      });
-    },
-
-    newQueryFindCode: function (options) {
-      FauxtonAPI.dispatch({
-        type: ActionTypes.MANGO_NEW_QUERY_FIND_CODE,
-        options: options
-      });
-    },
-
-    newQueryCreateIndexCode: function (options) {
-      FauxtonAPI.dispatch({
-        type: ActionTypes.MANGO_NEW_QUERY_CREATE_INDEX_CODE,
-        options: options
-      });
-    },
-
-    saveQuery: function (options) {
-      var queryCode = JSON.parse(options.queryCode),
-          mangoIndex = new Documents.MangoIndex(queryCode, {database: options.database});
-
-      FauxtonAPI.addNotification({
-        msg:  'Saving Index for Query...',
-        type: 'info',
-        clear: true
-      });
-
-      mangoIndex
-        .save()
-        .then(function (res) {
-          var url = '#' + FauxtonAPI.urls('mango', 'query-app', options.database.safeID());
-
-          FauxtonAPI.dispatch({
-            type: ActionTypes.MANGO_NEW_QUERY_FIND_CODE_FROM_FIELDS,
-            options: {
-              fields: queryCode.index.fields
-            }
-          });
-
-          var mangoIndexCollection = new Documents.MangoIndexCollection(null, {
-            database: options.database,
-            params: null,
-            paging: {
-              pageSize: IndexResultsStores.indexResultsStore.getPerPage()
-            }
-          });
+import app from "../../../app";
+import FauxtonAPI from "../../../core/api";
+import Documents from "../resources";
+import ActionTypes from "./mango.actiontypes";
+import Stores from "./mango.stores";
+import IndexResultsStores from "../index-results/stores";
+import IndexResultActions from "../index-results/actions";
+var store = Stores.mangoStore;
+
+export default {
+
+  setDatabase: function (options) {
+    FauxtonAPI.dispatch({
+      type: ActionTypes.MANGO_SET_DB,
+      options: options
+    });
+  },
+
+  newQueryFindCode: function (options) {
+    FauxtonAPI.dispatch({
+      type: ActionTypes.MANGO_NEW_QUERY_FIND_CODE,
+      options: options
+    });
+  },
+
+  newQueryCreateIndexCode: function (options) {
+    FauxtonAPI.dispatch({
+      type: ActionTypes.MANGO_NEW_QUERY_CREATE_INDEX_CODE,
+      options: options
+    });
+  },
+
+  saveQuery: function (options) {
+    var queryCode = JSON.parse(options.queryCode),
+        mangoIndex = new Documents.MangoIndex(queryCode, {database: options.database});
+
+    FauxtonAPI.addNotification({
+      msg:  'Saving Index for Query...',
+      type: 'info',
+      clear: true
+    });
+
+    mangoIndex
+      .save()
+      .then(function (res) {
+        var url = '#' + FauxtonAPI.urls('mango', 'query-app', options.database.safeID());
+
+        FauxtonAPI.dispatch({
+          type: ActionTypes.MANGO_NEW_QUERY_FIND_CODE_FROM_FIELDS,
+          options: {
+            fields: queryCode.index.fields
+          }
+        });
 
-          this.getIndexList({indexList: mangoIndexCollection}).then(function () {
+        var mangoIndexCollection = new Documents.MangoIndexCollection(null, {
+          database: options.database,
+          params: null,
+          paging: {
+            pageSize: IndexResultsStores.indexResultsStore.getPerPage()
+          }
+        });
 
-            IndexResultActions.reloadResultsList();
+        this.getIndexList({indexList: mangoIndexCollection}).then(function () {
 
-            FauxtonAPI.addNotification({
-              msg: 'Index is ready for querying. <a href="' + url + '">Run a Query.</a>',
-              type: 'success',
-              clear: true,
-              escape: false
-            });
-          }.bind(this));
+          IndexResultActions.reloadResultsList();
 
-        }.bind(this))
-        .fail(function (res) {
           FauxtonAPI.addNotification({
-            msg: res.responseJSON.reason,
-            type: 'error',
-            clear: true
+            msg: 'Index is ready for querying. <a href="' + url + '">Run a Query.</a>',
+            type: 'success',
+            clear: true,
+            escape: false
           });
-        });
-    },
+        }.bind(this));
 
-    mangoResetIndexList: function (options) {
-      FauxtonAPI.dispatch({
-        type: ActionTypes.MANGO_RESET,
-        options: options
-      });
-    },
-
-    getIndexList: function (options) {
-      FauxtonAPI.dispatch({
-        type: ActionTypes.MANGO_NEW_AVAILABLE_INDEXES,
-        options: options
-      });
-
-      return options.indexList.fetch({reset: true}).then(function () {
-        this.mangoResetIndexList({isLoading: false});
-      }.bind(this), function () {
+      }.bind(this))
+      .fail(function (res) {
         FauxtonAPI.addNotification({
-          msg: 'Bad request!',
-          type: "error",
-          clear:  true
-       });
+          msg: res.responseJSON.reason,
+          type: 'error',
+          clear: true
+        });
       });
-    }
-  };
-});
+  },
+
+  mangoResetIndexList: function (options) {
+    FauxtonAPI.dispatch({
+      type: ActionTypes.MANGO_RESET,
+      options: options
+    });
+  },
+
+  getIndexList: function (options) {
+    FauxtonAPI.dispatch({
+      type: ActionTypes.MANGO_NEW_AVAILABLE_INDEXES,
+      options: options
+    });
+
+    return options.indexList.fetch({reset: true}).then(function () {
+      this.mangoResetIndexList({isLoading: false});
+    }.bind(this), function () {
+      FauxtonAPI.addNotification({
+        msg: 'Bad request!',
+        type: "error",
+        clear:  true
+     });
+    });
+  }
+};

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/mango/mango.actiontypes.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/mango/mango.actiontypes.js b/app/addons/documents/mango/mango.actiontypes.js
index b6bdbcc..2e3014d 100644
--- a/app/addons/documents/mango/mango.actiontypes.js
+++ b/app/addons/documents/mango/mango.actiontypes.js
@@ -10,13 +10,11 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([], function () {
-  return {
-    MANGO_SET_DB: 'MANGO_SET_DB',
-    MANGO_NEW_QUERY_FIND_CODE_FROM_FIELDS: 'MANGO_NEW_QUERY_FIND_CODE_FROM_FIELDS',
-    MANGO_NEW_QUERY_FIND_CODE: 'MANGO_NEW_QUERY_FIND_CODE',
-    MANGO_NEW_QUERY_CREATE_INDEX_CODE: 'MANGO_NEW_QUERY_CREATE_INDEX_CODE',
-    MANGO_NEW_AVAILABLE_INDEXES: 'MANGO_NEW_AVAILABLE_INDEXES',
-    MANGO_RESET: 'MANGO_RESET'
-  };
-});
+export default {
+  MANGO_SET_DB: 'MANGO_SET_DB',
+  MANGO_NEW_QUERY_FIND_CODE_FROM_FIELDS: 'MANGO_NEW_QUERY_FIND_CODE_FROM_FIELDS',
+  MANGO_NEW_QUERY_FIND_CODE: 'MANGO_NEW_QUERY_FIND_CODE',
+  MANGO_NEW_QUERY_CREATE_INDEX_CODE: 'MANGO_NEW_QUERY_CREATE_INDEX_CODE',
+  MANGO_NEW_AVAILABLE_INDEXES: 'MANGO_NEW_AVAILABLE_INDEXES',
+  MANGO_RESET: 'MANGO_RESET'
+};

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/mango/mango.components.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/documents/mango/mango.components.react.jsx b/app/addons/documents/mango/mango.components.react.jsx
index e88a05b..113a7f9 100644
--- a/app/addons/documents/mango/mango.components.react.jsx
+++ b/app/addons/documents/mango/mango.components.react.jsx
@@ -10,283 +10,276 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../app',
-  '../../../core/api',
-  'react',
-  './mango.stores',
-  './mango.actions',
-  '../../components/react-components.react',
-  '../index-results/actions',
-  './mango.helper',
-
-  '../../../../assets/js/plugins/prettify'
-],
-
-function (app, FauxtonAPI, React, Stores, Actions,
-          ReactComponents, IndexResultActions, MangoHelper) {
-
-  var mangoStore = Stores.mangoStore;
-  var getDocUrl = app.helpers.getDocUrl;
-
-  var PaddedBorderedBox = ReactComponents.PaddedBorderedBox;
-  var CodeEditorPanel = ReactComponents.CodeEditorPanel;
-  var ConfirmButton = ReactComponents.ConfirmButton;
-
-  var MangoQueryEditorController = React.createClass({
-    getInitialState: function () {
-      return this.getStoreState();
-    },
-
-    getStoreState: function () {
-      return {
-        queryCode: mangoStore.getQueryFindCode(),
-        database: mangoStore.getDatabase(),
-        changedQuery: mangoStore.getQueryFindCodeChanged(),
-        availableIndexes: mangoStore.getAvailableQueryIndexes(),
-        additionalIndexes: mangoStore.getAvailableAdditionalIndexes(),
-        isLoading: mangoStore.getLoadingIndexes()
-      };
-    },
-
-    onChange: function () {
-      this.setState(this.getStoreState());
-    },
-
-    componentDidUpdate: function () {
-      prettyPrint();
-    },
-
-    componentDidMount: function () {
-      prettyPrint();
-      mangoStore.on('change', this.onChange, this);
-    },
-
-    componentWillUnmount: function () {
-      mangoStore.off('change', this.onChange);
-    },
-
-    getMangoEditor: function () {
-      return this.refs.mangoEditor;
-    },
-
-    render: function () {
-      var loadLines;
-      if (this.state.isLoading) {
-        return (
-          <div className="mango-editor-wrapper">
-            <ReactComponents.LoadLines />
-          </div>
-        );
-      }
-
+import app from "../../../app";
+import FauxtonAPI from "../../../core/api";
+import React from "react";
+import Stores from "./mango.stores";
+import Actions from "./mango.actions";
+import ReactComponents from "../../components/react-components.react";
+import IndexResultActions from "../index-results/actions";
+import MangoHelper from "./mango.helper";
+import "../../../../assets/js/plugins/prettify";
+
+var mangoStore = Stores.mangoStore;
+var getDocUrl = app.helpers.getDocUrl;
+
+var PaddedBorderedBox = ReactComponents.PaddedBorderedBox;
+var CodeEditorPanel = ReactComponents.CodeEditorPanel;
+var ConfirmButton = ReactComponents.ConfirmButton;
+
+var MangoQueryEditorController = React.createClass({
+  getInitialState: function () {
+    return this.getStoreState();
+  },
+
+  getStoreState: function () {
+    return {
+      queryCode: mangoStore.getQueryFindCode(),
+      database: mangoStore.getDatabase(),
+      changedQuery: mangoStore.getQueryFindCodeChanged(),
+      availableIndexes: mangoStore.getAvailableQueryIndexes(),
+      additionalIndexes: mangoStore.getAvailableAdditionalIndexes(),
+      isLoading: mangoStore.getLoadingIndexes()
+    };
+  },
+
+  onChange: function () {
+    this.setState(this.getStoreState());
+  },
+
+  componentDidUpdate: function () {
+    prettyPrint();
+  },
+
+  componentDidMount: function () {
+    prettyPrint();
+    mangoStore.on('change', this.onChange, this);
+  },
+
+  componentWillUnmount: function () {
+    mangoStore.off('change', this.onChange);
+  },
+
+  getMangoEditor: function () {
+    return this.refs.mangoEditor;
+  },
+
+  render: function () {
+    var loadLines;
+    if (this.state.isLoading) {
       return (
-        <MangoEditor
-          ref="mangoEditor"
-          description={this.props.description}
-          dbName={this.state.database.id}
-          onSubmit={this.runQuery}
-          title={this.props.editorTitle}
-          additionalIndexesText={this.props.additionalIndexesText}
-          docs={getDocUrl('MANGO_SEARCH')}
-          exampleCode={this.state.queryCode}
-          changedQuery={this.state.changedQuery}
-          availableIndexes={this.state.availableIndexes}
-          additionalIndexes={this.state.additionalIndexes}
-          confirmbuttonText="Run Query" />
+        <div className="mango-editor-wrapper">
+          <ReactComponents.LoadLines />
+        </div>
       );
-    },
-
-    runQuery: function (event) {
-      event.preventDefault();
-
-      if (this.getMangoEditor().hasErrors()) {
-        FauxtonAPI.addNotification({
-          msg:  'Please fix the Javascript errors and try again.',
-          type: 'error',
-          clear: true
-        });
-        return;
-      }
-
-      IndexResultActions.runMangoFindQuery({
-        database: this.state.database,
-        queryCode: this.getMangoEditor().getEditorValue(),
+    }
 
+    return (
+      <MangoEditor
+        ref="mangoEditor"
+        description={this.props.description}
+        dbName={this.state.database.id}
+        onSubmit={this.runQuery}
+        title={this.props.editorTitle}
+        additionalIndexesText={this.props.additionalIndexesText}
+        docs={getDocUrl('MANGO_SEARCH')}
+        exampleCode={this.state.queryCode}
+        changedQuery={this.state.changedQuery}
+        availableIndexes={this.state.availableIndexes}
+        additionalIndexes={this.state.additionalIndexes}
+        confirmbuttonText="Run Query" />
+    );
+  },
+
+  runQuery: function (event) {
+    event.preventDefault();
+
+    if (this.getMangoEditor().hasErrors()) {
+      FauxtonAPI.addNotification({
+        msg:  'Please fix the Javascript errors and try again.',
+        type: 'error',
+        clear: true
       });
+      return;
     }
-  });
-
-  var MangoEditor = React.createClass({
-    getDefaultProps: function () {
-      return {
-        changedQuery: null,
-        availableIndexes: null,
-        additionalIndexes: null
-      };
-    },
-
-    render: function () {
-      var url = '#/' + FauxtonAPI.urls('allDocs', 'app', this.props.dbName, '');
 
-      return (
-        <div className="mango-editor-wrapper">
-          <PaddedBorderedBox>
-            <div
-              dangerouslySetInnerHTML={{__html: this.props.description}}
-              className="editor-description">
-            </div>
-          </PaddedBorderedBox>
-          <PaddedBorderedBox>
-            <strong>Database</strong>
-            <div className="db-title">
-              <a href={url}>{this.props.dbName}</a>
-            </div>
-          </PaddedBorderedBox>
-          <form className="form-horizontal" onSubmit={this.props.onSubmit}>
-            <PaddedBorderedBox>
-              <CodeEditorPanel
-                id="query-field"
-                ref="field"
-                title={this.props.title}
-                docLink={this.props.docs}
-                defaultCode={this.props.exampleCode} />
-              {this.getChangedQueryText()}
-            </PaddedBorderedBox>
-            {this.getIndexBox()}
-            <div className="padded-box">
-              <div className="control-group">
-                <ConfirmButton text={this.props.confirmbuttonText} id="create-index-btn" showIcon={false} />
-              </div>
-            </div>
-          </form>
-        </div>
-      );
-    },
+    IndexResultActions.runMangoFindQuery({
+      database: this.state.database,
+      queryCode: this.getMangoEditor().getEditorValue(),
 
-    getChangedQueryText: function () {
-      if (!this.props.changedQuery) {
-        return null;
-      }
+    });
+  }
+});
 
-      return (
-        <div className="info-changed-query">
-          <strong>Info:</strong>
-          <div>We changed the default query based on the last Index you created.</div>
-        </div>
-      );
-    },
+var MangoEditor = React.createClass({
+  getDefaultProps: function () {
+    return {
+      changedQuery: null,
+      availableIndexes: null,
+      additionalIndexes: null
+    };
+  },
 
-    getIndexBox: function () {
-      if (!this.props.availableIndexes) {
-        return null;
-      }
+  render: function () {
+    var url = '#/' + FauxtonAPI.urls('allDocs', 'app', this.props.dbName, '');
 
-      return (
+    return (
+      <div className="mango-editor-wrapper">
         <PaddedBorderedBox>
-          <strong>Your available Indexes:</strong>
-          <a className="edit-link" href={'#' + FauxtonAPI.urls('mango', 'index-app', this.props.dbName)}>edit</a>
-          <pre
-            className="mango-available-indexes">
-            {this.getIndexes('index', this.props.availableIndexes)}
-            {this.getIndexes('additonal', this.props.additionalIndexes)}
-          </pre>
+          <div
+            dangerouslySetInnerHTML={{__html: this.props.description}}
+            className="editor-description">
+          </div>
         </PaddedBorderedBox>
-      );
-    },
-
-    getIndexes: function (prefix, indexes) {
-      if (!indexes) {
-        return;
-      }
-
-      return indexes.map(function (index, i) {
-        var name = MangoHelper.getIndexName(index);
-
-        return (
-          <div key={prefix + i}>{name}</div>
-        );
-      });
-    },
-
-    getEditorValue: function () {
-      return this.refs.field.getValue();
-    },
-
-    getEditor: function () {
-      return this.refs.field.getEditor();
-    },
+        <PaddedBorderedBox>
+          <strong>Database</strong>
+          <div className="db-title">
+            <a href={url}>{this.props.dbName}</a>
+          </div>
+        </PaddedBorderedBox>
+        <form className="form-horizontal" onSubmit={this.props.onSubmit}>
+          <PaddedBorderedBox>
+            <CodeEditorPanel
+              id="query-field"
+              ref="field"
+              title={this.props.title}
+              docLink={this.props.docs}
+              defaultCode={this.props.exampleCode} />
+            {this.getChangedQueryText()}
+          </PaddedBorderedBox>
+          {this.getIndexBox()}
+          <div className="padded-box">
+            <div className="control-group">
+              <ConfirmButton text={this.props.confirmbuttonText} id="create-index-btn" showIcon={false} />
+            </div>
+          </div>
+        </form>
+      </div>
+    );
+  },
+
+  getChangedQueryText: function () {
+    if (!this.props.changedQuery) {
+      return null;
+    }
 
-    hasErrors: function () {
-      return this.getEditor().hasErrors();
+    return (
+      <div className="info-changed-query">
+        <strong>Info:</strong>
+        <div>We changed the default query based on the last Index you created.</div>
+      </div>
+    );
+  },
+
+  getIndexBox: function () {
+    if (!this.props.availableIndexes) {
+      return null;
     }
-  });
 
-  var MangoIndexEditorController = React.createClass({
-    getInitialState: function () {
-      return this.getStoreState();
-    },
+    return (
+      <PaddedBorderedBox>
+        <strong>Your available Indexes:</strong>
+        <a className="edit-link" href={'#' + FauxtonAPI.urls('mango', 'index-app', this.props.dbName)}>edit</a>
+        <pre
+          className="mango-available-indexes">
+          {this.getIndexes('index', this.props.availableIndexes)}
+          {this.getIndexes('additonal', this.props.additionalIndexes)}
+        </pre>
+      </PaddedBorderedBox>
+    );
+  },
+
+  getIndexes: function (prefix, indexes) {
+    if (!indexes) {
+      return;
+    }
 
-    getStoreState: function () {
-      return {
-        queryIndexCode: mangoStore.getQueryIndexCode(),
-        database: mangoStore.getDatabase(),
-      };
-    },
+    return indexes.map(function (index, i) {
+      var name = MangoHelper.getIndexName(index);
 
-    onChange: function () {
-      this.setState(this.getStoreState());
-    },
+      return (
+        <div key={prefix + i}>{name}</div>
+      );
+    });
+  },
 
-    componentDidMount: function () {
-      mangoStore.on('change', this.onChange, this);
-    },
+  getEditorValue: function () {
+    return this.refs.field.getValue();
+  },
 
-    componentWillUnmount: function () {
-      mangoStore.off('change', this.onChange);
-    },
+  getEditor: function () {
+    return this.refs.field.getEditor();
+  },
 
-    getMangoEditor: function () {
-      return this.refs.mangoEditor;
-    },
+  hasErrors: function () {
+    return this.getEditor().hasErrors();
+  }
+});
 
-    render: function () {
-      return (
-        <MangoEditor
-          ref="mangoEditor"
-          description={this.props.description}
-          dbName={this.state.database.id}
-          onSubmit={this.saveQuery}
-          title="Index"
-          docs={getDocUrl('MANGO_INDEX')}
-          exampleCode={this.state.queryIndexCode}
-          confirmbuttonText="Create Index" />
-      );
-    },
-
-    saveQuery: function (event) {
-      event.preventDefault();
-
-      if (this.getMangoEditor().hasErrors()) {
-        FauxtonAPI.addNotification({
-          msg:  'Please fix the Javascript errors and try again.',
-          type: 'error',
-          clear: true
-        });
-        return;
-      }
-
-      Actions.saveQuery({
-        database: this.state.database,
-        queryCode: this.getMangoEditor().getEditorValue()
+var MangoIndexEditorController = React.createClass({
+  getInitialState: function () {
+    return this.getStoreState();
+  },
+
+  getStoreState: function () {
+    return {
+      queryIndexCode: mangoStore.getQueryIndexCode(),
+      database: mangoStore.getDatabase(),
+    };
+  },
+
+  onChange: function () {
+    this.setState(this.getStoreState());
+  },
+
+  componentDidMount: function () {
+    mangoStore.on('change', this.onChange, this);
+  },
+
+  componentWillUnmount: function () {
+    mangoStore.off('change', this.onChange);
+  },
+
+  getMangoEditor: function () {
+    return this.refs.mangoEditor;
+  },
+
+  render: function () {
+    return (
+      <MangoEditor
+        ref="mangoEditor"
+        description={this.props.description}
+        dbName={this.state.database.id}
+        onSubmit={this.saveQuery}
+        title="Index"
+        docs={getDocUrl('MANGO_INDEX')}
+        exampleCode={this.state.queryIndexCode}
+        confirmbuttonText="Create Index" />
+    );
+  },
+
+  saveQuery: function (event) {
+    event.preventDefault();
+
+    if (this.getMangoEditor().hasErrors()) {
+      FauxtonAPI.addNotification({
+        msg:  'Please fix the Javascript errors and try again.',
+        type: 'error',
+        clear: true
       });
+      return;
     }
-  });
 
-  var Views = {
-    MangoIndexEditorController: MangoIndexEditorController,
-    MangoQueryEditorController: MangoQueryEditorController
-  };
-
-  return Views;
+    Actions.saveQuery({
+      database: this.state.database,
+      queryCode: this.getMangoEditor().getEditorValue()
+    });
+  }
 });
+
+var Views = {
+  MangoIndexEditorController: MangoIndexEditorController,
+  MangoQueryEditorController: MangoQueryEditorController
+};
+
+export default Views;

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/mango/mango.helper.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/mango/mango.helper.js b/app/addons/documents/mango/mango.helper.js
index 5ed0807..4634adb 100644
--- a/app/addons/documents/mango/mango.helper.js
+++ b/app/addons/documents/mango/mango.helper.js
@@ -10,34 +10,30 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../core/api'
-], function (FauxtonAPI) {
+import FauxtonAPI from "../../../core/api";
 
-  function getIndexName (doc) {
-    var nameArray = [],
-        indexes;
+function getIndexName (doc) {
+  var nameArray = [],
+      indexes;
 
-    nameArray = doc.get('def').fields.reduce(function (acc, el, i) {
-      if (i === 0) {
-        acc.push(doc.get('type') + ': ' + Object.keys(el)[0]);
-      } else {
-        acc.push(Object.keys(el)[0]);
-      }
-
-      return acc;
-    }, []);
-
-    if (!nameArray.length) {
-      indexes = FauxtonAPI.getExtensions('mango:additionalIndexes')[0];
-      nameArray = indexes.createHeader(doc);
+  nameArray = doc.get('def').fields.reduce(function (acc, el, i) {
+    if (i === 0) {
+      acc.push(doc.get('type') + ': ' + Object.keys(el)[0]);
+    } else {
+      acc.push(Object.keys(el)[0]);
     }
 
-    return nameArray.join(', ');
+    return acc;
+  }, []);
+
+  if (!nameArray.length) {
+    indexes = FauxtonAPI.getExtensions('mango:additionalIndexes')[0];
+    nameArray = indexes.createHeader(doc);
   }
 
-  return {
-    getIndexName: getIndexName
-  };
+  return nameArray.join(', ');
+}
 
-});
+export default {
+  getIndexName: getIndexName
+};

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/mango/mango.stores.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/mango/mango.stores.js b/app/addons/documents/mango/mango.stores.js
index 42c4966..7836798 100644
--- a/app/addons/documents/mango/mango.stores.js
+++ b/app/addons/documents/mango/mango.stores.js
@@ -10,157 +10,151 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../core/api',
-  './mango.actiontypes'
-],
+import FauxtonAPI from "../../../core/api";
+import ActionTypes from "./mango.actiontypes";
+
+
+var defaultQueryIndexCode = {
+  "index": {
+    "fields": ["_id"]
+  },
+  "type" : "json"
+};
+
+var defaultQueryFindCode = {
+  "selector": {
+    "_id": {"$gt": null}
+  }
+};
+
+var Stores = {};
+
+Stores.MangoStore = FauxtonAPI.Store.extend({
+
+  initialize: function () {
+    this._queryFindCode = defaultQueryFindCode;
+    this._queryIndexCode = defaultQueryIndexCode;
+    this._queryFindCodeChanged = false;
+    this._availableIndexes = [];
+    this._getLoadingIndexes = true;
+  },
+
+  getQueryIndexCode: function () {
+    return this.formatCode(this._queryIndexCode);
+  },
+
+  setQueryIndexCode: function (options) {
+    this._queryIndexCode = options.code;
+  },
+
+  getQueryFindCode: function () {
+    return this.formatCode(this._queryFindCode);
+  },
+
+  setQueryFindCode: function (options) {
+    this._queryFindCode = options.code;
+  },
+
+  getLoadingIndexes: function () {
+    return this._getLoadingIndexes;
+  },
+
+  setLoadingIndexes: function (options) {
+    this._getLoadingIndexes = options.isLoading;
+  },
+
+  formatCode: function (code) {
+    return JSON.stringify(code, null, '  ');
+  },
+
+  newQueryFindCodeFromFields: function (options) {
+    var fields = options.fields,
+        queryCode = JSON.parse(JSON.stringify(this._queryFindCode)),
+        selectorContent;
+
+    if (!fields) {
+      return;
+    }
+
+    selectorContent = fields.reduce(function (acc, field) {
+      acc[field] = {"$gt": null};
+      return acc;
+    }, {});
+
+    queryCode.selector = selectorContent;
+    this._queryFindCode = queryCode;
+    this._queryFindCodeChanged = true;
+  },
+
+  getQueryFindCodeChanged: function () {
+    return this._queryFindCodeChanged;
+  },
+
+  setDatabase: function (options) {
+    this._database = options.database;
+  },
 
-function (FauxtonAPI, ActionTypes) {
+  getDatabase: function () {
+    return this._database;
+  },
 
+  setAvailableIndexes: function (options) {
+    this._availableIndexes = options.indexList;
+  },
 
-  var defaultQueryIndexCode = {
-    "index": {
-      "fields": ["_id"]
-    },
-    "type" : "json"
-  };
+  getAvailableQueryIndexes: function () {
+    return this._availableIndexes.filter(function (el) {
+      return ['json', 'special'].indexOf(el.get('type')) !== -1;
+    });
+  },
 
-  var defaultQueryFindCode = {
-    "selector": {
-      "_id": {"$gt": null}
+  getAvailableAdditionalIndexes: function () {
+    var indexes = FauxtonAPI.getExtensions('mango:additionalIndexes')[0];
+
+    if (!indexes) {
+      return;
     }
-  };
 
-  var Stores = {};
-
-  Stores.MangoStore = FauxtonAPI.Store.extend({
+    return this._availableIndexes.filter(function (el) {
+      return el.get('type').indexOf(indexes.type) !== -1;
+    });
+  },
+
+  dispatch: function (action) {
+    switch (action.type) {
 
-    initialize: function () {
-      this._queryFindCode = defaultQueryFindCode;
-      this._queryIndexCode = defaultQueryIndexCode;
-      this._queryFindCodeChanged = false;
-      this._availableIndexes = [];
-      this._getLoadingIndexes = true;
-    },
+      case ActionTypes.MANGO_SET_DB:
+        this.setDatabase(action.options);
+      break;
 
-    getQueryIndexCode: function () {
-      return this.formatCode(this._queryIndexCode);
-    },
+      case ActionTypes.MANGO_NEW_QUERY_CREATE_INDEX_CODE:
+        this.setQueryIndexCode(action.options);
+      break;
 
-    setQueryIndexCode: function (options) {
-      this._queryIndexCode = options.code;
-    },
-
-    getQueryFindCode: function () {
-      return this.formatCode(this._queryFindCode);
-    },
-
-    setQueryFindCode: function (options) {
-      this._queryFindCode = options.code;
-    },
-
-    getLoadingIndexes: function () {
-      return this._getLoadingIndexes;
-    },
-
-    setLoadingIndexes: function (options) {
-      this._getLoadingIndexes = options.isLoading;
-    },
-
-    formatCode: function (code) {
-      return JSON.stringify(code, null, '  ');
-    },
-
-    newQueryFindCodeFromFields: function (options) {
-      var fields = options.fields,
-          queryCode = JSON.parse(JSON.stringify(this._queryFindCode)),
-          selectorContent;
-
-      if (!fields) {
-        return;
-      }
-
-      selectorContent = fields.reduce(function (acc, field) {
-        acc[field] = {"$gt": null};
-        return acc;
-      }, {});
-
-      queryCode.selector = selectorContent;
-      this._queryFindCode = queryCode;
-      this._queryFindCodeChanged = true;
-    },
-
-    getQueryFindCodeChanged: function () {
-      return this._queryFindCodeChanged;
-    },
-
-    setDatabase: function (options) {
-      this._database = options.database;
-    },
-
-    getDatabase: function () {
-      return this._database;
-    },
-
-    setAvailableIndexes: function (options) {
-      this._availableIndexes = options.indexList;
-    },
-
-    getAvailableQueryIndexes: function () {
-      return this._availableIndexes.filter(function (el) {
-        return ['json', 'special'].indexOf(el.get('type')) !== -1;
-      });
-    },
-
-    getAvailableAdditionalIndexes: function () {
-      var indexes = FauxtonAPI.getExtensions('mango:additionalIndexes')[0];
-
-      if (!indexes) {
-        return;
-      }
-
-      return this._availableIndexes.filter(function (el) {
-        return el.get('type').indexOf(indexes.type) !== -1;
-      });
-    },
-
-    dispatch: function (action) {
-      switch (action.type) {
-
-        case ActionTypes.MANGO_SET_DB:
-          this.setDatabase(action.options);
-        break;
+      case ActionTypes.MANGO_NEW_QUERY_FIND_CODE_FROM_FIELDS:
+        this.newQueryFindCodeFromFields(action.options);
+      break;
 
-        case ActionTypes.MANGO_NEW_QUERY_CREATE_INDEX_CODE:
-          this.setQueryIndexCode(action.options);
-        break;
-
-        case ActionTypes.MANGO_NEW_QUERY_FIND_CODE_FROM_FIELDS:
-          this.newQueryFindCodeFromFields(action.options);
-        break;
-
-        case ActionTypes.MANGO_NEW_QUERY_FIND_CODE:
-          this.setQueryFindCode(action.options);
-        break;
+      case ActionTypes.MANGO_NEW_QUERY_FIND_CODE:
+        this.setQueryFindCode(action.options);
+      break;
 
-        case ActionTypes.MANGO_NEW_AVAILABLE_INDEXES:
-          this.setAvailableIndexes(action.options);
-        break;
+      case ActionTypes.MANGO_NEW_AVAILABLE_INDEXES:
+        this.setAvailableIndexes(action.options);
+      break;
 
-        case ActionTypes.MANGO_RESET:
-          this.setLoadingIndexes(action.options);
-        break;
-      }
-
-      this.triggerChange();
+      case ActionTypes.MANGO_RESET:
+        this.setLoadingIndexes(action.options);
+      break;
     }
 
-  });
+    this.triggerChange();
+  }
 
-  Stores.mangoStore = new Stores.MangoStore();
+});
 
-  Stores.mangoStore.dispatchToken = FauxtonAPI.dispatcher.register(Stores.mangoStore.dispatch);
+Stores.mangoStore = new Stores.MangoStore();
 
-  return Stores;
+Stores.mangoStore.dispatchToken = FauxtonAPI.dispatcher.register(Stores.mangoStore.dispatch);
 
-});
+export default Stores;


Mime
View raw message