mirror of
https://github.com/bodyrep/DemoApp.git
synced 2026-01-25 06:32:11 +00:00
fixed newexercise labels, added body to single workout page, added delete function for workouts
This commit is contained in:
@@ -17,7 +17,7 @@ module.exports = function(app) {
|
||||
|
||||
app.get('/admin', loggedIn, isAdmin, function(req, res){
|
||||
res.render('admin/index', { title: 'Admin' });
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/admin/users', loggedIn, isAdmin, function(req, res, next){
|
||||
var page = req.query.page && parseInt(req.query.page, 10) || 0;
|
||||
@@ -130,9 +130,13 @@ app.get('/admin/exercises', loggedIn, isAdmin, function(req, res, next){
|
||||
});
|
||||
|
||||
app.post('/admin/exercises/:_id', function(req, res, next){
|
||||
console.log("Upsert data " + JSON.stringify(req.body));
|
||||
var exercise = req.body;
|
||||
console.log("Upsert exercise " + JSON.stringify(exercise));
|
||||
var docid = req.body._id;
|
||||
console.log("DOCID " + docid);
|
||||
delete exercise["_id"];
|
||||
console.log("Upsert document " + JSON.stringify(exercise));
|
||||
Exercise.findByIdAndUpdate(docid, exercise, {upsert: false}, function(err) {
|
||||
if (err) {
|
||||
if (err.code === 11000) {
|
||||
@@ -150,9 +154,6 @@ app.get('/admin/exercises', loggedIn, isAdmin, function(req, res, next){
|
||||
}
|
||||
res.redirect('/admin/exercises');
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ var restrictUserToSelf = require('./middleware/restrict_user_to_self');
|
||||
var maxUsersPerPage = 5;
|
||||
var maxWorkoutsPerPage = 5;
|
||||
var Workout = require('../data/models/workout');
|
||||
var Moment = require('moment');
|
||||
|
||||
module.exports = function(app) {
|
||||
|
||||
@@ -78,8 +79,12 @@ module.exports = function(app) {
|
||||
var workouts = results[1];
|
||||
|
||||
var lastPage = (page + 1) * maxWorkoutsPerPage >= count;
|
||||
|
||||
|
||||
workouts.forEach(function (thisworkout) {
|
||||
console.log("thisworkouts " + JSON.stringify(thisworkout));
|
||||
thisworkout.PrettyDate = Moment.utc(thisworkout.workoutDate).format("ddd, hA");
|
||||
console.log("time" + Moment.utc(thisworkout.workoutDate).format("ddd, hA"));
|
||||
console.log("thisworkouts " + JSON.stringify(thisworkout.PrettyDate));
|
||||
});
|
||||
|
||||
res.render('users/profile', {
|
||||
title: 'User profile',
|
||||
|
||||
@@ -52,6 +52,15 @@ module.exports = function(app) {
|
||||
var lastPage = (page + 1) * maxWorkoutsPerPage >= count;
|
||||
|
||||
console.log("workouts- " + JSON.stringify(workouts));
|
||||
//console.log("time" + Moment.utc(req.workout.workoutDate).format("ddd, hA"));
|
||||
//foreach
|
||||
//json[0].workoutDate
|
||||
workouts.forEach(function (thisworkout) {
|
||||
console.log("thisworkouts " + JSON.stringify(thisworkout));
|
||||
thisworkout.PrettyDate = Moment.utc(thisworkout.workoutDate).format("ddd, hA");
|
||||
console.log("time" + Moment.utc(thisworkout.workoutDate).format("ddd, hA"));
|
||||
console.log("thisworkouts " + JSON.stringify(thisworkout.PrettyDate));
|
||||
});
|
||||
|
||||
res.render('workouts/recent', {
|
||||
recentworkouts: workouts,
|
||||
|
||||
Reference in New Issue
Block a user