mirror of
https://github.com/bodyrep/DemoApp.git
synced 2026-01-25 14:43:00 +00:00
started moving content to corretn divs
This commit is contained in:
8
app.js
8
app.js
@@ -11,7 +11,7 @@ var app = express();
|
||||
var dbURL = 'mongodb://localhost/database';
|
||||
var db = require('mongoose').connect(dbURL);
|
||||
var qs = require('qs');
|
||||
|
||||
var MongoStore = require('connect-mongo')(express);
|
||||
|
||||
// Configuration
|
||||
app.configure(function(){
|
||||
@@ -22,7 +22,11 @@ app.configure(function(){
|
||||
app.use(express.cookieParser('my secret string'));
|
||||
app.use(express.session({
|
||||
secret: 'my secret string',
|
||||
maxAge: 3600000
|
||||
maxAge: 3600000,
|
||||
store: new MongoStore({
|
||||
db: 'sessions',
|
||||
url: dbURL
|
||||
})
|
||||
}));
|
||||
app.use(function(req, res, next){
|
||||
res.locals.session = req.session;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
$(document).ready(function() {
|
||||
//makes buttons buttons
|
||||
$("button").button();
|
||||
|
||||
console.log('document ready');
|
||||
//makes datepickers
|
||||
$( ".datepicker" ).datepicker();
|
||||
//$('#newworkout').find('input.datepicker').datepicker();
|
||||
@@ -25,6 +25,8 @@ $(document).ready(function() {
|
||||
}
|
||||
});
|
||||
|
||||
originalExerciselist = $.getValues("/api/exerciselist");
|
||||
|
||||
|
||||
$("button#addExercise").click(function() {
|
||||
console.log("click!");
|
||||
@@ -128,6 +130,124 @@ $(document).ready(function() {
|
||||
|
||||
//$('#newworkout').trigger('sortupdate');
|
||||
|
||||
$("button.map-link").click(function () {
|
||||
console.log('mapclick');
|
||||
var id = $(this).attr('value');
|
||||
console.log(id);
|
||||
$('div#Rightpane').empty().load(id, function(){
|
||||
PopulateExerciseList(originalExerciselist);
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.addthisExercise',(function() {
|
||||
// $("button.addthisExercise").click(function() {
|
||||
console.log("This exercise name li" + JSON.stringify($(this).closest('li').data()));
|
||||
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');
|
||||
$( ".hiddenelement" ).hide();
|
||||
$("button").button();
|
||||
$( "ul#exercises" ).sortable( "refresh" );
|
||||
$( "ul#sets" ).sortable( "refresh" );
|
||||
$('#newworkout').trigger('sortupdate');
|
||||
})
|
||||
);
|
||||
|
||||
//filteredExerciseArray = filterarray(originalExerciselist);
|
||||
//PopulateExerciseList(arr);
|
||||
|
||||
$(document).on('click', '.filter',(function (){
|
||||
var keyREGEX= "";
|
||||
if ($(".filter:checked").length > 0)
|
||||
{
|
||||
// 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)';
|
||||
}
|
||||
|
||||
console.log("Regex= " + keyREGEX);
|
||||
filteredExerciseArray = filterarray(originalExerciselist, keyREGEX);
|
||||
PopulateExerciseList(filteredExerciseArray);
|
||||
console.timeEnd('Filter');
|
||||
}));
|
||||
|
||||
|
||||
function filterarray(input, regex){
|
||||
console.log('passed regex' + regex);
|
||||
var keyRE=new RegExp(regex);
|
||||
var arr = jQuery.grep(input, function(n, i){
|
||||
return keyRE.test(n.keywords);
|
||||
// return $.grep(n.keywords, function (item, i) {
|
||||
// return keyRE.test(item);
|
||||
// });
|
||||
});
|
||||
console.log("arr " + arr.length);
|
||||
return arr;
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
// Pseudocode for 1RM calcs
|
||||
|
||||
// for each exercise in workout
|
||||
// get H1RM for exercise
|
||||
// C1RMsum = 0
|
||||
// for each set in exercise
|
||||
// calculate C1RM and store in array
|
||||
// find highest C1RM in array
|
||||
// if C1RM > H1RM then
|
||||
// H1RM = C1RM
|
||||
// set comment to "yay"
|
||||
// for each value in array
|
||||
// set[index] = value/H1RM
|
||||
// C1RMsum += value/H1RM
|
||||
// Done
|
||||
|
||||
|
||||
// assume sum sumarray * each in musclearray
|
||||
|
||||
|
||||
|
||||
////// Make below standalone funtion "updateExerciselistDIV"
|
||||
function PopulateExerciseList(exerciselist) {
|
||||
console.time('PopulateExList');
|
||||
var newExerciselist = $('<div></div>');
|
||||
$.each(exerciselist, function (i, item) {
|
||||
//console.log("Exercisename = " + item.name);
|
||||
var newElem = $('<li>'+item.name + ' - ' + item.description + ' - ' + item.keywords +'<button type="button" class="addthisExercise">+</li>');
|
||||
$(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);
|
||||
newExerciselist.append(newElem);
|
||||
});
|
||||
console.log("newexlist outside= " + newExerciselist);
|
||||
$('#exerciselist').empty();
|
||||
$(newExerciselist).appendTo('#exerciselist');
|
||||
$("button").button();
|
||||
console.timeEnd('PopulateExList');
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +59,26 @@
|
||||
return arr;
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
// Pseudocode for 1RM calcs
|
||||
|
||||
// for each exercise in workout
|
||||
// get H1RM for exercise
|
||||
// C1RMsum = 0
|
||||
// for each set in exercise
|
||||
// calculate C1RM and store in array
|
||||
// find highest C1RM in array
|
||||
// if C1RM > H1RM then
|
||||
// H1RM = C1RM
|
||||
// set comment to "yay"
|
||||
// for each value in array
|
||||
// set[index] = value/H1RM
|
||||
// C1RMsum += value/H1RM
|
||||
// Done
|
||||
|
||||
|
||||
// assume sum sumarray * each in musclearray
|
||||
|
||||
|
||||
|
||||
////// Make below standalone funtion "updateExerciselistDIV"
|
||||
@@ -85,5 +105,3 @@ function PopulateExerciseList(exerciselist) {
|
||||
var originalExerciselist = $.getValues("/api/exerciselist");
|
||||
PopulateExerciseList(originalExerciselist);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,14 @@ list-style-type: none;
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
#Leftpane {
|
||||
float: left;
|
||||
}
|
||||
|
||||
|
||||
#Rightpane {
|
||||
float: left;
|
||||
}
|
||||
|
||||
#exerciselist {
|
||||
width : 500px;
|
||||
|
||||
@@ -12,6 +12,7 @@ var maxUsersPerPage = 5;
|
||||
|
||||
module.exports = function(app) {
|
||||
|
||||
|
||||
app.get('/users', loggedIn, isAdmin, function(req, res, next){
|
||||
var page = req.query.page && parseInt(req.query.page, 10) || 0;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ var Workout = require('../data/models/workout');
|
||||
var notLoggedIn = require('./middleware/not_logged_in');
|
||||
var loadWorkout = require('./middleware/load_workout');
|
||||
var loggedIn = require('./middleware/logged_in');
|
||||
var loadUser = require('./middleware/load_user');
|
||||
var maxWorkoutsPerPage = 5;
|
||||
var Exercise = require('../data/models/exercise');
|
||||
var loadExercise = require('./middleware/load_exercise');
|
||||
@@ -16,7 +17,7 @@ var Moment = require('moment');
|
||||
|
||||
module.exports = function(app) {
|
||||
|
||||
app.get('/workouts', loggedIn, function(req, res, next){
|
||||
app.get('/workouts/recent', loggedIn, function(req, res, next){
|
||||
var page = req.query.page && parseInt(req.query.page, 10) || 0;
|
||||
async.parallel([
|
||||
|
||||
@@ -45,7 +46,7 @@ module.exports = function(app) {
|
||||
|
||||
var lastPage = (page + 1) * maxWorkoutsPerPage >= count;
|
||||
|
||||
res.render('workouts/index', {
|
||||
res.render('workouts/recent', {
|
||||
title: 'workouts',
|
||||
workouts: workouts,
|
||||
page: page,
|
||||
@@ -60,6 +61,18 @@ module.exports = function(app) {
|
||||
res.render('workouts/new', {title: "New workout"});
|
||||
});
|
||||
|
||||
app.get('/workouts/:name/recent', loadUser, function(req, res, next){
|
||||
req.user.recentworkouts(function(err, workouts) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.render('workouts/recent', {
|
||||
//user: req.user,
|
||||
//requested: req.params.name,
|
||||
recentworkouts: workouts
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/workouts/:_id', loggedIn, loadWorkout, function(req, res, next){
|
||||
console.log("time" + Moment.utc(req.workout.workoutDate).format("ddd, hA"));
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
extends ../layout
|
||||
//extends ../layout
|
||||
|
||||
block content
|
||||
h1 Bodyrep
|
||||
p Admin Index
|
||||
//block content
|
||||
h1 Bodyrep
|
||||
p Admin Index
|
||||
|
||||
p
|
||||
a(href="/users") List Users
|
||||
p
|
||||
a(href="/workouts") List workouts
|
||||
p
|
||||
a(href="/admin") Admin Index
|
||||
p
|
||||
a(href="/admin/users") Admin Users
|
||||
p
|
||||
a(href="/admin/exercises") Admin Exercises
|
||||
p
|
||||
a(href="/users") List Users
|
||||
p
|
||||
a(href="/workouts") List workouts
|
||||
p
|
||||
a(href="/admin") Admin Index
|
||||
p
|
||||
a(href="/admin/users") Admin Users
|
||||
p
|
||||
a(href="/admin/exercises") Admin Exercises
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
- if (session.user)
|
||||
p
|
||||
span
|
||||
b UserName
|
||||
span= session.user.name
|
||||
span
|
||||
b  UserID
|
||||
span= session.user._id
|
||||
p
|
||||
form(method="POST", action="/session")
|
||||
input(type="hidden", name="_method", value="DELETE")
|
||||
input(type="submit", value="Log out")
|
||||
- else
|
||||
p
|
||||
a(href="/session/new") Login
|
||||
span or
|
||||
a(href="/users/new") Join Bodyrep Now!
|
||||
div#top
|
||||
|
||||
- if (session.user)
|
||||
p
|
||||
span
|
||||
b UserName
|
||||
span= session.user.name
|
||||
span
|
||||
b  UserID
|
||||
span= session.user._id
|
||||
form(method="POST", action="/session")
|
||||
input(type="hidden", name="_method", value="DELETE")
|
||||
input(type="submit", value="Log out")
|
||||
- else
|
||||
p
|
||||
a(href="/session/new") Login
|
||||
span or
|
||||
a(href="/users/new") Join Bodyrep Now!
|
||||
@@ -1,25 +1,29 @@
|
||||
extends ../layout
|
||||
//block additionalscripts
|
||||
// script(src='/javascripts/workout.js')
|
||||
|
||||
block content
|
||||
|
||||
h1= user.name
|
||||
div#Leftpane
|
||||
h2= user.name
|
||||
|
||||
- if (session.user)
|
||||
- if (session.user.name === requested)
|
||||
h1 Private View
|
||||
- if (session.user)
|
||||
- if (session.user.name === requested)
|
||||
h2 Private View
|
||||
div
|
||||
button.map-link(value="/workouts/" + encodeURIComponent(session.user.name) + "/recent") Recent workouts
|
||||
div
|
||||
button.map-link(value="/workouts/new") Create new workout
|
||||
|
||||
p
|
||||
a(href="/workouts/new") Create new workout
|
||||
- else
|
||||
h2 Public View
|
||||
|
||||
- else
|
||||
h1 Public View
|
||||
- if (session.user)
|
||||
- if (session.user.is_admin === true)
|
||||
div
|
||||
button.map-link(value="/admin") Goto Admin Page
|
||||
|
||||
h2 Recent workouts:
|
||||
ul
|
||||
- recentworkouts.forEach(function(workout) {
|
||||
li
|
||||
a(href="/workouts/" + encodeURIComponent(workout._id))= workout._id
|
||||
- });
|
||||
div#Rightpane
|
||||
|
||||
include ../workouts/recent
|
||||
|
||||
- if (session.user)
|
||||
- if (session.user.is_admin === true)
|
||||
a(href="/admin") Goto Admin Page
|
||||
@@ -1,45 +1,43 @@
|
||||
extends ../layout
|
||||
//extends ../layout
|
||||
//block content
|
||||
h1 New workout
|
||||
|
||||
block additionalscripts
|
||||
script(src='/javascripts/workout.js')
|
||||
h3 Exercises (dynamically loaded from database)
|
||||
ul#exerciselist
|
||||
li Unpopulated
|
||||
|
||||
block content
|
||||
h1 New workout
|
||||
div#filters
|
||||
h3 Filters
|
||||
label Free Weights
|
||||
input.filter(type="checkbox", checked=true, value="Free Weights")
|
||||
label Bodyweight
|
||||
input.filter(type="checkbox", checked=true, value="Bodyweight")
|
||||
label Exercise Machines
|
||||
input.filter(type="checkbox", checked=true, value='Exercise Machine')
|
||||
label Kettlebells
|
||||
input.filter(type="checkbox", checked=true, value='Kettlebells')
|
||||
label Cardio
|
||||
input.filter(type="checkbox", checked=true, value='Cardio')
|
||||
|
||||
h3 Exercises (dynamically loaded from database)
|
||||
ul#exerciselist
|
||||
//button#addExercise(type="button") Add Exercise
|
||||
hr
|
||||
|
||||
div#filters
|
||||
h3 Filters
|
||||
label Free Weights
|
||||
input.filter(type="checkbox", checked=true, value="Free Weights")
|
||||
label Bodyweight
|
||||
input.filter(type="checkbox", checked=true, value="Bodyweight")
|
||||
label Exercise Machines
|
||||
input.filter(type="checkbox", checked=true, value='Exercise Machine')
|
||||
label Kettlebells
|
||||
input.filter(type="checkbox", checked=true, value='Kettlebells')
|
||||
label Cardio
|
||||
input.filter(type="checkbox", checked=true, value='Cardio')
|
||||
form#newworkout(method="POST", action="/workouts")
|
||||
ul
|
||||
li
|
||||
label(for="title", value="UserID") UserID
|
||||
input#title(name="userID", value=session.user._id)
|
||||
li
|
||||
label(for="datepicker", value="Date") workoutDate
|
||||
input.datepicker(name="workoutDate")
|
||||
li
|
||||
label(for="timepicker", value="Time") workoutTime
|
||||
select(name="workoutTime")
|
||||
option(value='0100') 1 AM
|
||||
option(value='0130') 1:30 AM
|
||||
option(value='0200') 2 AM
|
||||
|
||||
//button#addExercise(type="button") Add Exercise
|
||||
hr
|
||||
ul#exercises
|
||||
|
||||
form#newworkout(method="POST", action="/workouts")
|
||||
ul
|
||||
li
|
||||
label(for="title", value="UserID") UserID
|
||||
input#title(name="userID", value=session.user._id)
|
||||
li
|
||||
label(for="datepicker", value="Date") workoutDate
|
||||
input.datepicker(name="workoutDate")
|
||||
li
|
||||
label(for="timepicker", value="Time") workoutTime
|
||||
select(name="workoutTime")
|
||||
option(value='0100') 1 AM
|
||||
option(value='0130') 1:30 AM
|
||||
option(value='0200') 2 AM
|
||||
|
||||
ul#exercises
|
||||
|
||||
button(type="submit", value="Save") Save
|
||||
button(type="submit", value="Save") Save
|
||||
|
||||
Reference in New Issue
Block a user