Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1F4CB10760 for ; Thu, 20 Mar 2014 19:06:21 +0000 (UTC) Received: (qmail 45178 invoked by uid 500); 20 Mar 2014 19:06:20 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 45035 invoked by uid 500); 20 Mar 2014 19:06:13 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 45013 invoked by uid 99); 20 Mar 2014 19:06:11 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Mar 2014 19:06:11 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DD2FD986AD4; Thu, 20 Mar 2014 19:06:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: deathbear@apache.org To: commits@couchdb.apache.org Date: Thu, 20 Mar 2014 19:06:10 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/3] couchdb commit: updated refs/heads/master to 3be8c85 Repository: couchdb Updated Branches: refs/heads/master 7dba42236 -> 3be8c85bd Keys validation, textarea and cleanup Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/3be8c85b Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/3be8c85b Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/3be8c85b Branch: refs/heads/master Commit: 3be8c85bde6d4ee513a736cdaf7d7aaf171d825d Parents: 65c814a Author: Garren Smith Authored: Thu Mar 20 18:35:43 2014 +0200 Committer: suelockwood Committed: Thu Mar 20 15:06:02 2014 -0400 ---------------------------------------------------------------------- .../addons/documents/assets/less/documents.less | 16 +++++ src/fauxton/app/addons/documents/resources.js | 23 ++++--- .../documents/templates/advanced_options.html | 10 +-- src/fauxton/app/addons/documents/views.js | 69 +++++++++++++++----- 4 files changed, 90 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/3be8c85b/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 61d864b..36429ff 100644 --- a/src/fauxton/app/addons/documents/assets/less/documents.less +++ b/src/fauxton/app/addons/documents/assets/less/documents.less @@ -39,6 +39,10 @@ button.beautify { } +#query div.controls-group.well{ + height: 150px; +} + /** used in all_docs_list.html **/ .view { table td div { @@ -97,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/3be8c85b/src/fauxton/app/addons/documents/resources.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/documents/resources.js b/src/fauxton/app/addons/documents/resources.js index 6f4323a..efd7f69 100644 --- a/src/fauxton/app/addons/documents/resources.js +++ b/src/fauxton/app/addons/documents/resources.js @@ -468,14 +468,21 @@ function(app, FauxtonAPI) { if (this.skipFirstItem) { rows = rows.splice(1); } - return _.map(rows, function(row) { - return { - _id: row.id, - _rev: row.value.rev, - value: row.value, - key: row.key, - doc: row.doc || undefined - }; + + // remove any query errors that may return without doc info + // important for when querying keys on all docs + var noQueryErrors = _.filter(rows, function(row){ + return row.value; + }); + + return _.map(noQueryErrors, function(row) { + return { + _id: row.id, + _rev: row.value.rev, + value: row.value, + key: row.key, + doc: row.doc || undefined + }; }); } })); http://git-wip-us.apache.org/repos/asf/couchdb/blob/3be8c85b/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 8acf30a..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.
- + +
@@ -48,7 +49,7 @@ the License.
- Limit & and Skip are disabled when using Keys.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/3be8c85b/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 1e7addf..cc23e19 100644 --- a/src/fauxton/app/addons/documents/views.js +++ b/src/fauxton/app/addons/documents/views.js @@ -1107,13 +1107,13 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum showKeys: function(){ this.$("#js-showKeys, .js-disabled-message").show(); - this.$('[name="skip"],[name="startkey"],[name="limit"],[name="endkey"],[name="inclusive_end"]').attr("disabled","true"); + this.$('[name="startkey"],[name="endkey"],[name="inclusive_end"]').attr("disabled","true"); this.$('[name="keys"]').removeAttr("disabled"); }, showStartEnd: function(){ this.$("#js-showStartEnd").show(); - this.$('[name="skip"],[name="startkey"],[name="limit"],[name="endkey"],[name="inclusive_end"]').removeAttr("disabled"); + this.$('[name="startkey"],[name="endkey"],[name="inclusive_end"]').removeAttr("disabled"); this.$('.js-disabled-message').hide(); this.$('[name="keys"]').attr("disabled","true"); }, @@ -1132,33 +1132,62 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum this.hasReduce = hasReduce; this.render(); }, - validateKeys: function(val){ - return JSON.parse(val); + + parseJSON: function (value) { + try { + return JSON.parse(value); + } catch(e) { + return undefined; + } + }, + + validateKeys: function(param){ + var errorMsg = false, + parsedValue = this.parseJSON(param.value); + + if (_.isUndefined(parsedValue)) { + errorMsg = "Keys must be valid json."; + } else if (!_.isArray(parsedValue)) { + errorMsg = "Keys values must be in an array. E.g [1,2,3]"; + } + + if (errorMsg) { + this.$('.js-keys-error').empty(); + FauxtonAPI.addNotification({ + type: "error", + msg: errorMsg, + 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) { - if (_.contains(keyParams, param.name)) { - try { - JSON.parse(param.value); - return false; - } catch(e) { + if (_.contains(keyParams, param.name) && _.isUndefined(this.parseJSON(param.value))) { return true; } - } else { + return false; - } - }); + }, this); return {params: params, errorParams: errorParams}; }, @@ -1222,6 +1251,10 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum } this.updateFiltersFor(key, $ele); break; + case "key": + case "keys": + $form.find("textarea[name='"+key+"']").val(val); + break; default: $form.find("input[name='"+key+"']").val(val); break; @@ -1231,11 +1264,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 () { @@ -1615,6 +1652,8 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum }, toggleIndexNav: function (event) { + $('#dashboard-content').scrollTop(0); //scroll up + var $targetId = this.$(event.target).attr('id'), $previousTab = this.$(this.$('li.active a').attr('href')), $targetTab = this.$(this.$(event.target).attr('href'));