You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ro...@apache.org on 2014/09/08 15:24:15 UTC

[1/4] fauxton commit: updated refs/heads/master to bacf6fd

Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master c33249069 -> bacf6fd71


Config: allow creation of new sections

closes COUCHDB-2302


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

Branch: refs/heads/master
Commit: bacf6fd71daaa348030a992f1d56f5f5c5d5a1b0
Parents: 410b055
Author: Robert Kowalski <ro...@kowalski.gd>
Authored: Fri Sep 5 19:46:12 2014 +0200
Committer: Robert Kowalski <ro...@kowalski.gd>
Committed: Mon Sep 8 15:25:41 2014 +0200

----------------------------------------------------------------------
 app/addons/config/resources.js         |  8 +++++++-
 app/addons/config/templates/modal.html |  1 -
 app/addons/config/tests/configSpec.js  | 14 ++++++++++++++
 app/addons/config/views.js             | 26 ++++++++++++++++++--------
 4 files changed, 39 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/bacf6fd7/app/addons/config/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/config/resources.js b/app/addons/config/resources.js
index 28087ed..806615c 100644
--- a/app/addons/config/resources.js
+++ b/app/addons/config/resources.js
@@ -67,7 +67,13 @@ function (app, FauxtonAPI) {
 
     findEntryInSection: function (sectionName, entry) {
       var section = _.findWhere(this.toJSON(), {"section": sectionName}),
-          options = _.findWhere(section.options, {name: entry});
+          options;
+
+      if (!section) {
+        return false;
+      }
+
+      options = _.findWhere(section.options, {name: entry});
 
       return options;
     },

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/bacf6fd7/app/addons/config/templates/modal.html
----------------------------------------------------------------------
diff --git a/app/addons/config/templates/modal.html b/app/addons/config/templates/modal.html
index f32bd10..ca50db9 100644
--- a/app/addons/config/templates/modal.html
+++ b/app/addons/config/templates/modal.html
@@ -21,7 +21,6 @@ the License.
   <form id="js-add-section-form" class="form well">
     <label>Section</label>
     <input type="text" name="section" placeholder="Section" >
-    <span class="help-block">Enter an existing section name to add to it.</span>
     <input type="text" name="name" placeholder="Name">
     <br/>
     <input type="text" name="value" placeholder="Value">

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/bacf6fd7/app/addons/config/tests/configSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/config/tests/configSpec.js b/app/addons/config/tests/configSpec.js
index 67301de..346ab43 100644
--- a/app/addons/config/tests/configSpec.js
+++ b/app/addons/config/tests/configSpec.js
@@ -63,6 +63,16 @@ define([
       modal.$('input[name="name"]').val("testname2");
       assert.notOk(modal.isUniqueEntryInSection(collection));
     });
+
+    it("does not send an error for a new section", function () {
+      modal.$('input[name="section"]').val("newsection");
+      modal.$('input[name="name"]').val("testname");
+      modal.$('input[name="value"]').val("testvalue");
+      var spy = sinon.spy(modal, "errorMessage");
+
+      modal.validate();
+      assert.notOk(spy.called);
+    });
   });
 
   describe("Config: Collection", function () {
@@ -70,6 +80,10 @@ define([
       assert.ok(collection.findEntryInSection("foo1", "testname"));
       assert.notOk(collection.findEntryInSection("foo1", "testname2"));
     });
+
+    it("returns false if findEntryInSection does not have the section", function () {
+      assert.notOk(collection.findEntryInSection("foo-not-exists", "testname"));
+    });
   });
 
   describe("Config: TableRow", function () {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/bacf6fd7/app/addons/config/views.js
----------------------------------------------------------------------
diff --git a/app/addons/config/views.js b/app/addons/config/views.js
index 87b57c9..d6d9518 100644
--- a/app/addons/config/views.js
+++ b/app/addons/config/views.js
@@ -151,23 +151,28 @@ function(app, FauxtonAPI, Config, Components) {
 
   Views.Modal = FauxtonAPI.View.extend({
     className: "modal hide fade",
+
     template:  "addons/config/templates/modal",
+
     events: {
-      "submit #js-add-section-form": "validate"
+      "submit #js-add-section-form": "submitClick"
     },
+
     initialize: function () {
       this.sourceArray = _.map(this.collection.toJSON(), function (item, key) {
         return item.section;
       });
     },
-    afterRender: function(){
+
+    afterRender: function () {
       this.sectionTypeAhead = new Components.Typeahead({
         source: this.sourceArray,
         el: 'input[name="section"]'
       });
       this.sectionTypeAhead.render();
     },
-    submitForm: function (event) {
+
+    submitForm: function () {
       var option = new Config.OptionModel({
         section: this.$('input[name="section"]').val(),
         name: this.$('input[name="name"]').val(),
@@ -193,26 +198,31 @@ function(app, FauxtonAPI, Config, Components) {
       Views.Events.trigger("newSection");
 
     },
+
     isUniqueEntryInSection: function (collection) {
       var sectionName = this.$('input[name="section"]').val(),
           entry = this.$('input[name="name"]').val();
 
       return collection.findEntryInSection(sectionName, entry);
     },
-    isSection: function(){
+
+    isSection: function () {
       var section = this.$('input[name="section"]').val();
       return _.find(this.sourceArray, function(item){ return item === section; });
     },
-    validate: function (event){
+
+    submitClick: function (event) {
       event.preventDefault();
+      this.validate();
+    },
+
+    validate: function () {
       var section = this.$('input[name="section"]').val(),
           name = this.$('input[name="name"]').val(),
           value = this.$('input[name="value"]').val(),
           collection = this.collection;
 
-      if(!this.isSection()){
-         this.errorMessage("You need to use an existing section");
-      } else if (!name) {
+      if (!name) {
         this.errorMessage("Add a name");
       } else if (!value) {
         this.errorMessage("Add a value");


[4/4] fauxton commit: updated refs/heads/master to bacf6fd

Posted by ro...@apache.org.
Config: Set Modal under tests


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

Branch: refs/heads/master
Commit: 07173963337bcd1a2dc70cb93f523cde88ae3dc2
Parents: c332490
Author: Robert Kowalski <ro...@kowalski.gd>
Authored: Fri Sep 5 18:48:58 2014 +0200
Committer: Robert Kowalski <ro...@kowalski.gd>
Committed: Mon Sep 8 15:25:41 2014 +0200

----------------------------------------------------------------------
 app/addons/config/tests/configSpec.js | 44 ++++++++++++++++++++++++++++++
 app/addons/config/views.js            | 10 +++----
 2 files changed, 49 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/07173963/app/addons/config/tests/configSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/config/tests/configSpec.js b/app/addons/config/tests/configSpec.js
index 8699e36..a2b9ee8 100644
--- a/app/addons/config/tests/configSpec.js
+++ b/app/addons/config/tests/configSpec.js
@@ -18,6 +18,50 @@ define([
   var assert = testUtils.assert,
       ViewSandbox = testUtils.ViewSandbox;
 
+  describe("Config: Modal", function () {
+    var optionModels = [],
+        viewSandbox,
+        modal,
+        collection;
+
+    beforeEach(function (done) {
+      _.each([1, 2, 3], function (i) {
+        optionModels
+          .push(new Resources.OptionModel({
+            section: "foo" + i,
+            name: "bar" + i,
+            options: [{
+              name: "testname"
+            }]
+          }));
+      });
+
+      collection = new Resources.Collection(optionModels);
+
+      modal = new Views.Modal({
+        collection: collection
+      });
+
+      viewSandbox = new ViewSandbox();
+      viewSandbox.renderView(modal, done);
+    });
+
+    afterEach(function () {
+      viewSandbox.remove();
+    });
+
+    it("looks if entries are new", function () {
+      modal.$('input[name="section"]').val("foo1");
+      modal.$('input[name="name"]').val("testname");
+      assert.ok(modal.isNew(collection));
+
+      modal.$('input[name="name"]').val("testname2");
+      assert.notOk(modal.isNew(collection));
+    });
+
+  });
+
+
   describe("Config: TableRow", function () {
     var tabMenu, optionModel;
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/07173963/app/addons/config/views.js
----------------------------------------------------------------------
diff --git a/app/addons/config/views.js b/app/addons/config/views.js
index 7952182..1725157 100644
--- a/app/addons/config/views.js
+++ b/app/addons/config/views.js
@@ -46,7 +46,7 @@ function(app, FauxtonAPI, Config, Components) {
 
     uniqueName: function(name){
       var section = _.findWhere(this.collection.toJSON(), {"section":this.model.get("section")});
-      
+
       return _.findWhere(section.options, {name: name});
     },
 
@@ -157,9 +157,9 @@ function(app, FauxtonAPI, Config, Components) {
     events: {
       "submit #js-add-section-form": "validate"
     },
-    initialize: function(){
-      this.sourceArray = _.map(this.collection.toJSON(), function(item, key){ 
-        return item.section; 
+    initialize: function () {
+      this.sourceArray = _.map(this.collection.toJSON(), function (item, key) {
+        return item.section;
       });
     },
     afterRender: function(){
@@ -200,7 +200,7 @@ function(app, FauxtonAPI, Config, Components) {
           name = this.$('input[name="name"]').val();
           var section = _.findWhere(collection.toJSON(), {"section":sectionName});
           var options = _.findWhere(section.options, {name: name});
-          
+
           return options;
     },
     isSection: function(){


[2/4] fauxton commit: updated refs/heads/master to bacf6fd

Posted by ro...@apache.org.
Config: refactor: move method to collection


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

Branch: refs/heads/master
Commit: 0ad739cf9bf894ea12da39ea424b7fbc705fdc08
Parents: 0717396
Author: Robert Kowalski <ro...@kowalski.gd>
Authored: Fri Sep 5 19:03:09 2014 +0200
Committer: Robert Kowalski <ro...@kowalski.gd>
Committed: Mon Sep 8 15:25:41 2014 +0200

----------------------------------------------------------------------
 app/addons/config/resources.js        | 10 ++++++
 app/addons/config/tests/configSpec.js | 50 ++++++++++++++++++------------
 app/addons/config/views.js            | 26 +++++++---------
 3 files changed, 51 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ad739cf/app/addons/config/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/config/resources.js b/app/addons/config/resources.js
index bbd0d2a..28087ed 100644
--- a/app/addons/config/resources.js
+++ b/app/addons/config/resources.js
@@ -52,16 +52,26 @@ function (app, FauxtonAPI) {
 
   Config.Collection = Backbone.Collection.extend({
     model: Config.Model,
+
     documentation: "config",
+
     comparator: function (OptionModel) {
       if (OptionModel.get("section")) {
         return OptionModel.get("section");
       }
     },
+
     url: function () {
       return app.host + '/_config';
     },
 
+    findEntryInSection: function (sectionName, entry) {
+      var section = _.findWhere(this.toJSON(), {"section": sectionName}),
+          options = _.findWhere(section.options, {name: entry});
+
+      return options;
+    },
+
     parse: function (resp) {
       return _.map(resp, function (section, section_name) {
         return {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ad739cf/app/addons/config/tests/configSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/config/tests/configSpec.js b/app/addons/config/tests/configSpec.js
index a2b9ee8..67301de 100644
--- a/app/addons/config/tests/configSpec.js
+++ b/app/addons/config/tests/configSpec.js
@@ -16,28 +16,33 @@ define([
       'testUtils'
 ], function (FauxtonAPI, Resources, Views, testUtils) {
   var assert = testUtils.assert,
-      ViewSandbox = testUtils.ViewSandbox;
+      ViewSandbox = testUtils.ViewSandbox,
+      collection;
 
-  describe("Config: Modal", function () {
-    var optionModels = [],
-        viewSandbox,
-        modal,
-        collection;
 
-    beforeEach(function (done) {
-      _.each([1, 2, 3], function (i) {
-        optionModels
-          .push(new Resources.OptionModel({
-            section: "foo" + i,
-            name: "bar" + i,
-            options: [{
-              name: "testname"
-            }]
-          }));
+  beforeEach(function () {
+    var optionModels = [];
+
+    _.each([1, 2, 3], function (i) {
+      var model = new Resources.OptionModel({
+        section: "foo" + i,
+        name: "bar" + i,
+        options: [{
+          name: "testname"
+        }]
       });
 
-      collection = new Resources.Collection(optionModels);
+      optionModels.push(model);
+    });
 
+    collection = new Resources.Collection(optionModels);
+  });
+
+  describe("Config: Modal", function () {
+    var viewSandbox,
+        modal;
+
+    beforeEach(function (done) {
       modal = new Views.Modal({
         collection: collection
       });
@@ -53,14 +58,19 @@ define([
     it("looks if entries are new", function () {
       modal.$('input[name="section"]').val("foo1");
       modal.$('input[name="name"]').val("testname");
-      assert.ok(modal.isNew(collection));
+      assert.ok(modal.isUniqueEntryInSection(collection));
 
       modal.$('input[name="name"]').val("testname2");
-      assert.notOk(modal.isNew(collection));
+      assert.notOk(modal.isUniqueEntryInSection(collection));
     });
-
   });
 
+  describe("Config: Collection", function () {
+    it("looks if entries are new", function () {
+      assert.ok(collection.findEntryInSection("foo1", "testname"));
+      assert.notOk(collection.findEntryInSection("foo1", "testname2"));
+    });
+  });
 
   describe("Config: TableRow", function () {
     var tabMenu, optionModel;

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ad739cf/app/addons/config/views.js
----------------------------------------------------------------------
diff --git a/app/addons/config/views.js b/app/addons/config/views.js
index 1725157..71b4839 100644
--- a/app/addons/config/views.js
+++ b/app/addons/config/views.js
@@ -44,12 +44,6 @@ function(app, FauxtonAPI, Config, Components) {
       this.remove();
     },
 
-    uniqueName: function(name){
-      var section = _.findWhere(this.collection.toJSON(), {"section":this.model.get("section")});
-
-      return _.findWhere(section.options, {name: name});
-    },
-
     editValue: function (event) {
       this.$(event.currentTarget).find(".js-show-value").addClass("js-hidden");
       this.$(event.currentTarget).find(".js-edit-value-form").removeClass("js-hidden");
@@ -81,12 +75,16 @@ function(app, FauxtonAPI, Config, Components) {
     },
     saveAndRender: function (event) {
       var options = {},
-          $input = this.$(event.currentTarget).parents('td').find(".js-value-input");
+          $input = this.$(event.currentTarget).parents('td').find(".js-value-input"),
+          sectionName,
+          nameInSectionExists;
 
       options[$input.attr('name')] = $input.val();
 
-      if ($input.attr('name')==='name'){
-        if (this.uniqueName($input.val())){
+      if ($input.attr('name') === 'name') {
+        sectionName = this.model.get("section");
+        nameInSectionExists = this.collection.findEntryInSection(sectionName, $input.val());
+        if (nameInSectionExists) {
           this.error = FauxtonAPI.addNotification({
             msg: "This config already exists, enter a unique name",
             type: "error",
@@ -195,13 +193,11 @@ function(app, FauxtonAPI, Config, Components) {
       Views.Events.trigger("newSection");
 
     },
-    isNew: function(collection){
+    isUniqueEntryInSection: function (collection) {
       var sectionName = this.$('input[name="section"]').val(),
-          name = this.$('input[name="name"]').val();
-          var section = _.findWhere(collection.toJSON(), {"section":sectionName});
-          var options = _.findWhere(section.options, {name: name});
+          entry = this.$('input[name="name"]').val();
 
-          return options;
+      return collection.findEntryInSection(sectionName, entry);
     },
     isSection: function(){
       var section = this.$('input[name="section"]').val();
@@ -220,7 +216,7 @@ function(app, FauxtonAPI, Config, Components) {
         this.errorMessage("Add a name");
       } else if (!value) {
         this.errorMessage("Add a value");
-      } else if (this.isNew(collection)){
+      } else if (this.isUniqueEntryInSection(collection)) {
         this.errorMessage("Must have a unique name");
       } else {
         this.submitForm();


[3/4] fauxton commit: updated refs/heads/master to bacf6fd

Posted by ro...@apache.org.
Config: remove unused this.error


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

Branch: refs/heads/master
Commit: 410b055f27a8d8de743e7bedc461c5837da925a7
Parents: 0ad739c
Author: Robert Kowalski <ro...@kowalski.gd>
Authored: Fri Sep 5 19:15:55 2014 +0200
Committer: Robert Kowalski <ro...@kowalski.gd>
Committed: Mon Sep 8 15:25:41 2014 +0200

----------------------------------------------------------------------
 app/addons/config/views.js | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/410b055f/app/addons/config/views.js
----------------------------------------------------------------------
diff --git a/app/addons/config/views.js b/app/addons/config/views.js
index 71b4839..87b57c9 100644
--- a/app/addons/config/views.js
+++ b/app/addons/config/views.js
@@ -85,7 +85,7 @@ function(app, FauxtonAPI, Config, Components) {
         sectionName = this.model.get("section");
         nameInSectionExists = this.collection.findEntryInSection(sectionName, $input.val());
         if (nameInSectionExists) {
-          this.error = FauxtonAPI.addNotification({
+          FauxtonAPI.addNotification({
             msg: "This config already exists, enter a unique name",
             type: "error",
             clear: true
@@ -222,14 +222,16 @@ function(app, FauxtonAPI, Config, Components) {
         this.submitForm();
       }
     },
-    errorMessage: function(msg){
-      this.error = FauxtonAPI.addNotification({
-          msg: msg,
-          type: "error",
-          clear: true,
-          selector: ".js-form-error-config"
+
+    errorMessage: function (msg) {
+      FauxtonAPI.addNotification({
+        msg: msg,
+        type: "error",
+        clear: true,
+        selector: ".js-form-error-config"
       });
     },
+
     show: function(){
       this.$el.modal({show:true});
     },