Getting A better Log Entry Experience, and history setup
This commit is contained in:
parent
98a86ca6a8
commit
5d3396c333
15 changed files with 428 additions and 140 deletions
|
|
@ -6,25 +6,23 @@
|
|||
<header>
|
||||
<h3>Workouts</h3>
|
||||
</header>
|
||||
<div role="group">
|
||||
<div role="group" class="infoBody" id="workoutData">
|
||||
<div>
|
||||
<h4>Workouts</h4>
|
||||
</div>
|
||||
<div>
|
||||
{{workoutCount}}
|
||||
</div>
|
||||
<h4>{{workoutCount}} Workout Routines</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div role="group">
|
||||
<div>
|
||||
<h4>Exercise Logs</h4>
|
||||
<h4>{{logCount}} Exercise Logs</h4>
|
||||
</div>
|
||||
</div>
|
||||
<footer role="group">
|
||||
<div>
|
||||
<a href="#!" id="workoutData"><i class="material-icons">chart</i> Workout History</a>
|
||||
</div>
|
||||
<div>
|
||||
{{logCount}}
|
||||
<a href="#!" id="logWorkout"><i class="material-icons">notes</i> Log a Workout</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<footer>
|
||||
<a href="#!" id="logWorkout"><i class="material-icons">notes</i> Log a Workout</a>
|
||||
</footer>
|
||||
</article>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -36,4 +36,7 @@ Template.home.events({
|
|||
'click #logMeasure' (e) {
|
||||
FlowRouter.go('/measLogEntry');
|
||||
},
|
||||
'click #workoutData' (e) {
|
||||
FlowRouter.go('/workoutData');
|
||||
}
|
||||
});
|
||||
|
|
@ -39,7 +39,6 @@ Template.measLogEntry.events({
|
|||
if (!measInfo) {
|
||||
console.log(" UNABLE to find measurement info.");
|
||||
} else {
|
||||
console.dir(measInfo);
|
||||
let measure1 = $("#" + measInfo.measurementName).val();
|
||||
let measureName = measInfo.measurementName;
|
||||
let units = measInfo.measurementUnits;
|
||||
|
|
|
|||
|
|
@ -5,63 +5,91 @@
|
|||
<select name="selectExerciseToLog" class="selectExerciseToLog" id="selectExerciseToLog">
|
||||
<option value="" disabled selected> + Add Log Entry</option>
|
||||
{{#each workoutLog}}
|
||||
<option value="{{_id}}">{{exerciseName}}</option>
|
||||
<option value="{{_id}} | {{exerciseName}}">{{exerciseName}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{#if $eq exIdSelected true}}
|
||||
<!-- add fields for log based on selection from drop button above -->
|
||||
<div class="grid">
|
||||
<div>
|
||||
<h3>{{exerciseToLog.exerciseName}}</h3>
|
||||
<div class="grid">
|
||||
{{#if $eq logIdSet false}}
|
||||
<div>
|
||||
<input type="number" class="exerciseWeight" id="exerciseWeight" placeholder="Enter Weight..." />
|
||||
</div>
|
||||
{{else}}
|
||||
<div>
|
||||
<h4>{{enteredWeight}}</h4>
|
||||
</div>
|
||||
{{/if}}
|
||||
<div>
|
||||
<button class="outline addASet" id="addASet">+ Add a Set</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<label>{{exerciseToLog.exerciseMeasure}}</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="number" id="{{exerciseToLog.exerciseMeasure}}" />
|
||||
</div>
|
||||
<div>
|
||||
<label>{{exerciseToLog.exerciseUnitMeasure}}</label>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="grid">
|
||||
{{#if $neq exerciseToLog.exerciseMeasure2 ""}}
|
||||
<div>
|
||||
<label>{{exerciseToLog.exerciseMeasure2}}</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="number" id="{{exerciseToLog.exerciseMeasure2}}" />
|
||||
</div>
|
||||
<div>
|
||||
{{exerciseToLog.exerciseUnitMeasure2}}
|
||||
{{#if $eq addSet true}}
|
||||
<div class="grid">
|
||||
<div>
|
||||
<input type="number" class="addRepsVal" id="addRepsVal_{{ setNo }}">
|
||||
</div>
|
||||
<div>
|
||||
<button class="saveSet secondary" id="saveSet">Save Set</button>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Set #</th>
|
||||
<th>Reps</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each setsRecorded}}
|
||||
<tr>
|
||||
<td>{{setNumber}}</td>
|
||||
<td>{{repCount}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{#if $neq prevWorkout false}}
|
||||
<hr>
|
||||
<div class="article">
|
||||
<header>Last Workout on {{prevWorkout.dateAdded}}</header>
|
||||
<table class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Weight</th>
|
||||
<th>Sets</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{prevWorkout.exerciseWeight}}</td>
|
||||
<td>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Set #</th>
|
||||
<th>Reps</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each prevWorkout.sets}}
|
||||
<tr>
|
||||
<td>{{setNumber}}</td>
|
||||
<td>{{repCount}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
<hr>
|
||||
<div class="grid">
|
||||
{{#if $neq exerciseToLog.exerciseMeasure3 ""}}
|
||||
<div>
|
||||
<label>{{exerciseToLog.exerciseMeasure3}}</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="number" id="{{exerciseToLog.exerciseMeasure3}}" />
|
||||
</div>
|
||||
<div>
|
||||
{{exerciseToLog.exerciseUnitMeasure3}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<button class="primary saveLogEntry right" id="saveLogEntry">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{> snackbar}}
|
||||
</template>
|
||||
|
|
@ -2,6 +2,7 @@ import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
|||
import { Workouts } from '../../../../imports/api/workouts';
|
||||
import { WorkoutLog } from '../../../../imports/api/workoutLog';
|
||||
import { LogEntry } from '../../../../imports/api/logEntry';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
Template.logEntry.onCreated(function() {
|
||||
this.subscribe("myWorkoutRoutines");
|
||||
|
|
@ -12,6 +13,9 @@ Template.logEntry.onCreated(function() {
|
|||
Template.logEntry.onRendered(function() {
|
||||
Session.set("exId", "");
|
||||
Session.set("exIdSelected", false);
|
||||
Session.set("setNo", 0);
|
||||
Session.set("addSet", false);
|
||||
Session.set("logId", "f");
|
||||
});
|
||||
|
||||
Template.logEntry.helpers({
|
||||
|
|
@ -24,70 +28,121 @@ Template.logEntry.helpers({
|
|||
},
|
||||
exIdSelected: function() {
|
||||
return Session.get("exIdSelected");
|
||||
}
|
||||
},
|
||||
setNo: function() {
|
||||
return Session.get("setNo");
|
||||
},
|
||||
addSet: function() {
|
||||
return Session.get("addSet");
|
||||
},
|
||||
setsRecorded: async() => {
|
||||
let logId = Session.get("logId");
|
||||
const logInfo = await LogEntry.findOneAsync({ _id: logId });
|
||||
|
||||
if (logInfo) {
|
||||
return logInfo && logInfo.sets ? logInfo.sets : [];
|
||||
}
|
||||
},
|
||||
logIdSet: function() {
|
||||
let logId = Session.get("logId");
|
||||
if (logId != "f") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
enteredWeight: function() {
|
||||
return Session.get("enteredWeight");
|
||||
},
|
||||
prevWorkout: async() => {
|
||||
let exerciseName = Session.get("exerciseName");
|
||||
let logs = await LogEntry.findOneAsync({ exerciseName: exerciseName }, { sort: { _id: -1 } });
|
||||
let todayDateTime = new Date();
|
||||
let today = dayjs(todayDateTime).format('YYYY-MM-DD');
|
||||
if (logs) {
|
||||
if (logs.dateAdded != today) {
|
||||
return logs;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Template.logEntry.events({
|
||||
'change #selectExerciseToLog' (e) {
|
||||
let exerciseId = $("#selectExerciseToLog").val();
|
||||
let exerciseNameAndId = $("#selectExerciseToLog").val();
|
||||
let splitExNameId = exerciseNameAndId.split(' | ');
|
||||
let exerciseId = splitExNameId[0];
|
||||
let exerciseName = splitExNameId[1];
|
||||
|
||||
Session.set("setNo", 0);
|
||||
Session.set("exerciseName", exerciseName);
|
||||
Session.set("exerciseLogId", exerciseId);
|
||||
Session.set("exIdSelected", true);
|
||||
Session.set("logId", "f");
|
||||
},
|
||||
'click #saveLogEntry' (e) {
|
||||
let logId = Session.get("exerciseLogId");
|
||||
'click #addASet' (e) {
|
||||
let setNo = Session.get("setNo");
|
||||
let logId = Session.get("logId");
|
||||
setNo = setNo+=1;
|
||||
Session.set("setNo", setNo);
|
||||
Session.set("addSet", true);
|
||||
let exerciseNameAndId = $("#selectExerciseToLog").val();
|
||||
let splitExNameId = exerciseNameAndId.split(' | ');
|
||||
let exerciseId = splitExNameId[0];
|
||||
let exerciseName = splitExNameId[1];
|
||||
let weight = $("#exerciseWeight").val();
|
||||
let weightNo = Number(weight);
|
||||
|
||||
const getRoutine = async() => {
|
||||
let workout = await WorkoutLog.findOneAsync({ _id: logId });
|
||||
|
||||
if (!workout) {
|
||||
console.log("no workout found.");
|
||||
} else {
|
||||
let routineId = workout.routineId;
|
||||
let exerName = workout.exerciseName;
|
||||
let measure1 = $("#" + workout.exerciseMeasure).val();
|
||||
let measUnit1 = workout.exerciseUnitMeasure;
|
||||
let measure2 = $("#" + workout.exerciseMeasure2).val();
|
||||
let measUnit2 = workout.exerciseUnitMeasure2;
|
||||
let measure3 = $("#" + workout.exerciseMeasure3).val();
|
||||
let measUnit3 = workout.exerciseUnitMeasure3;
|
||||
let measName1 = workout.exerciseMeasure;
|
||||
let measName2 = workout.exerciseMeasure2;
|
||||
let measName3 = workout.exerciseMeasure3;
|
||||
|
||||
let meas1 = Number(measure1);
|
||||
let meas2 = Number(measure2);
|
||||
let meas3 = Number(measure3);
|
||||
|
||||
if (meas1 == "" || meas1 == null) {
|
||||
showSnackbar("Measurement for " + workout.exerciseMeasure + " is required!", " red");
|
||||
return;
|
||||
} else {
|
||||
const saveLogEntry = async() => {
|
||||
try {
|
||||
const result = Meteor.callAsync('add.logEntry', routineId, logId, exerName, measName1, meas1, measUnit1, measName2, meas2, measUnit2, measName3, meas3, measUnit3);
|
||||
if (!result) {
|
||||
console.log(" UNABLE TO SAVE LOG ENTRY!");
|
||||
showSnackbar("Unable to save log entry!", "red");
|
||||
} else {
|
||||
$("#" + workout.exerciseMeasure).val("");
|
||||
$("#" + workout.exerciseMeasure2).val("");
|
||||
$("#" + workout.exerciseMeasure3).val("");
|
||||
$("#selectExerciseToLog").val("");
|
||||
Session.set("exIdSelected", false);
|
||||
Session.set("exerciseLogId", "");
|
||||
showSnackbar("Log Entry Added!", "green");
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR saving log entry: " + error);
|
||||
}
|
||||
if (logId == "f") {
|
||||
Session.set('enteredWeight', weight);
|
||||
const addLogEntry = async() => {
|
||||
try {
|
||||
const result = await Meteor.callAsync('add.logEntry', exerciseId, exerciseName, weightNo);
|
||||
if (!result) {
|
||||
console.log(" UNABLE to add log entry.");
|
||||
showSnackbar("Unable to add Log Entry!", "red");
|
||||
} else {
|
||||
Session.set("logId", result);
|
||||
showSnackbar("Log Started!", "green");
|
||||
}
|
||||
saveLogEntry();
|
||||
} catch (error) {
|
||||
console.log(" ERROR adding log entry: " + error);
|
||||
}
|
||||
}
|
||||
addLogEntry();
|
||||
}
|
||||
getRoutine();
|
||||
|
||||
},
|
||||
'click #saveSet' (e) {
|
||||
let logId = Session.get("logId");
|
||||
let setNo = Session.get("setNo");
|
||||
let reps = $("#addRepsVal_" + setNo).val();
|
||||
|
||||
let sets = Number(setNo);
|
||||
let repCount = Number(reps);
|
||||
|
||||
}
|
||||
// add meteor call to add this set to the log entry.
|
||||
const addSetToLog = async() => {
|
||||
try {
|
||||
const result = await Meteor.callAsync('add.setToLog', logId, sets, repCount);
|
||||
if (!result) {
|
||||
console.log(" UNABLE to add set to log entry.");
|
||||
showSnackbar("Set NOT added to log!", "red");
|
||||
} else {
|
||||
showSnackbar("Set Added Successfully!", "green");
|
||||
$("#addRepsVal_" + setNo).val("");
|
||||
Session.set("addSet", false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(" ERROR adding set to log entry: " + error);
|
||||
}
|
||||
}
|
||||
addSetToLog();
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
34
client/General/Workouts/Workoutdata/workoutData.js
Normal file
34
client/General/Workouts/Workoutdata/workoutData.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
||||
import { Workouts } from '../../../../imports/api/workouts';
|
||||
import { WorkoutLog } from '../../../../imports/api/workoutLog';
|
||||
import { LogEntry } from '../../../../imports/api/logEntry';
|
||||
import { Chart } from 'chart.js';
|
||||
import { dayjs } from 'dayjs';
|
||||
|
||||
Template.workoutData.onCreated(function() {
|
||||
this.subscribe("myWorkoutRoutines");
|
||||
this.subscribe("myWorkoutLog");
|
||||
this.subscribe("myLogEntries");
|
||||
});
|
||||
|
||||
Template.workoutData.onRendered(function() {
|
||||
|
||||
});
|
||||
|
||||
Template.workoutData.helpers({
|
||||
workoutLog: function() {
|
||||
return WorkoutLog.find({});
|
||||
},
|
||||
lastWorkout: async() => {
|
||||
const mostRecentDate = await LogEntry.findOneAsync({}, { sort: { dateAdded: -1 } });
|
||||
if (mostRecentDate) {
|
||||
return LogEntry.find({ dateAdded: mostRecentDate.dateAdded });
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Template.workoutData.events({
|
||||
|
||||
});
|
||||
45
client/General/Workouts/Workoutdata/workoutdata.html
Normal file
45
client/General/Workouts/Workoutdata/workoutdata.html
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<template name="workoutData">
|
||||
<h1>Workouts</h1>
|
||||
<ul class="collection">
|
||||
<li class="collection-header">Last Workout</li>
|
||||
|
||||
<li class="collection-item">
|
||||
<table class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Exercise</th>
|
||||
<th>Weight</th>
|
||||
<th>Sets</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each lastWorkout}}
|
||||
<tr>
|
||||
<td>{{exerciseName}}</td>
|
||||
<td>{{exerciseWeight}}</td>
|
||||
<td>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Sets</th>
|
||||
<th>Reps</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each sets}}
|
||||
<tr>
|
||||
<td>{{setNumber}}</td>
|
||||
<td>{{repCount}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</template>
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
<ul>
|
||||
{{#if currentUser}}
|
||||
{{#if isInRole "systemadmin"}}
|
||||
<li><a href="#" id="manage" class="navBtn">Manage</a></li>
|
||||
<li><a href="#" id="systemAdmin" class="navBtn">Manage</a></li>
|
||||
{{/if}}
|
||||
<li><a href="#!" id="home" class="navBtn">Home</a></li>
|
||||
<li><a href="#!" id="logEntry" class="navBtn">Log Entry</a></li>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue