start building zipline views and controller
This commit is contained in:
161
controllers/zipLine.js
Normal file
161
controllers/zipLine.js
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
var _ = require('lodash'),
|
||||||
|
debug = require('debug')('freecc:cntr:zipline'),
|
||||||
|
Zipline = require('./../models/Zipline'),
|
||||||
|
User = require('./../models/User'),
|
||||||
|
resources = require('./resources'),
|
||||||
|
R = require('ramda');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bonfire controller
|
||||||
|
*/
|
||||||
|
|
||||||
|
exports.showAllZiplines = function(req, res) {
|
||||||
|
var completedZiplines = req.user.completedZiplines.map(function(elem) {
|
||||||
|
return elem._id;
|
||||||
|
});
|
||||||
|
|
||||||
|
var noDuplicateZiplines = R.uniq(completedZiplines);
|
||||||
|
var data = {};
|
||||||
|
data.ziplineList = resources.allZiplineNames();
|
||||||
|
data.completedList = noDuplicateZiplines;
|
||||||
|
res.send(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.index = function(req, res) {
|
||||||
|
res.render('ziplines/show.jade', {
|
||||||
|
completedWith: null,
|
||||||
|
title: 'Choose Your Zipline',
|
||||||
|
name: 'Choose Your Zipline',
|
||||||
|
difficulty: 0,
|
||||||
|
//cc: req.user ? req.user.bonfiresHash : undefined,
|
||||||
|
verb: resources.randomVerb(),
|
||||||
|
phrase: resources.randomPhrase(),
|
||||||
|
compliments: resources.randomCompliment(),
|
||||||
|
ziplines: []
|
||||||
|
//ziplineHash: 'test'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.returnIndividualZipline = function(req, res, next) {
|
||||||
|
var dashedName = req.params.ziplineName;
|
||||||
|
|
||||||
|
ziplineName = dashedName.replace(/\-/g, ' ');
|
||||||
|
|
||||||
|
Zipline.find({"name" : new RegExp(ziplineName, 'i')}, function(err, zipline) {
|
||||||
|
if (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (zipline.length < 1) {
|
||||||
|
req.flash('errors', {
|
||||||
|
msg: "404: We couldn't find a bonfire with that name. Please double check the name."
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.redirect('/ziplines');
|
||||||
|
}
|
||||||
|
|
||||||
|
zipline = zipline.pop();
|
||||||
|
var dashedNameFull = zipline.name.toLowerCase().replace(/\s/g, '-');
|
||||||
|
if (dashedNameFull != dashedName) {
|
||||||
|
return res.redirect('../ziplines/' + dashedNameFull);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.render('ziplines/show', {
|
||||||
|
completedWith: null,
|
||||||
|
title: zipline.name,
|
||||||
|
dashedName: dashedName,
|
||||||
|
name: zipline.name,
|
||||||
|
difficulty: Math.floor(+zipline.difficulty),
|
||||||
|
details: zipline.details,
|
||||||
|
tests: zipline.tests,
|
||||||
|
challengeSeed: zipline.challengeSeed,
|
||||||
|
//cc: !!req.user,
|
||||||
|
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||||
|
verb: resources.randomVerb(),
|
||||||
|
phrase: resources.randomPhrase(),
|
||||||
|
compliment: resources.randomCompliment(),
|
||||||
|
ziplines: zipline
|
||||||
|
//ziplineHash: zipline._id
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.completedZipline = function (req, res) {
|
||||||
|
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
|
||||||
|
var isCompletedDate = Math.round(+new Date() / 1000);
|
||||||
|
//var ziplineHash = req.body.bonfireInfo.bonfireHash;
|
||||||
|
|
||||||
|
if (isCompletedWith) {
|
||||||
|
var paired = User.find({"profile.username": isCompletedWith.toLowerCase()}).limit(1);
|
||||||
|
paired.exec(function (err, pairedWith) {
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
} else {
|
||||||
|
//var index = req.user.uncompletedZiplines.indexOf(ziplineHash);
|
||||||
|
//if (index > -1) {
|
||||||
|
// req.user.progressTimestamps.push(Date.now() / 1000 | 0);
|
||||||
|
// req.user.uncompletedZiplines.splice(index, 1)
|
||||||
|
//}
|
||||||
|
//pairedWith = pairedWith.pop();
|
||||||
|
//
|
||||||
|
//index = pairedWith.uncompletedZiplines.indexOf(bonfiHash);
|
||||||
|
//if (index > -1) {
|
||||||
|
// pairedWith.progressTimestamps.push(Date.now() / 1000 | 0);
|
||||||
|
// pairedWith.uncompletedZiplines.splice(index, 1);
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//pairedWith.completedBonfires.push({
|
||||||
|
// _id: bonfireHash,
|
||||||
|
// completedWith: req.user._id,
|
||||||
|
// completedDate: isCompletedDate,
|
||||||
|
// solution: isSolution
|
||||||
|
//});
|
||||||
|
//
|
||||||
|
//req.user.completedBonfires.push({
|
||||||
|
// _id: bonfireHash,
|
||||||
|
// completedWith: pairedWith._id,
|
||||||
|
// completedDate: isCompletedDate,
|
||||||
|
// solution: isSolution
|
||||||
|
//})
|
||||||
|
//
|
||||||
|
//req.user.save(function (err, user) {
|
||||||
|
// pairedWith.save(function (err, paired) {
|
||||||
|
// if (err) {
|
||||||
|
// throw err;
|
||||||
|
// }
|
||||||
|
// if (user && paired) {
|
||||||
|
// res.send(true);
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
//});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//req.user.completedBonfires.push({
|
||||||
|
// _id: bonfireHash,
|
||||||
|
// completedWith: null,
|
||||||
|
// completedDate: isCompletedDate,
|
||||||
|
// solution: isSolution
|
||||||
|
//});
|
||||||
|
//
|
||||||
|
//var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
|
||||||
|
//if (index > -1) {
|
||||||
|
// req.user.progressTimestamps.push(Date.now() / 1000 | 0);
|
||||||
|
// req.user.uncompletedBonfires.splice(index, 1)
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//req.user.save(function (err, user) {
|
||||||
|
// if (err) {
|
||||||
|
// throw err;
|
||||||
|
// }
|
||||||
|
// if (user) {
|
||||||
|
// debug('Saving user');
|
||||||
|
// res.send(true)
|
||||||
|
// }
|
||||||
|
//});
|
||||||
|
}
|
||||||
|
};
|
@ -7,15 +7,16 @@ var secrets = require('../config/secrets');
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
var zipLineSchema = new mongoose.Schema({
|
var ziplineSchema = new mongoose.Schema({
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
unique: true
|
unique: true
|
||||||
},
|
},
|
||||||
picture: String,
|
picture: String,
|
||||||
|
video: String,
|
||||||
gitHubLink: String,
|
gitHubLink: String,
|
||||||
demoLink: String,
|
demoLink: String,
|
||||||
description: Array,
|
details: Array
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = mongoose.model('Zipline', zipLineSchema);
|
module.exports = mongoose.model('Zipline', ziplineSchema);
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
[
|
|
||||||
|
|
||||||
]
|
|
0
views/ziplines/index.jade
Normal file
0
views/ziplines/index.jade
Normal file
50
views/ziplines/show.jade
Normal file
50
views/ziplines/show.jade
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
extends ../layout-wide
|
||||||
|
block content
|
||||||
|
.row
|
||||||
|
.col-xs-12.col-sm-12.col-md-4.bonfire-top
|
||||||
|
h1.text-center= name
|
||||||
|
.well
|
||||||
|
h4
|
||||||
|
ol
|
||||||
|
for step in details
|
||||||
|
li!= step
|
||||||
|
.col-xs-12.col-sm-12.col-md-8
|
||||||
|
.embed-responsive.embed-responsive-16by9
|
||||||
|
iframe.embed-responsive-item(src='//player.vimeo.com/video/#{video}')
|
||||||
|
br
|
||||||
|
- if (cc)
|
||||||
|
a.btn.btn-primary.btn-lg.btn-block#completed-zipline I've completed this Zipline (ctrl + enter)
|
||||||
|
script.
|
||||||
|
var userLoggedIn = true;
|
||||||
|
- else
|
||||||
|
a.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress
|
||||||
|
script.
|
||||||
|
var userLoggedIn = false;
|
||||||
|
br
|
||||||
|
script(type="text/javascript").
|
||||||
|
var tests = !{JSON.stringify(tests)};
|
||||||
|
var passedCoursewareHash = !{JSON.stringify(coursewareHash)};
|
||||||
|
var challengeName = !{JSON.stringify(name)};
|
||||||
|
var passedCoursewareName = challengeName;
|
||||||
|
var started = Math.floor(Date.now() / 1000);
|
||||||
|
#complete-courseware-dialog.modal(tabindex='-1')
|
||||||
|
.modal-dialog.animated.zoomIn.fast-animation
|
||||||
|
.modal-content
|
||||||
|
.modal-header.challenge-list-header= compliment
|
||||||
|
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
|
||||||
|
.modal-body(ng-controller="pairedWithController")
|
||||||
|
.text-center
|
||||||
|
.animated.zoomInDown.delay-half
|
||||||
|
span.completion-icon.ion-checkmark-circled.text-primary
|
||||||
|
- if (cc)
|
||||||
|
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf) Go to my next challenge (ctrl + enter)
|
||||||
|
- if (points && points > 2)
|
||||||
|
a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20Bonfire:%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/bonfires/#{dashedName}&hashtags=LearnToCode, JavaScript" target="_blank")
|
||||||
|
i.fa.fa-twitter  
|
||||||
|
= phrase
|
||||||
|
- else
|
||||||
|
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress
|
||||||
|
h1 #{name}
|
||||||
|
script.
|
||||||
|
var challengeName = !{JSON.stringify(name)};
|
||||||
|
var passedCoursewareHash = !{JSON.stringify(coursewareHash)};
|
Reference in New Issue
Block a user