Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'release/v0.8.0'

  • Loading branch information...
commit 74852bc266ed601309f8a83507843dfcf3a383e9 2 parents 14240f1 + 2ec3ae9
andzdroid authored
8 app.js
View
@@ -249,13 +249,17 @@ var middleware = function(req, res, next) {
//Routes
app.get('/', middleware, routes.index);
+
app.get('/db/:database/:collection/:document', middleware, routes.viewDocument);
+app.put('/db/:database/:collection/:document', middleware, routes.updateDocument);
+
app.get('/db/:database/:collection', middleware, routes.viewCollection);
-app.del('/db/:database/:collection', middleware, routes.deleteCollection);
app.put('/db/:database/:collection', middleware, routes.renameCollection);
-app.get('/db/:database', middleware, routes.viewDatabase);
+app.del('/db/:database/:collection', middleware, routes.deleteCollection);
app.post('/db/:database', middleware, routes.addCollection);
+app.get('/db/:database', middleware, routes.viewDatabase);
+
app.listen(config.site.port || 80);
console.log("Mongo Express server listening on port " + (config.site.port || 80));
2  filters.js
View
@@ -1,3 +1,3 @@
exports.json = function(input) {
- return JSON.stringify(input, null, ' ');
+ return JSON.stringify(input, null, ' ');
};
2  package.json
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.7.1",
+ "version": "0.8.0",
"repository": {
"type": "git",
"url": "git://github.com/andzdroid/mongo-express.git"
33 routes/document.js
View
@@ -1,4 +1,5 @@
var config = require('../config');
+var mongodb = require('mongodb');
exports.viewDocument = function(req, res, next) {
var ctx = {
@@ -8,3 +9,35 @@ exports.viewDocument = function(req, res, next) {
res.render('document', ctx);
};
+
+exports.updateDocument = 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');
+ }
+
+ var id = new mongodb.ObjectID.createFromHexString(docJSON._id);
+ docJSON._id = id;
+
+ req.collection.save(docJSON, {safe: true}, function(err, result) {
+ if (err) {
+ //TODO: handle error
+ //document was not saved
+ console.error(err);
+ return res.redirect('back');
+ }
+
+ return res.redirect('/db/' + req.dbName + '/' + req.collectionName);
+ });
+};
4 routes/index.js
View
@@ -2,12 +2,16 @@
var db = require('./database');
var coll = require('./collection');
var doc = require('./document');
+
exports.viewDatabase = db.viewDatabase;
+
exports.viewCollection = coll.viewCollection;
exports.addCollection = coll.addCollection;
exports.deleteCollection = coll.deleteCollection;
exports.renameCollection = coll.renameCollection;
+
exports.viewDocument = doc.viewDocument;
+exports.updateDocument = doc.updateDocument;
//Homepage route
3  views/collection.html
View
@@ -13,7 +13,7 @@
<style type="text/css">
.CodeMirror-scroll {
- height: 100px;
+ height: 120px;
overflow: auto;
}
</style>
@@ -59,6 +59,7 @@
var doc = CodeMirror.fromTextArea(document.getElementById('doc_{{ loop.index }}'), {
mode: { name: "javascript", json: true },
readOnly: true,
+ indentUnit: 4,
autoClearEmptyLines: true,
matchBrackets: true,
theme: "{{ editorTheme }}",
14 views/document.html
View
@@ -43,11 +43,21 @@
{% block content %}
-<textarea class="span9" id="documentContent" name="documentContent">{{ document|json }}</textarea>
+<form method="POST" action="db/{{ dbName }}/{{ collectionName }}/{{ document._id }}">
+ <input type="hidden" name="_method" value="put">
+ <button type="submit" class="btn btn-success btn-large">
+ <i class="icon-folder-open icon-white"></i>
+ Save
+ </button>
+ <br /><br />
+
+ <textarea class="span9" id="document" name="document">{{ document|json }}</textarea>
+</form>
<script>
- var doc = CodeMirror.fromTextArea(document.getElementById('documentContent'), {
+ var doc = CodeMirror.fromTextArea(document.getElementById('document'), {
mode: { name: "javascript", json: true },
+ indentUnit: 4,
lineNumbers: true,
autoClearEmptyLines: true,
matchBrackets: true,
Please sign in to comment.
Something went wrong with that request. Please try again.