Permalink
Browse files

Merge branch 'release/v0.7.0'

  • Loading branch information...
2 parents e11b7fd + e9b7963 commit 4545d8a41596526d99c5804557f2c929932d0f17 @andzdroid andzdroid committed May 5, 2012
Showing with 120 additions and 14 deletions.
  1. +21 −2 app.js
  2. +3 −0 config.js
  3. +1 −1 package.json
  4. +7 −6 public/stylesheets/style.css
  5. +0 −3 routes/collection.js
  6. +7 −0 routes/document.js
  7. +2 −0 routes/index.js
  8. +29 −2 views/collection.html
  9. +11 −0 views/database.html
  10. +30 −0 views/document.html
  11. +9 −0 views/layout.html
View
23 app.js
@@ -177,7 +177,7 @@ app.param('database', function(req, res, next, id) {
//Make sure database exists
if (!_.include(databases, id)) {
//TODO: handle error
- return next('Error!');
+ return next('Error! Database not found!');
}
req.dbName = id;
@@ -207,7 +207,7 @@ app.param('collection', function(req, res, next, id) {
connections[req.dbName].collection(id, function(err, coll) {
if (err) {
//TODO: handle error
- return next('Error!');
+ return next('Error! Collection not found!');
}
req.collection = coll;
@@ -216,6 +216,24 @@ app.param('collection', function(req, res, next, id) {
});
});
+//:document param MUST be preceded by a :collection param
+app.param('document', function(req, res, next, id) {
+ //Convert id string to mongodb object ID
+ var id = new mongodb.ObjectID.createFromHexString(id);
+
+ req.collection.findOne({_id: id}, function(err, doc) {
+ if (err) {
+ //TODO: handle error
+ return next('Error! Document not found!');
+ }
+
+ req.document = doc;
+ res.locals.document = doc;
+
+ next();
+ });
+});
+
//mongodb middleware
var middleware = function(req, res, next) {
@@ -231,6 +249,7 @@ var middleware = function(req, res, next) {
//Routes
app.get('/', middleware, routes.index);
+app.get('/db/:database/:collection/:document', middleware, routes.viewDocument);
app.get('/db/:database/:collection', middleware, routes.viewCollection);
app.del('/db/:database/:collection', middleware, routes.deleteCollection);
app.put('/db/:database/:collection', middleware, routes.renameCollection);
View
@@ -16,10 +16,13 @@ module.exports = {
},
site: {
//baseUrl: the URL that mongo express will be located at
+ //Remember to add the trailing forward slash at the end!
baseUrl: 'http://localhost:8081/',
port: 8081
},
options: {
+ //The options below aren't being used yet
+
//cmdType: the type of command line you want mongo express to run
//values: eval, subprocess
// eval - uses db.eval. commands block, so only use this if you have to
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.6.0",
+ "version": "0.7.0",
"repository": {
"type": "git",
"url": "git://github.com/andzdroid/mongo-express.git"
@@ -1,8 +1,9 @@
-body {
- padding: 50px;
- font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+.documentlist {
+ height: 100px;
+ overflow: auto;
}
-a {
- color: #00B7FF;
-}
+.documentlist:hover {
+ cursor: pointer;
+ background: #EEE;
+}
View
@@ -1,6 +1,3 @@
-var utils = require('../utils');
-
-
//view all entries in a collection
exports.viewCollection = function(req, res, next) {
var query_options = {
View
@@ -0,0 +1,7 @@
+exports.viewDocument = function(req, res, next) {
+ var ctx = {
+ title: 'Viewing Document: ' + req.document._id,
+ };
+
+ res.render('document', ctx);
+};
View
@@ -1,11 +1,13 @@
//Add routes from other files
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;
//Homepage route
View
@@ -2,16 +2,43 @@
{% block title %}{{ collectionName }}{% endblock %}
+{% block breadcrumb %}
+<li>
+ <a href="">Home</a>
+ <span class="divider">/</span>
+</li>
+<li>
+ <a href="/db/{{ dbName }}">{{ dbName }}</a>
+ <span class="divider">/</span>
+</li>
+<li class="active">
+ {{ collectionName }}
+</li>
+{% endblock %}
+
+
{% block content %}
{% if documents.length == 0 %}
<p class="well">
No documents found.
</p>
{% else %}
+
+{% if collectionName != 'system.indexes' %}
+<script type="text/javascript">
+function loadDocument(id) {
+ location.href = '{{ baseHref }}db/{{ dbName }}/{{ collectionName }}/' + id;
+}
+</script>
+{% endif %}
+
{% for document in documents %}
- <pre class="prettyprint">{{ document|json }}</pre>
- <!--<a href="db/{{ db_name }}/{{ collectionName }}/{{ document._id }}">Edit</a>-->
+ <pre class="prettyprint documentlist"
+ {%- if collectionName != 'system.indexes' %} onclick="loadDocument('{{ document._id }}')"{% endif -%}
+ >
+{{ document|json }}
+ </pre>
{% endfor %}
{% endif %}
View
@@ -2,6 +2,17 @@
{% block title %}{{ dbName }}{% endblock %}
+{% block breadcrumb %}
+<li>
+ <a href="">Home</a>
+ <span class="divider">/</span>
+</li>
+<li class="active">
+ {{ dbName }}
+</li>
+{% endblock %}
+
+
{% block content %}
<h2>Create Collection</h2>
<form class="well form-inline" method="POST">
View
@@ -0,0 +1,30 @@
+{% extends 'layout.html' %}
+
+{% block title %}{{ document._id }}{% endblock %}
+
+{% block breadcrumb %}
+<li>
+ <a href="">Home</a>
+ <span class="divider">/</span>
+</li>
+<li>
+ <a href="/db/{{ dbName }}">{{ dbName }}</a>
+ <span class="divider">/</span>
+</li>
+<li>
+ <a href="/db/{{ dbName }}/{{ collectionName }}">{{ collectionName }}</a>
+ <span class="divider">/</span>
+</li>
+<li class="active">
+ {{ document._id }}
+</li>
+{% endblock %}
+
+
+{% block content %}
+
+<textarea class="prettyprint span9" style="height: 500px;">
+{{ document|json }}
+</textarea>
+
+{% endblock %}
View
@@ -8,6 +8,7 @@
<link href="stylesheets/bootstrap.css" rel="stylesheet">
<link href="stylesheets/prettify.css" rel="stylesheet" />
+ <link href="stylesheets/style.css" rel="stylesheet" />
<style type="text/css">
body {
padding-top: 60px;
@@ -69,6 +70,14 @@
</div>
<div class="span9">
+ <ul class="breadcrumb">
+ {% block breadcrumb %}
+ <li class="active">
+ Home
+ </li>
+ {% endblock %}
+ </ul>
+
<div class="page-header">
<h1 id="pageTitle">{{ title }}</h1>
</div>

0 comments on commit 4545d8a

Please sign in to comment.