Browse files

added displaying real data + paging support #gklst

  • Loading branch information...
1 parent 3f3cdaf commit e5c0992606f9995ded04a0121df6eeaf5fca0f53 @donwb committed May 6, 2012
Showing with 29 additions and 30 deletions.
  1. +11 −2 ImageProvider.js
  2. +14 −2 app.js
  3. +4 −26 views/index.jade
View
13 ImageProvider.js
@@ -6,7 +6,8 @@ var Schema = mongoose.Schema, ObjectID = Schema.ObjectId;
var Img = new Schema({
name : {type: String, required: true},
description : {type: String, required: true},
- filename : {type: String, required: true}
+ filename : {type: String, required: true},
+ tags : [String]
});
mongoose.connect('mongodb://' + db.user + ':' + db.pass + '@' + db.host + ':' + db.port + '/' + db.name);
@@ -17,7 +18,15 @@ var Img = mongoose.model('Img');
ImageProvider = function(){};
ImageProvider.prototype.getImages = function(callback) {
- Img.find({}, function(err, images){
+ Img.find({}, function(err, images){
+ callback(null, images);
+ })
+};
+
+
+ImageProvider.prototype.pageImages = function(s, l, callback) {
+ Img.find({}, ['name', 'description', 'filename', 'tags'] , {skip: s, limit: l}, function(err, images){
+ //console.log(images);
callback(null, images);
})
};
View
16 app.js
@@ -30,8 +30,7 @@ app.configure('production', function(){
//
app.get('/', function(req, res){
- ImageProvider.getImages(function(err, images){
-
+ ImageProvider.pageImages(0, 4, function(err, images){
res.render('index', {layout: true,
locals: {
title: 'Landmark coasters',
@@ -41,6 +40,19 @@ app.get('/', function(req, res){
});
+app.get('/:pagenum', function(req, res){
+ // need some error checking for input param
+
+ var next = ((req.params.pagenum - 1) * 4);
+ ImageProvider.pageImages(next, 4, function(err, images){
+ res.render('index', {layout: true,
+ locals: {
+ title: 'Landmark Coasters',
+ images: images
+ }});
+ })
+
+});
var port = process.env.PORT || 3000;
if(!module.parent){
View
30 views/index.jade
@@ -3,32 +3,10 @@ div.row
div(class="sixteen columns")
div.shadowbox
ul
- li
- h1 Clermont Dancers
- img(src="http://coasters.tracibrowning.com/images/Clermont-2.jpg")
- li
- h1 Chairs
- img(src="http://coasters.tracibrowning.com/images/Chairs.jpg")
-
- li
- h1 Atkins Park
- img(src="http://coasters.tracibrowning.com/images/atkins-park.jpg")
- li
- h1 Double Clermont
- img(src="http://coasters.tracibrowning.com/images/Clermont.jpg")
- li
- h1 Ebenezer
- img(src="http://coasters.tracibrowning.com/images/Ebenezer.jpg")
- li
- h1 Fox Theater
- img(src="http://coasters.tracibrowning.com/images/Fox.jpg")
-
- li
- h1 Downtown Day
- img(src="http://coasters.tracibrowning.com/images/Jackson-St-daybreak.jpg")
- li
- h1 Grant Park
- img(src="http://coasters.tracibrowning.com/images/Grant-Park-Sign.jpg")
+ each img in images
+ li
+ h1= img.name
+ img(src="#{img.filename}")
div.row
div(class="sixteen columns")

0 comments on commit e5c0992

Please sign in to comment.