Added Measurements input
This commit is contained in:
parent
ba17d57987
commit
98a86ca6a8
12 changed files with 337 additions and 10 deletions
|
|
@ -3,25 +3,47 @@
|
|||
<div class="grid">
|
||||
<div>
|
||||
<article class="infoCard" id="workouts">
|
||||
<div class="grid">
|
||||
<div>
|
||||
<header>
|
||||
<h3>Workouts</h3>
|
||||
</header>
|
||||
<div role="group">
|
||||
<div>
|
||||
<h4>Workouts</h4>
|
||||
</div>
|
||||
<div>
|
||||
<p class="right">{{workoutCount}}</p>
|
||||
{{workoutCount}}
|
||||
</div>
|
||||
</div>
|
||||
<div role="group">
|
||||
<div>
|
||||
<h4>Exercise Logs</h4>
|
||||
</div>
|
||||
<div>
|
||||
{{logCount}}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<footer>
|
||||
<a href="#!" id="logWorkout"><i class="material-icons">notes</i> Log a Workout</a>
|
||||
</footer>
|
||||
</article>
|
||||
</div>
|
||||
<div>
|
||||
<article class="infoCard" id="meals">
|
||||
<h3>Meals</h3>
|
||||
<header><h3>Meals</h3></header>
|
||||
|
||||
<footer>
|
||||
<a href="#!" id="logMeal"><i class="material-icons">notes</i>Log a Meal</a>
|
||||
</footer>
|
||||
</article>
|
||||
</div>
|
||||
<div>
|
||||
<article class="infoCard" id="measurements">
|
||||
<h3>Measurements</h3>
|
||||
<header><h3>Measurements</h3></header>
|
||||
|
||||
<footer>
|
||||
<a id="logMeasure"><i class="material-icons">notes</i>Log a Measurement</a>
|
||||
</footer>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { LogEntry } from '../../../imports/api/logEntry';
|
|||
Template.home.onCreated(function() {
|
||||
this.subscribe("myWorkoutRoutines");
|
||||
this.subscribe("myWorkoutLog");
|
||||
this.subscribe("myLogEntries");
|
||||
this.subscribe("allMyLogEntries");
|
||||
});
|
||||
|
||||
Template.home.onRendered(function() {
|
||||
|
|
@ -20,6 +20,9 @@ Template.home.helpers({
|
|||
workoutCount: function() {
|
||||
return Workouts.find({}).count();
|
||||
},
|
||||
logCount: function() {
|
||||
return LogEntry.find({}).count();
|
||||
},
|
||||
});
|
||||
|
||||
Template.home.events({
|
||||
|
|
@ -27,4 +30,10 @@ Template.home.events({
|
|||
let route = e.currentTarget.id;
|
||||
FlowRouter.go('/' + route);
|
||||
},
|
||||
'click #logWorkout' (e) {
|
||||
FlowRouter.go('/logEntry');
|
||||
},
|
||||
'click #logMeasure' (e) {
|
||||
FlowRouter.go('/measLogEntry');
|
||||
},
|
||||
});
|
||||
23
client/General/Measurements/measLogEntry.html
Normal file
23
client/General/Measurements/measLogEntry.html
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<template name="measLogEntry">
|
||||
<h1>Measurement Log Entry</h1>
|
||||
<label for="selectPart">Select Measurement</label>
|
||||
<select name="selectPart" id="selectPart">
|
||||
<option value="" disabled selected>...</option>
|
||||
{{#each bodyPart}}
|
||||
<option value="{{_id}}">{{measurementName}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
|
||||
{{#if $eq measIdSelected true}}
|
||||
<div class="group">
|
||||
<div>
|
||||
<label>{{measureToLog.measurementName}} ({{measureToLog.measurementUnits}})</label>
|
||||
<input type="number" id="{{measureToLog.measurementName}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<button class="primary savePartMeasure" id="savePartMeasure">Save</button>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{> snackbar}}
|
||||
</template>
|
||||
68
client/General/Measurements/measLogEntry.js
Normal file
68
client/General/Measurements/measLogEntry.js
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
||||
import { Measurements } from '../../../imports/api/measurements';
|
||||
import { MeasureLogEntry } from '../../../imports/api/measureLogEntry';
|
||||
|
||||
Template.measLogEntry.onCreated(function() {
|
||||
this.subscribe("myMeasures");
|
||||
this.subscribe("myMeasureLog");
|
||||
});
|
||||
|
||||
Template.measLogEntry.onRendered(function() {
|
||||
Session.set("measIdSelected", false);
|
||||
});
|
||||
|
||||
Template.measLogEntry.helpers({
|
||||
bodyPart: function() {
|
||||
return Measurements.find({});
|
||||
},
|
||||
measIdSelected: function() {
|
||||
return Session.get("measIdSelected");
|
||||
},
|
||||
measureToLog: function() {
|
||||
let partId = Session.get("measurePartId");
|
||||
return Measurements.findOneAsync({ _id: partId });
|
||||
}
|
||||
});
|
||||
|
||||
Template.measLogEntry.events({
|
||||
'change #selectPart' (e) {
|
||||
Session.set("measIdSelected", true);
|
||||
let partId = $("#selectPart").val();
|
||||
Session.set("measurePartId", partId);
|
||||
},
|
||||
'click #savePartMeasure' (e) {
|
||||
let partId = Session.get("measurePartId");
|
||||
|
||||
const thisMeasure = async() => {
|
||||
try {
|
||||
let measInfo = await Measurements.findOneAsync({ _id: partId });
|
||||
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;
|
||||
|
||||
if (measure1 == "" || measure1 == null) {
|
||||
showSnackbar("Measurement is required!", "red");
|
||||
return;
|
||||
} else {
|
||||
let measure = Number(measure1);
|
||||
const result = await Meteor.callAsync("add.measureLog", measureName, measure, units);
|
||||
if (!result) {
|
||||
console.log(" ISSUE adding measurement to database.");
|
||||
} else {
|
||||
showSnackbar("Measurement Added!", "green");
|
||||
$("#selectPart").val("");
|
||||
Session.set("measIdSelected", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(" ERROR adding measurement: " + error);
|
||||
}
|
||||
}
|
||||
thisMeasure();
|
||||
}
|
||||
});
|
||||
33
client/General/Measurements/measurements.html
Normal file
33
client/General/Measurements/measurements.html
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<template name="measurements">
|
||||
<h1>Workouts</h1>
|
||||
{{#if $eq showAddMeasurementForm true}}
|
||||
<div id="addMasurementForm">
|
||||
<div class="grid">
|
||||
<div>
|
||||
<label for="measurementName">Body Part to Measure *</label>
|
||||
<input type="text" required class="measurementName" id="measurementName" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="measurementUnits">Measurement Units</label>
|
||||
<select name="measurementUnits" id="measurementUnits">
|
||||
<option value="" disabled selected>...</option>
|
||||
<option value="in">in</option>
|
||||
<option value="cm">cm</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<button class="primary right" id="addMeasurementForm">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
<ul class="collection">
|
||||
{{#each measurements}}
|
||||
<li class="collection-item clickable measure" id="{{_id}}"><div class="group"><span>{{measurementName}}</span><span class="right">({{measurementUnits}})</span></div></li>
|
||||
{{/each}}
|
||||
<li class="collection-footer clickable" id="addMeasurement"> + Add a Measurement to Make</li>
|
||||
</ul>
|
||||
{{> snackbar}}
|
||||
</template>
|
||||
62
client/General/Measurements/measurements.js
Normal file
62
client/General/Measurements/measurements.js
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
||||
import { Measurements } from '../../../imports/api/measurements';
|
||||
|
||||
Template.measurements.onCreated(function() {
|
||||
this.subscribe("myMeasures");
|
||||
});
|
||||
|
||||
Template.measurements.onRendered(function() {
|
||||
Session.set("showAddMeasurementForm", false);
|
||||
});
|
||||
|
||||
Template.measurements.helpers({
|
||||
showAddMeasurementForm: function() {
|
||||
return Session.get("showAddMeasurementForm");
|
||||
},
|
||||
measurements: function() {
|
||||
return Measurements.find({});
|
||||
},
|
||||
});
|
||||
|
||||
Template.measurements.events({
|
||||
'click #addMeasurement' (e) {
|
||||
Session.set("showAddMeasurementForm", true);
|
||||
},
|
||||
'click #addMeasurementForm' (e) {
|
||||
let measurementName = $("#measurementName").val();
|
||||
let measurementUnits = $("#measurementUnits").val();
|
||||
|
||||
if (measurementName == "" || measurementName == null) {
|
||||
showSnackbar("Measurement Name is Required!", "red");
|
||||
return;
|
||||
} else if (measurementUnits == "" || measurementUnits == null) {
|
||||
showSnackbar("Measurement Units are Required!", "red");
|
||||
return;
|
||||
} else {
|
||||
// console.log("Measurement Name: " + measurementName);
|
||||
const addMeasure = async() => {
|
||||
try {
|
||||
const result = await Meteor.callAsync('add.measurement', measurementName, measurementUnits);
|
||||
if (!result) {
|
||||
console.log("An issue occurred adding the measurement name.");
|
||||
showSnackbar("Issue adding measurement!", "red");
|
||||
} else {
|
||||
console.log("Measurement added : " + result);
|
||||
$("#measurementName").val("");
|
||||
$("#measurementUnits").val("");
|
||||
showSnackbar("Measurement Added!", "green");
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR adding measurement nemae: " + error);
|
||||
}
|
||||
}
|
||||
addMeasure();
|
||||
}
|
||||
},
|
||||
'click .measure' (e) {
|
||||
let measureId = e.currentTarget.id;
|
||||
console.log("Measurement ID set: " + measureId);
|
||||
Session.set("measureId", measureId);
|
||||
FlowRouter.go('/measureLog');
|
||||
},
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<template name="logEntry">
|
||||
<h1>Log Entry</h1>
|
||||
<h1>Workout Log Entry</h1>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<select name="selectExerciseToLog" class="selectExerciseToLog" id="selectExerciseToLog">
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@
|
|||
<option value="Meters">Meters</option>
|
||||
<option value="Yards">Yards</option>
|
||||
<option value="Feet">Feet</option>
|
||||
<option value="Laps">Laps</option>
|
||||
{{/if}}
|
||||
{{#if $eq exMeas2 "Weight"}}
|
||||
<option value="Kilograms">Kilograms</option>
|
||||
|
|
|
|||
32
imports/api/measureLogEntry.js
Normal file
32
imports/api/measureLogEntry.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
export const MeasureLogEntry = new Mongo.Collection('measureLogEntry');
|
||||
|
||||
MeasureLogEntry.allow({
|
||||
insert: function(userId, doc){
|
||||
// if use id exists, allow insert
|
||||
return !!userId;
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
async 'add.measureLog' (measureName, measure, units) {
|
||||
check(measureName, String);
|
||||
check(measure, Number);
|
||||
check(units, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to add measurement log entries. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return MeasureLogEntry.insertAsync({
|
||||
measureName: measureName,
|
||||
measure: measure,
|
||||
measureUnits: units,
|
||||
addedBy: this.userId,
|
||||
addedOn: new Date(),
|
||||
});
|
||||
},
|
||||
});
|
||||
31
imports/api/measurements.js
Normal file
31
imports/api/measurements.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
export const Measurements = new Mongo.Collection('measurements');
|
||||
|
||||
Measurements.allow({
|
||||
insert: function(userId, doc){
|
||||
// if use id exists, allow insert
|
||||
return !!userId;
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
async 'add.measurement' (measurementName, measurementUnits) {
|
||||
check(measurementName, String);
|
||||
check(measurementUnits, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to add measurements. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return await Measurements.insertAsync({
|
||||
measurementName: measurementName,
|
||||
measurementUnits: measurementUnits,
|
||||
addedBy: this.userId,
|
||||
addedOn: new Date(),
|
||||
measurementActive: true,
|
||||
});
|
||||
},
|
||||
});
|
||||
14
lib/route.js
14
lib/route.js
|
|
@ -90,3 +90,17 @@ FlowRouter.route('/logEntry', {
|
|||
this.render('MainLayout', { main: 'logEntry'});
|
||||
}
|
||||
});
|
||||
|
||||
FlowRouter.route('/measurements', {
|
||||
name: 'measurements',
|
||||
action() {
|
||||
this.render('MainLayout', { main: 'measurements'});
|
||||
}
|
||||
});
|
||||
|
||||
FlowRouter.route('/measLogEntry', {
|
||||
name: 'measLogEntry',
|
||||
action() {
|
||||
this.render('MainLayout', { main: 'measLogEntry'});
|
||||
}
|
||||
});
|
||||
|
|
@ -6,6 +6,8 @@ import { Roels } from "meteor/roles";
|
|||
import { Workouts } from "../imports/api/workouts";
|
||||
import { WorkoutLog } from "../imports/api/workoutLog";
|
||||
import { LogEntry } from "../imports/api/logEntry";
|
||||
import { Measurements } from "../imports/api/measurements";
|
||||
import { MeasureLogEntry } from "../imports/api/measureLogEntry";
|
||||
|
||||
Meteor.publish("SystemConfig", function() {
|
||||
try {
|
||||
|
|
@ -67,3 +69,33 @@ Meteor.publish("myLogEntries", function (routineId) {
|
|||
console.log(" ERROR in pulling workout routines: " + error);
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.publish("allMyLogEntries", function() {
|
||||
try {
|
||||
if (this.userId) {
|
||||
return LogEntry.find({ addedBy: this.userId });
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR returning all of my log entries: " + error);
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.publish("myMeasures", function() {
|
||||
try {
|
||||
if (this.userId) {
|
||||
return Measurements.find({ addedBy: this.userId, measurementActive: true });
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR returning all of my measurements: " + error);
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.publish("myMeasureLog", function() {
|
||||
try {
|
||||
if (this.userId) {
|
||||
return MeasureLogEntry.find({ addedBy: this.userId });
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR returning all of my measurement log entries: " + error);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue