From b5bab7b2a65af02052c6d36d1959d4a83e7474fd Mon Sep 17 00:00:00 2001 From: Brian McGonagill Date: Sun, 8 Feb 2026 11:03:21 -0600 Subject: [PATCH] Adding Log Entry --- .../Workouts/WorkoutLogs/logEntry.html | 67 +++++++++++++ .../General/Workouts/WorkoutLogs/logEntry.js | 93 +++++++++++++++++++ client/General/headerbar.html | 2 + imports/api/logEntry.js | 50 ++++++++++ lib/route.js | 7 ++ server/publish.js | 11 +++ 6 files changed, 230 insertions(+) create mode 100644 client/General/Workouts/WorkoutLogs/logEntry.html create mode 100644 client/General/Workouts/WorkoutLogs/logEntry.js create mode 100644 imports/api/logEntry.js diff --git a/client/General/Workouts/WorkoutLogs/logEntry.html b/client/General/Workouts/WorkoutLogs/logEntry.html new file mode 100644 index 0000000..493112e --- /dev/null +++ b/client/General/Workouts/WorkoutLogs/logEntry.html @@ -0,0 +1,67 @@ + \ No newline at end of file diff --git a/client/General/Workouts/WorkoutLogs/logEntry.js b/client/General/Workouts/WorkoutLogs/logEntry.js new file mode 100644 index 0000000..1fa81e3 --- /dev/null +++ b/client/General/Workouts/WorkoutLogs/logEntry.js @@ -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(); + + + + } +}); diff --git a/client/General/headerbar.html b/client/General/headerbar.html index 5042c41..ca6c049 100644 --- a/client/General/headerbar.html +++ b/client/General/headerbar.html @@ -8,6 +8,8 @@ {{#if isInRole "systemadmin"}}
  • Manage
  • {{/if}} +
  • Home
  • +
  • Log Entry
  • Log Out
  • {{#if $eq updateExists true}}
  • notifications
  • diff --git a/imports/api/logEntry.js b/imports/api/logEntry.js new file mode 100644 index 0000000..df88841 --- /dev/null +++ b/imports/api/logEntry.js @@ -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() + }); + }, +}); \ No newline at end of file diff --git a/lib/route.js b/lib/route.js index b79efe1..df17b02 100644 --- a/lib/route.js +++ b/lib/route.js @@ -82,4 +82,11 @@ FlowRouter.route('/logbook', { action() { this.render('MainLayout', { main: "logbook"}); } +}); + +FlowRouter.route('/logEntry', { + name: 'logEntry', + action() { + this.render('MainLayout', { main: 'logEntry'}); + } }); \ No newline at end of file diff --git a/server/publish.js b/server/publish.js index 537d767..deeec46 100644 --- a/server/publish.js +++ b/server/publish.js @@ -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); + } +});