sidebar: fix collapsible for special chars fix collapsible for design docs with special chars in their name, like `_design////design//foo` or `_design/bar.foo.bar`
internally sizzle works with `querySelectorAll` which needs escaping for special chars in css selectors. based on a patch from Michelle Phung <[email protected]> PR: #353 PR-URL: https://github.com/apache/couchdb-fauxton/pull/353 Reviewed-By: Michelle Phung <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/fb8387ea Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/fb8387ea Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/fb8387ea Branch: refs/heads/master Commit: fb8387ea6119d4ed7d409d6935098bb0eaacc899 Parents: 8260f08 Author: Robert Kowalski <[email protected]> Authored: Wed Apr 1 19:29:42 2015 +0200 Committer: Robert Kowalski <[email protected]> Committed: Mon Apr 13 13:35:00 2015 +0200 ---------------------------------------------------------------------- app/addons/documents/shared-views.js | 15 ++++++--- .../documents/templates/design_doc_menu.html | 10 +++--- .../tests/nightwatch/checkSidebarBehavior.js | 35 ++++++++++++++++++++ .../documents/tests/nightwatch/viewCreate.js | 4 +-- app/config.js | 1 + 5 files changed, 54 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/fb8387ea/app/addons/documents/shared-views.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/shared-views.js b/app/addons/documents/shared-views.js index 627c682..5beee95 100644 --- a/app/addons/documents/shared-views.js +++ b/app/addons/documents/shared-views.js @@ -17,7 +17,8 @@ define([ "addons/fauxton/components", "addons/documents/resources", - "addons/databases/resources" + "addons/databases/resources", + "css.escape" ], function (app, FauxtonAPI, Components, Documents, Databases) { @@ -168,9 +169,14 @@ function (app, FauxtonAPI, Components, Documents, Databases) { "click .js-collapse-toggle": "toggleArrow" }, - toggleArrow: function (e) { - this.$(e.currentTarget).toggleClass("down"); + toggleArrow: function (e) { + var escapedId = window.CSS.escape(e.currentTarget.id), + $toggleElement = this.$('#' + escapedId).next(); + + this.$('#' + escapedId).toggleClass('down'); + $toggleElement.collapse('toggle'); }, + buildIndexList: function (designDocs, info) { var design = this.model.id.replace(/^_design\//, ""); var databaseId = this.model.database.id; @@ -188,13 +194,14 @@ function (app, FauxtonAPI, Components, Documents, Databases) { serialize: function () { var ddocName = this.model.id.replace(/^_design\//, ""), + escapedId = window.CSS.escape(ddocName), docSafe = app.utils.safeURLName(ddocName), databaseName = this.collection.database.safeID(); return { designDocMetaUrl: FauxtonAPI.urls('designDocs', 'app', databaseName, docSafe), designDoc: ddocName, - ddoc_clean: docSafe, + escapedId: escapedId }; }, http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/fb8387ea/app/addons/documents/templates/design_doc_menu.html ---------------------------------------------------------------------- diff --git a/app/addons/documents/templates/design_doc_menu.html b/app/addons/documents/templates/design_doc_menu.html index eea0b9a..4a0b6a9 100644 --- a/app/addons/documents/templates/design_doc_menu.html +++ b/app/addons/documents/templates/design_doc_menu.html @@ -1,4 +1,4 @@ -<!-- +<%/* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -10,19 +10,19 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ---> +*/%> <li class="nav-header"> -<div class="js-collapse-toggle accordion-header" data-toggle="collapse" data-target="#<%- ddoc_clean %>" id="nav-header-<%- ddoc_clean %>" > +<div class="js-collapse-toggle accordion-header" id="nav-header-<%- escapedId %>" > <div class="accordion-list-item"> <div class="fonticon-play"></div> <p class="design-doc-name"><span title="_design/<%- designDoc%>">_design/<%- designDoc%></span></p> </div> <div class="new-button add-dropdown"></div> </div> -<ul class="accordion-body collapse" id="<%- ddoc_clean %>"> +<ul class="accordion-body collapse <%- escapedId %>" id="<%- escapedId %>"> <li> - <a id="<%- ddoc_clean %>_metadata" href="#/<%- designDocMetaUrl %>" class="toggle-view accordion-header"> + <a id="<%- escapedId %>_metadata" href="#/<%- designDocMetaUrl %>" class="toggle-view accordion-header"> <span class="fonticon-sidenav-info fonticon"></span> Design Doc Metadata </a> http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/fb8387ea/app/addons/documents/tests/nightwatch/checkSidebarBehavior.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/tests/nightwatch/checkSidebarBehavior.js b/app/addons/documents/tests/nightwatch/checkSidebarBehavior.js new file mode 100644 index 0000000..c259b00 --- /dev/null +++ b/app/addons/documents/tests/nightwatch/checkSidebarBehavior.js @@ -0,0 +1,35 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +module.exports = { + + 'Checks if design docs that have a dot symbol in the id show up in the UI': function (client) { + var waitTime = 10000, + newDatabaseName = client.globals.testDatabaseName, + baseUrl = client.globals.test_settings.launch_url; + + client + .loginToGUI() + .createDocument('_design/ddoc_normal', newDatabaseName) + .createDocument('_design/ddoc.with.specialcharacters', newDatabaseName) + .url(baseUrl + '/#/database/' + newDatabaseName + '/_all_docs') + .waitForElementPresent('.nav-list', waitTime, false) + .assert.hidden('a[href="#/database/' + newDatabaseName + '/_design/ddoc_normal/_info"]') + .assert.hidden('a[href="#/database/' + newDatabaseName + '/_design/ddoc.with.specialcharacters/_info"]') + + .clickWhenVisible('#nav-header-ddoc_normal') + .assert.visible('a[href="#/database/' + newDatabaseName + '/_design/ddoc_normal/_info"]') + .clickWhenVisible('[title="_design/ddoc.with.specialcharacters"]') + .assert.visible('a[href="#/database/' + newDatabaseName + '/_design/ddoc.with.specialcharacters/_info"]') + .end(); + } +}; http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/fb8387ea/app/addons/documents/tests/nightwatch/viewCreate.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/tests/nightwatch/viewCreate.js b/app/addons/documents/tests/nightwatch/viewCreate.js index 98b7b1e..45dd0e7 100644 --- a/app/addons/documents/tests/nightwatch/viewCreate.js +++ b/app/addons/documents/tests/nightwatch/viewCreate.js @@ -63,7 +63,7 @@ var tests = { var waitTime = client.globals.maxWaitTime; /*jshint multistr: true */ - openDifferentDropdownsAndClick(client, '[data-target="#testdesigndoc"]') + openDifferentDropdownsAndClick(client, '#nav-header-testdesigndoc') .clearValue('#index-name') .setValue('#index-name', 'test-new-view') .execute('\ @@ -77,7 +77,7 @@ var tests = { }) //go back to all docs .url(baseUrl + '/#/database/' + newDatabaseName + '/_all_docs') - .clickWhenVisible('[data-target="#testdesigndoc"]', waitTime, false) + .clickWhenVisible('#nav-header-testdesigndoc', waitTime, false) .clickWhenVisible('[data-target="#testdesigndocviews"]', waitTime, false) .clickWhenVisible('#testdesigndoc_testnewview', waitTime, false) .waitForElementPresent('.prettyprint', waitTime, false) http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/fb8387ea/app/config.js ---------------------------------------------------------------------- diff --git a/app/config.js b/app/config.js index 27acfd5..da2b606 100644 --- a/app/config.js +++ b/app/config.js @@ -36,6 +36,7 @@ require.config({ react: "../assets/js/libs/react", flux: "../assets/js/libs/flux", "es5-shim": "../assets/js/libs/es5-shim", + "css.escape": "../assets/js/libs/css.escape", moment: '../assets/js/libs/moment' },
