Permalink
Browse files

Merge branch 'release/v0.14.0'

  • Loading branch information...
andzdroid committed May 12, 2012
2 parents e1f2fba + 42ae66d commit 1ed91240e319579e9ff56e31e76ca031e4990d7b
Showing with 86 additions and 34 deletions.
  1. +2 −0 .gitignore
  2. +8 −7 README.md
  3. +15 −1 app.js
  4. +3 −1 config.js → config.default.js
  5. +1 −1 package.json
  6. +23 −12 routes/collection.js
  7. +15 −11 routes/document.js
  8. +5 −1 views/database.html
  9. +14 −0 views/layout.html
View
@@ -15,3 +15,5 @@ results
node_modules
npm-debug.log
+
+config.js
View
@@ -17,7 +17,6 @@ Current features:
Planned features:
-* Error messages/responses
* Support for replica set connections
* Web-based command-line interface
* Site authentication
@@ -45,25 +44,27 @@ These screenshots are from version 0.11.0.
Usage
-----
-To install:
+**To install:**
npm install mongo-express
Or if you want to install a global copy:
npm install -g mongo-express
-To configure:
+**To configure:**
-Open config.js and fill in your MongoDB server connection and admin auth details.
+Copy `config.default.js` into a new file called `config.js`.
-To run:
+Fill in your MongoDB connection details, and any other options you want to change.
+
+**To run:**
node app
-To use:
+**To use:**
-Visit http://localhost:8081 or whatever URL/port you entered into your config.
+Visit `http://localhost:8081` or whatever URL/port you entered into your config.
License
View
16 app.js
@@ -16,6 +16,8 @@ var swig = require('swig');
var swigFilters = require('./filters');
var app = express();
+var config = require('./config');
+
//Set up swig
swig.init({
root: __dirname + '/views',
@@ -48,6 +50,8 @@ app.configure(function(){
app.use(express.logger('dev'));
app.use(express.static(__dirname + '/public'));
app.use(express.bodyParser());
+ app.use(express.cookieParser(config.site.cookieSecret));
+ app.use(express.session({ secret: config.site.sessionSecret }));
app.use(express.methodOverride());
app.use(app.router);
});
@@ -58,7 +62,6 @@ app.configure('development', function(){
//Set up database stuff
-var config = require('./config');
var host = config.mongodb.server || 'localhost';
var port = config.mongodb.port || mongodb.Connection.DEFAULT_PORT;
var dbOptions = {
@@ -204,6 +207,17 @@ app.locals.use(function(req, res) {
res.locals.baseHref = config.site.baseUrl;
res.locals.databases = databases;
res.locals.collections = collections;
+
+ //Flash messages
+ if (req.session.success) {
+ res.locals.messageSuccess = req.session.success;
+ delete req.session.success;
+ }
+
+ if (req.session.error) {
+ res.locals.messageError = req.session.error;
+ delete req.session.error;
+ }
});
@@ -43,7 +43,9 @@ module.exports = {
//baseUrl: the URL that mongo express will be located at
//Remember to add the forward slash at the end!
baseUrl: 'http://localhost:8081/',
- port: 8081
+ port: 8081,
+ cookieSecret: 'cookiesecret',
+ sessionSecret: 'sessionsecret'
},
options: {
//documentsPerPage: how many documents you want to see at once in collection view
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.13.0",
+ "version": "0.14.0",
"repository": {
"type": "git",
"url": "git://github.com/andzdroid/mongo-express.git"
View
@@ -61,25 +61,26 @@ exports.viewCollection = function(req, res, next) {
exports.addCollection = function(req, res, next) {
var name = req.body.collection;
- if (name === undefined) {
- //TODO: handle error
+ if (name === undefined || name.length == 0) {
+ req.session.error = "You forgot to enter a collection name!";
return res.redirect('back');
}
//Collection names must begin with a letter or underscore, and can contain only letters, underscores, numbers or dots
if (!name.match(/^[a-zA-Z_][a-zA-Z0-9\._]*$/)) {
- //TODO: handle error
+ req.session.error = "That collection name is invalid.";
return res.redirect('back');
}
req.db.createCollection(name, function(err, collection) {
if (err) {
- //TODO: handle error
+ req.session.error = "Something went wrong: " + err;
console.error(err);
+ return res.redirect('back');
}
req.updateCollections(req.db, req.dbName, function() {
- //TODO: use session flash to show success or error message
+ req.session.success = 'Collection created!';
res.redirect('/db/' + req.dbName + '/' + name);
});
});
@@ -89,18 +90,21 @@ exports.addCollection = function(req, res, next) {
exports.deleteCollection = function(req, res, next) {
req.collection.drop(function(err, result) {
if (err) {
- //TODO: handle error
+ req.session.error = "Something went wrong: " + err;
console.error(err);
+ return res.redirect('back');
}
//If delete was successful, result === true
req.updateCollections(req.db, req.dbName, function(err) {
if (err) {
- //TODO: handle error
+ req.session.error = "Something went wrong: " + err;
console.error(err);
+ return res.redirect('back');
}
+ req.session.success = "Collection '" + req.collectionName + "' deleted!";
res.redirect('/db/' + req.dbName);
});
});
@@ -110,24 +114,31 @@ exports.deleteCollection = function(req, res, next) {
exports.renameCollection = function(req, res, next) {
var name = req.body.collection;
- if (name == undefined) {
- //TODO: handle error
+ if (name == undefined || name.length == 0) {
+ req.session.error = "You forgot to enter a collection name!";
return res.redirect('back');
}
//Collection names must begin with a letter or underscore, and can contain only letters, underscores, numbers or dots
if (!name.match(/^[a-zA-Z_][a-zA-Z0-9\._]*$/)) {
- //TODO: handle error
+ req.session.error = "That collection name is invalid.";
return res.redirect('back');
}
req.collection.rename(name, function(err, collection) {
if (err) {
- //TODO: handle error
+ req.session.error('Something went wrong: ' + err);
console.error(err);
+ return res.redirect('back');
}
- req.updateCollections(req.db, req.dbName, function() {
+ req.updateCollections(req.db, req.dbName, function(err) {
+ if (err) {
+ req.session.error('Something went wrong: ' + err);
+ return res.redirect('back');
+ }
+
+ req.session.success('Collection renamed!');
res.redirect('/db/' + req.dbName + '/' + name);
});
});
View
@@ -14,27 +14,28 @@ exports.viewDocument = function(req, res, next) {
exports.addDocument = function(req, res, next) {
var doc = req.body.document;
- if (doc == undefined) {
- //TODO: handle error
+ if (doc == undefined || doc.length == 0) {
+ req.session.error = "You forgot to enter a document!";
return res.redirect('back');
}
var docJSON;
try {
docJSON = JSON.parse(doc);
} catch (err) {
- //TODO: handle error
+ req.session.error = "That document is not valid!";
console.error(err)
return res.redirect('back');
}
req.collection.insert(docJSON, {safe: true}, function(err, result) {
if (err) {
- //TODO: handle error
+ req.session.error = "Something went wrong: " + err;
console.error(err);
return res.redirect('back');
}
+ req.session.success = "Document added!";
res.redirect('/db/' + req.dbName + '/' + req.collectionName);
});
};
@@ -43,16 +44,16 @@ exports.addDocument = function(req, res, next) {
exports.updateDocument = function(req, res, next) {
var doc = req.body.document;
- if (doc == undefined) {
- //TODO: handle error
+ if (doc == undefined || doc.length == 0) {
+ req.session.error = "You forgot to enter a document!";
return res.redirect('back');
}
var docJSON;
try {
docJSON = JSON.parse(doc);
} catch (err) {
- //TODO: handle error
+ req.session.error = "That document is not valid!";
console.error(err);
return res.redirect('back');
}
@@ -61,24 +62,27 @@ exports.updateDocument = function(req, res, next) {
req.collection.update(req.document, docJSON, {safe: true}, function(err, result) {
if (err) {
- //TODO: handle error
//document was not saved
+ req.session.error = "Something went wrong: " + err;
console.error(err);
return res.redirect('back');
}
- return res.redirect('/db/' + req.dbName + '/' + req.collectionName);
+ req.session.success = "Document updated!";
+ res.redirect('/db/' + req.dbName + '/' + req.collectionName);
});
};
exports.deleteDocument = function(req, res, next) {
req.collection.remove(req.document, {safe: true}, function(err, result) {
if (err) {
- //TODO: handle error
+ req.session.error = "Something went wrong! " + err;
console.error(err);
+ return res.redirect('back');
}
- return res.redirect('/db/' + req.dbName + '/' + req.collectionName);
+ req.session.success = "Document deleted!";
+ res.redirect('/db/' + req.dbName + '/' + req.collectionName);
});
};
View
@@ -18,14 +18,18 @@ <h2>Create Collection</h2>
<form class="well form-inline" method="POST">
<div class="input-prepend">
<span class="add-on">{{ dbName }} . </span>
- <input class="input-medium" type="text" id="collection" name="collection" placeholder="Collection Name">
+ <input class="input-medium" type="text" id="collection" name="collection" placeholder="Collection Name" title="Collection Name">
</div>
<button type="submit" class="btn btn-primary">
<i class="icon-folder-open icon-white"></i>
Create collection
</button>
</form>
+<script>
+ $('#collection').popover({content: "Collection names must begin with a letter or underscore, and can contain only letters, numbers, underscores and dots."});
+</script>
+
<h2>Collections</h2>
<table class="table table-bordered table-striped table-condensed">
View
@@ -84,6 +84,20 @@
<h1 id="pageTitle">{{ title }}</h1>
</div>
+ {% if messageSuccess %}
+ <div class="alert alert-success">
+ <button class="close" data-dismiss="alert">×</button>
+ <strong>{{ messageSuccess }}</strong>
+ </div>
+ {% endif %}
+
+ {% if messageError %}
+ <div class="alert alert-error">
+ <button class="close" data-dismiss="alert">×</button>
+ <strong>{{ messageError }}</strong>
+ </div>
+ {% endif %}
+
{% block content %}{% endblock %}
</div>
</div>

0 comments on commit 1ed9124

Please sign in to comment.