Skip to content

Commit

Permalink
Merge branch 'release/v0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
andzdroid committed May 5, 2012
2 parents e11b7fd + e9b7963 commit 4545d8a
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 14 deletions.
23 changes: 21 additions & 2 deletions app.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions config.js
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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"
Expand Down
13 changes: 7 additions & 6 deletions public/stylesheets/style.css
@@ -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;
}
3 changes: 0 additions & 3 deletions routes/collection.js
@@ -1,6 +1,3 @@
var utils = require('../utils');


//view all entries in a collection
exports.viewCollection = function(req, res, next) {
var query_options = {
Expand Down
7 changes: 7 additions & 0 deletions routes/document.js
@@ -0,0 +1,7 @@
exports.viewDocument = function(req, res, next) {
var ctx = {
title: 'Viewing Document: ' + req.document._id,
};

res.render('document', ctx);
};
2 changes: 2 additions & 0 deletions routes/index.js
@@ -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
Expand Down
31 changes: 29 additions & 2 deletions views/collection.html
Expand Up @@ -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 %}

Expand Down
11 changes: 11 additions & 0 deletions views/database.html
Expand Up @@ -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">
Expand Down
30 changes: 30 additions & 0 deletions views/document.html
@@ -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 %}
9 changes: 9 additions & 0 deletions views/layout.html
Expand Up @@ -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;
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 4545d8a

Please sign in to comment.