You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by de...@apache.org on 2014/07/28 15:47:49 UTC
[1/8] fauxton commit: updated refs/heads/secondary-indexes to 4c45e12
Repository: couchdb-fauxton
Updated Branches:
refs/heads/secondary-indexes ef01e241b -> 4c45e1296 (forced update)
restore state of couchdb in couchdb-fauxon
automatically expand ace correctly
remove unnecessary resize, improve comments
have save warning right in principle
final brush-up
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/b340f1dd
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/b340f1dd
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/b340f1dd
Branch: refs/heads/secondary-indexes
Commit: b340f1dd3b04e41c4bdc28d8a4e2d9524053a6f8
Parents: 99665a1
Author: sebastianrothbucher <se...@googlemail.com>
Authored: Mon Jul 14 23:08:18 2014 +0200
Committer: sebastianrothbucher <se...@googlemail.com>
Committed: Fri Jul 18 00:26:34 2014 +0200
----------------------------------------------------------------------
app/addons/documents/assets/less/documents.less | 24 ++++
app/addons/documents/templates/code_editor.html | 2 +
.../documents/templates/string_edit_modal.html | 30 +++++
app/addons/documents/views.js | 122 ++++++++++++++++++-
app/addons/fauxton/components.js | 48 +++++++-
5 files changed, 223 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b340f1dd/app/addons/documents/assets/less/documents.less
----------------------------------------------------------------------
diff --git a/app/addons/documents/assets/less/documents.less b/app/addons/documents/assets/less/documents.less
index e62be30..0537595 100644
--- a/app/addons/documents/assets/less/documents.less
+++ b/app/addons/documents/assets/less/documents.less
@@ -152,4 +152,28 @@ button.beautify {
}
}
+button.string-edit {
+ position: absolute;
+ padding: 0;
+ z-index: 1000;
+ width: 16px;
+ left: 22px;
+}
+
+button.string-edit[disabled] {
+ display: none;
+}
+
+#string-edit-modal {
+ div.modal {
+ overflow-x: visible;
+ width: initial;
+ min-width: 560px;
+ }
+}
+
+#string-editor-wrapper {
+ height: 500px;
+ width: 100%;
+}
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b340f1dd/app/addons/documents/templates/code_editor.html
----------------------------------------------------------------------
diff --git a/app/addons/documents/templates/code_editor.html b/app/addons/documents/templates/code_editor.html
index 811e111..2198079 100644
--- a/app/addons/documents/templates/code_editor.html
+++ b/app/addons/documents/templates/code_editor.html
@@ -22,6 +22,7 @@ the License.
</div>
<div class="span7">
+ <button class="btn string-edit" title="Edit line" disabled="true"><i class="icon icon-edit"></i></button>
<% if (attachments) { %>
<div class="btn-group">
<button class="dropdown-toggle btn" data-bypass="true" data-toggle="dropdown">
@@ -48,6 +49,7 @@ the License.
<div id="upload-modal"> </div>
<div id="duplicate-modal"> </div>
+<div id="string-edit-modal"> </div>
</div>
<div id="editor-container" class="doc-code"><%- JSON.stringify(doc.attributes, null, " ") %></div>
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b340f1dd/app/addons/documents/templates/string_edit_modal.html
----------------------------------------------------------------------
diff --git a/app/addons/documents/templates/string_edit_modal.html b/app/addons/documents/templates/string_edit_modal.html
new file mode 100644
index 0000000..1177795
--- /dev/null
+++ b/app/addons/documents/templates/string_edit_modal.html
@@ -0,0 +1,30 @@
+<!--
+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.
+-->
+
+<div class="modal hide fade">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
+ <h3>Edit text <span id="string-edit-header"></span></h3>
+ </div>
+ <div class="modal-body">
+ <div id="modal-error" class="hide alert alert-error"/>
+ <div id="string-editor-wrapper"><div id="string-editor-container" class="doc-code"></div></div>
+ </div>
+ <div class="modal-footer">
+ <button data-dismiss="modal" class="btn"><i class="icon fonticon-circle-x"></i> Cancel</button>
+ <button id="string-edit-save-btn" class="btn btn-success save"><i class="fonticon-circle-check"></i> Save</button>
+ </div>
+</div>
+
+
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b340f1dd/app/addons/documents/views.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/views.js b/app/addons/documents/views.js
index 6ccb733..9e397af 100644
--- a/app/addons/documents/views.js
+++ b/app/addons/documents/views.js
@@ -247,6 +247,62 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
}
});
+ Views.StringEditModal = Components.ModalView.extend({
+ template: "addons/documents/templates/string_edit_modal",
+
+ initialize: function () {
+ _.bindAll(this);
+ },
+
+ events: {
+ "click #string-edit-save-btn":"saveString"
+ },
+
+ saveString: function (event) {
+ event.preventDefault();
+ var newStr = this.subEditor.getValue();
+ this.subEditor.editSaved();
+ this.editor.replaceCurrentLine(this.indent + this.hashKey + JSON.stringify(newStr) + this.comma + "\n");
+ this.hideModal();
+ },
+
+ _showModal: function () {
+ this.$('.bar').css({width: '0%'});
+ this.$('.progress').addClass('hide');
+ this.clear_error_msg();
+ },
+
+ openWin: function(editor, indent, hashKey, jsonString, comma) {
+ this.editor = editor;
+ this.indent = indent;
+ this.hashKey = hashKey;
+ this.$('#string-edit-header').text(hashKey);
+ this.subEditor.setValue(JSON.parse(jsonString));
+ /* make sure we don't have save warnings w/out change */
+ this.subEditor.editSaved();
+ this.comma = comma;
+ this.showModal();
+ },
+
+ afterRender: function() {
+ /* make sure we init only ONCE */
+ if (!this.subEditor) {
+ this.subEditor = new Components.Editor({
+ editorId: "string-editor-container",
+ mode: "plain"
+ });
+ this.subEditor.render();
+ /* optimize by disabling auto sizing (35 is the lines fitting into the pop-up) */
+ this.subEditor.configureFixedHeightEditor(35);
+ }
+ },
+
+ cleanup: function () {
+ if (this.subEditor) this.subEditor.remove();
+ }
+
+ });
+
Views.Document = FauxtonAPI.View.extend({
template: "addons/documents/templates/all_docs_item",
tagName: "tr",
@@ -751,7 +807,8 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
"click button.delete": "destroy",
"click button.duplicate": "duplicate",
"click button.upload": "upload",
- "click button.cancel-button": "goback"
+ "click button.cancel-button": "goback",
+ "click button.string-edit": "stringEditing"
},
disableLoader: true,
@@ -765,6 +822,57 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
FauxtonAPI.navigate(this.database.url("index") + "?limit=100");
},
+ determineStringEditMatch: function(event) {
+ var selStart = this.editor.getSelectionStart().row;
+ var selEnd = this.editor.getSelectionEnd().row;
+ /* one JS(ON) string can't span more than one line - we edit one string, so ensure we don't select several lines */
+ if (selStart >=0 && selEnd >= 0 && selStart === selEnd && this.editor.isRowExpanded(selStart)) {
+ var editLine = this.editor.getLine(selStart);
+ var editMatch = editLine.match(/^([ \t]*)("[a-zA-Z0-9_]*": )?(".*",?[ \t]*)$/);
+ if (editMatch) {
+ return editMatch;
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ },
+
+ showHideEditDocString: function (event) {
+ this.$("button.string-edit").attr("disabled", "true");
+ if (!this.hasValidCode()) {
+ return false;
+ }
+ var editMatch = this.determineStringEditMatch(event);
+ if (editMatch) {
+ this.$("button.string-edit").removeAttr("disabled");
+ /* remove the following line (along with CSS) to go back to the toolbar */
+ this.$("button.string-edit").css("top", (this.$("#editor-container")[0].offsetTop - 2 + this.editor.getRowHeight() * this.editor.documentToScreenRow(this.editor.getSelectionStart().row)) + "px");
+ return true;
+ }
+ return false;
+ },
+
+ stringEditing: function(event) {
+ event.preventDefault();
+ if (!this.hasValidCode()) {
+ return;
+ }
+ var editMatch = this.determineStringEditMatch(event);
+ if (editMatch) {
+ var indent = editMatch[1] || "",
+ hashKey = editMatch[2] || "",
+ editText = editMatch[3],
+ comma = "";
+ if (editText.substring(editText.length - 1) === ",") {
+ editText = editText.substring(0, editText.length - 1);
+ comma = ",";
+ }
+ this.stringEditModal.openWin(this.editor, indent, hashKey, editText, comma);
+ }
+ },
+
destroy: function(event) {
if (this.model.isNewDoc()) {
FauxtonAPI.addNotification({
@@ -802,6 +910,10 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
this.duplicateModal = this.setView('#duplicate-modal', new Views.DuplicateDocModal({model: this.model}));
this.duplicateModal.render();
+
+ /* initialization is automatic - and make sure ONCE */
+ this.stringEditModal = this.stringEditModal || this.setView('#string-edit-modal', new Views.StringEditModal());
+ /* this.stringEditModal.render(); */
},
upload: function (event) {
@@ -999,6 +1111,14 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
clear: true
});
});
+
+ var that = this;
+ this.listenTo(editor.editor, "changeSelection", function (event) {
+ that.showHideEditDocString(event);
+ });
+ this.listenTo(editor.editor.session, "changeBackMarker", function (event) {
+ that.showHideEditDocString(event);
+ });
},
cleanup: function () {
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b340f1dd/app/addons/fauxton/components.js
----------------------------------------------------------------------
diff --git a/app/addons/fauxton/components.js b/app/addons/fauxton/components.js
index 79a9320..f0dcc31 100644
--- a/app/addons/fauxton/components.js
+++ b/app/addons/fauxton/components.js
@@ -419,8 +419,9 @@ function(app, FauxtonAPI, ace, spin) {
this.setHeightToLineCount();
this.editor.setTheme("ace/theme/" + this.theme);
-
- this.editor.getSession().setMode("ace/mode/" + this.mode);
+ if (this.mode != "plain") {
+ this.editor.getSession().setMode("ace/mode/" + this.mode);
+ }
this.editor.setShowPrintMargin(false);
this.addCommands();
@@ -529,6 +530,49 @@ function(app, FauxtonAPI, ace, spin) {
isIgnorableError: function(msg) {
return _.contains(this.excludedViewErrors, msg);
+ },
+
+ configureFixedHeightEditor: function(numLines) {
+ this.editor.renderer.setVScrollBarAlwaysVisible(true);
+ this.editor.renderer.setHScrollBarAlwaysVisible(true);
+ /* customize the ace scrolling for static edit height */
+ this.editor.renderer.$autosize = function() {
+ this.$size.height = numLines * this.lineHeight;
+ this.desiredHeight = numLines * this.lineHeight;
+ this.container.style.height = this.desiredHeight + "px";
+ this.scrollBarV.setVisible(true);
+ this.scrollBarH.setVisible(true);
+ };
+ },
+
+ replaceCurrentLine: function(replacement) {
+ this.editor.getSelection().selectLine();
+ this.editor.insert(replacement);
+ this.editor.getSelection().moveCursorUp();
+ },
+
+ getLine: function(lineNum) {
+ return this.editor.session.getLine(lineNum);
+ },
+
+ getSelectionStart: function() {
+ return this.editor.getSelectionRange().start;
+ },
+
+ getSelectionEnd: function() {
+ return this.editor.getSelectionRange().end;
+ },
+
+ getRowHeight: function() {
+ return this.editor.renderer.layerConfig.lineHeight;
+ },
+
+ isRowExpanded: function(row) {
+ return !this.editor.getSession().isRowFolded(row);
+ },
+
+ documentToScreenRow: function(row) {
+ return this.editor.getSession().documentToScreenRow(row, 0);
}
});
[8/8] fauxton commit: updated refs/heads/secondary-indexes to 4c45e12
Posted by de...@apache.org.
Ripping out views into it's own addon
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/4c45e129
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/4c45e129
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/4c45e129
Branch: refs/heads/secondary-indexes
Commit: 4c45e12966f22065ff333e500af4f926f84bf358
Parents: df3f068
Author: deathbearbrown <de...@gmail.com>
Authored: Tue Jul 22 16:40:06 2014 -0400
Committer: deathbearbrown <de...@gmail.com>
Committed: Mon Jul 28 09:47:38 2014 -0400
----------------------------------------------------------------------
app/addons/documents/routes.js | 102 +---
.../templates/design_doc_selector.html | 38 --
app/addons/documents/templates/view_editor.html | 91 ---
app/addons/documents/views-index.js | 574 -------------------
app/addons/indexes/index-components.js | 2 +
app/addons/indexes/routes-filter.js | 47 ++
app/addons/indexes/routes-list.js | 47 ++
app/addons/indexes/routes-show.js | 47 ++
app/addons/indexes/routes-viewindexes.js | 204 +++++++
app/addons/indexes/routes.js | 24 +-
.../indexes/templates/design_doc_selector.html | 38 ++
app/addons/indexes/templates/view_editor.html | 70 +++
app/addons/indexes/views.js | 559 +++++++++++++++++-
settings.json.default | 1 +
14 files changed, 1021 insertions(+), 823 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/documents/routes.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/routes.js b/app/addons/documents/routes.js
index 9c266be..449e50e 100644
--- a/app/addons/documents/routes.js
+++ b/app/addons/documents/routes.js
@@ -19,14 +19,13 @@ define([
//views
"addons/documents/views",
"addons/documents/views-changes",
- "addons/documents/views-index",
"addons/documents/views-doceditor",
"addons/databases/base",
"addons/documents/resources"
],
-function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resources) {
+function(app, FauxtonAPI, Documents, Changes, DocEditor, Databases, Resources) {
var DocEditorRouteObject = FauxtonAPI.RouteObject.extend({
layout: "one_pane",
@@ -133,28 +132,10 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
route: "allDocs",
roles: ["_reader","_writer","_admin"]
},
- "database/:database/_design/:ddoc/_view/:view": {
- route: "viewFn",
- roles: ['_admin']
- },
- "database/:database/_design/:ddoc/_lists/:fn": {
- route: "tempFn",
- roles: ['_admin']
- },
- "database/:database/_design/:ddoc/_filters/:fn": {
- route: "tempFn",
- roles: ['_admin']
- },
- "database/:database/_design/:ddoc/_show/:fn": {
- route: "tempFn",
- roles: ['_admin']
- },
"database/:database/_design/:ddoc/metadata": {
route: "designDocMetadata",
roles: ['_admin']
},
- "database/:database/new_view": "newViewEditor",
- "database/:database/new_view/:designDoc": "newViewEditor",
"database/:database/_changes(:params)": "changes"
},
@@ -213,15 +194,6 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
this.apiUrl = [designDocInfo.url('apiurl'), designDocInfo.documentation() ];
},
- tempFn: function(databaseName, ddoc, fn){
- this.setView("#dashboard-upper-content", new Documents.Views.temp({}));
- this.crumbs = function () {
- return [
- {"name": this.data.database.id, "link": Databases.databaseUrl(this.data.database)},
- ];
- };
-
- },
establish: function () {
return this.data.designDocs.fetch({reset: true});
@@ -286,56 +258,6 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
this.apiUrl = [this.data.database.allDocs.urlRef("apiurl", urlParams), this.data.database.allDocs.documentation() ];
},
- viewFn: function (databaseName, ddoc, view) {
- var params = this.createParams(),
- urlParams = params.urlParams,
- docParams = params.docParams,
- decodeDdoc = decodeURIComponent(ddoc);
-
- view = view.replace(/\?.*$/,'');
-
- this.data.indexedDocs = new Documents.IndexCollection(null, {
- database: this.data.database,
- design: decodeDdoc,
- view: view,
- params: docParams,
- paging: {
- pageSize: this.getDocPerPageLimit(urlParams, parseInt(docParams.limit, 10))
- }
- });
-
- this.viewEditor = this.setView("#dashboard-upper-content", new Index.ViewEditor({
- model: this.data.database,
- ddocs: this.data.designDocs,
- viewName: view,
- params: urlParams,
- newView: false,
- database: this.data.database,
- ddocInfo: this.ddocInfo(decodeDdoc, this.data.designDocs, view)
- }));
-
- this.toolsView && this.toolsView.remove();
-
- this.documentsView = this.createViewDocumentsView({
- designDoc: decodeDdoc,
- docParams: docParams,
- urlParams: urlParams,
- database: this.data.database,
- indexedDocs: this.data.indexedDocs,
- designDocs: this.data.designDocs,
- view: view
- });
-
- this.sidebar.setSelectedTab(app.utils.removeSpecialCharacters(ddoc) + '_' + app.utils.removeSpecialCharacters(view));
-
- this.crumbs = function () {
- return [
- {"name": this.data.database.id, "link": Databases.databaseUrl(this.data.database)},
- ];
- };
-
- this.apiUrl = [this.data.indexedDocs.urlRef("apiurl", urlParams), "docs"];
- },
ddocInfo: function (designDoc, designDocs, view) {
return {
@@ -358,28 +280,6 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
}));
},
- newViewEditor: function (database, designDoc) {
- var params = app.getParams();
-
- this.toolsView && this.toolsView.remove();
- this.documentsView && this.documentsView.remove();
-
- this.viewEditor = this.setView("#dashboard-upper-content", new Index.ViewEditor({
- currentddoc: "_design/"+designDoc || "",
- ddocs: this.data.designDocs,
- params: params,
- database: this.data.database,
- newView: true
- }));
-
- this.sidebar.setSelectedTab('new-view');
- this.crumbs = function () {
- return [
- {"name": this.data.database.id, "link": Databases.databaseUrl(this.data.database)},
- ];
- };
- },
-
updateAllDocsFromView: function (event) {
var view = event.view,
params = this.createParams(),
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/documents/templates/design_doc_selector.html
----------------------------------------------------------------------
diff --git a/app/addons/documents/templates/design_doc_selector.html b/app/addons/documents/templates/design_doc_selector.html
deleted file mode 100644
index 828b5a5..0000000
--- a/app/addons/documents/templates/design_doc_selector.html
+++ /dev/null
@@ -1,38 +0,0 @@
-<!--
-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.
--->
-<div class="span3">
- <label for="ddoc">Save to Design Document <a class="help-link" href="<%-getDocUrl('design_doc')%>" target="_blank"><i class="icon-question-sign"></i></a></label>
- <select id="ddoc">
- <optgroup label="Select a document">
- <option value="new-doc">New document</option>
-
- <% ddocs.each(function(ddoc) { %>
- <%= ddoc.id %>
- <%= ddocName %>
- <% if (ddoc.id === ddocName) { %>
- <option selected="selected" value="<%- ddoc.id %>"><%- ddoc.id %></option>
- <% } else { %>
- <option value="<%- ddoc.id %>"><%- ddoc.id %></option>
- <% } %>
- <% }); %>
- </optgroup>
- </select>
-</div>
-
-<div id="new-ddoc-section" class="span5" style="display:none">
- <label class="control-label" for="new-ddoc"> _design/ </label>
- <div class="controls">
- <input type="text" id="new-ddoc" placeholder="newDesignDoc" />
- </div>
-</div>
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/documents/templates/view_editor.html
----------------------------------------------------------------------
diff --git a/app/addons/documents/templates/view_editor.html b/app/addons/documents/templates/view_editor.html
deleted file mode 100644
index e6fbbc1..0000000
--- a/app/addons/documents/templates/view_editor.html
+++ /dev/null
@@ -1,91 +0,0 @@
-<!--
-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.
--->
-<div class="dashboard-upper-menu">
- <ul class="nav nav-tabs" id="db-views-tabs-nav">
- <li class="active"> <a data-bypass="true" id="index-nav" data-toggle="tab" href="#index">
- <i class="fonticon-wrench fonticon"></i>
- <% if (newView) { %>Create Index <% } else { %>Edit Index <% } %></a></li>
- <% if (!newView) { %>
- <li><a data-bypass="true" id="query-nav" href="#query" data-toggle="tab">
- <i class="fonticon-plus fonticon"></i> Query Options</a>
- </li>
- <% } %>
- </ul>
-</div>
- <div class="all-docs-list errors-container"></div>
- <div class="tab-content">
- <div id="query-options-wrapper"></div>
- <div class="tab-pane active" id="index">
- <div id="define-view" class="ddoc-alert well">
- <div class="errors-container"></div>
- <form class="form-horizontal view-query-save">
-
- <div class="control-group design-doc-group">
- </div>
-
- <div class="control-group">
- <label for="index-name">Index name <a class="help-link" href="<%-getDocUrl('view_functions')%>" target="_blank"><i class="icon-question-sign"></i></a></label>
- <input type="text" id="index-name" value="<%- viewName %>" placeholder="Index name" />
- </div>
-
-
- <div class="control-group">
- <label for="map-function">Map function <a class="help-link" href="<%-getDocUrl('map_functions')%>" target="_blank"><i class="icon-question-sign"></i></a></label>
- <% if (newView) { %>
- <div class="js-editor" id="map-function"><%= langTemplates.map %></div>
- <% } else { %>
- <div class="js-editor" id="map-function"><%- ddoc.get('views')[viewName].map %></div>
- <button class="beautify beautify_map btn btn-primary btn-large hide beautify-tooltip" type="button" data-toggle="tooltip" title="Reformat your minified code to make edits to it.">beautify this code</button>
- <% } %>
- </div>
-
-
- <div class="control-group">
- <label for="reduce-function-selector">Reduce (optional) <a class="help-link" href="<%-getDocUrl('reduce_functions')%>" target="_blank"><i class="icon-question-sign"></i></a></label>
-
- <select id="reduce-function-selector">
- <option value="" <%- !reduceFunStr ? 'selected="selected"' : '' %>>None</option>
- <% _.each(["_sum", "_count", "_stats"], function(reduce) { %>
- <option value="<%- reduce %>" <% if (reduce == reduceFunStr) { %>selected<% } %>><%= reduce %></option>
- <% }) %>
- <option value="CUSTOM" <% if (isCustomReduce) { %>selected<% } %>>Custom Reduce function</option>
- </select>
- </div>
-
- <div class="control-group reduce-function">
- <label for="reduce-function">Custom Reduce function</label>
- <% if (newView) { %>
- <div class="js-editor" id="reduce-function"><%- langTemplates.reduce %></div>
- <% } else { %>
- <div class="js-editor" id="reduce-function"><%- ddoc.get('views')[viewName].reduce %></div>
- <button class="beautify beautify_reduce btn btn-primary btn-large hide beautify-tooltip" type="button" data-toggle="tooltip" title="Reformat your minified code to make edits to it.">beautify this code</button>
- <% } %>
- </div>
-
- <div class="control-group">
- <button class="btn btn-success save"><i class="icon fonticon-ok-circled"></i> Save & Build Index</button>
- <% if (!newView) { %>
- <button class="btn btn-danger delete"><i class="icon fonticon-cancel-circled"></i> Delete</button>
- <% } %>
- </div>
- <div class="clearfix"></div>
- </form>
- </div>
- </div>
- <div class="tab-pane" id="metadata">
- <div id="ddoc-info" class="well"> </div>
- </div>
- <div class="tab-pane" id="query">
- </div>
- </div>
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/documents/views-index.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/views-index.js b/app/addons/documents/views-index.js
deleted file mode 100644
index d0ed8ed..0000000
--- a/app/addons/documents/views-index.js
+++ /dev/null
@@ -1,574 +0,0 @@
-// 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.
-
-define([
- "app",
-
- "api",
- "addons/fauxton/components",
-
- "addons/documents/resources",
- "addons/databases/resources",
- "addons/pouchdb/base",
- //views
- "addons/documents/views-advancedopts",
- // Libs
- "addons/fauxton/resizeColumns",
-
- // Plugins
- "plugins/beautify",
- "plugins/prettify"
-],
-
-function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
- QueryOptions, resizeColumns, beautify, prettify) {
-
- var Views = {};
-
- Views.ViewEditor = FauxtonAPI.View.extend({
- template: "addons/documents/templates/view_editor",
- builtinReduces: ['_sum', '_count', '_stats'],
-
- events: {
- "click button.save": "saveView",
- "click button.delete": "deleteView",
- "change select#reduce-function-selector": "updateReduce",
- "click button.preview": "previewView",
- "click #db-views-tabs-nav": 'toggleIndexNav',
- "click .beautify_map": "beautifyCode",
- "click .beautify_reduce": "beautifyCode",
- "click #query-options-wrapper": 'toggleIndexNav'
- },
-
- langTemplates: {
- "javascript": {
- map: "function(doc) {\n emit(doc._id, 1);\n}",
- reduce: "function(keys, values, rereduce){\n if (rereduce){\n return sum(values);\n } else {\n return values.length;\n }\n}"
- }
- },
-
- defaultLang: "javascript",
-
- initialize: function(options) {
- this.newView = options.newView || false;
- this.ddocs = options.ddocs;
- this.params = options.params;
- this.database = options.database;
- this.currentDdoc = options.currentddoc;
- if (this.newView) {
- this.viewName = 'newView';
- } else {
- this.ddocID = options.ddocInfo.id;
- this.viewName = options.viewName;
- this.ddocInfo = new Documents.DdocInfo({_id: this.ddocID},{database: this.database});
- }
-
- this.showIndex = false;
- _.bindAll(this);
- },
-
- establish: function () {
- if (this.ddocInfo) {
- return this.ddocInfo.fetch();
- }
- },
-
- updateValues: function() {
- var notification;
- if (this.model.changedAttributes()) {
- notification = FauxtonAPI.addNotification({
- msg: "Document saved successfully.",
- type: "success",
- clear: true
- });
- this.editor.setValue(this.model.prettyJSON());
- }
- },
-
- updateReduce: function(event) {
- var $ele = $("#reduce-function-selector");
- var $reduceContainer = $(".control-group.reduce-function");
- if ($ele.val() == "CUSTOM") {
- this.createReduceEditor();
- this.reduceEditor.setValue(this.langTemplates.javascript.reduce);
- $reduceContainer.show();
- } else {
- $reduceContainer.hide();
- }
- },
-
- deleteView: function (event) {
- event.preventDefault();
-
- if (this.newView) { return alert('Cannot delete a new view.'); }
- if (!confirm('Are you sure you want to delete this view?')) {return;}
-
- var that = this,
- promise,
- viewName = this.$('#index-name').val(),
- ddocName = this.$('#ddoc :selected').val(),
- ddoc = this.getCurrentDesignDoc();
-
- ddoc.removeDdocView(viewName);
-
- if (ddoc.hasViews()) {
- promise = ddoc.save();
- } else {
- promise = ddoc.destroy();
- }
-
- promise.then(function () {
- FauxtonAPI.navigate('/database/' + that.database.safeID() + '/_all_docs?limit=' + Databases.DocLimit);
- FauxtonAPI.triggerRouteEvent('reloadDesignDocs');
- });
- },
-
- saveView: function(event) {
- var json, notification,
- that = this;
-
- if (event) { event.preventDefault();}
-
- $('#dashboard-content').scrollTop(0); //scroll up
-
- if (this.hasValidCode() && this.$('#new-ddoc:visible').val() !=="") {
- var mapVal = this.mapEditor.getValue(),
- reduceVal = this.reduceVal(),
- viewName = this.$('#index-name').val(),
- ddoc = this.getCurrentDesignDoc(),
- ddocName = ddoc.id,
- viewNameChange = false;
-
- if (this.viewName !== viewName) {
- ddoc.removeDdocView(this.viewName);
- this.viewName = viewName;
- viewNameChange = true;
- }
-
- notification = FauxtonAPI.addNotification({
- msg: "Saving document.",
- selector: "#define-view .errors-container",
- clear: true
- });
-
- ddoc.setDdocView(viewName, mapVal, reduceVal);
-
- ddoc.save().then(function () {
- that.ddocs.add(ddoc);
-
- that.mapEditor.editSaved();
- that.reduceEditor && that.reduceEditor.editSaved();
-
-
- FauxtonAPI.addNotification({
- msg: "View has been saved.",
- type: "success",
- selector: "#define-view .errors-container",
- clear: true
- });
-
- if (that.newView || viewNameChange) {
- var fragment = '/database/' + that.database.safeID() +'/' + ddoc.safeID() + '/_view/' + app.utils.safeURLName(viewName);
-
- FauxtonAPI.navigate(fragment, {trigger: false});
- that.newView = false;
- that.ddocID = ddoc.safeID();
- that.viewName = viewName;
- that.ddocInfo = ddoc;
- that.showIndex = true;
- that.render();
- FauxtonAPI.triggerRouteEvent('reloadDesignDocs', {
- selectedTab: app.utils.removeSpecialCharacters(ddocName.replace(/_design\//,'')) + '_' + app.utils.removeSpecialCharacters(viewName)
- });
- }
-
- if (that.reduceFunStr !== reduceVal) {
- that.reduceFunStr = reduceVal;
- that.advancedOptions.renderOnUpdatehasReduce(that.hasReduce());
- }
-
- FauxtonAPI.triggerRouteEvent('updateAllDocs', {ddoc: ddocName, view: viewName});
-
- }, function(xhr) {
- var responseText = JSON.parse(xhr.responseText).reason;
- notification = FauxtonAPI.addNotification({
- msg: "Save failed: " + responseText,
- type: "error",
- clear: true
- });
- });
- } else {
- var errormessage = (this.$('#new-ddoc:visible').val() ==="")?"Enter a design doc name":"Please fix the Javascript errors and try again.";
- notification = FauxtonAPI.addNotification({
- msg: errormessage,
- type: "error",
- selector: "#define-view .errors-container",
- clear: true
- });
- }
- },
-
- updateView: function(event, paramInfo) {
- event.preventDefault();
-
- if (this.newView) { return alert('Please save this new view before querying it.'); }
-
- var errorParams = paramInfo.errorParams,
- params = paramInfo.params;
-
- if (_.any(errorParams)) {
- _.map(errorParams, function(param) {
-
- // TODO: Where to add this error?
- // bootstrap wants the error on a control-group div, but we're not using that
- //$('form.view-query-update input[name='+param+'], form.view-query-update select[name='+param+']').addClass('error');
- return FauxtonAPI.addNotification({
- msg: "JSON Parse Error on field: "+param.name,
- type: "error",
- selector: ".advanced-options .errors-container",
- clear: true
- });
- });
- FauxtonAPI.addNotification({
- msg: "Make sure that strings are properly quoted and any other values are valid JSON structures",
- type: "warning",
- selector: ".advanced-options .errors-container",
- clear: true
- });
-
- return false;
- }
-
- var fragment = window.location.hash.replace(/\?.*$/, '');
- if (!_.isEmpty(params)) {
- fragment = fragment + '?' + $.param(params);
- }
-
- FauxtonAPI.navigate(fragment, {trigger: false});
- FauxtonAPI.triggerRouteEvent('updateAllDocs', {ddoc: this.ddocID, view: this.viewName});
- },
-
-
- previewView: function(event, paramsInfo) {
- event.preventDefault();
- var that = this,
- mapVal = this.mapVal(),
- reduceVal = this.reduceVal(),
- paramsArr = [];
-
- if (paramsInfo && paramsInfo.params) {
- paramsArr = paramsInfo.params;
- }
-
- var params = _.reduce(paramsArr, function (params, param) {
- params[param.name] = param.value;
- return params;
- }, {reduce: false});
-
- FauxtonAPI.addNotification({
- msg: "<strong>Warning!</strong> Preview executes the Map/Reduce functions in your browser, and may behave differently from CouchDB.",
- type: "warning",
- selector: ".advanced-options .errors-container",
- fade: true,
- escape: false // beware of possible XSS when the message changes
- });
-
- var promise = FauxtonAPI.Deferred();
-
- if (!this.database.allDocs || this.database.allDocs.params.include_docs !== true) {
- this.database.buildAllDocs({limit: Databases.DocLimit.toString(), include_docs: true});
- promise = this.database.allDocs.fetch();
- } else {
- promise.resolve();
- }
-
- promise.then(function () {
- params.docs = that.database.allDocs.map(function (model) { return model.get('doc');});
- var queryPromise = pouchdb.runViewQuery({map: mapVal, reduce: reduceVal}, params);
- queryPromise.then(function (results) {
- FauxtonAPI.triggerRouteEvent('updatePreviewDocs', {rows: results.rows, ddoc: that.getCurrentDesignDoc().id, view: that.viewName});
- });
- });
- },
-
- getCurrentDesignDoc: function () {
- return this.designDocSelector.getCurrentDesignDoc();
- },
-
- isCustomReduceEnabled: function() {
- return $("#reduce-function-selector").val() == "CUSTOM";
- },
-
- mapVal: function () {
- if (this.mapEditor) {
- return this.mapEditor.getValue();
- }
-
- return this.$('#map-function').text();
- },
-
- reduceVal: function() {
- var reduceOption = this.$('#reduce-function-selector :selected').val(),
- reduceVal = "";
-
- if (reduceOption === 'CUSTOM') {
- if (!this.reduceEditor) { this.createReduceEditor(); }
- reduceVal = this.reduceEditor.getValue();
- } else if ( reduceOption !== 'NONE') {
- reduceVal = reduceOption;
- }
-
- return reduceVal;
- },
-
-
- hasValidCode: function() {
- return _.every(["mapEditor", "reduceEditor"], function(editorName) {
- var editor = this[editorName];
- if (editorName === "reduceEditor" && ! this.isCustomReduceEnabled()) {
- return true;
- }
- return editor.hadValidCode();
- }, this);
- },
-
- 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'));
-
- if ($targetTab.attr('id') !== $previousTab.attr('id')) {
- $previousTab.removeAttr('style');
- }
-
- if ($targetId === 'index-nav') {
- if (this.newView) { return; }
- var that = this;
- $('#dashboard-content').scrollTop(0); //scroll up
- $targetTab.toggle('slow', function(){
- that.showEditors();
- });
- } else {
- $targetTab.toggle('slow');
- }
- },
-
- serialize: function() {
- return {
- ddocs: this.ddocs,
- ddoc: this.model,
- ddocName: this.model.id,
- viewName: this.viewName,
- reduceFunStr: this.reduceFunStr,
- isCustomReduce: this.hasCustomReduce(),
- newView: this.newView,
- langTemplates: this.langTemplates.javascript
- };
- },
-
- hasCustomReduce: function() {
- return this.reduceFunStr && ! _.contains(this.builtinReduces, this.reduceFunStr);
- },
-
- hasReduce: function () {
- return this.reduceFunStr || false;
- },
-
- createReduceEditor: function () {
- if (this.reduceEditor) {
- this.reduceEditor.remove();
- }
-
- this.reduceEditor = new Components.Editor({
- editorId: "reduce-function",
- mode: "javascript",
- couchJSHINT: true
- });
- this.reduceEditor.render();
-
- if (this.reduceEditor.getLines() === 1){
- this.$('.beautify_reduce').removeClass("hide");
- $('.beautify-tooltip').tooltip();
- }
- },
- beforeRender: function () {
-
- if (this.newView) {
- this.reduceFunStr = '';
- if (this.ddocs.length === 0) {
- this.model = new Documents.Doc(null, {database: this.database});
- } else {
- this.model = this.ddocs.first().dDocModel();
- }
- this.ddocID = this.model.id;
- } else {
- var ddocDecode = decodeURIComponent(this.ddocID);
- this.model = this.ddocs.get(this.ddocID).dDocModel();
- this.reduceFunStr = this.model.viewHasReduce(this.viewName);
- }
-
- var viewFilters = FauxtonAPI.getExtensions('sidebar:viewFilters'),
- filteredModels = this.ddocs.models,
- designDocs = this.ddocs.clone();
-
- if (!_.isEmpty(viewFilters)) {
- _.each(viewFilters, function (filter) {
- filteredModels = _.filter(filteredModels, filter);
- });
- designDocs.reset(filteredModels, {silent: true});
- }
-
- this.designDocSelector = this.setView('.design-doc-group', new Views.DesignDocSelector({
- collection: designDocs,
- ddocName: this.currentDdoc || this.model.id,
- database: this.database
- }));
-
- if (!this.newView) {
- this.eventer = _.extend({}, Backbone.Events);
-
- this.advancedOptions = this.insertView('#query', new QueryOptions.AdvancedOptions({
- updateViewFn: this.updateView,
- previewFn: this.previewView,
- database: this.database,
- viewName: this.viewName,
- ddocName: this.model.id,
- hasReduce: this.hasReduce(),
- eventer: this.eventer,
- showStale: true
- }));
- }
-
- },
-
- afterRender: function() {
-
- if (this.params && !this.newView) {
- this.advancedOptions.updateFromParams(this.params);
- }
-
- this.designDocSelector.updateDesignDoc();
- if (this.newView || this.showIndex) {
- this.showEditors();
- this.showIndex = false;
- } else {
- this.$('#index').hide();
- this.$('#index-nav').parent().removeClass('active');
- }
-
- },
-
- showEditors: function () {
- this.mapEditor = new Components.Editor({
- editorId: "map-function",
- mode: "javascript",
- couchJSHINT: true
- });
- this.mapEditor.render();
-
- if (this.hasCustomReduce()) {
- this.createReduceEditor();
- } else {
- $(".control-group.reduce-function").hide();
- }
-
- if (this.newView) {
- this.mapEditor.setValue(this.langTemplates[this.defaultLang].map);
- //Use a built in view by default
- //this.reduceEditor.setValue(this.langTemplates[this.defaultLang].reduce);
- }
-
- this.mapEditor.editSaved();
- this.reduceEditor && this.reduceEditor.editSaved();
-
- if (this.mapEditor.getLines() === 1){
- this.$('.beautify_map').removeClass("hide");
- $('.beautify-tooltip').tooltip();
- }
- },
- beautifyCode: function(e){
- e.preventDefault();
- var targetEditor = $(e.currentTarget).hasClass('beautify_reduce')?this.reduceEditor:this.mapEditor;
- var beautifiedCode = beautify(targetEditor.getValue());
- targetEditor.setValue(beautifiedCode);
- },
- cleanup: function () {
- this.mapEditor && this.mapEditor.remove();
- this.reduceEditor && this.reduceEditor.remove();
- }
- });
-
- Views.DesignDocSelector = FauxtonAPI.View.extend({
- template: "addons/documents/templates/design_doc_selector",
-
- events: {
- "change select#ddoc": "updateDesignDoc"
- },
-
- initialize: function (options) {
- this.ddocName = options.ddocName;
- this.database = options.database;
- this.listenTo(this.collection, 'add', this.ddocAdded);
- this.DocModel = options.DocModel || Documents.Doc;
- },
-
- ddocAdded: function (ddoc) {
- this.ddocName = ddoc.id;
- this.render();
- },
-
- serialize: function () {
- return {
- ddocName: this.ddocName,
- ddocs: this.collection
- };
- },
-
- updateDesignDoc: function () {
- if (this.newDesignDoc()) {
- this.$('#new-ddoc-section').show();
- } else {
- this.$('#new-ddoc-section').hide();
- }
- },
-
- newDesignDoc: function () {
-
- return this.$('#ddoc').val() === 'new-doc';
- },
-
- newDocValidation: function(){
- return this.newDesignDoc() && this.$('#new-ddoc').val()==="";
- },
- getCurrentDesignDoc: function () {
- if (this.newDesignDoc()) {
- var doc = {
- _id: '_design/' + this.$('#new-ddoc').val(),
- views: {},
- language: "javascript"
- };
- var ddoc = new this.DocModel(doc, {database: this.database});
- //this.collection.add(ddoc);
- return ddoc;
- } else if ( !this.newDesignDoc() ) {
- var ddocName = this.$('#ddoc').val();
- return this.collection.find(function (ddoc) {
- return ddoc.id === ddocName;
- }).dDocModel();
- }
- }
- });
-
- return Views;
-});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/indexes/index-components.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/index-components.js b/app/addons/indexes/index-components.js
index ffb22a0..1ec34e2 100644
--- a/app/addons/indexes/index-components.js
+++ b/app/addons/indexes/index-components.js
@@ -23,6 +23,8 @@ define([
],
function(app, FauxtonAPI) {
+ var Components = {};
+ return Components;
});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/indexes/routes-filter.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/routes-filter.js b/app/addons/indexes/routes-filter.js
new file mode 100644
index 0000000..492b014
--- /dev/null
+++ b/app/addons/indexes/routes-filter.js
@@ -0,0 +1,47 @@
+// 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.
+define([
+ "app",
+ "api",
+ "addons/databases/base",
+ "addons/indexes/views",
+ "addons/documents/views",
+ "addons/indexes/resources"
+],
+
+function (app, FauxtonAPI, Databases, Views, Documents, Resources) {
+
+ var FilterIndexes = FauxtonAPI.RouteObject.extend({
+ layout: "two_pane",
+ routes: {
+ "database/:database/_design/:ddoc/_filters/:fn": {
+ route: "tempFn",
+ roles: ['_admin']
+ },
+ "database/:database/new_filter": "newFilterEditor",
+ "database/:database/new_filter/:designDoc": "newFilterEditor"
+ },
+ newFilterEditor: function(){
+ return false;
+ },
+ tempFn: function(databaseName, ddoc, fn){
+ this.setView("#dashboard-upper-content", new Documents.Views.temp({}));
+ this.crumbs = function () {
+ return [
+ {"name": this.data.database.id, "link": Databases.databaseUrl(this.data.database)},
+ ];
+ };
+ }
+ });
+
+ return FilterIndexes;
+});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/indexes/routes-list.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/routes-list.js b/app/addons/indexes/routes-list.js
new file mode 100644
index 0000000..10141b7
--- /dev/null
+++ b/app/addons/indexes/routes-list.js
@@ -0,0 +1,47 @@
+// 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.
+define([
+ "app",
+ "api",
+ "addons/databases/base",
+ "addons/indexes/views",
+ "addons/documents/views",
+ "addons/indexes/resources"
+],
+
+function (app, FauxtonAPI, Databases, Views, Documents, Resources) {
+
+ var ListIndexes = FauxtonAPI.RouteObject.extend({
+ layout: "two_pane",
+ routes: {
+ "database/:database/_design/:ddoc/_lists/:fn": {
+ route: "tempFn",
+ roles: ['_admin']
+ },
+ "database/:database/new_lists": "newListsEditor",
+ "database/:database/new_lists/:designDoc": "newListsEditor"
+ },
+ newListsEditor: function(){
+ return false;
+ },
+ tempFn: function(databaseName, ddoc, fn){
+ this.setView("#dashboard-upper-content", new Documents.Views.temp({}));
+ this.crumbs = function () {
+ return [
+ {"name": this.data.database.id, "link": Databases.databaseUrl(this.data.database)},
+ ];
+ };
+ }
+ });
+
+ return ListIndexes;
+});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/indexes/routes-show.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/routes-show.js b/app/addons/indexes/routes-show.js
new file mode 100644
index 0000000..1861fd1
--- /dev/null
+++ b/app/addons/indexes/routes-show.js
@@ -0,0 +1,47 @@
+// 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.
+define([
+ "app",
+ "api",
+ "addons/databases/base",
+ "addons/indexes/views",
+ "addons/documents/views",
+ "addons/indexes/resources"
+],
+
+function (app, FauxtonAPI, Databases, Views, Documents, Resources) {
+
+ var ShowIndexes = FauxtonAPI.RouteObject.extend({
+ layout: "two_pane",
+ routes: {
+ "database/:database/_design/:ddoc/_show/:fn": {
+ route: "tempFn",
+ roles: ['_admin']
+ },
+ "database/:database/new_show": "newShowEditor",
+ "database/:database/new_show/:designDoc": "newShowEditor"
+ },
+ newShowEditor: function(){
+ return false;
+ },
+ tempFn: function(databaseName, ddoc, fn){
+ this.setView("#dashboard-upper-content", new Documents.Views.temp({}));
+ this.crumbs = function () {
+ return [
+ {"name": this.data.database.id, "link": Databases.databaseUrl(this.data.database)},
+ ];
+ };
+ }
+ });
+
+ return ShowIndexes;
+});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/indexes/routes-viewindexes.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/routes-viewindexes.js b/app/addons/indexes/routes-viewindexes.js
new file mode 100644
index 0000000..9577cbb
--- /dev/null
+++ b/app/addons/indexes/routes-viewindexes.js
@@ -0,0 +1,204 @@
+// 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.
+define([
+ "app",
+ "api",
+ "addons/databases/base",
+ "addons/indexes/views",
+ "addons/documents/views",
+ "addons/indexes/resources"
+],
+
+function (app, FauxtonAPI, Databases, Views, Documents, Resources) {
+
+ var ViewIndexes = FauxtonAPI.RouteObject.extend({
+ layout: "two_pane",
+ routes: {
+ "database/:database/_design/:ddoc/_view/:view": {
+ route: "viewFn",
+ roles: ['_admin']
+ },
+ "database/:database/new_view": "newViewEditor",
+ "database/:database/new_view/:designDoc": "newViewEditor"
+ },
+ initialize: function (route, masterLayout, options) {
+ this.databaseName = options[0];
+
+ this.data = {
+ database: new Databases.Model({id:this.databaseName})
+ };
+
+ this.data.designDocs = new Documents.AllDocs(null, {
+ database: this.data.database,
+ paging: {
+ pageSize: 500
+ },
+ params: {
+ startkey: '_design',
+ endkey: '_design1',
+ include_docs: true,
+ limit: 500
+ }
+ });
+ },
+
+
+ createViewDocumentsView: function (options) {
+ return this.setView("#right-content", new Documents.Views.AllDocsList({
+ database: options.database,
+ collection: options.indexedDocs,
+ nestedView: Documents.Views.Row,
+ viewList: true,
+ ddocInfo: this.ddocInfo(options.designDoc, options.designDocs, options.view),
+ docParams: options.docParams,
+ params: options.urlParams
+ }));
+ },
+
+ ddocInfo: function (designDoc, designDocs, view) {
+ return {
+ id: "_design/" + designDoc,
+ currView: view,
+ designDocs: designDocs
+ };
+ },
+
+ createParams: function (options) {
+ var urlParams = app.getParams(options);
+ var params = Documents.QueryParams.parse(urlParams);
+
+ return {
+ urlParams: urlParams,
+ docParams: _.extend(params, {limit: this.getDocPerPageLimit(params, 20)})
+ };
+ },
+
+ getDocPerPageLimit: function (urlParams, perPage) {
+ var storedPerPage = perPage;
+
+ if (window.localStorage) {
+ storedPerPage = window.localStorage.getItem('fauxton:perpage');
+
+ if (!storedPerPage) {
+ this.setDocPerPageLimit(perPage);
+ storedPerPage = perPage;
+ } else {
+ storedPerPage = parseInt(storedPerPage, 10);
+ }
+ }
+
+ if (!urlParams.limit || urlParams.limit > storedPerPage) {
+ return parseInt(storedPerPage, 10);
+ } else {
+ return parseInt(urlParams.limit, 10);
+ }
+ },
+
+ establish: function () {
+ return this.data.designDocs.fetch({reset: true});
+ },
+
+ updateAllDocsFromPreview: function (event) {
+ var view = event.view,
+ rows = event.rows,
+ ddoc = event.ddoc;
+
+ this.data.indexedDocs = new Documents.PouchIndexCollection(null, {
+ database: this.data.database,
+ design: ddoc,
+ view: view,
+ rows: rows
+ });
+
+ // this.documentsView = this.setView("#dashboard-lower-content", new Documents.Views.AllDocsList({
+ // database: this.data.database,
+ // collection: this.data.indexedDocs,
+ // nestedView: Documents.Views.Row,
+ // viewList: true
+ // }));
+ },
+
+ newViewEditor: function (database, designDoc) {
+ var params = app.getParams();
+
+ this.toolsView && this.toolsView.remove();
+ this.documentsView && this.documentsView.remove();
+
+ this.viewEditor = this.setView("#left-content", new Views.ViewEditor({
+ currentddoc: "_design/"+designDoc || "",
+ ddocs: this.data.designDocs,
+ params: params,
+ database: this.data.database,
+ newView: true
+ }));
+
+ this.sidebar.setSelectedTab('new-view');
+ this.crumbs = function () {
+ return [
+ {"name": this.data.database.id, "link": Databases.databaseUrl(this.data.database)},
+ ];
+ };
+ },
+
+ viewFn: function (databaseName, ddoc, view) {
+ var params = this.createParams(),
+ urlParams = params.urlParams,
+ docParams = params.docParams,
+ decodeDdoc = decodeURIComponent(ddoc);
+
+ view = view.replace(/\?.*$/,'');
+
+ this.data.indexedDocs = new Documents.IndexCollection(null, {
+ database: this.data.database,
+ design: decodeDdoc,
+ view: view,
+ params: docParams,
+ paging: {
+ pageSize: this.getDocPerPageLimit(urlParams, parseInt(docParams.limit, 10))
+ }
+ });
+
+ this.viewEditor = this.setView("#left-content", new Views.ViewEditor({
+ model: this.data.database,
+ ddocs: this.data.designDocs,
+ viewName: view,
+ params: urlParams,
+ newView: false,
+ database: this.data.database,
+ ddocInfo: this.ddocInfo(decodeDdoc, this.data.designDocs, view)
+ }));
+
+ this.toolsView && this.toolsView.remove();
+
+ this.documentsView = this.createViewDocumentsView({
+ designDoc: decodeDdoc,
+ docParams: docParams,
+ urlParams: urlParams,
+ database: this.data.database,
+ indexedDocs: this.data.indexedDocs,
+ designDocs: this.data.designDocs,
+ view: view
+ });
+
+
+ this.crumbs = function () {
+ return [
+ {"name": this.data.database.id, "link": Databases.databaseUrl(this.data.database)},
+ ];
+ };
+
+ this.apiUrl = [this.data.indexedDocs.urlRef("apiurl", urlParams), "docs"];
+ }
+ });
+
+ return ViewIndexes;
+});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/indexes/routes.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/routes.js b/app/addons/indexes/routes.js
index 4c7515d..52771d6 100644
--- a/app/addons/indexes/routes.js
+++ b/app/addons/indexes/routes.js
@@ -12,22 +12,14 @@
define([
"app",
"api",
- "addons/indexes/resources",
- "addons/indexes/views"
+ "addons/indexes/views",
+ "addons/indexes/routes-viewindexes",
+ "addons/indexes/routes-filter",
+ "addons/indexes/routes-show",
+ "addons/indexes/routes-list",
],
-function (app, FauxtonAPI, Resources, Views) {
-
- var ViewIndexes = FauxtonAPI.RouteObject.extend({});
-
- var FilterIndexes = FauxtonAPI.RouteObject.extend({});
-
- var ShowIndexes = FauxtonAPI.RouteObject.extend({});
-
- var ListIndexes = FauxtonAPI.RouteObject.extend({});
-
-
- Resources.RouteObjects = [ViewIndexes, FilterIndexes, ShowIndexes, ListIndexes];
-
- return Resources;
+function (app, FauxtonAPI, Views, ViewIndex, Filter, Show, List) {
+ Views.RouteObjects = [ViewIndex, Filter, Show, List];
+ return Views;
});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/indexes/templates/design_doc_selector.html
----------------------------------------------------------------------
diff --git a/app/addons/indexes/templates/design_doc_selector.html b/app/addons/indexes/templates/design_doc_selector.html
new file mode 100644
index 0000000..828b5a5
--- /dev/null
+++ b/app/addons/indexes/templates/design_doc_selector.html
@@ -0,0 +1,38 @@
+<!--
+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.
+-->
+<div class="span3">
+ <label for="ddoc">Save to Design Document <a class="help-link" href="<%-getDocUrl('design_doc')%>" target="_blank"><i class="icon-question-sign"></i></a></label>
+ <select id="ddoc">
+ <optgroup label="Select a document">
+ <option value="new-doc">New document</option>
+
+ <% ddocs.each(function(ddoc) { %>
+ <%= ddoc.id %>
+ <%= ddocName %>
+ <% if (ddoc.id === ddocName) { %>
+ <option selected="selected" value="<%- ddoc.id %>"><%- ddoc.id %></option>
+ <% } else { %>
+ <option value="<%- ddoc.id %>"><%- ddoc.id %></option>
+ <% } %>
+ <% }); %>
+ </optgroup>
+ </select>
+</div>
+
+<div id="new-ddoc-section" class="span5" style="display:none">
+ <label class="control-label" for="new-ddoc"> _design/ </label>
+ <div class="controls">
+ <input type="text" id="new-ddoc" placeholder="newDesignDoc" />
+ </div>
+</div>
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/indexes/templates/view_editor.html
----------------------------------------------------------------------
diff --git a/app/addons/indexes/templates/view_editor.html b/app/addons/indexes/templates/view_editor.html
new file mode 100644
index 0000000..afc7454
--- /dev/null
+++ b/app/addons/indexes/templates/view_editor.html
@@ -0,0 +1,70 @@
+<!--
+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.
+-->
+<div class="all-docs-list errors-container"></div>
+<div id="define-view" class="ddoc-alert well">
+ <div class="errors-container"></div>
+ <form class="form-horizontal view-query-save">
+
+ <div class="control-group design-doc-group">
+ </div>
+
+ <div class="control-group">
+ <label for="index-name">Index name <a class="help-link" href="<%-getDocUrl('view_functions')%>" target="_blank"><i class="icon-question-sign"></i></a></label>
+ <input type="text" id="index-name" value="<%- viewName %>" placeholder="Index name" />
+ </div>
+
+
+ <div class="control-group">
+ <label for="map-function">Map function <a class="help-link" href="<%-getDocUrl('map_functions')%>" target="_blank"><i class="icon-question-sign"></i></a></label>
+ <% if (newView) { %>
+ <div class="js-editor" id="map-function"><%= langTemplates.map %></div>
+ <% } else { %>
+ <div class="js-editor" id="map-function"><%- ddoc.get('views')[viewName].map %></div>
+ <button class="beautify beautify_map btn btn-primary btn-large hide beautify-tooltip" type="button" data-toggle="tooltip" title="Reformat your minified code to make edits to it.">beautify this code</button>
+ <% } %>
+ </div>
+
+
+ <div class="control-group">
+ <label for="reduce-function-selector">Reduce (optional) <a class="help-link" href="<%-getDocUrl('reduce_functions')%>" target="_blank"><i class="icon-question-sign"></i></a></label>
+
+ <select id="reduce-function-selector">
+ <option value="" <%- !reduceFunStr ? 'selected="selected"' : '' %>>None</option>
+ <% _.each(["_sum", "_count", "_stats"], function(reduce) { %>
+ <option value="<%- reduce %>" <% if (reduce == reduceFunStr) { %>selected<% } %>><%= reduce %></option>
+ <% }) %>
+ <option value="CUSTOM" <% if (isCustomReduce) { %>selected<% } %>>Custom Reduce function</option>
+ </select>
+ </div>
+
+ <div class="control-group reduce-function">
+ <label for="reduce-function">Custom Reduce function</label>
+ <% if (newView) { %>
+ <div class="js-editor" id="reduce-function"><%- langTemplates.reduce %></div>
+ <% } else { %>
+ <div class="js-editor" id="reduce-function"><%- ddoc.get('views')[viewName].reduce %></div>
+ <button class="beautify beautify_reduce btn btn-primary btn-large hide beautify-tooltip" type="button" data-toggle="tooltip" title="Reformat your minified code to make edits to it.">beautify this code</button>
+ <% } %>
+ </div>
+
+ <div class="control-group">
+ <button class="btn btn-success save"><i class="icon fonticon-ok-circled"></i> Save & Build Index</button>
+ <% if (!newView) { %>
+ <button class="btn btn-danger delete"><i class="icon fonticon-cancel-circled"></i> Delete</button>
+ <% } %>
+ </div>
+ <div class="clearfix"></div>
+ </form>
+</div>
+
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/app/addons/indexes/views.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/views.js b/app/addons/indexes/views.js
index e8383cf..42a9066 100644
--- a/app/addons/indexes/views.js
+++ b/app/addons/indexes/views.js
@@ -9,13 +9,566 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
+
define([
- "app",
- "api"
+ "app",
+
+ "api",
+ "addons/fauxton/components",
+
+ "addons/documents/resources",
+ "addons/databases/resources",
+ "addons/pouchdb/base",
+ //views
+ "addons/documents/views-advancedopts",
+ // Libs
+ "addons/fauxton/resizeColumns",
+
+ // Plugins
+ "plugins/beautify",
+ "plugins/prettify"
],
-function (app, FauxtonAPI) {
+function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
+ QueryOptions, resizeColumns, beautify, prettify) {
+
var Views = {};
+ Views.ViewEditor = FauxtonAPI.View.extend({
+ template: "addons/indexes/templates/view_editor",
+ builtinReduces: ['_sum', '_count', '_stats'],
+
+ events: {
+ "click button.save": "saveView",
+ "click button.delete": "deleteView",
+ "change select#reduce-function-selector": "updateReduce",
+ "click button.preview": "previewView",
+ "click #db-views-tabs-nav": 'toggleIndexNav',
+ "click .beautify_map": "beautifyCode",
+ "click .beautify_reduce": "beautifyCode",
+ "click #query-options-wrapper": 'toggleIndexNav'
+ },
+
+ langTemplates: {
+ "javascript": {
+ map: "function(doc) {\n emit(doc._id, 1);\n}",
+ reduce: "function(keys, values, rereduce){\n if (rereduce){\n return sum(values);\n } else {\n return values.length;\n }\n}"
+ }
+ },
+
+ defaultLang: "javascript",
+
+ initialize: function(options) {
+ this.newView = options.newView || false;
+ this.ddocs = options.ddocs;
+ this.params = options.params;
+ this.database = options.database;
+ this.currentDdoc = options.currentddoc;
+ if (this.newView) {
+ this.viewName = 'newView';
+ } else {
+ this.ddocID = options.ddocInfo.id;
+ this.viewName = options.viewName;
+ this.ddocInfo = new Documents.DdocInfo({_id: this.ddocID},{database: this.database});
+ }
+
+ this.showIndex = false;
+ _.bindAll(this);
+ },
+
+ establish: function () {
+ if (this.ddocInfo) {
+ return this.ddocInfo.fetch();
+ }
+ },
+
+ updateValues: function() {
+ var notification;
+ if (this.model.changedAttributes()) {
+ notification = FauxtonAPI.addNotification({
+ msg: "Document saved successfully.",
+ type: "success",
+ clear: true
+ });
+ this.editor.setValue(this.model.prettyJSON());
+ }
+ },
+
+ updateReduce: function(event) {
+ var $ele = $("#reduce-function-selector");
+ var $reduceContainer = $(".control-group.reduce-function");
+ if ($ele.val() == "CUSTOM") {
+ this.createReduceEditor();
+ this.reduceEditor.setValue(this.langTemplates.javascript.reduce);
+ $reduceContainer.show();
+ } else {
+ $reduceContainer.hide();
+ }
+ },
+
+ deleteView: function (event) {
+ event.preventDefault();
+
+ if (this.newView) { return alert('Cannot delete a new view.'); }
+ if (!confirm('Are you sure you want to delete this view?')) {return;}
+
+ var that = this,
+ promise,
+ viewName = this.$('#index-name').val(),
+ ddocName = this.$('#ddoc :selected').val(),
+ ddoc = this.getCurrentDesignDoc();
+
+ ddoc.removeDdocView(viewName);
+
+ if (ddoc.hasViews()) {
+ promise = ddoc.save();
+ } else {
+ promise = ddoc.destroy();
+ }
+
+ promise.then(function () {
+ FauxtonAPI.navigate('/database/' + that.database.safeID() + '/_all_docs?limit=' + Databases.DocLimit);
+ FauxtonAPI.triggerRouteEvent('reloadDesignDocs');
+ });
+ },
+
+ saveView: function(event) {
+ var json, notification,
+ that = this;
+
+ if (event) { event.preventDefault();}
+
+ $('#dashboard-content').scrollTop(0); //scroll up
+
+ if (this.hasValidCode() && this.$('#new-ddoc:visible').val() !=="") {
+ var mapVal = this.mapEditor.getValue(),
+ reduceVal = this.reduceVal(),
+ viewName = this.$('#index-name').val(),
+ ddoc = this.getCurrentDesignDoc(),
+ ddocName = ddoc.id,
+ viewNameChange = false;
+
+ if (this.viewName !== viewName) {
+ ddoc.removeDdocView(this.viewName);
+ this.viewName = viewName;
+ viewNameChange = true;
+ }
+
+ notification = FauxtonAPI.addNotification({
+ msg: "Saving document.",
+ selector: "#define-view .errors-container",
+ clear: true
+ });
+
+ ddoc.setDdocView(viewName, mapVal, reduceVal);
+
+ ddoc.save().then(function () {
+ that.ddocs.add(ddoc);
+
+ that.mapEditor.editSaved();
+ that.reduceEditor && that.reduceEditor.editSaved();
+
+
+ FauxtonAPI.addNotification({
+ msg: "View has been saved.",
+ type: "success",
+ selector: "#define-view .errors-container",
+ clear: true
+ });
+
+ if (that.newView || viewNameChange) {
+ var fragment = '/database/' + that.database.safeID() +'/' + ddoc.safeID() + '/_view/' + app.utils.safeURLName(viewName);
+
+ FauxtonAPI.navigate(fragment, {trigger: false});
+ that.newView = false;
+ that.ddocID = ddoc.safeID();
+ that.viewName = viewName;
+ that.ddocInfo = ddoc;
+ that.showIndex = true;
+ that.render();
+ FauxtonAPI.triggerRouteEvent('reloadDesignDocs', {
+ selectedTab: app.utils.removeSpecialCharacters(ddocName.replace(/_design\//,'')) + '_' + app.utils.removeSpecialCharacters(viewName)
+ });
+ }
+
+ if (that.reduceFunStr !== reduceVal) {
+ that.reduceFunStr = reduceVal;
+ that.advancedOptions.renderOnUpdatehasReduce(that.hasReduce());
+ }
+
+ FauxtonAPI.triggerRouteEvent('updateAllDocs', {ddoc: ddocName, view: viewName});
+
+ }, function(xhr) {
+ var responseText = JSON.parse(xhr.responseText).reason;
+ notification = FauxtonAPI.addNotification({
+ msg: "Save failed: " + responseText,
+ type: "error",
+ clear: true
+ });
+ });
+ } else {
+ var errormessage = (this.$('#new-ddoc:visible').val() ==="")?"Enter a design doc name":"Please fix the Javascript errors and try again.";
+ notification = FauxtonAPI.addNotification({
+ msg: errormessage,
+ type: "error",
+ selector: "#define-view .errors-container",
+ clear: true
+ });
+ }
+ },
+
+ updateView: function(event, paramInfo) {
+ event.preventDefault();
+
+ if (this.newView) { return alert('Please save this new view before querying it.'); }
+
+ var errorParams = paramInfo.errorParams,
+ params = paramInfo.params;
+
+ if (_.any(errorParams)) {
+ _.map(errorParams, function(param) {
+
+ // TODO: Where to add this error?
+ // bootstrap wants the error on a control-group div, but we're not using that
+ //$('form.view-query-update input[name='+param+'], form.view-query-update select[name='+param+']').addClass('error');
+ return FauxtonAPI.addNotification({
+ msg: "JSON Parse Error on field: "+param.name,
+ type: "error",
+ selector: ".advanced-options .errors-container",
+ clear: true
+ });
+ });
+ FauxtonAPI.addNotification({
+ msg: "Make sure that strings are properly quoted and any other values are valid JSON structures",
+ type: "warning",
+ selector: ".advanced-options .errors-container",
+ clear: true
+ });
+
+ return false;
+ }
+
+ var fragment = window.location.hash.replace(/\?.*$/, '');
+ if (!_.isEmpty(params)) {
+ fragment = fragment + '?' + $.param(params);
+ }
+
+ FauxtonAPI.navigate(fragment, {trigger: false});
+ FauxtonAPI.triggerRouteEvent('updateAllDocs', {ddoc: this.ddocID, view: this.viewName});
+ },
+
+
+ previewView: function(event, paramsInfo) {
+ event.preventDefault();
+ var that = this,
+ mapVal = this.mapVal(),
+ reduceVal = this.reduceVal(),
+ paramsArr = [];
+
+ if (paramsInfo && paramsInfo.params) {
+ paramsArr = paramsInfo.params;
+ }
+
+ var params = _.reduce(paramsArr, function (params, param) {
+ params[param.name] = param.value;
+ return params;
+ }, {reduce: false});
+
+ FauxtonAPI.addNotification({
+ msg: "<strong>Warning!</strong> Preview executes the Map/Reduce functions in your browser, and may behave differently from CouchDB.",
+ type: "warning",
+ selector: ".advanced-options .errors-container",
+ fade: true,
+ escape: false // beware of possible XSS when the message changes
+ });
+
+ var promise = FauxtonAPI.Deferred();
+
+ if (!this.database.allDocs || this.database.allDocs.params.include_docs !== true) {
+ this.database.buildAllDocs({limit: Databases.DocLimit.toString(), include_docs: true});
+ promise = this.database.allDocs.fetch();
+ } else {
+ promise.resolve();
+ }
+
+ promise.then(function () {
+ params.docs = that.database.allDocs.map(function (model) { return model.get('doc');});
+ var queryPromise = pouchdb.runViewQuery({map: mapVal, reduce: reduceVal}, params);
+ queryPromise.then(function (results) {
+ FauxtonAPI.triggerRouteEvent('updatePreviewDocs', {rows: results.rows, ddoc: that.getCurrentDesignDoc().id, view: that.viewName});
+ });
+ });
+ },
+
+ getCurrentDesignDoc: function () {
+ return this.designDocSelector.getCurrentDesignDoc();
+ },
+
+ isCustomReduceEnabled: function() {
+ return $("#reduce-function-selector").val() == "CUSTOM";
+ },
+
+ mapVal: function () {
+ if (this.mapEditor) {
+ return this.mapEditor.getValue();
+ }
+
+ return this.$('#map-function').text();
+ },
+
+ reduceVal: function() {
+ var reduceOption = this.$('#reduce-function-selector :selected').val(),
+ reduceVal = "";
+
+ if (reduceOption === 'CUSTOM') {
+ if (!this.reduceEditor) { this.createReduceEditor(); }
+ reduceVal = this.reduceEditor.getValue();
+ } else if ( reduceOption !== 'NONE') {
+ reduceVal = reduceOption;
+ }
+
+ return reduceVal;
+ },
+
+
+ hasValidCode: function() {
+ return _.every(["mapEditor", "reduceEditor"], function(editorName) {
+ var editor = this[editorName];
+ if (editorName === "reduceEditor" && ! this.isCustomReduceEnabled()) {
+ return true;
+ }
+ return editor.hadValidCode();
+ }, this);
+ },
+
+ 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'));
+
+ if ($targetTab.attr('id') !== $previousTab.attr('id')) {
+ $previousTab.removeAttr('style');
+ }
+
+ if ($targetId === 'index-nav') {
+ if (this.newView) { return; }
+ var that = this;
+ $('#dashboard-content').scrollTop(0); //scroll up
+ $targetTab.toggle('slow', function(){
+ that.showEditors();
+ });
+ } else {
+ $targetTab.toggle('slow');
+ }
+ },
+
+ serialize: function() {
+ return {
+ ddocs: this.ddocs,
+ ddoc: this.model,
+ ddocName: this.model.id,
+ viewName: this.viewName,
+ reduceFunStr: this.reduceFunStr,
+ isCustomReduce: this.hasCustomReduce(),
+ newView: this.newView,
+ langTemplates: this.langTemplates.javascript
+ };
+ },
+
+ hasCustomReduce: function() {
+ return this.reduceFunStr && ! _.contains(this.builtinReduces, this.reduceFunStr);
+ },
+
+ hasReduce: function () {
+ return this.reduceFunStr || false;
+ },
+
+ createReduceEditor: function () {
+ if (this.reduceEditor) {
+ this.reduceEditor.remove();
+ }
+
+ this.reduceEditor = new Components.Editor({
+ editorId: "reduce-function",
+ mode: "javascript",
+ couchJSHINT: true
+ });
+ this.reduceEditor.render();
+
+ if (this.reduceEditor.getLines() === 1){
+ this.$('.beautify_reduce').removeClass("hide");
+ $('.beautify-tooltip').tooltip();
+ }
+ },
+ beforeRender: function () {
+
+ if (this.newView) {
+ this.reduceFunStr = '';
+ if (this.ddocs.length === 0) {
+ this.model = new Documents.Doc(null, {database: this.database});
+ } else {
+ this.model = this.ddocs.first().dDocModel();
+ }
+ this.ddocID = this.model.id;
+ } else {
+ var ddocDecode = decodeURIComponent(this.ddocID);
+ this.model = this.ddocs.get(this.ddocID).dDocModel();
+ this.reduceFunStr = this.model.viewHasReduce(this.viewName);
+ }
+
+ var viewFilters = FauxtonAPI.getExtensions('sidebar:viewFilters'),
+ filteredModels = this.ddocs.models,
+ designDocs = this.ddocs.clone();
+
+ if (!_.isEmpty(viewFilters)) {
+ _.each(viewFilters, function (filter) {
+ filteredModels = _.filter(filteredModels, filter);
+ });
+ designDocs.reset(filteredModels, {silent: true});
+ }
+
+ this.designDocSelector = this.setView('.design-doc-group', new Views.DesignDocSelector({
+ collection: designDocs,
+ ddocName: this.currentDdoc || this.model.id,
+ database: this.database
+ }));
+
+ if (!this.newView) {
+ this.eventer = _.extend({}, Backbone.Events);
+
+ this.advancedOptions = this.insertView('#query', new QueryOptions.AdvancedOptions({
+ updateViewFn: this.updateView,
+ previewFn: this.previewView,
+ database: this.database,
+ viewName: this.viewName,
+ ddocName: this.model.id,
+ hasReduce: this.hasReduce(),
+ eventer: this.eventer,
+ showStale: true
+ }));
+ }
+
+ },
+
+ afterRender: function() {
+
+ if (this.params && !this.newView) {
+ this.advancedOptions.updateFromParams(this.params);
+ }
+
+ this.designDocSelector.updateDesignDoc();
+ if (this.newView || this.showIndex) {
+ this.showEditors();
+ this.showIndex = false;
+ } else {
+ this.$('#index').hide();
+ this.$('#index-nav').parent().removeClass('active');
+ }
+
+ },
+
+ showEditors: function () {
+ this.mapEditor = new Components.Editor({
+ editorId: "map-function",
+ mode: "javascript",
+ couchJSHINT: true
+ });
+ this.mapEditor.render();
+
+ if (this.hasCustomReduce()) {
+ this.createReduceEditor();
+ } else {
+ $(".control-group.reduce-function").hide();
+ }
+
+ if (this.newView) {
+ this.mapEditor.setValue(this.langTemplates[this.defaultLang].map);
+ //Use a built in view by default
+ //this.reduceEditor.setValue(this.langTemplates[this.defaultLang].reduce);
+ }
+
+ this.mapEditor.editSaved();
+ this.reduceEditor && this.reduceEditor.editSaved();
+
+ if (this.mapEditor.getLines() === 1){
+ this.$('.beautify_map').removeClass("hide");
+ $('.beautify-tooltip').tooltip();
+ }
+ },
+ beautifyCode: function(e){
+ e.preventDefault();
+ var targetEditor = $(e.currentTarget).hasClass('beautify_reduce')?this.reduceEditor:this.mapEditor;
+ var beautifiedCode = beautify(targetEditor.getValue());
+ targetEditor.setValue(beautifiedCode);
+ },
+ cleanup: function () {
+ this.mapEditor && this.mapEditor.remove();
+ this.reduceEditor && this.reduceEditor.remove();
+ }
+ });
+
+ Views.DesignDocSelector = FauxtonAPI.View.extend({
+ template: "addons/indexes/templates/design_doc_selector",
+
+ events: {
+ "change select#ddoc": "updateDesignDoc"
+ },
+
+ initialize: function (options) {
+ this.ddocName = options.ddocName;
+ this.database = options.database;
+ this.listenTo(this.collection, 'add', this.ddocAdded);
+ this.DocModel = options.DocModel || Documents.Doc;
+ },
+
+ ddocAdded: function (ddoc) {
+ this.ddocName = ddoc.id;
+ this.render();
+ },
+
+ serialize: function () {
+ return {
+ ddocName: this.ddocName,
+ ddocs: this.collection
+ };
+ },
+
+ updateDesignDoc: function () {
+ if (this.newDesignDoc()) {
+ this.$('#new-ddoc-section').show();
+ } else {
+ this.$('#new-ddoc-section').hide();
+ }
+ },
+
+ newDesignDoc: function () {
+
+ return this.$('#ddoc').val() === 'new-doc';
+ },
+
+ newDocValidation: function(){
+ return this.newDesignDoc() && this.$('#new-ddoc').val()==="";
+ },
+ getCurrentDesignDoc: function () {
+ if (this.newDesignDoc()) {
+ var doc = {
+ _id: '_design/' + this.$('#new-ddoc').val(),
+ views: {},
+ language: "javascript"
+ };
+ var ddoc = new this.DocModel(doc, {database: this.database});
+ //this.collection.add(ddoc);
+ return ddoc;
+ } else if ( !this.newDesignDoc() ) {
+ var ddocName = this.$('#ddoc').val();
+ return this.collection.find(function (ddoc) {
+ return ddoc.id === ddocName;
+ }).dDocModel();
+ }
+ }
+ });
+
return Views;
});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4c45e129/settings.json.default
----------------------------------------------------------------------
diff --git a/settings.json.default b/settings.json.default
index bc5a617..d278368 100644
--- a/settings.json.default
+++ b/settings.json.default
@@ -3,6 +3,7 @@
{ "name": "fauxton" },
{ "name": "databases" },
{ "name": "documents" },
+ { "name": "indexes" },
{ "name": "pouchdb" },
{ "name": "activetasks" },
{ "name": "config" },
[4/8] fauxton commit: updated refs/heads/secondary-indexes to 4c45e12
Posted by de...@apache.org.
Fix failing test in documents
The changes-view was moved to a separate file.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/b6e4fd12
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/b6e4fd12
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/b6e4fd12
Branch: refs/heads/secondary-indexes
Commit: b6e4fd1296bc5972d34b157c7241500f0076cbbf
Parents: d68bc8e
Author: Robert Kowalski <ro...@kowalski.gd>
Authored: Fri Jul 25 20:03:38 2014 +0200
Committer: Robert Kowalski <ro...@kowalski.gd>
Committed: Fri Jul 25 20:04:55 2014 +0200
----------------------------------------------------------------------
app/addons/documents/tests/viewsSpec.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b6e4fd12/app/addons/documents/tests/viewsSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/tests/viewsSpec.js b/app/addons/documents/tests/viewsSpec.js
index 8bc1397..341ed8e 100644
--- a/app/addons/documents/tests/viewsSpec.js
+++ b/app/addons/documents/tests/viewsSpec.js
@@ -17,7 +17,7 @@ define([
describe('DocumentsViews', function () {
it('should load', function () {
- assert.equal(typeof Views.Views.Changes, 'function');
+ assert.equal(typeof Views.Views.AllDocsList, 'function');
});
});
});
[7/8] fauxton commit: updated refs/heads/secondary-indexes to 4c45e12
Posted by de...@apache.org.
Setting Up Indexes addon
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/df3f068b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/df3f068b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/df3f068b
Branch: refs/heads/secondary-indexes
Commit: df3f068b6ad392df004a9e7b8abcf2ad6b39f25f
Parents: 57923f4
Author: deathbearbrown <de...@gmail.com>
Authored: Tue Jul 22 11:39:46 2014 -0400
Committer: deathbearbrown <de...@gmail.com>
Committed: Mon Jul 28 09:47:38 2014 -0400
----------------------------------------------------------------------
.gitignore | 1 +
app/addons/indexes/base.js | 44 +++++++++++++++++++++++++++++
app/addons/indexes/index-components.js | 28 ++++++++++++++++++
app/addons/indexes/resources.js | 21 ++++++++++++++
app/addons/indexes/routes.js | 33 ++++++++++++++++++++++
app/addons/indexes/views.js | 21 ++++++++++++++
6 files changed, 148 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/df3f068b/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 1baaaf1..4d2ca75 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ app/addons/*
!app/addons/replication
!app/addons/contribute
!app/addons/auth
+!app/addons/indexes
!app/addons/exampleAuth
!app/addons/permissions
!app/addons/verifyinstall
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/df3f068b/app/addons/indexes/base.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/base.js b/app/addons/indexes/base.js
new file mode 100644
index 0000000..a7107a1
--- /dev/null
+++ b/app/addons/indexes/base.js
@@ -0,0 +1,44 @@
+// 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.
+
+
+/* View Indexes */
+define([
+ "app",
+ "api",
+ "addons/indexes/views",
+ "addons/indexes/routes"
+],
+function(app, FauxtonAPI, Views, Routes) {
+ Routes.initialize = function() {
+
+ /*
+ Example of an extension:
+ An extension is just an event that may or may not have listener in another view.
+ In this case the listener is in the documents addon in the sidebar.
+
+ If there are is a view that you want rendered in another route, this is the way to do it.
+
+ Each Secondary index is going to trigger this event with the views it's passing.
+ The views will be rendered and have links to the routes defined in this addon. Then it's just business as usual.
+
+ FauxtonAPI.registerExtension('sidebar:list', new Views.IndexMenu({}));
+ FauxtonAPI.registerExtension('sidebar:links',{
+ title: "New View",
+ url: "new_view"
+ });
+
+
+ */
+ };
+ return Routes;
+});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/df3f068b/app/addons/indexes/index-components.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/index-components.js b/app/addons/indexes/index-components.js
new file mode 100644
index 0000000..ffb22a0
--- /dev/null
+++ b/app/addons/indexes/index-components.js
@@ -0,0 +1,28 @@
+// 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.
+
+
+/*
+ Index components includes any common, generic, and reusable code for creating secondary indexes
+ View functions, List functions, Show Functions, and Filter functions, as well as anything created by
+ couchdb affiliates.
+*/
+
+define([
+ "app",
+ "api"
+],
+
+function(app, FauxtonAPI) {
+
+
+});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/df3f068b/app/addons/indexes/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/resources.js b/app/addons/indexes/resources.js
new file mode 100644
index 0000000..667eaba
--- /dev/null
+++ b/app/addons/indexes/resources.js
@@ -0,0 +1,21 @@
+// 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.
+define([
+ "app",
+ "addons/fauxton/base",
+],
+
+function (app, Fauxton) {
+ var Resources = {};
+
+ return Resources;
+});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/df3f068b/app/addons/indexes/routes.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/routes.js b/app/addons/indexes/routes.js
new file mode 100644
index 0000000..4c7515d
--- /dev/null
+++ b/app/addons/indexes/routes.js
@@ -0,0 +1,33 @@
+// 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.
+define([
+ "app",
+ "api",
+ "addons/indexes/resources",
+ "addons/indexes/views"
+],
+
+function (app, FauxtonAPI, Resources, Views) {
+
+ var ViewIndexes = FauxtonAPI.RouteObject.extend({});
+
+ var FilterIndexes = FauxtonAPI.RouteObject.extend({});
+
+ var ShowIndexes = FauxtonAPI.RouteObject.extend({});
+
+ var ListIndexes = FauxtonAPI.RouteObject.extend({});
+
+
+ Resources.RouteObjects = [ViewIndexes, FilterIndexes, ShowIndexes, ListIndexes];
+
+ return Resources;
+});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/df3f068b/app/addons/indexes/views.js
----------------------------------------------------------------------
diff --git a/app/addons/indexes/views.js b/app/addons/indexes/views.js
new file mode 100644
index 0000000..e8383cf
--- /dev/null
+++ b/app/addons/indexes/views.js
@@ -0,0 +1,21 @@
+// 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.
+define([
+ "app",
+ "api"
+],
+
+function (app, FauxtonAPI) {
+ var Views = {};
+
+ return Views;
+});
[5/8] fauxton commit: updated refs/heads/secondary-indexes to 4c45e12
Posted by de...@apache.org.
readd travis support
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/c8299826
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/c8299826
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/c8299826
Branch: refs/heads/secondary-indexes
Commit: c82998263fd6b6607915a21406255557065b4fdc
Parents: b6e4fd1
Author: Robert Kowalski <ro...@kowalski.gd>
Authored: Sat Jul 26 18:22:54 2014 +0200
Committer: Robert Kowalski <ro...@kowalski.gd>
Committed: Sat Jul 26 18:22:54 2014 +0200
----------------------------------------------------------------------
.travis.yml | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/c8299826/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..6e5919d
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+ - "0.10"
[6/8] fauxton commit: updated refs/heads/secondary-indexes to 4c45e12
Posted by de...@apache.org.
Fauxton: Fix database view after the merge
The type is now an Array, not a String
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/57923f45
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/57923f45
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/57923f45
Branch: refs/heads/secondary-indexes
Commit: 57923f457bb1e95f76d279b321415384676c7159
Parents: c829982
Author: Robert Kowalski <ro...@kowalski.gd>
Authored: Fri Jul 18 19:11:48 2014 +0200
Committer: Robert Kowalski <ro...@kowalski.gd>
Committed: Sun Jul 27 12:19:37 2014 +0200
----------------------------------------------------------------------
app/addons/databases/resources.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/57923f45/app/addons/databases/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/databases/resources.js b/app/addons/databases/resources.js
index e9e68a4..fa8a435 100644
--- a/app/addons/databases/resources.js
+++ b/app/addons/databases/resources.js
@@ -136,7 +136,7 @@ function(app, FauxtonAPI, Documents) {
if (full || (typeof(updateSeq) === 'number')) {
return updateSeq;
} else if (updateSeq) {
- return updateSeq.split('-')[0];
+ return updateSeq[0];
} else {
return 0;
}
[2/8] fauxton commit: updated refs/heads/secondary-indexes to 4c45e12
Posted by de...@apache.org.
upstream merge
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/12f282c4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/12f282c4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/12f282c4
Branch: refs/heads/secondary-indexes
Commit: 12f282c455e91f359a33d02668f20e429d679683
Parents: b340f1d 893e988
Author: sebastianrothbucher <se...@googlemail.com>
Authored: Thu Jul 24 22:50:48 2014 +0200
Committer: sebastianrothbucher <se...@googlemail.com>
Committed: Thu Jul 24 22:50:48 2014 +0200
----------------------------------------------------------------------
Gruntfile.js | 11 +-
app/addons/activetasks/templates/tabs.html | 11 +-
app/addons/activetasks/views.js | 2 +
app/addons/config/templates/item.html | 8 +-
.../documents/assets/less/advancedOptions.less | 1 +
app/addons/documents/assets/less/changes.less | 31 +
app/addons/documents/assets/less/documents.less | 87 +-
app/addons/documents/assets/less/sidenav.less | 147 ++
app/addons/documents/routes.js | 137 +-
.../documents/templates/all_docs_layout.html | 12 +-
app/addons/documents/templates/changes.html | 4 +-
app/addons/documents/templates/code_editor.html | 4 +-
app/addons/documents/templates/ddoc_info.html | 2 +-
.../templates/delete_database_modal.html | 4 +-
.../documents/templates/design_doc_menu.html | 32 +
.../templates/design_doc_selector.html | 3 +
.../templates/duplicate_doc_modal.html | 4 +-
.../documents/templates/index_menu_item.html | 17 +-
app/addons/documents/templates/search.html | 15 -
app/addons/documents/templates/sidebar.html | 69 +-
.../documents/templates/upload_modal.html | 4 +-
app/addons/documents/templates/view_editor.html | 7 +-
app/addons/documents/views-advancedopts.js | 270 +++
app/addons/documents/views-changes.js | 84 +
app/addons/documents/views-doceditor.js | 535 +++++
app/addons/documents/views-index.js | 574 ++++++
app/addons/documents/views-sidebar.js | 253 +++
app/addons/documents/views.js | 1587 +--------------
app/addons/fauxton/base.js | 22 +-
app/addons/fauxton/components.js | 27 +
app/addons/fauxton/templates/api_bar.html | 16 +-
app/addons/fauxton/templates/breadcrumbs.html | 2 +-
app/addons/fauxton/templates/menu_dropdown.html | 33 +
app/addons/permissions/templates/section.html | 4 +-
app/addons/verifyinstall/base.js | 2 +-
app/templates/layouts/two_pane.html | 1 -
app/templates/layouts/with_tabs_sidebar.html | 6 +-
assets/fonts/FontAwesome.otf | Bin 0 -> 61896 bytes
assets/fonts/Gemfile | 5 +
assets/fonts/Gemfile.lock | 31 +
assets/fonts/README.md | 39 +
assets/fonts/fauxtonicon.eot | Bin 0 -> 16314 bytes
assets/fonts/fauxtonicon.svg | 644 ++++++
assets/fonts/fauxtonicon.ttf | Bin 0 -> 16130 bytes
assets/fonts/fauxtonicon.woff | Bin 0 -> 5804 bytes
assets/fonts/fontawesome-webfont.eot | Bin 0 -> 37405 bytes
assets/fonts/fontawesome-webfont.svg | 399 ++++
assets/fonts/fontawesome-webfont.ttf | Bin 0 -> 79076 bytes
assets/fonts/fontawesome-webfont.woff | Bin 0 -> 43572 bytes
assets/fonts/fontcustom.yml | 51 +
.../fonts/styleguide/fauxtonicon-preview.html | 1868 ++++++++++++++++++
assets/fonts/templates/icons.less | 30 +
assets/icons/activetasks.svg | 8 +
assets/icons/arrow-box-down.svg | 8 +
assets/icons/arrow-box-up.svg | 8 +
assets/icons/arrow_left.svg | 7 +
assets/icons/arrow_right.svg | 7 +
assets/icons/arrows-cw.svg | 8 +
assets/icons/article.svg | 8 +
assets/icons/attention-alt.svg | 8 +
assets/icons/attention-circled.svg | 8 +
assets/icons/block.svg | 8 +
assets/icons/bookmark-ribbon-wplus.svg | 8 +
assets/icons/bookmark.svg | 8 +
assets/icons/burger.svg | 8 +
assets/icons/cancel-circled.svg | 8 +
assets/icons/cancel-circled2.svg | 8 +
assets/icons/cancel.svg | 8 +
assets/icons/circle-empty.svg | 8 +
assets/icons/clipboard.svg | 8 +
assets/icons/clock.svg | 8 +
assets/icons/cog.svg | 8 +
assets/icons/collapse.svg | 8 +
assets/icons/cw.svg | 8 +
assets/icons/dashboard.svg | 8 +
assets/icons/database.svg | 8 +
assets/icons/deselect-all.svg | 15 +
assets/icons/document.svg | 8 +
assets/icons/documents.svg | 8 +
assets/icons/dot-circled.svg | 8 +
assets/icons/down-1.svg | 8 +
assets/icons/down-circled.svg | 8 +
assets/icons/down-dir.svg | 8 +
assets/icons/down-open.svg | 8 +
assets/icons/down.svg | 8 +
assets/icons/drop-down-dots.svg | 8 +
assets/icons/exchange.svg | 8 +
assets/icons/expand.svg | 8 +
assets/icons/eye.svg | 8 +
assets/icons/help-circled.svg | 8 +
assets/icons/help.svg | 8 +
assets/icons/info-circled.svg | 8 +
assets/icons/json.svg | 8 +
assets/icons/key.svg | 8 +
assets/icons/left-1.svg | 8 +
assets/icons/left-circled.svg | 8 +
assets/icons/left-dir.svg | 8 +
assets/icons/left-open.svg | 8 +
assets/icons/left.svg | 8 +
assets/icons/link.svg | 8 +
assets/icons/list-alt.svg | 8 +
assets/icons/lock.svg | 8 +
assets/icons/mail-alt.svg | 8 +
assets/icons/mail.svg | 8 +
assets/icons/megaphone.svg | 8 +
assets/icons/minus-circled.svg | 8 +
assets/icons/minus-circled2.svg | 9 +
assets/icons/minus-squared-alt.svg | 8 +
assets/icons/minus-squared.svg | 8 +
assets/icons/minus.svg | 8 +
assets/icons/mixer.svg | 8 +
assets/icons/new-database.svg | 8 +
assets/icons/ok-circled-2.svg | 8 +
assets/icons/ok-circled.svg | 8 +
assets/icons/ok.svg | 8 +
assets/icons/paperclip.svg | 1364 +++++++++++++
assets/icons/pencil.svg | 8 +
assets/icons/picture.svg | 8 +
assets/icons/play.svg | 8 +
assets/icons/plus-circled.svg | 8 +
assets/icons/plus-circled2.svg | 10 +
assets/icons/plus-squared-alt.svg | 8 +
assets/icons/plus-squared.svg | 8 +
assets/icons/plus.svg | 8 +
assets/icons/popin.svg | 8 +
assets/icons/popout.svg | 8 +
assets/icons/profile.svg | 8 +
assets/icons/replicate.svg | 8 +
assets/icons/reply-all.svg | 8 +
assets/icons/reply.svg | 8 +
assets/icons/resize-full-reverse.svg | 8 +
assets/icons/resize-full.svg | 8 +
assets/icons/resize-small-reverse.svg | 8 +
assets/icons/resize-small.svg | 8 +
assets/icons/right-1.svg | 8 +
assets/icons/right-circled.svg | 8 +
assets/icons/right-dir.svg | 8 +
assets/icons/right-open.svg | 8 +
assets/icons/right.svg | 8 +
assets/icons/save.svg | 8 +
assets/icons/search.svg | 8 +
assets/icons/select-all.svg | 11 +
assets/icons/sidenav-filter-function.svg | 10 +
assets/icons/sidenav-info.svg | 15 +
assets/icons/sidenav-list-function.svg | 12 +
assets/icons/sidenav-map-reduce.svg | 13 +
assets/icons/sidenav-search.svg | 17 +
assets/icons/sidenav-show-function.svg | 13 +
assets/icons/sidenav-update-function.svg | 12 +
assets/icons/sitemap.svg | 8 +
assets/icons/stats.svg | 8 +
assets/icons/support.svg | 8 +
assets/icons/swap-arrows.svg | 1318 ++++++++++++
assets/icons/table.svg | 8 +
assets/icons/trash.svg | 8 +
assets/icons/up-1.svg | 8 +
assets/icons/up-circled.svg | 8 +
assets/icons/up-dir.svg | 8 +
assets/icons/up-open.svg | 8 +
assets/icons/up.svg | 8 +
assets/icons/user.svg | 8 +
assets/icons/users.svg | 8 +
assets/icons/wrench.svg | 8 +
assets/img/FontAwesome.otf | Bin 61896 -> 0 bytes
assets/img/fontawesome-webfont.eot | Bin 37405 -> 0 bytes
assets/img/fontawesome-webfont.svg | 399 ----
assets/img/fontawesome-webfont.ttf | Bin 79076 -> 0 bytes
assets/img/fontawesome-webfont.woff | Bin 43572 -> 0 bytes
assets/img/fontcustom_fauxton.eot | Bin 7364 -> 0 bytes
assets/img/fontcustom_fauxton.svg | 200 --
assets/img/fontcustom_fauxton.ttf | Bin 9636 -> 0 bytes
assets/img/fontcustom_fauxton.woff | Bin 4816 -> 0 bytes
assets/less/bootstrap/dropdowns.less | 37 +-
.../less/bootstrap/font-awesome/variables.less | 2 +-
assets/less/bootstrap/navs.less | 3 -
assets/less/bootstrap/variables.less | 8 +-
assets/less/fauxton.less | 191 +-
assets/less/icons.less | 272 ++-
assets/less/mixins.less | 21 +
assets/less/variables.less | 4 +-
package.json | 4 +-
readme.md | 41 +-
tasks/couchserver.js | 4 +-
183 files changed, 9388 insertions(+), 2494 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/12f282c4/app/addons/documents/assets/less/documents.less
----------------------------------------------------------------------
diff --cc app/addons/documents/assets/less/documents.less
index 0537595,c466e53..13bd4fc
--- a/app/addons/documents/assets/less/documents.less
+++ b/app/addons/documents/assets/less/documents.less
@@@ -119,6 -100,6 +100,31 @@@ button.beautify
font-size: 16px;
}
++button.string-edit {
++ position: absolute;
++ padding: 0;
++ z-index: 1000;
++ width: 16px;
++ left: 22px;
++}
++
++button.string-edit[disabled] {
++ display: none;
++}
++
++#string-edit-modal {
++ div.modal {
++ overflow-x: visible;
++ width: initial;
++ min-width: 560px;
++ }
++}
++
++#string-editor-wrapper {
++ height: 500px;
++ width: 100%;
++}
++
#keys-input {
width: 100%;
}
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/12f282c4/app/addons/documents/templates/code_editor.html
----------------------------------------------------------------------
diff --cc app/addons/documents/templates/code_editor.html
index 2198079,4a14a9e..76d37ef
--- a/app/addons/documents/templates/code_editor.html
+++ b/app/addons/documents/templates/code_editor.html
@@@ -22,7 -22,6 +22,7 @@@ the License
</div>
<div class="span7">
- <button class="btn string-edit" title="Edit line" disabled="true"><i class="icon icon-edit"></i></button>
++ <button class="btn string-edit" title="Edit line" disabled="true"><i class="icon icon-edit"></i></button>
<% if (attachments) { %>
<div class="btn-group">
<button class="dropdown-toggle btn" data-bypass="true" data-toggle="dropdown">
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/12f282c4/app/addons/documents/views-doceditor.js
----------------------------------------------------------------------
diff --cc app/addons/documents/views-doceditor.js
index 0000000,add8d8c..5514bd2
mode 000000,100644..100644
--- a/app/addons/documents/views-doceditor.js
+++ b/app/addons/documents/views-doceditor.js
@@@ -1,0 -1,416 +1,535 @@@
+ // 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.
+
+ define([
+ "app",
+
+ "api",
+ "addons/fauxton/components",
+
+ "addons/documents/resources",
+ "addons/databases/resources",
+
+ // Libs
+ "addons/fauxton/resizeColumns",
+
+ // Plugins
+ "plugins/prettify"
+ ],
+
+ function(app, FauxtonAPI, Components, Documents, Databases,
+ resizeColumns, prettify) {
+
+ var Views = {};
+
+ /* Attachments upload modal */
+
+ Views.UploadModal = Components.ModalView.extend({
+ template: "addons/documents/templates/upload_modal",
+
+ events: {
+ "click #upload-btn": "uploadFile"
+ },
+
+ uploadFile: function (event) {
+ event.preventDefault();
+
+ var docRev = this.model.get('_rev'),
+ that = this,
+ $form = this.$('#file-upload');
+
+ if (!docRev) {
+ return this.set_error_msg('The document needs to be saved before adding an attachment.');
+ }
+
+ if ($('input[type="file"]')[0].files.length === 0) {
+ return this.set_error_msg('Selected a file to be uploaded.');
+ }
+
+ this.$('#_rev').val(docRev);
+
+ $form.ajaxSubmit({
+ url: this.model.url(),
+ type: 'POST',
+ beforeSend: this.beforeSend,
+ uploadProgress: this.uploadProgress,
+ success: this.success,
+ error: function (resp) {
+ console.log('ERR on upload', resp);
+ return that.set_error_msg('Could not upload document: ' + JSON.parse(resp.responseText).reason);
+ }
+ });
+ },
+
+ success: function (resp) {
+ var hideModal = this.hideModal,
+ $form = this.$('#file-upload');
+
+ FauxtonAPI.triggerRouteEvent('reRenderDoc');
+ //slight delay to make this transistion a little more fluid and less jumpy
+ setTimeout(function () {
+ $form.clearForm();
+ hideModal();
+ $('.modal-backdrop').remove();
+ }, 1000);
+ },
+
+ uploadProgress: function(event, position, total, percentComplete) {
+ this.$('.bar').css({width: percentComplete + '%'});
+ },
+
+ beforeSend: function () {
+ this.$('.progress').removeClass('hide');
+ },
+
+ _showModal: function () {
+ this.$('.bar').css({width: '0%'});
+ this.$('.progress').addClass('hide');
+ }
+ });
+
++ Views.StringEditModal = Components.ModalView.extend({
++ template: "addons/documents/templates/string_edit_modal",
++
++ initialize: function () {
++ _.bindAll(this);
++ },
++
++ events: {
++ "click #string-edit-save-btn":"saveString"
++ },
++
++ saveString: function (event) {
++ event.preventDefault();
++ var newStr = this.subEditor.getValue();
++ this.subEditor.editSaved();
++ this.editor.replaceCurrentLine(this.indent + this.hashKey + JSON.stringify(newStr) + this.comma + "\n");
++ this.hideModal();
++ },
++
++ _showModal: function () {
++ this.$('.bar').css({width: '0%'});
++ this.$('.progress').addClass('hide');
++ this.clear_error_msg();
++ },
++
++ openWin: function(editor, indent, hashKey, jsonString, comma) {
++ this.editor = editor;
++ this.indent = indent;
++ this.hashKey = hashKey;
++ this.$('#string-edit-header').text(hashKey);
++ this.subEditor.setValue(JSON.parse(jsonString));
++ /* make sure we don't have save warnings w/out change */
++ this.subEditor.editSaved();
++ this.comma = comma;
++ this.showModal();
++ },
++
++ afterRender: function() {
++ /* make sure we init only ONCE */
++ if (!this.subEditor) {
++ this.subEditor = new Components.Editor({
++ editorId: "string-editor-container",
++ mode: "plain"
++ });
++ this.subEditor.render();
++ /* optimize by disabling auto sizing (35 is the lines fitting into the pop-up) */
++ this.subEditor.configureFixedHeightEditor(35);
++ }
++ },
++
++ cleanup: function () {
++ if (this.subEditor) this.subEditor.remove();
++ }
++
++ });
+
+
+ /* Doc Duplication modal */
+ Views.DuplicateDocModal = Components.ModalView.extend({
+ template: "addons/documents/templates/duplicate_doc_modal",
+
+ initialize: function () {
+ _.bindAll(this);
+ },
+
+ events: {
+ "click #duplicate-btn":"duplicate",
+ "submit #doc-duplicate": "duplicate"
+
+ },
+
+ duplicate: function (event) {
+ event.preventDefault();
+ var newId = this.$('#dup-id').val(),
+ isDDoc = newId.match(/^_design\//),
+ removeDDocID = newId.replace(/^_design\//,""),
+ encodedID = isDDoc? "_design/"+ app.utils.safeURLName(removeDDocID):app.utils.safeURLName(newId);
+
+ this.hideModal();
+ FauxtonAPI.triggerRouteEvent('duplicateDoc', encodedID);
+ },
+
+ _showModal: function () {
+ this.$('.bar').css({width: '0%'});
+ this.$('.progress').addClass('hide');
+ this.clear_error_msg();
+ this.$('.modal').modal();
+ // hack to get modal visible
+ $('.modal-backdrop').css('z-index',1025);
+ },
+
+ showModal: function () {
+ var showModal = this._showModal,
+ setDefaultIdValue = this.setDefaultIdValue,
+ uuid = new FauxtonAPI.UUID();
+
+ uuid.fetch().then(function () {
+ setDefaultIdValue(uuid.next());
+ showModal();
+ });
+ },
+
+ setDefaultIdValue: function (id) {
+ this.$('#dup-id').val(id);
+ }
+ });
+
+ /* Document editor*/
+ Views.CodeEditor = FauxtonAPI.View.extend({
+ template: "addons/documents/templates/code_editor",
+ events: {
+ "click button.save-doc": "saveDoc",
+ "click button.delete": "destroy",
+ "click button.duplicate": "duplicate",
+ "click button.upload": "upload",
- "click button.cancel-button": "goback"
++ "click button.cancel-button": "goback",
++ "click button.string-edit": "stringEditing"
+ },
+
+ disableLoader: true,
+
+ initialize: function (options) {
+ this.database = options.database;
+ _.bindAll(this);
+ },
+
+ goback: function(){
+ FauxtonAPI.navigate(this.database.url("index") + "?limit=100");
+ },
+
++ determineStringEditMatch: function(event) {
++ var selStart = this.editor.getSelectionStart().row;
++ var selEnd = this.editor.getSelectionEnd().row;
++ /* one JS(ON) string can't span more than one line - we edit one string, so ensure we don't select several lines */
++ if (selStart >=0 && selEnd >= 0 && selStart === selEnd && this.editor.isRowExpanded(selStart)) {
++ var editLine = this.editor.getLine(selStart);
++ var editMatch = editLine.match(/^([ \t]*)("[a-zA-Z0-9_]*": )?(".*",?[ \t]*)$/);
++ if (editMatch) {
++ return editMatch;
++ } else {
++ return null;
++ }
++ } else {
++ return null;
++ }
++ },
++
++ showHideEditDocString: function (event) {
++ this.$("button.string-edit").attr("disabled", "true");
++ if (!this.hasValidCode()) {
++ return false;
++ }
++ var editMatch = this.determineStringEditMatch(event);
++ if (editMatch) {
++ this.$("button.string-edit").removeAttr("disabled");
++ /* remove the following line (along with CSS) to go back to the toolbar */
++ this.$("button.string-edit").css("top", (this.$("#editor-container")[0].offsetTop - 2 + this.editor.getRowHeight() * this.editor.documentToScreenRow(this.editor.getSelectionStart().row)) + "px");
++ return true;
++ }
++ return false;
++ },
++
++ stringEditing: function(event) {
++ event.preventDefault();
++ if (!this.hasValidCode()) {
++ return;
++ }
++ var editMatch = this.determineStringEditMatch(event);
++ if (editMatch) {
++ var indent = editMatch[1] || "",
++ hashKey = editMatch[2] || "",
++ editText = editMatch[3],
++ comma = "";
++ if (editText.substring(editText.length - 1) === ",") {
++ editText = editText.substring(0, editText.length - 1);
++ comma = ",";
++ }
++ this.stringEditModal.openWin(this.editor, indent, hashKey, editText, comma);
++ }
++ },
++
+ destroy: function(event) {
+ if (this.model.isNewDoc()) {
+ FauxtonAPI.addNotification({
+ msg: 'This document has not been saved yet.',
+ type: 'warning',
+ clear: true
+ });
+ return;
+ }
+
+ if (!window.confirm("Are you sure you want to delete this doc?")) {
+ return false;
+ }
+
+ var database = this.model.database;
+
+ this.model.destroy().then(function(resp) {
+ FauxtonAPI.addNotification({
+ msg: "Succesfully deleted your doc",
+ clear: true
+ });
+ FauxtonAPI.navigate(database.url("index"));
+ }, function(resp) {
+ FauxtonAPI.addNotification({
+ msg: "Failed to delete your doc!",
+ type: "error",
+ clear: true
+ });
+ });
+ },
+
+ beforeRender: function () {
+ this.uploadModal = this.setView('#upload-modal', new Views.UploadModal({model: this.model}));
+ this.uploadModal.render();
+
+ this.duplicateModal = this.setView('#duplicate-modal', new Views.DuplicateDocModal({model: this.model}));
++
++ /* initialization is automatic - and make sure ONCE */
++ this.stringEditModal = this.stringEditModal || this.setView('#string-edit-modal', new Views.StringEditModal());
++ /* this.stringEditModal.render(); */
+ this.duplicateModal.render();
+ },
+
+ upload: function (event) {
+ event.preventDefault();
+ if (this.model.isNewDoc()) {
+ FauxtonAPI.addNotification({
+ msg: 'Please save the document before uploading an attachment.',
+ type: 'warning',
+ clear: true
+ });
+ return;
+ }
+ this.uploadModal.showModal();
+ },
+
+ duplicate: function(event) {
+ if (this.model.isNewDoc()) {
+ FauxtonAPI.addNotification({
+ msg: 'Please save the document before duplicating it.',
+ type: 'warning',
+ clear: true
+ });
+ return;
+ }
+ event.preventDefault();
+ this.duplicateModal.showModal();
+ },
+
+ updateValues: function() {
+ if (this.model.changedAttributes()) {
+ FauxtonAPI.addNotification({
+ msg: "Document saved successfully.",
+ type: "success",
+ clear: true
+ });
+ this.editor.setValue(this.model.prettyJSON());
+ }
+ },
+
+ establish: function() {
+ var promise = this.model.fetch(),
+ databaseId = this.database.safeID(),
+ deferred = $.Deferred(),
+ that = this;
+
+ promise.then(function () {
+ deferred.resolve();
+ }, function (xhr, reason, msg) {
+ if (xhr.status === 404) {
+ FauxtonAPI.addNotification({
+ msg: 'The document does not exist',
+ type: 'error',
+ clear: true
+ });
+ that.goback();
+ }
+ deferred.reject();
+ });
+
+ return deferred;
+ },
+
+ saveDoc: function(event) {
+ var json,
+ that = this,
+ editor = this.editor,
+ validDoc = this.getDocFromEditor();
+
+ if (validDoc) {
+ this.getDocFromEditor();
+
+ FauxtonAPI.addNotification({msg: "Saving document."});
+
+ this.model.save().then(function () {
+ editor.editSaved();
+ FauxtonAPI.navigate('/database/' + that.database.safeID() + '/' + that.model.id);
+ }).fail(function(xhr) {
+ var responseText = JSON.parse(xhr.responseText).reason;
+ FauxtonAPI.addNotification({
+ msg: "Save failed: " + responseText,
+ type: "error",
+ fade: false,
+ clear: true,
+ selector: "#doc .errors-container"
+ });
+ });
+ } else if(this.model.validationError && this.model.validationError === 'Cannot change a documents id.') {
+ FauxtonAPI.addNotification({
+ msg: "Cannot save: " + 'Cannot change a documents _id, try Duplicate doc instead!',
+ type: "error",
+ selector: "#doc .errors-container",
+ clear: true
+ });
+ delete this.model.validationError;
+ } else {
+ FauxtonAPI.addNotification({
+ msg: "Please fix the JSON errors and try again.",
+ type: "error",
+ selector: "#doc .errors-container",
+ clear: true
+ });
+ }
+ },
+
+ getDocFromEditor: function () {
+ var json;
+
+ if (!this.hasValidCode()) {
+ return false;
+ }
+
+ json = JSON.parse(this.editor.getValue());
+
+ this.model.clear().set(json, {validate: true});
+ if (this.model.validationError) {
+ return false;
+ }
+
+ return this.model;
+ },
+
+ hasValidCode: function() {
+ var errors = this.editor.getAnnotations();
+ return errors.length === 0;
+ },
+
+ serialize: function() {
+ return {
+ doc: this.model,
+ attachments: this.getAttachments()
+ };
+ },
+
+ getAttachments: function () {
+ var attachments = this.model.get('_attachments');
+
+ if (!attachments) { return false; }
+
+ return _.map(attachments, function (att, key) {
+ return {
+ fileName: key,
+ size: att.length,
+ contentType: att.content_type,
+ url: this.model.url() + '/' + app.utils.safeURLName(key)
+ };
+ }, this);
+ },
+
+ afterRender: function() {
+ var saveDoc = this.saveDoc,
+ editor,
+ model;
+
+ this.editor = new Components.Editor({
+ editorId: "editor-container",
+ forceMissingId: true,
+ commands: [{
+ name: 'save',
+ bindKey: {win: 'Ctrl-S', mac: 'Ctrl-S'},
+ exec: function(editor) {
+ saveDoc();
+ },
+ readOnly: true // false if this command should not apply in readOnly mode
+ }]
+ });
+ this.editor.render();
+
+ editor = this.editor;
+ model = this.model;
+
+ this.listenTo(this.model, "sync", this.updateValues);
+ this.listenTo(editor.editor, "change", function (event) {
+ var changedDoc;
+ try {
+ changedDoc = JSON.parse(editor.getValue());
+ } catch(exception) {
+ //not complete doc. Cannot work with it
+ return;
+ }
+
+ var keyChecked = ["_id"];
+ if (model.get("_rev")) { keyChecked.push("_rev");}
+
+ //check the changedDoc has all the required standard keys
+ if (_.isEmpty(_.difference(keyChecked, _.keys(changedDoc)))) { return; }
+
+ editor.setReadOnly(true);
+ setTimeout(function () { editor.setReadOnly(false);}, 400);
+ // use extend so that _id stays at the top of the object with displaying the doc
+ changedDoc = _.extend({_id: model.id, _rev: model.get("_rev")}, changedDoc);
+ editor.setValue(JSON.stringify(changedDoc, null, " "));
+ FauxtonAPI.addNotification({
+ type: "error",
+ msg: "Cannot remove a documents Id or Revision.",
+ clear: true
+ });
+ });
++
++ var that = this;
++ this.listenTo(editor.editor, "changeSelection", function (event) {
++ that.showHideEditDocString(event);
++ });
++ this.listenTo(editor.editor.session, "changeBackMarker", function (event) {
++ that.showHideEditDocString(event);
++ });
+ },
+
+ cleanup: function () {
+ if (this.editor) this.editor.remove();
+ }
+ });
+
+ return Views;
+ });
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/12f282c4/app/addons/fauxton/components.js
----------------------------------------------------------------------
diff --cc app/addons/fauxton/components.js
index f0dcc31,85f7b34..fc0f500
--- a/app/addons/fauxton/components.js
+++ b/app/addons/fauxton/components.js
@@@ -419,9 -419,8 +419,11 @@@ function(app, FauxtonAPI, ace, spin)
this.setHeightToLineCount();
this.editor.setTheme("ace/theme/" + this.theme);
+
- this.editor.getSession().setMode("ace/mode/" + this.mode);
+ if (this.mode != "plain") {
+ this.editor.getSession().setMode("ace/mode/" + this.mode);
+ }
++
this.editor.setShowPrintMargin(false);
this.addCommands();
[3/8] fauxton commit: updated refs/heads/secondary-indexes to 4c45e12
Posted by de...@apache.org.
Fine tune string edit.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/d68bc8e4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/d68bc8e4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/d68bc8e4
Branch: refs/heads/secondary-indexes
Commit: d68bc8e4c6c72118f8679f82651b04216b3afae6
Parents: 12f282c
Author: sebastianrothbucher <se...@googlemail.com>
Authored: Thu Jul 24 23:00:06 2014 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Fri Jul 25 09:55:05 2014 +0200
----------------------------------------------------------------------
app/addons/documents/views-doceditor.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/d68bc8e4/app/addons/documents/views-doceditor.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/views-doceditor.js b/app/addons/documents/views-doceditor.js
index 5514bd2..e05b8f4 100644
--- a/app/addons/documents/views-doceditor.js
+++ b/app/addons/documents/views-doceditor.js
@@ -252,8 +252,9 @@ function(app, FauxtonAPI, Components, Documents, Databases,
var editMatch = this.determineStringEditMatch(event);
if (editMatch) {
this.$("button.string-edit").removeAttr("disabled");
- /* remove the following line (along with CSS) to go back to the toolbar */
- this.$("button.string-edit").css("top", (this.$("#editor-container")[0].offsetTop - 2 + this.editor.getRowHeight() * this.editor.documentToScreenRow(this.editor.getSelectionStart().row)) + "px");
+ /* remove the following line (along with CSS) to go back to the toolbar: take the offset top of the editor, go down as many lines as we are positioned including fold and adjust by two pixels as the button is slightly larger than a line */
+ var positionFromTop = (this.$("#editor-container").offset().top - 2 + this.editor.getRowHeight() * this.editor.documentToScreenRow(this.editor.getSelectionStart().row));
+ this.$("button.string-edit").css("top", positionFromTop + "px");
return true;
}
return false;