From 91edf73965a58bc34d1b7656e672e300c6633423 Mon Sep 17 00:00:00 2001 From: Michael Q Larson Date: Sat, 21 Mar 2015 17:23:13 -0700 Subject: [PATCH] start building zipline views and controller --- controllers/zipLine.js | 161 ++++++++++++++++++++++++++++++++++++++ models/Zipline.js | 7 +- seed_data/comments.json | 3 - views/ziplines/index.jade | 0 views/ziplines/show.jade | 50 ++++++++++++ 5 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 controllers/zipLine.js delete mode 100644 seed_data/comments.json create mode 100644 views/ziplines/index.jade create mode 100644 views/ziplines/show.jade diff --git a/controllers/zipLine.js b/controllers/zipLine.js new file mode 100644 index 0000000000..53c5510971 --- /dev/null +++ b/controllers/zipLine.js @@ -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) + // } + //}); + } +}; \ No newline at end of file diff --git a/models/Zipline.js b/models/Zipline.js index f87cf11033..cfb23420e9 100644 --- a/models/Zipline.js +++ b/models/Zipline.js @@ -7,15 +7,16 @@ var secrets = require('../config/secrets'); */ -var zipLineSchema = new mongoose.Schema({ +var ziplineSchema = new mongoose.Schema({ name: { type: String, unique: true }, picture: String, + video: String, gitHubLink: String, demoLink: String, - description: Array, + details: Array }); -module.exports = mongoose.model('Zipline', zipLineSchema); +module.exports = mongoose.model('Zipline', ziplineSchema); diff --git a/seed_data/comments.json b/seed_data/comments.json deleted file mode 100644 index c44dc44f37..0000000000 --- a/seed_data/comments.json +++ /dev/null @@ -1,3 +0,0 @@ -[ - -] \ No newline at end of file diff --git a/views/ziplines/index.jade b/views/ziplines/index.jade new file mode 100644 index 0000000000..e69de29bb2 diff --git a/views/ziplines/show.jade b/views/ziplines/show.jade new file mode 100644 index 0000000000..fbc786d94f --- /dev/null +++ b/views/ziplines/show.jade @@ -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)}; \ No newline at end of file