Get initial view working, sort out mongo mess with seed file
This commit is contained in:
17
app.js
17
app.js
@@ -34,6 +34,11 @@ var express = require('express'),
|
||||
bonfireController = require('./controllers/bonfire'),
|
||||
coursewareController = require('./controllers/courseware'),
|
||||
|
||||
/**
|
||||
* Stories
|
||||
*/
|
||||
storyController = require('./controllers/story');
|
||||
|
||||
/**
|
||||
* User model
|
||||
*/
|
||||
@@ -272,6 +277,18 @@ app.post(
|
||||
userController.updateProgress
|
||||
);
|
||||
|
||||
/**
|
||||
* Main routes.
|
||||
*/
|
||||
app.get(
|
||||
'/stories/',
|
||||
storyController.index
|
||||
);
|
||||
app.get(
|
||||
'/stories/index',
|
||||
storyController.json
|
||||
);
|
||||
|
||||
/**
|
||||
* Challenge related routes
|
||||
*/
|
||||
|
@@ -1,6 +1,6 @@
|
||||
var R = require('ramda'),
|
||||
debug = require('debug')('freecc:cntr:post'),
|
||||
Post = require('./../models/Post'),
|
||||
Story = require('./../models/Story'),
|
||||
Comment = require('./../models/Comment'),
|
||||
User = require('./../models/User'),
|
||||
resources = require('./resources');
|
||||
@@ -9,12 +9,22 @@ var R = require('ramda'),
|
||||
* Post Controller
|
||||
*/
|
||||
|
||||
exports.index = function(req, res, next) {
|
||||
var posts = Post.find({}).sort({'rank': -1});
|
||||
posts.exec(function(err, listings) {
|
||||
exports.json = function(req, res, next) {
|
||||
var story = Story.find({}).sort({'rank': -1});
|
||||
story.exec(function(err, stories) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
res.json(listing);
|
||||
res.json(stories);
|
||||
});
|
||||
};
|
||||
|
||||
exports.index = function(req, res, next) {
|
||||
var story = Story.find({}).sort({'rank': -1});
|
||||
story.exec(function(err, stories) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
res.render('post/index');
|
||||
});
|
||||
};
|
@@ -2,13 +2,31 @@ var mongoose = require('mongoose');
|
||||
var secrets = require('../config/secrets');
|
||||
|
||||
var storySchema = new mongoose.Schema({
|
||||
headline: String,
|
||||
link: String,
|
||||
body: String,
|
||||
rank: { type: Number, default: -Infinity },
|
||||
upVotes: { type: Array, default: [] },
|
||||
headline: {
|
||||
type: String,
|
||||
unique: false
|
||||
},
|
||||
link: {
|
||||
type: String,
|
||||
unique: false
|
||||
},
|
||||
body: {
|
||||
type: String,
|
||||
unique: false
|
||||
},
|
||||
rank: {
|
||||
type: Number,
|
||||
default: -Infinity
|
||||
},
|
||||
upVotes: {
|
||||
type: Array,
|
||||
default: []
|
||||
},
|
||||
author: {},
|
||||
comments: { type: Array, default: [] }
|
||||
comments: {
|
||||
type: Array,
|
||||
default: []
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Story', storySchema);
|
||||
|
@@ -84,7 +84,7 @@ Story.remove({}, function(err, data) {
|
||||
} else {
|
||||
console.log('Deleted ', data);
|
||||
}
|
||||
Story.create(coursewares, function(err, data) {
|
||||
Story.create(stories, function(err, data) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
|
@@ -7,7 +7,7 @@
|
||||
"upVotes": [],
|
||||
"author": {
|
||||
"username": "terakilobyte",
|
||||
"id": "a2ad135e2aa27c14fc73ee11",
|
||||
"userId": "a2ad135e2aa27c14fc73ee11",
|
||||
"picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413"
|
||||
},
|
||||
"comments": []
|
||||
@@ -20,7 +20,7 @@
|
||||
"upVotes": [],
|
||||
"author": {
|
||||
"username": "terakilobyte",
|
||||
"id": "a2ad135e2aa27c14fc73ee11",
|
||||
"userId": "a2ad135e2aa27c14fc73ee22",
|
||||
"picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413"
|
||||
},
|
||||
"comments": []
|
||||
@@ -33,7 +33,7 @@
|
||||
"upVotes": [],
|
||||
"author": {
|
||||
"username": "terakilobyte",
|
||||
"id": "a2ad135e2aa27c14fc73ee11",
|
||||
"userId": "a2ad135e2aa27c14fc73ee33",
|
||||
"picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413"
|
||||
},
|
||||
"comments": []
|
||||
@@ -46,7 +46,7 @@
|
||||
"upVotes": [],
|
||||
"author": {
|
||||
"username": "terakilobyte",
|
||||
"id": "a2ad135e2aa27c14fc73ee11",
|
||||
"userId": "a2ad135e2aa27c14fc73ee44",
|
||||
"picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413"
|
||||
},
|
||||
"comments": []
|
||||
@@ -59,7 +59,7 @@
|
||||
"upVotes": [],
|
||||
"author": {
|
||||
"username": "terakilobyte",
|
||||
"id": "a2ad135e2aa27c14fc73ee11",
|
||||
"userId": "a2ad135e2aa27c14fc73ee55",
|
||||
"picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413"
|
||||
},
|
||||
"comments": []
|
||||
|
@@ -1,5 +1,5 @@
|
||||
extends ../layout
|
||||
block content
|
||||
.panel.text-center
|
||||
h1.hug-top Camper News
|
||||
include parials/post
|
||||
h1 Camper News
|
||||
include ./posts
|
@@ -1,24 +1,22 @@
|
||||
h3
|
||||
ol#bonfireList Test!
|
||||
h2
|
||||
ul#story-list Top Stories
|
||||
h3
|
||||
script(src="https://cdn.jsdelivr.net/ramda/0.10.0/ramda.min.js")
|
||||
script.
|
||||
var getLinkedName = function getLinkedName(name) {
|
||||
return name.toLowerCase().replace(/\s/g, '-');
|
||||
}
|
||||
$.ajax({
|
||||
url: '/stories/index',
|
||||
type: 'GET'
|
||||
})
|
||||
.success(
|
||||
function(data) {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var li = document.createElement('li');
|
||||
var linkedName = getLinkedName(data[i].headline);
|
||||
|
||||
//script(src="https://cdn.jsdelivr.net/ramda/0.10.0/ramda.min.js")
|
||||
//script.
|
||||
// var getLinkedName = function getLinkedName(name) {
|
||||
// return name.toLowerCase().replace(/\s/g, '-');
|
||||
// }
|
||||
// $.ajax({
|
||||
// url: '/bonfires/getBonfireList',
|
||||
// type: 'GET'
|
||||
// })
|
||||
// .success(
|
||||
// function(data) {
|
||||
// for (var i = 0; i < data.bonfireList.length; i++) {
|
||||
// var li = document.createElement('li');
|
||||
// var linkedName = getLinkedName(data.bonfireList[i].name);
|
||||
// if (R.contains(data.bonfireList[i].id, data.completedList)) {
|
||||
// $(li).addClass('strikethrough');
|
||||
// }
|
||||
// $(li).html("<a href='/bonfires/" + linkedName + "'>" + data.bonfireList[i].name + "</a></li>");
|
||||
// $(li).appendTo($('#bonfireList'));
|
||||
// }
|
||||
// });
|
||||
$(li).html("<a href='/stories/" + linkedName + "'>" + data[i].headline + "</a></li>");
|
||||
$(li).appendTo($('#story-list'));
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user