Adding Log Entry

This commit is contained in:
Brian McGonagill 2026-02-08 11:03:21 -06:00
parent e8649038ad
commit b5bab7b2a6
6 changed files with 230 additions and 0 deletions

View file

@ -0,0 +1,67 @@
<template name="logEntry">
<h1>Log Entry</h1>
<div class="grid">
<div>
<select name="selectExerciseToLog" class="selectExerciseToLog" id="selectExerciseToLog">
<option value="" disabled selected> + Add Log Entry</option>
{{#each workoutLog}}
<option value="{{_id}}">{{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>
</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}}
</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>

View file

@ -0,0 +1,93 @@
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';
Template.logEntry.onCreated(function() {
this.subscribe("myWorkoutRoutines");
this.subscribe("myWorkoutLog");
this.subscribe("myLogEntries");
});
Template.logEntry.onRendered(function() {
Session.set("exId", "");
Session.set("exIdSelected", false);
});
Template.logEntry.helpers({
workoutLog: function() {
return WorkoutLog.find({});
},
exerciseToLog: function() {
let exId = Session.get("exerciseLogId");
return WorkoutLog.findOneAsync({ _id: exId });
},
exIdSelected: function() {
return Session.get("exIdSelected");
}
});
Template.logEntry.events({
'change #selectExerciseToLog' (e) {
let exerciseId = $("#selectExerciseToLog").val();
Session.set("exerciseLogId", exerciseId);
Session.set("exIdSelected", true);
},
'click #saveLogEntry' (e) {
let logId = Session.get("exerciseLogId");
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);
}
}
saveLogEntry();
}
}
}
getRoutine();
}
});

View file

@ -8,6 +8,8 @@
{{#if isInRole "systemadmin"}}
<li><a href="#" id="manage" 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>
<li class="signOut"><a href="#" class="signOut">Log Out</a></li>
{{#if $eq updateExists true}}
<li><a href="#!"><i class="material-icons" id='dashboard'>notifications</i></a></li>

50
imports/api/logEntry.js Normal file
View file

@ -0,0 +1,50 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const LogEntry = new Mongo.Collection('logEntry');
LogEntry.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
async 'add.logEntry' (routineId, logId, exerciseName, measName1, measure1, measUnit1, measName2, measure2, measUnit2, measName3, measure3, measUnit3) {
check(routineId, String);
check(logId, String);
check(exerciseName, String);
check(measName1, String);
check(measure1, Number);
check(measUnit1, String);
check(measName2, String);
check(measure2, Number);
check(measUnit2, String);
check(measName3, String);
check(measure3, Number);
check(measUnit3, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add log entries. Make sure you are logged in with valid user credentials.');
}
return await LogEntry.insertAsync({
routineId: routineId,
logId: logId,
exerciseName: exerciseName,
measName1: measName1,
measure1: measure1,
measUnit1: measUnit1,
measName2: measName2,
measrue2: measure2,
measUnit2: measUnit2,
measName3: measName3,
measure3: measure3,
measUnit3: measUnit3,
addedBy: this.userId,
addedOn: new Date()
});
},
});

View file

@ -82,4 +82,11 @@ FlowRouter.route('/logbook', {
action() {
this.render('MainLayout', { main: "logbook"});
}
});
FlowRouter.route('/logEntry', {
name: 'logEntry',
action() {
this.render('MainLayout', { main: 'logEntry'});
}
});

View file

@ -5,6 +5,7 @@ import { UserInfo } from "../imports/api/userInfo";
import { Roels } from "meteor/roles";
import { Workouts } from "../imports/api/workouts";
import { WorkoutLog } from "../imports/api/workoutLog";
import { LogEntry } from "../imports/api/logEntry";
Meteor.publish("SystemConfig", function() {
try {
@ -56,3 +57,13 @@ Meteor.publish("myWorkoutLog", function () {
console.log(" ERROR in pulling workout routines: " + error);
}
});
Meteor.publish("myLogEntries", function (routineId) {
try {
if (this.userId) {
return LogEntry.find({ "addedBy": this.userId, "routineId": routineId });
}
} catch(error) {
console.log(" ERROR in pulling workout routines: " + error);
}
});