couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From deathb...@apache.org
Subject [1/8] fauxton commit: updated refs/heads/secondary-indexes to 4c45e12
Date Mon, 28 Jul 2014 13:47:49 GMT
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 <sebastianrothbucher@googlemail.com>
Authored: Mon Jul 14 23:08:18 2014 +0200
Committer: sebastianrothbucher <sebastianrothbucher@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">&times;</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);
     }
 
   });


Mime
View raw message