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 @@
+
+ Log Entry
+
+
+
+
+
+
+ {{#if $eq exIdSelected true}}
+
+
+
+
{{exerciseToLog.exerciseName}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{#if $neq exerciseToLog.exerciseMeasure2 ""}}
+
+
+
+
+
+
+
+ {{exerciseToLog.exerciseUnitMeasure2}}
+
+ {{/if}}
+
+
+
+ {{#if $neq exerciseToLog.exerciseMeasure3 ""}}
+
+
+
+
+
+
+
+ {{exerciseToLog.exerciseUnitMeasure3}}
+
+ {{/if}}
+
+
+ {{/if}}
+ {{> snackbar}}
+
\ 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);
+ }
+});