Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
abarnhard committed Aug 24, 2014
1 parent 3a5030d commit 536c1ce
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 3 deletions.
23 changes: 21 additions & 2 deletions app/controllers/stops.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'use strict';

var Stop = require('../models/stop');
var Stop = require('../models/stop'),
Trip = require('../models/trip'),
mp = require('multiparty');

exports.create = function(req, res){
req.body.tripId = req.params.tripId;
// console.log(req.body);
Stop.create(req.body, function(data){
// console.log(data);
res.send(data);
Trip.updateStops(req.params.tripId, data.length, function(){
res.send(data);
});
});

};
Expand All @@ -19,8 +23,23 @@ exports.show = function(req, res){
};

exports.addEvent = function(req, res){
req.body.stopId = req.params.stopId;
console.log(req.body);
Stop.addEvents(req.body, function(count){
Trip.updateEvents(req.params.tripId, count, function(){
res.redirect('/trips/'+req.params.tripId+'/stops/' + req.params.stopId);
});
});
};

exports.addPhoto = function(req, res){
var form = new mp.Form();
form.parse(req, function(err, fields, files){
Stop.addPhotos(req.params.stopId, files, function(count){
Trip.updatePhotos(req.params.tripId, count, function(){
res.redirect('/trips/'+req.params.tripId+'/stops/' + req.params.stopId);
});
});
});
};

28 changes: 28 additions & 0 deletions app/models/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ Stop.create = function(obj, cb){

};

Stop.addEvents = function(obj, cb){
Stop.findById(obj.stopId, function(err, s){
var count = 0;
if(typeof obj.events !== 'string'){
count = obj.events.length;
obj.events.forEach(function(event){
s.events.push(event);
});
}else{
count = 1;
s.events.push(obj.events);
}
s.save(function(){
cb(count);
});
});
};

Stop.addPhotos = function(id, files, cb){
Stop.findById(id, function(err, s){
var count = s.moveFiles(files);
s.save(function(){
cb(count);
});
});
};

Stop.prototype.moveFiles = function(files){
var baseDir = __dirname + '/../static',
relDir = '/img/' + this._id,
Expand Down Expand Up @@ -87,6 +114,7 @@ Stop.prototype.moveFiles = function(files){
self.photos.push(photo);
});
}
return photos.length;
};

Stop.prototype.save = function(cb){
Expand Down
18 changes: 18 additions & 0 deletions app/models/trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ Trip.updateDist = function(id, body, cb){
Trip.collection.update({_id:id}, {$set:{distance:parseFloat(body.distance)}}, cb);
};

Trip.updateStops = function(id, count, cb){
id = Mongo.ObjectID(id);
// console.log(body.distance);
Trip.collection.update({_id:id}, {$inc:{numStops:parseInt(count)}}, cb);
};

Trip.updatePhotos = function(id, count, cb){
id = Mongo.ObjectID(id);
// console.log(body.distance);
Trip.collection.update({_id:id}, {$inc:{photos:parseInt(count)}}, cb);
};

Trip.updateEvents = function(id, count, cb){
id = Mongo.ObjectID(id);
// console.log(id, count);
Trip.collection.update({_id:id}, {$inc:{events:parseInt(count)}}, cb);
};

Trip.prototype.save = function(cb){
Trip.collection.save(this, cb);
};
Expand Down
2 changes: 1 addition & 1 deletion app/static/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions app/static/css/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ tr {
#spacer {
height: 20px;
}

.stop-photo {
display: inline-block;
height: 200px;
width: 200px;
background-size: cover;
margin: 5px;
}
Empty file removed app/static/img/.gitkeep
Empty file.
Binary file removed app/static/img/53fa1d315eba332f065b8de9/0.jpg
Binary file not shown.
Binary file removed app/static/img/53fa1f59862b366c07650cd5/0.jpg
Binary file not shown.
2 changes: 2 additions & 0 deletions app/views/stops/show.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ block content
.col-xs-12
.row
.col-xs-6
h4 Events:
ul#events
each event in stop.events
li= event
Expand All @@ -27,6 +28,7 @@ block content
#spacer
.row
.col-xs-6
h4 Photos:
each photo in stop.photos
.stop-photo(style='background-image:url(#{photo})')
.col-xs-6
Expand Down

0 comments on commit 536c1ce

Please sign in to comment.