Added Measurements input
This commit is contained in:
parent
ba17d57987
commit
98a86ca6a8
12 changed files with 337 additions and 10 deletions
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();
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue