couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [28/28] couchdb commit: updated refs/heads/Query-Options-UI to 1295cce
Date Fri, 14 Mar 2014 16:46:06 GMT
Improved key support


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

Branch: refs/heads/Query-Options-UI
Commit: 1295cce44da89be044d31f95987e4351fe658423
Parents: 0687d47
Author: Garren Smith <garren.smith@gmail.com>
Authored: Fri Mar 14 12:05:55 2014 -0400
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Fri Mar 14 12:05:55 2014 -0400

----------------------------------------------------------------------
 src/fauxton/app/addons/documents/views.js | 53 ++++++++++++++------------
 1 file changed, 29 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/1295cce4/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 c00a771..b5715f2 100644
--- a/src/fauxton/app/addons/documents/views.js
+++ b/src/fauxton/app/addons/documents/views.js
@@ -1118,12 +1118,21 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
resizeColum
       this.render();
     },
     getKeys: function(val){
-      var keys = val.value.replace(/\s/g,"").split(',');
+      var keys = val.value.replace(/\s/g,"");
+      
+      var regKeys = keys.match(/(\[.*?\])/g); 
+      if (regKeys) {
+        keys = regKeys;
+      } else {
+        keys = keys.split(',');
+      }
+
+      keys = _.map(keys, function (key) { return JSON.parse(key); });
 
-      if (keys.length > 1){
+      if (_.isArray(keys)){
         return {
           name: "keys",
-          value:  JSON.stringify(keys)
+          value: JSON.stringify(keys)
         };
       } else if (keys.length === 1) {
         return {
@@ -1131,37 +1140,23 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
resizeColum
           value: keys[0]
         };
       }
-
     },
     queryParams: function () {
       var $form = this.$(".js-view-query-update"),
           getKeys = this.getKeys;
 
-      var rawParams = _.reduce($form.serializeArray(), function(params, param) {
+      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"){
+          param = getKeys(param);
+        }
 
         params.push(param);
         return params;
       }, []);
 
-      var filteredParams = _.filter(rawParams, function(param) {
-        return param.value;
-      });
-
-      console.log('filtered', filteredParams);
-      var params = filteredParams;
-      /*var params = _.map(filteredParams, function(param) {
-        if (param.name === "keys"){
-          param.value = JSON.parse(param.value);
-          //param.value = JSON.stringify(b);
-          return param;
-          //return getKeys(param);
-        }else{
-          return param;
-        }
-      });*/
-
       // Validate *key* params to ensure they're valid JSON
       var keyParams = ["keys","startkey","endkey"];
       var errorParams = _.filter(params, function(param) {
@@ -1177,8 +1172,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
resizeColum
         }
       });
 
-      console.log('params', params);
-      return {params: params, errorParams: {}}; //errorParams};
+      return {params: params, errorParams: errorParams};
     },
 
     updateFilters: function(event) {
@@ -1239,6 +1233,17 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
resizeColum
           }
           this.updateFiltersFor(key, $ele);
           break;
+          case "keys":
+            val = JSON.parse(val);
+            var processVal = val;
+            if (_.isArray(val)) {
+              processVal = _.map(val, function (arr) {
+                return JSON.stringify(arr);
+              }).join(', ');
+            }
+
+            $form.find("input[name='keys']").val(processVal);
+            break;
           default:
             $form.find("input[name='"+key+"']").val(val);
           break;


Mime
View raw message