add logic to add campers to nonprofit projects of interest to them

This commit is contained in:
Michael Q Larson
2015-04-02 17:23:45 -07:00
parent 4aea12abca
commit 3cff4e9879
5 changed files with 57 additions and 22 deletions

View File

@@ -115,6 +115,20 @@ exports.returnIndividualNonprofit = function(req, res, next) {
if (dashedNameFull != dashedName) {
return res.redirect('../nonprofit/' + dashedNameFull);
}
var buttonActive = false;
if (req.user) {
if (req.user.uncompletedBonfires.length === 0) {
if (req.user.completedCoursewares.length > 63) {
var hasShownInterest = nonprofit.interestedCampers.filter(function ( obj ) {
return obj.username === req.user.profile.username;
});
console.log(hasShownInterest);
if (hasShownInterest.length === 0) {
buttonActive = true;
}
}
}
}
res.render('nonprofits/show', {
dashedName: dashedNameFull,
title: nonprofit.name,
@@ -132,7 +146,9 @@ exports.returnIndividualNonprofit = function(req, res, next) {
websiteLink: nonprofit.websiteLink,
imageUrl: nonprofit.imageUrl,
whatDoesNonprofitDo: nonprofit.whatDoesNonprofitDo,
interestedCampers: nonprofit.interestedCampers
interestedCampers: nonprofit.interestedCampers,
assignedCampers: nonprofit.assignedCampers,
buttonActive: buttonActive
});
});
};
@@ -144,13 +160,18 @@ exports.showAllNonprofits = function(req, res) {
};
exports.interestedInNonprofit = function(req, res) {
if (req.user.uncompletedBonfires !== [] && req.user.uncompletedCoursewares !== []) {
Nonprofit.find({name: req.params.nonprofitName.replace(/-/, ' ')}, function(err, nonprofit) {
if (req.user) {
Nonprofit.findOne({name: new RegExp(req.params.nonprofitName.replace(/-/, ' '), 'i')}, function(err, nonprofit) {
if (err) { return next(err); }
nonprofit.interestedCampers.push({"name": req.user.username, "picture": req.user.picture, "timeOfInterest": Date.now()});
req.flash('success', { msg: 'Thanks for expressing interest in this nonprofit project!' });
nonprofit.interestedCampers.push({"username": req.user.profile.username,
"picture": req.user.profile.picture,
"timeOfInterest": Date.now()
});
nonprofit.save(function(err) {
if (err) { return done(err); }
req.flash('success', { msg: "Thanks for expressing interest in this nonprofit project! We've added you to this project as an interested camper!" });
res.redirect('back');
});
});
}
res.redirect('back');
};

View File

@@ -6,7 +6,7 @@ var secrets = require('../config/secrets');
* @type {exports.Schema}
*/
var Long = mongoose.Types.Long;
var nonprofitSchema = new mongoose.Schema({
name: String,
requestedDeliverables: Array,

View File

@@ -98,8 +98,6 @@ block content
.hidden-xs.col-sm-12
#cal-heatmap.img-center
script(src="//d3js.org/d3.v3.min.js")
script(src="//cdn.jsdelivr.net/cal-heatmap/3.3.10/cal-heatmap.min.js")
script.
var cal = new CalHeatMap();
var calendar = !{JSON.stringify(calender)};

View File

@@ -21,11 +21,13 @@ block content
h4= whatDoesNonprofitDo
h4
a(href=websiteLink)= websiteLink
.spacer
h3 Project Description:
.col-xs-12
h4.negative-15 #{projectDescription} (About #{estimatedHours} hours per camper)
.spacer
h3 This project involves building:
.col-xs-12
h4.negative-15.col-xs-12
if (approvedWebsite)
.ion-android-globe   Website
if (approvedDonor)
@@ -42,18 +44,30 @@ block content
.ion-university   E-learning Platform
if (approvedOther)
.ion-settings   Other tools
if (interestedCampers && interestedCampers.length > 0)
h3 Interested campers:
.col-xs-12.text-left
for interestedCamper in interestedCampers
a(href='/' + interestedCamper.username class="interested-camper-image")
img.profile-picture.float-right(src=interestedCamper.picture)
if (assignedCampers && assignedCampers.length > 0)
h3 Assigned campers:
.col-xs-12.text-left
for assignedCamper in assignedCampers
a(href='/' + assignedCamper.username class="interested-camper-image")
img.profile-picture.float-right(src=assignedCamper.picture)
.spacer
.col-xs-12.text-center
h3 Interested campers:
for interestedCamper in interestedCampers
a(href='/' + interestedCamper.username class="interested-camper-image")
img.profile-picture.float-right(src=interestedUser.profile.picture)
.col-xs-12.text-center
h3 Assigned campers:
.col-xs-12.col-sm-8.col-sm-offset-2
.text-center
a.btn.btn-primary.btn-big.btn-block(href='/nonprofits/interested-in-nonprofit/#{dashedName}') I'm interested in building this project
#showAllButton.btn.btn-info.btn-big.btn-block Show all Nonprofits Projects
if (!buttonActive)
.col-xs-12.col-sm-8.col-sm-offset-2
.text-center
a.btn.btn-primary.btn-big.btn-block.disabled(href='/nonprofits/interested-in-nonprofit/#{dashedName}') I'm interested in building this project *
p * Complete all our Bonfires, 10 Ziplines, and 3 Basejumps to unlock this.
#showAllButton.btn.btn-info.btn-big.btn-block Show all Nonprofits Projects
if (buttonActive)
.col-xs-12.col-sm-8.col-sm-offset-2
.text-center
a.btn.btn-primary.btn-big.btn-block(href='/nonprofits/interested-in-nonprofit/#{dashedName}') I'm interested in building this project
#showAllButton.btn.btn-info.btn-big.btn-block Show all Nonprofits Projects
.row
.col-xs-12.text-center
if !user

View File

@@ -1,6 +1,8 @@
script(src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js")
script(src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js")
script(src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.0/ui-bootstrap-tpls.min.js")
script(src="//d3js.org/d3.v3.min.js")
script(src="//cdn.jsdelivr.net/cal-heatmap/3.3.10/cal-heatmap.min.js")
include meta
title #{title} | Free Code Camp
meta(charset='utf-8')