couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [26/26] couchdb commit: updated refs/heads/Query-Options-UI to cf93bbf
Date Thu, 20 Mar 2014 10:21:50 GMT
Add keys validation


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

Branch: refs/heads/Query-Options-UI
Commit: cf93bbfc3e8cbf2229af115a50c0c5efe2006345
Parents: f237411
Author: Garren Smith <garren.smith@gmail.com>
Authored: Thu Mar 20 12:20:44 2014 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Thu Mar 20 12:20:44 2014 +0200

----------------------------------------------------------------------
 .../addons/documents/assets/less/documents.less | 12 ++++++++
 .../documents/templates/advanced_options.html   |  3 +-
 src/fauxton/app/addons/documents/views.js       | 29 ++++++++++++++++----
 3 files changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/cf93bbfc/src/fauxton/app/addons/documents/assets/less/documents.less
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/assets/less/documents.less b/src/fauxton/app/addons/documents/assets/less/documents.less
index 40a1d8c..36429ff 100644
--- a/src/fauxton/app/addons/documents/assets/less/documents.less
+++ b/src/fauxton/app/addons/documents/assets/less/documents.less
@@ -101,3 +101,15 @@ button.beautify {
     height: 688px;
     font-size: 16px;
 }
+
+#keys-input {
+  display: inline-block;
+  width: 35%;
+}
+
+#keys-error {
+  display: inline-block;
+}
+
+
+

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cf93bbfc/src/fauxton/app/addons/documents/templates/advanced_options.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/templates/advanced_options.html b/src/fauxton/app/addons/documents/templates/advanced_options.html
index f823d1a..d8d57cd 100644
--- a/src/fauxton/app/addons/documents/templates/advanced_options.html
+++ b/src/fauxton/app/addons/documents/templates/advanced_options.html
@@ -28,7 +28,8 @@ the License.
   <div class="controls-group well">
     <div class="row-fluid" id="js-showKeys">
       <div class="controls controls-row">
-        <textarea name="keys" class="input-xxlarge" rows="5" type="text" placeholder="Enter
a key, an array of keys. This must be valid JSON."></textarea>
+        <textarea id="keys-input" name="keys" class="input-xxlarge" rows="5" type="text"
placeholder="Enter a key, an array of keys. This must be valid JSON."></textarea>
+        <div id="keys-error" class="inline-block js-keys-error"></div>
       </div>
     </div>
     <div class="row-fluid hide" id="js-showStartEnd">

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cf93bbfc/src/fauxton/app/addons/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/views.js b/src/fauxton/app/addons/documents/views.js
index d3da5f1..90460e2 100644
--- a/src/fauxton/app/addons/documents/views.js
+++ b/src/fauxton/app/addons/documents/views.js
@@ -1132,19 +1132,34 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
resizeColum
       this.hasReduce = hasReduce;
       this.render();
     },
-    validateKeys:  function(val){
-      return JSON.parse(val);
+    validateKeys:  function(param){
+      var parsedValue = JSON.parse(param.value);
+      if (!_.isArray(parsedValue)) {
+        FauxtonAPI.addNotification({
+          type: "error",
+          msg: "Keys values must be in an array. E.g [1,2,3]",
+          clear:  false,
+          selector: '.js-keys-error'
+        });
+        return false;
+      }
+      return true; 
     },
     queryParams: function () {
-      var $form = this.$(".js-view-query-update");
+      var $form = this.$(".js-view-query-update"),
+          keysParam = false;
 
       var params = _.reduce($form.serializeArray(), function(params, param) {
         if (!param.value) { return params; }
         if (param.name === "limit" && param.value === 'None') { return params; }
+        if (param.name === "keys") { keysParam = param; }
         params.push(param);
         return params;
       }, []);
 
+
+      if (keysParam && !this.validateKeys(keysParam)) { return false; }
+
       // Validate *key* params to ensure they're valid JSON
       var keyParams = ["keys","startkey","endkey"];
       var errorParams = _.filter(params, function(param) {
@@ -1235,11 +1250,15 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
resizeColum
 
     updateView: function (event) {
       event.preventDefault();
-      this.updateViewFn(event, this.queryParams());
+      var params = this.queryParams();
+      if (!params) { return;}
+      this.updateViewFn(event, params);
     },
 
     previewView: function (event) {
-      this.previewFn(event, this.queryParams());
+      var params = this.queryParams();
+      if (!params) { return;}
+      this.previewFn(event, params);
     },
 
     serialize: function () {


Mime
View raw message