mirror of
https://github.com/bodyrep/DemoApp.git
synced 2026-01-25 06:32:11 +00:00
added methods and routes for getting an exercises history, and the sum of a workouts musclearrays -- incl a modifier
This commit is contained in:
1
app.js
1
app.js
@@ -8,7 +8,6 @@ http = require('http');
|
|||||||
routes = require('./routes');
|
routes = require('./routes');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
var dbURL = 'mongodb://localhost/database';
|
var dbURL = 'mongodb://localhost/database';
|
||||||
var db = require('mongoose').connect(dbURL);
|
var db = require('mongoose').connect(dbURL);
|
||||||
var qs = require('qs');
|
var qs = require('qs');
|
||||||
|
|||||||
@@ -1,13 +1,21 @@
|
|||||||
var mongoose = require('mongoose');
|
var mongoose = require('mongoose');
|
||||||
var Schema = require('mongoose').Schema;
|
var Schema = require('mongoose').Schema;
|
||||||
|
|
||||||
|
|
||||||
|
var ExerciseStat = new Schema({
|
||||||
|
exerciseID: { type: Schema.ObjectId, ref: 'Exercise'},
|
||||||
|
modifier: {type: Number}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
var UserSchema = new mongoose.Schema({
|
var UserSchema = new mongoose.Schema({
|
||||||
username: {type: String, unique: true, required: true},
|
username: {type: String, unique: true, required: true},
|
||||||
name: String,
|
name: String,
|
||||||
password: String,
|
password: String,
|
||||||
is_admin: {type: Boolean, 'default': false },
|
is_admin: {type: Boolean, 'default': false },
|
||||||
is_imperial: {type: Boolean, 'default': false },
|
is_imperial: {type: Boolean, 'default': false },
|
||||||
favorites: [{ type: Schema.ObjectId, ref: 'Exercises'}]
|
favorites: [{ type: Schema.ObjectId, ref: 'Exercises'}],
|
||||||
|
exercisestats: [ExerciseStat]
|
||||||
});
|
});
|
||||||
|
|
||||||
UserSchema.methods.recentworkouts = function(callback) {
|
UserSchema.methods.recentworkouts = function(callback) {
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ var Split = new Schema({
|
|||||||
|
|
||||||
|
|
||||||
var Element = new Schema({
|
var Element = new Schema({
|
||||||
exerciseID: String,
|
exerciseID: { type: Schema.ObjectId, ref: 'Exercise'},
|
||||||
|
modifier: {type: Number},
|
||||||
splits: [Split]
|
splits: [Split]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -66,30 +66,41 @@ $(document).ready(function() {
|
|||||||
$("#newworkout").bind('sortupdate', function(event, ui) {
|
$("#newworkout").bind('sortupdate', function(event, ui) {
|
||||||
$('#exercises > li').each(function(){
|
$('#exercises > li').each(function(){
|
||||||
var itemindex= $(this).index();
|
var itemindex= $(this).index();
|
||||||
var newname = $(this).find('input, select').attr('name').replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']');
|
// var newname = $(this).find('input, select').attr('name').replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']');
|
||||||
|
$(this).find('input, select').each(function() {
|
||||||
|
var newname = $(this).attr('name').replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']');
|
||||||
|
$(this).attr('name', newname);
|
||||||
|
});
|
||||||
|
// $(this).find('label').each(function() {
|
||||||
|
// var value = $(this).attr('href');
|
||||||
|
// console.log ('value -' + value);
|
||||||
|
// $(this).attr('href', value.replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']'));
|
||||||
|
|
||||||
$(this).children('label').html(newname);
|
// //var newname = $(this).html.replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']');
|
||||||
$(this).children('input').attr('name', newname);
|
// //$(this).html(newname);
|
||||||
|
// });
|
||||||
|
|
||||||
$(this).find('ul li').each(function(){
|
$(this).find('ul li').each(function(){
|
||||||
var itemindex2= $(this).index();
|
var itemindex2= $(this).index();
|
||||||
|
|
||||||
$(this).children('input').each(function(){
|
$(this).children('input').each(function(){
|
||||||
var newname2 = $(this).attr('name').replace(/\[splits\]\[[0-9]*\]/,'[splits][' + itemindex2 + ']');
|
var newname2 = $(this).attr('name').replace(/\[splits\]\[[0-9]*\]/,'[splits][' + itemindex2 + ']');
|
||||||
newname2 = newname2.replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']');
|
newname2 = newname2.replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']');
|
||||||
$(this).attr('name', newname2);
|
$(this).attr('name', newname2);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(this).children('label').each(function(){
|
$(this).children('label').each(function(){
|
||||||
var newname2 = $(this).attr('name').replace(/\[splits\]\[[0-9]*\]/,'[splits][' + itemindex2 + ']');
|
//var newname2 = $(this).attr('name').replace(/\[splits\]\[[0-9]*\]/,'[splits][' + itemindex2 + ']');
|
||||||
newname2 = newname2.replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']');
|
//newname2 = newname2.replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']');
|
||||||
|
var newname2 = 'Set '+ (itemindex2 + 1 ) + '';
|
||||||
$(this).html(newname2);
|
$(this).html(newname2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Only show delete if more than 1 set
|
||||||
if ( $(this).siblings('.set').length > 0 ) {
|
if ( $(this).siblings('.set').length > 0 ) {
|
||||||
$(this).children('.delete').show();
|
$(this).children('.delete').show();
|
||||||
console.log(">1 " + $(this).siblings('.set').length);
|
|
||||||
} else {
|
} else {
|
||||||
$(this).children('.delete').hide();
|
$(this).children('.delete').hide();
|
||||||
console.log("=1 " + $(this).siblings('.set').length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
$(document).on('click', '.addthisExercise',(function() {
|
$(document).on('click', '.addthisExercise',(function() {
|
||||||
// $("button.addthisExercise").click(function() {
|
// $("button.addthisExercise").click(function() {
|
||||||
console.log("This exercise name li" + JSON.stringify($(this).closest('li').data()));
|
console.log("This exercise name li" + JSON.stringify($(this).closest('li').data()));
|
||||||
var newElem = $('<li class=ui-state-default ><label for="element">elements[0][exerciseID]<br /></label><input name="elements[][exerciseID]" class="element" value="' + $(this).closest('li').data('name') + '"><button type="button" class="addSet">Add Set</button><button type="button" class="delete">Delete Exercise</button><ul class="sets"><li class="set"><label for="element" name="elements[0][splits][0][reps]">elements[0][splits][0][reps]<br /></label><input name="elements[0][splits][0][reps]" class="element"><label for="element" name="elements[0][splits][0][weight]"><br />elements[0][splits][0][weight]<br /></label><input name="elements[0][splits][0][weight]" class="element"><button type="button" class="delete">Delete Set</button></li></ul></li>');
|
var newElem = $('<li class=ui-state-default ><label for="element">Name</label><input name="exercisename" class="element" value="' + $(this).closest('li').data('name') + '"><input name="elements[][exerciseID]" class="hiddenelement" value="' + $(this).closest('li').data('exid') + '"><input name="elements[][Modifier]" class="element" value="' + $(this).closest('li').data('musclearrayMod') + '"><button type="button" class="addSet">Add Set</button><button type="button" class="delete">Delete Exercise</button><ul class="sets"><li class="set"><label for="element" name="elements[0][splits][0][reps]">elements[0][splits][0][reps]<br /></label><input name="elements[0][splits][0][reps]" class="element"><label for="element" name="elements[0][splits][0][weight]"><br />elements[0][splits][0][weight]<br /></label><input name="elements[0][splits][0][weight]" class="element"><button type="button" class="delete">Delete Set</button></li></ul></li>');
|
||||||
|
$(newElem).data('musclearray', $(this).closest('li').data('musclearray'));
|
||||||
|
$(newElem).data('musclearrayMod', $(this).closest('li').data('musclearrayMod'));
|
||||||
$(newElem).appendTo('ul#exercises');
|
$(newElem).appendTo('ul#exercises');
|
||||||
|
$( ".hiddenelement" ).hide();
|
||||||
$("button").button();
|
$("button").button();
|
||||||
$( "ul#exercises" ).sortable( "refresh" );
|
$( "ul#exercises" ).sortable( "refresh" );
|
||||||
$( "ul#sets" ).sortable( "refresh" );
|
$( "ul#sets" ).sortable( "refresh" );
|
||||||
@@ -16,19 +19,26 @@
|
|||||||
//PopulateExerciseList(arr);
|
//PopulateExerciseList(arr);
|
||||||
|
|
||||||
$(document).on('click', '.filter',(function (){
|
$(document).on('click', '.filter',(function (){
|
||||||
console.time('Filter');
|
var keyREGEX= "";
|
||||||
var keyREGEX= "";
|
if ($(".filter:checked").length > 0)
|
||||||
var len = $('.filter').length;
|
{
|
||||||
$(".filter").each(function(index, element) {
|
// any one is checked
|
||||||
|
var len = $('.filter').length;
|
||||||
|
$(".filter").each(function(index, element) {
|
||||||
|
|
||||||
|
if ($(this).is (':checked'))
|
||||||
|
{
|
||||||
|
// Do stuff
|
||||||
|
keyREGEX += '('+ $(this).val() +')';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//keyREGEX += "'";
|
||||||
|
keyREGEX = keyREGEX.replace(")(", ")|(");
|
||||||
|
} else {
|
||||||
|
// none is checked
|
||||||
|
keyREGEX = '(none is checked)';
|
||||||
|
}
|
||||||
|
|
||||||
if ($(this).is (':checked'))
|
|
||||||
{
|
|
||||||
// Do stuff
|
|
||||||
keyREGEX += '('+ $(this).val() +')';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//keyREGEX += "'";
|
|
||||||
keyREGEX = keyREGEX.replace(")(", ")|(");
|
|
||||||
console.log("Regex= " + keyREGEX);
|
console.log("Regex= " + keyREGEX);
|
||||||
filteredExerciseArray = filterarray(originalExerciselist, keyREGEX);
|
filteredExerciseArray = filterarray(originalExerciselist, keyREGEX);
|
||||||
PopulateExerciseList(filteredExerciseArray);
|
PopulateExerciseList(filteredExerciseArray);
|
||||||
@@ -59,6 +69,9 @@ function PopulateExerciseList(exerciselist) {
|
|||||||
//console.log("Exercisename = " + item.name);
|
//console.log("Exercisename = " + item.name);
|
||||||
var newElem = $('<li>'+item.name + ' - ' + item.description + ' - ' + item.keywords +'<button type="button" class="addthisExercise">+</li>');
|
var newElem = $('<li>'+item.name + ' - ' + item.description + ' - ' + item.keywords +'<button type="button" class="addthisExercise">+</li>');
|
||||||
$(newElem).data('name', item.name);
|
$(newElem).data('name', item.name);
|
||||||
|
$(newElem).data('exid', item._id);
|
||||||
|
$(newElem).data('musclearray', item.musclearray);
|
||||||
|
//$(newElem).data('musclearrayMod', item.musclearrayMod);
|
||||||
$(newElem).data('datafields', item.datafields);
|
$(newElem).data('datafields', item.datafields);
|
||||||
newExerciselist.append(newElem);
|
newExerciselist.append(newElem);
|
||||||
});
|
});
|
||||||
@@ -74,9 +87,3 @@ function PopulateExerciseList(exerciselist) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// function populateHandles() {
|
|
||||||
// var options = '';
|
|
||||||
// for (var i = 0; i < handles.length; i++) {
|
|
||||||
// options += '<option value="' + handles[i] + '">' + handles[i] + '</option>';
|
|
||||||
// }
|
|
||||||
// $('#listBox').html(options);
|
|
||||||
@@ -15,6 +15,7 @@ list-style-type: none;
|
|||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#exerciselist {
|
#exerciselist {
|
||||||
width : 500px;
|
width : 500px;
|
||||||
height : 400px;
|
height : 400px;
|
||||||
|
|||||||
@@ -30,4 +30,43 @@ module.exports = function(app) {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/api/getexercisemodifier/:userid/:exerciseid', function(req, res) {
|
||||||
|
res.contentType('json');
|
||||||
|
console.log('userID' + req.params.userid);
|
||||||
|
console.log('exerciseID' + req.params.exerciseid);
|
||||||
|
//DB search workouts
|
||||||
|
// where userid
|
||||||
|
//where exerciseid
|
||||||
|
|
||||||
|
Workout
|
||||||
|
.where('userID', req.params.userid)
|
||||||
|
.where('elements.exerciseID', req.params.exerciseid)
|
||||||
|
.select('elements')
|
||||||
|
// .exec(callback);
|
||||||
|
|
||||||
|
// workout.findOne({_id: req.params._id})
|
||||||
|
// //.populate('elements.exerciseID')
|
||||||
|
.exec(function(err, workout) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if (! workout) {
|
||||||
|
return res.send('Not found', 404);
|
||||||
|
}
|
||||||
|
//need for loop for workout as it returns an array
|
||||||
|
var filteredarray = workout[0].elements.filter( function(i) {
|
||||||
|
return i.exerciseID == req.params.exerciseid;
|
||||||
|
});
|
||||||
|
// then for each in filtered array grab sets reps weight
|
||||||
|
// punch that into an array.
|
||||||
|
|
||||||
|
// res.send(filteredarray);
|
||||||
|
// //console.log("hmm" + JSON.stringify(workout[0].elements));
|
||||||
|
res.send(workout);
|
||||||
|
//next();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -3,7 +3,7 @@ var workout = require('../../data/models/workout');
|
|||||||
function loadworkout(req, res, next) {
|
function loadworkout(req, res, next) {
|
||||||
console.log('fetch id' + req.params._id );
|
console.log('fetch id' + req.params._id );
|
||||||
workout.findOne({_id: req.params._id})
|
workout.findOne({_id: req.params._id})
|
||||||
//.populate('elements')
|
.populate('elements.exerciseID')
|
||||||
.exec(function(err, workout) {
|
.exec(function(err, workout) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ var loggedIn = require('./middleware/logged_in');
|
|||||||
var maxWorkoutsPerPage = 5;
|
var maxWorkoutsPerPage = 5;
|
||||||
var Exercise = require('../data/models/exercise');
|
var Exercise = require('../data/models/exercise');
|
||||||
var loadExercise = require('./middleware/load_exercise');
|
var loadExercise = require('./middleware/load_exercise');
|
||||||
|
var MuscleArray = require('./middleware/musclearray');
|
||||||
var Moment = require('moment');
|
var Moment = require('moment');
|
||||||
|
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
@@ -60,8 +61,11 @@ module.exports = function(app) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.get('/workouts/:_id', loadWorkout, function(req, res, next){
|
app.get('/workouts/:_id', loggedIn, loadWorkout, function(req, res, next){
|
||||||
console.log("time" + Moment.utc(req.workout.workoutDate).format("ddd, hA"));
|
console.log("time" + Moment.utc(req.workout.workoutDate).format("ddd, hA"));
|
||||||
|
var output = MuscleArray(req.workout);
|
||||||
|
console.log('output - ' + JSON.stringify(output));
|
||||||
|
|
||||||
res.render('workouts/workout', {title: req.workout.title,
|
res.render('workouts/workout', {title: req.workout.title,
|
||||||
workout: req.workout,
|
workout: req.workout,
|
||||||
workouttime: Moment.utc(req.workout.workoutDate).format("ddd, hA")
|
workouttime: Moment.utc(req.workout.workoutDate).format("ddd, hA")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ block content
|
|||||||
ul#exerciselist
|
ul#exerciselist
|
||||||
|
|
||||||
div#filters
|
div#filters
|
||||||
h3 Filters ( currently just placeholder )
|
h3 Filters
|
||||||
label Free Weights
|
label Free Weights
|
||||||
input.filter(type="checkbox", checked=true, value="Free Weights")
|
input.filter(type="checkbox", checked=true, value="Free Weights")
|
||||||
label Bodyweight
|
label Bodyweight
|
||||||
|
|||||||
Reference in New Issue
Block a user