Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect homepage #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion models/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { Schema } = mongoose;
const schema = new Schema({
subjectName:{
type:String,
require
required: true
},
beforeclass: Number,
afterClass: Number,
Expand Down
80 changes: 24 additions & 56 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
const express = require('express');
const router = express.Router();
const fs = require('fs');
const mongoose = require('mongoose');
const MongoClient = require('mongodb').MongoClient;
const ObjectID = require('mongodb').ObjectID;
const bodyParser = require('body-parser')
router.use(bodyParser.json());
const mongoConnection = process.env.MONGODB_URI || 'mongodb://localhost:27017/progressTracker';
/* GET home page. */

const Topic = require('../models/topic');


/* GET home page. */

router.get('/', function (req, res) {
res.render('index');
})

router.get('/add', function (req, res) {
res.render('add');
Expand All @@ -14,63 +24,21 @@ router.get('/add', function (req, res) {
router.get('/edit', function (req, res) {
res.render('edit');
});
router.get('/', function (req, res, next) {
//router.get('/', function (req, res, next) {

/**
/**
* Define a callback function to render the
* homepage once the topics data has been loaded
*/
const renderTopics = function (error, file) {

if (error) {
throw error;
}

const fileData = file.toString();
const topicsData = JSON.parse(fileData);
res.render('index', {
title: 'Progress Tracker',
description: 'Keep track of your progress learning new topics. Add a topic below and rate your knowledge of the topic between 1 (no knowledge) and 10 (very confident).',
columns: [
{
label: 'Topic',
hideLabel: true
},
{
label: 'Before Class',
},
{
label: 'After Class',
},
{
label: 'Monday',
},
{
label: 'Tuesday',
},
{
label: 'Wednesday',
},
{
label: 'Thursday',
},
{
label: 'Friday',
},
{
label: 'Edit',
hideLabel: true
}
],
topics: topicsData,
});
};

/**
* Load the topics file
*/
const topicsFilePath = __dirname + '/../data/topics.json';
fs.readFile(topicsFilePath, renderTopics);
* homepage once the topics data has been loaded
*/

router.get('/topics', (req, res, next) => {
mongoose.connect(mongoConnection);
Topic.find({}, (error, topics) => {
res.render('details', {
topics: topics
})
});
});


module.exports = router;
1 change: 1 addition & 0 deletions views/index.handlebars
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<table class="table table--progress">

<tr>
{{#each columns}}
<th>
Expand Down