|
| 1 | +var modelProvider = require('../models/model').instance; |
| 2 | + |
| 3 | + |
| 4 | +exports.tutorial = function(req, res) { |
| 5 | + var tutorialId = req.params.tid; |
| 6 | + |
| 7 | + var tut = { |
| 8 | + id: tutorialId, |
| 9 | + title: 'NodeJS web basic', |
| 10 | + createdBy: 'Hung Doan', |
| 11 | + star: 5, |
| 12 | + desc: "In this tutorial I will run you through the process setting up an Express.js app and making it do what a basic website might do. You will learn the basics of routes, views, Jade templates, Stylus CSS engine, handling POST and GET requests.", |
| 13 | + url: 'http://www.hacksparrow.com/express-js-tutorial.html', |
| 14 | + stat: { |
| 15 | + likes: 103, |
| 16 | + shares: 50, |
| 17 | + views: 1042 |
| 18 | + }, |
| 19 | + requires: [ |
| 20 | + 'javascript-basic', |
| 21 | + 'nodejs-basic', |
| 22 | + 'javascript', |
| 23 | + 'nodejs', |
| 24 | + ], |
| 25 | + acquires: [ |
| 26 | + 'nodejs-intermediate', |
| 27 | + 'expressjs-basic', |
| 28 | + 'nodejs-basic', |
| 29 | + 'javascript', |
| 30 | + ], |
| 31 | + comments: [ |
| 32 | + {poster: |
| 33 | + {name: 'Hung Doan', |
| 34 | + profile_url: 'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/371019_697811725_247259128_q.jpg'}, |
| 35 | + content: 'Hello world!'} |
| 36 | + ] |
| 37 | + }; |
| 38 | + if (!tutorialId) { |
| 39 | + res.send("Error"); |
| 40 | + } else { |
| 41 | + // fetch tutorial based on id |
| 42 | + modelProvider.findTutorialById (tutorialId , function (err, tutorial){ |
| 43 | + if (err != null) |
| 44 | + res.send(err) |
| 45 | + console.log(tutorial); |
| 46 | + tut.id = tutorial.id; |
| 47 | + tut.title = tutorial.name; |
| 48 | + tut.desc = tutorial.description; |
| 49 | + tut.url = tutorial.content; |
| 50 | + res.render('tutorial', { |
| 51 | + title: tut.title, |
| 52 | + tut: tut |
| 53 | + }); |
| 54 | + |
| 55 | + }) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +exports.newTutorial = function(req, res){ |
| 64 | + console.log("new tut "); |
| 65 | + res.render('new_tut', {}); |
| 66 | +}; |
| 67 | + |
| 68 | +exports.postNewTutorial = function(req, res){ |
| 69 | + var tut = {}; |
| 70 | + tut.name = req.body.title; |
| 71 | + tut.description = req.body.description; |
| 72 | + tut.author = req.body.author; |
| 73 | + tut.content = req.body.url; |
| 74 | + tut.imageUrl = req.body.imageUrl; |
| 75 | + tut.enableTopics = req.body.acquires; |
| 76 | + tut.requiredTopics = req.body.requires; |
| 77 | + modelProvider.createTutorial(tut, function(err, tut_id) { |
| 78 | + var title; |
| 79 | + if (err) |
| 80 | + title = err; |
| 81 | + else |
| 82 | + title = tut_id; |
| 83 | + res.redirect('/tutorial/'+tut_id); |
| 84 | + }); |
| 85 | + |
| 86 | +}; |
| 87 | + |
| 88 | +exports.postTutorialComment = function(req, res){ |
| 89 | + |
| 90 | + var comment = req.body.comment; |
| 91 | + var tutorialId = req.params.tid; |
| 92 | + console.log("comment " + comment + " tutorial id " +tutorialId); |
| 93 | + res.send("respond with a resource"); |
| 94 | +}; |
| 95 | + |
| 96 | + |
| 97 | +exports.postTutorialLike = function(req, res){ |
| 98 | + |
| 99 | + var comment = req.body.comment; |
| 100 | + var tutorialId = req.params.tid; |
| 101 | + console.log("comment " + comment + " tutorial id " +tutorialId); |
| 102 | + res.send("respond with a resource"); |
| 103 | +}; |
| 104 | + |
| 105 | + |
| 106 | +exports.postTutorialShare = function(req, res){ |
| 107 | + |
| 108 | + var comment = req.body.comment; |
| 109 | + var tutorialId = req.params.tid; |
| 110 | + console.log("comment " + comment + " tutorial id " +tutorialId); |
| 111 | + res.send("respond with a resource"); |
| 112 | +}; |
| 113 | + |
0 commit comments