Permalink
Browse files

Merge branch 'release/v0.10.0'

  • Loading branch information...
2 parents fa65e1b + f6ba54d commit c8bf1f5614d35ce0efdbb8a954ed29d2349f7a2e @andzdroid andzdroid committed May 7, 2012
Showing with 92 additions and 9 deletions.
  1. +2 −2 README.md
  2. +1 −0 app.js
  3. +1 −1 package.json
  4. +29 −0 routes/document.js
  5. +1 −0 routes/index.js
  6. +58 −6 views/collection.html
View
@@ -12,11 +12,11 @@ Current features:
* Supports multiple databases
* Database blacklist/whitelist
* View/add/rename/delete collections
-* View/update/delete documents
+* View/add/update/delete documents
Planned features:
-* Add documents
+* Error messages/responses
* Support for replica set connections
* Web-based command-line interface
* Site authentication
View
1 app.js
@@ -253,6 +253,7 @@ app.get('/', middleware, routes.index);
app.get('/db/:database/:collection/:document', middleware, routes.viewDocument);
app.put('/db/:database/:collection/:document', middleware, routes.updateDocument);
app.del('/db/:database/:collection/:document', middleware, routes.deleteDocument);
+app.post('/db/:database/:collection', middleware, routes.addDocument);
app.get('/db/:database/:collection', middleware, routes.viewCollection);
app.put('/db/:database/:collection', middleware, routes.renameCollection);
View
@@ -2,7 +2,7 @@
"author": "Chun-hao Hu <hu.chunhao@gmail.com> (http://blog.huchunhao.com)",
"name": "mongo-express",
"description": "Web-based admin interface for MongoDB",
- "version": "0.9.0",
+ "version": "0.10.0",
"repository": {
"type": "git",
"url": "git://github.com/andzdroid/mongo-express.git"
View
@@ -11,6 +11,35 @@ exports.viewDocument = function(req, res, next) {
};
+exports.addDocument = function(req, res, next) {
+ var doc = req.body.document;
+
+ if (doc == undefined) {
+ //TODO: handle error
+ return res.redirect('back');
+ }
+
+ var docJSON;
+ try {
+ docJSON = JSON.parse(doc);
+ } catch (err) {
+ //TODO: handle error
+ console.error(err)
+ return res.redirect('back');
+ }
+
+ req.collection.insert(docJSON, {safe: true}, function(err, result) {
+ if (err) {
+ //TODO: handle error
+ console.error(err);
+ return res.redirect('back');
+ }
+
+ res.redirect('/db/' + req.dbName + '/' + req.collectionName);
+ });
+};
+
+
exports.updateDocument = function(req, res, next) {
var doc = req.body.document;
View
@@ -13,6 +13,7 @@ exports.renameCollection = coll.renameCollection;
exports.viewDocument = doc.viewDocument;
exports.updateDocument = doc.updateDocument;
exports.deleteDocument = doc.deleteDocument;
+exports.addDocument = doc.addDocument;
//Homepage route
View
@@ -16,6 +16,14 @@
height: 120px;
overflow: auto;
}
+
+ .modal-body .CodeMirror .CodeMirror-scroll {
+ height: auto;
+ min-height: 200px;
+ overflow-y: hidden;
+ overflow-x: auto;
+ width: 100%;
+ }
</style>
{% endblock %}
@@ -37,6 +45,49 @@
{% block content %}
+<p>
+<a data-toggle="modal" href="#addDocument" class="btn btn-success btn-large">
+ <i class="icon-file icon-white"></i>
+ New Document
+</a>
+</p>
+
+<div class="modal fade" id="addDocument">
+ <form method="post" action="db/{{ dbName }}/{{ collectionName }}">
+
+ <div class="modal-header">
+ <button class="close" data-dismiss="modal">×</button>
+ <h3>Add Document</h3>
+ </div>
+
+ <div class="modal-body">
+ <textarea id="document" name="document">{
+}</textarea>
+ </div>
+
+ <div class="modal-footer">
+ <button class="btn btn-error" data-dismiss="modal">Close</button>
+ <button type="submit" class="btn btn-success">
+ <i class="icon-pencil icon-white"></i>
+ Save
+ </button>
+ </div>
+
+ </form>
+</div>
+
+<script>
+ $("#addDocument").modal("hide");
+ var addDoc = CodeMirror.fromTextArea(document.getElementById('document'), {
+ mode: { name: "javascript", json: true },
+ indentUnit: 4,
+ electricChars: true,
+ matchBrackets: true,
+ lineNumbers: true,
+ theme: "{{ editorTheme }}"
+ });
+</script>
+
{% if documents.length == 0 %}
<p class="well">
No documents found.
@@ -58,12 +109,10 @@
<p>&nbsp;</p>
<script>
- var doc = CodeMirror.fromTextArea(document.getElementById('doc_{{ loop.index }}'), {
+ var doc_{{ loop.index }} = CodeMirror.fromTextArea(document.getElementById('doc_{{ loop.index }}'), {
mode: { name: "javascript", json: true },
readOnly: true,
indentUnit: 4,
- autoClearEmptyLines: true,
- matchBrackets: true,
theme: "{{ editorTheme }}",
lineNumbers: true
{%- if collectionName != 'system.indexes' %},
@@ -76,7 +125,7 @@
<br /><br />
<form method="POST" action="db/{{ dbName }}/{{ collectionName }}/{{ document._id }}">
<input type="hidden" name="_method" value="delete">
- <button type="submit" name="submit" class="btn btn-danger btn-mini">
+ <button type="submit" class="btn btn-danger btn-mini">
<i class="icon-remove icon-white"></i>
</button>
</form>
@@ -129,13 +178,16 @@
<h2>Delete Collection</h2>
<form method="POST" action="db/{{ dbName }}/{{ collectionName }}" class="well">
<input type="hidden" name="_method" value="delete">
- <p>Are you sure you want to delete this collection? All documents will be deleted.</p>
- <button type="submit" class="btn btn-danger">
+ <button id="deleteButton" type="submit" class="btn btn-danger" title="Warning">
<i class="icon-trash icon-white"></i>
Delete
</button>
</form>
+<script>
+ $('#deleteButton').popover({content: "Are you sure you want to delete this collection? All documents will be deleted."});
+</script>
+
</div>
{% endblock %}

0 comments on commit c8bf1f5

Please sign in to comment.