diff --git a/perfectSteak.js b/perfectSteak.js index 82a340c..b64b631 100644 --- a/perfectSteak.js +++ b/perfectSteak.js @@ -255,7 +255,10 @@ var perfectSteak = function (div) { cookButt.css("width",'100%'); displayDiv.append(saveModal) - + + /* + updateTime goes through the table and updates the total cooking time entered. It also checks for any entries that are in seconds and calls to change them into the format mm:ss + */ var updateTime=function(){ var time=0; for(var i=0;i
Saved Methods
"); - var dropdown1=$(''); - var dropdown2=$(''); - + /* + addDropdown configures the two dropdowns associated with comparing different meats. It accounts for selecting a previous meat and calling a function to draw that meat in the appropriate window + */ + var addDropdown=function(){ + $(".dropdown").remove(); + + var dropdownDiv=$(""); + var dropdown1=$(''); + var dropdown2=$(''); + + for(var key in model.currentInfo['recipe']){ + dropdown1.append($('')); + dropdown2.append($('')); + } - for(var key in model.currentInfo['recipe']){ - dropdown1.append($('')); - dropdown2.append($('')); - } - - - dropdownDiv.change(function(){ - - var e1 = document.getElementById("d1"); - var name1 = e1.options[e1.selectedIndex].text; - var e2 = document.getElementById("d2"); - var name2 = e2.options[e2.selectedIndex].text; - var info=model.currentInfo['recipe'][name1]; - d3.selectAll('.finalsteak').remove(); - drawFinished(info[0],info[1],info[2],info[3],0); - var inf=model.currentInfo['recipe'][name2]; - drawFinished(inf[0],inf[1],inf[2],inf[3],0); - }); - - - dropdownDiv.append(dropdown1,dropdown2); - $(".span9").prepend(dropdownDiv); - - } - - - var buildDisplay = function () { - if (model.currentInfo["OKToGraph"]){ + dropdownDiv.change(function(){ + var e1 = document.getElementById("d1"); + var name1 = e1.options[e1.selectedIndex].text; + var e2 = document.getElementById("d2"); + var name2 = e2.options[e2.selectedIndex].text; + var info=model.currentInfo['recipe'][name1]; + d3.selectAll('.finalsteak').remove(); + drawFinished(info[0],info[1],info[2],info[3],0); + var inf=model.currentInfo['recipe'][name2]; + drawFinished(inf[0],inf[1],inf[2],inf[3],0); + }); + + dropdownDiv.append(dropdown1,dropdown2); + $(".span9").prepend(dropdownDiv); + } + + /* + buildDisplay places the necessary items on the screen for the user to interact with. + */ + var buildDisplay = function () { + if (model.currentInfo["OKToGraph"]){ div.append("
"); $(".span3").append(displayDiv); -//
var switches=$('
'); div.append(switches); + switches.change(function(){ - console.log($('.mytog:checked').attr('id')) - graph(false,$('.mytog:checked').attr('id')); + graph(false,$('.mytog:checked').attr('id')); }); - $("#startModal").modal("show"); + + $("#startModal").modal("show"); cookButton = $(".cookButton"); -// $(".table-container").append(displayDiv); buildTable(); - } - else{ + } + + else{ (".") + } + + + addDropdown(); + } + + var buildTable = function () { + + var timeStep = model.timeStep; + var len = model.currentInfo["data"].length; + var newData = [] + var sumtime=0; + for (var i = 0; i < model.currentInfo["numRows"]; i++) { + var iminus = i - 1; + addButton = $(""); + + flipButton = $(""); + + var row = $(""); + + if(i>0){ + var vals=parseFloat($("#row" + (i-1) + "time").val()); + } + + var duration = $(""); + var inp1 = $(""); + var inp2 = $(""); + var step1Col = $(""); + step1Col.append(inp1); + var step2Col = $(""); + step2Col.append(inp2); + step1Col.append(flipButton); + + row.append(duration, step1Col, step2Col); + $(".inputTable").append(row); + if (i == model.currentInfo["numRows"] - 1) { + saveBut=$('Save'); + var saveModal=$(''); + var nameInp=$(''); + var okModal=$(''); + okModal.on("click", function(){ + + + model.saveRecipe($("#recipeName").val()); + var name=$("#recipeName").val(); + var dropdown1=$("#d1"); + var dropdown2=$("#d2"); + dropdown1.append($('')); + dropdown2.append($('')); + var e1 = document.getElementById("d1"); + var name1 = e1.options[e1.selectedIndex].text; + var e2 = document.getElementById("d2"); + var name2 = e2.options[e2.selectedIndex].text; + var info=model.currentInfo['recipe'][name1]; + d3.selectAll('.finalsteak').remove(); + drawFinished(info[0],info[1],info[2],info[3],0); + var inf=model.currentInfo['recipe'][name2]; + drawFinished(inf[0],inf[1],inf[2],inf[3],0); + }) + saveModal.append(nameInp,okModal); + + cookButt.on("click",function(){ + model.checkDiv() + model.buildData(); + updateTime(); + model.buildData(); + + if(clicked&&model.currentInfo["OKToGraph"]){ + graph(false,$('.mytog:checked').attr('id')) + } + + else{ + d3.selectAll(".containers").remove(); + d3.selectAll(".mysteak").remove(); + model.dataClear(); + } + }) + + $(".inputTable").append(addButton);//, saveBut,saveModal); + $(".span3").append(cookButt); + addDropdown(); } + var sumtime=0; + var time=$("#row" + i + "time").val().replace(':','.').split('.'); + for (var k=0;k+"); - - flipButton = $(""); + } else if (i <= len) { - var row = $(""); + inp1.val(model.currentInfo["data"][i][1]); + inp2.val(model.currentInfo["data"][i][2]); - if(i>0){ - var vals=parseFloat($("#row" + (i-1) + "time").val()); + model.dataAdd([sumtime, parseFloat($("#inp1_" + i).val()), parseFloat($("#inp2_" + i).val())]) + } else { - - } + inp1.val(model.currentInfo["data"][i - 1][1]); + inp2.val(model.currentInfo["data"][i - 1][2]); - var duration = $(""); - var inp1 = $(""); - var inp2 = $(""); - var step1Col = $(""); - step1Col.append(inp1); - var step2Col = $(""); - step2Col.append(inp2); - step1Col.append(flipButton); + model.dataAdd([sumtime, parseFloat($("#inp1_" + iminus).val()), parseFloat($("#inp2_" + iminus).val())]) + } + timeFun(i); + flipButtonFun(i); + } - row.append(duration, step1Col, step2Col); - $(".inputTable").append(row); - if (i == model.currentInfo["numRows"] - 1) { - saveBut=$('Save'); - var saveModal=$(''); - var nameInp=$(''); - var okModal=$(''); - okModal.on("click", function(){ + model.dataClear(); + addButtonFun(); + CookButtonFun(); + closeRowFun(); + }; - - model.saveRecipe($("#recipeName").val()); - var name=$("#recipeName").val(); - var dropdown1=$("#d1"); - var dropdown2=$("#d2"); - dropdown1.append($('')); - dropdown2.append($('')); - var e1 = document.getElementById("d1"); - var name1 = e1.options[e1.selectedIndex].text; - var e2 = document.getElementById("d2"); - var name2 = e2.options[e2.selectedIndex].text; - var info=model.currentInfo['recipe'][name1]; - d3.selectAll('.finalsteak').remove(); - drawFinished(info[0],info[1],info[2],info[3],0); - var inf=model.currentInfo['recipe'][name2]; - drawFinished(inf[0],inf[1],inf[2],inf[3],0); - }) - saveModal.append(nameInp,okModal); - - cookButt.on("click",function(){ - model.checkDiv() - model.buildData(); - updateTime(); - // for (var j=0; j1) - // {var time=parseFloat(timeInSecs[0])+60*parseFloat(timeInSecs[1]);} - // else{var time=parseFloat(timeInSecs[0]);} - // $("#row"+j+"time").val(time) - // } - //} - model.buildData(); + var addRow = function (table) { + flipButton = $(""); + var i = model.currentInfo["numRows"] - 1; + var row = $(""); - if(clicked&&model.currentInfo["OKToGraph"]){graph(false,$('.mytog:checked').attr('id'))} - else{ d3.selectAll(".containers").remove(); - d3.selectAll(".mysteak").remove(); - model.dataClear(); - - -} - - -}) - - $(".inputTable").append(addButton);//, saveBut,saveModal); - $(".span3").append(cookButt); - addDropdown(); - } -var sumtime=0; -var time=$("#row" + i + "time").val().replace(':','.').split('.'); -for (var k=0;k0){ + var vals=parseFloat($("#row" + (i-1) + "time").val()); + + + var duration = $(""); + var inp1 = $(""); + var inp2 = $(""); + var step1Col = $(""); + step1Col.append(inp1); + var step2Col = $(""); + step2Col.append(inp2); + step1Col.append(flipButton); + row.append(duration, step1Col, step2Col); + $('.displayDiv').stop().animate({ + scrollTop: $(".displayDiv")[0].scrollHeight + }, 800); + timeFun(i); flipButtonFun(i); + table.append(row); + inp1.val($("#inp1_" + (i-1)).val()); + inp2.val($("#inp2_" + (i-1)).val()); + var sumtime=0; + var time=$("#row" + i + "time").val().replace(':','.').split('.'); + for (var k=0;k"); - var i = model.currentInfo["numRows"] - 1; -var row = $(""); - - - -if(i>0){ -var vals=parseFloat($("#row" + (i-1) + "time").val()); - - - var duration = $(""); - var inp1 = $(""); - var inp2 = $(""); - var step1Col = $(""); - step1Col.append(inp1); - var step2Col = $(""); - step2Col.append(inp2); - step1Col.append(flipButton); - row.append(duration, step1Col, step2Col); -$('.displayDiv').stop().animate({ -scrollTop: $(".displayDiv")[0].scrollHeight -}, 800); - - timeFun(i); - flipButtonFun(i); - table.append(row); - inp1.val($("#inp1_" + (i-1)).val()); - inp2.val($("#inp2_" + (i-1)).val()); -var sumtime=0; -var time=$("#row" + i + "time").val().replace(':','.').split('.'); -for (var k=0;k1){ -var sumtime=parseFloat(time[1]); - -sumtime+=parseFloat(60*time[0]); -} -else{var sumtime=parseFloat(time[0]);} - - - model.dataAdd([sumtime, cur1, cur2]); + + var addButtonFun = function () { + addButton.on("click", function () { + model.buildData(); + model.numRowsPlus(); + addRow($(".inputTable")); + }); + }; + + + var closeRowFun=function(){ + $(".closeRow").on("click", function(){ + var rowNum=String($(this).attr("id").charAt(3)) + $("#row"+rowNum).remove(); + model.numRowsMinus(); + + //NOW WE NEED TO CHANGE THE ROW NUMBER OF ALL THE OTHER ROWS + for (var l=rowNum+1; lTemperature is not a valid number"); - var thicknessAlert=$("
Thickness is not a valid number
"); - if (String(parseInt($("#steakTemp").val()))=='NaN'){ - $("#tempInpDiv").append(tempAlert); - OKtoCook=false; - }else if(parseInt($("#steakTemp").val())<-273||parseInt($("#steakTemp").val())>300){ - $("#tempInpDiv").append(tempAlert); - OKtoCook=false; - }else{ - model.changeMeatTemp(parseFloat($("#steakTemp").val())) - }; - - if (String(parseInt($("#thicknessInp").val()))=='NaN'){ - $("#thickInpDiv").append(thicknessAlert); - OKtoCook=false; - }else if(parseFloat($("#thicknessInp").val())<0.5||parseFloat($("thicknessInp").val())>35){ - $("#thickInpDiv").append(thicknessAlert); - OKtoCook=false; - }else{ - model.changeThickness(parseFloat($("#thicknessInp").val())) - }; - - //add to on click and calculate(blah,blah,blah, meatType) - var meatType = $("input[type='radio'][name='meat']:checked").attr('id'); - if(falseColor=='T') - { - meatType='False'; - } - //THIS WILL COOK THE STEAK IF WE HAVE VALID INPUTS - if (OKtoCook==true){ - var steak = [model.currentInfo["data"][0][1]]; - for (var m = 0; m < parseFloat($("#thicknessInp").val()) * 10; m++) { - steak.push(parseFloat($("#steakTemp").val())) - } - steak.push(model.currentInfo["data"][0][2]); - calculate(model.currentInfo["data"], steak,meatType,isFirst,model.currentInfo["totalTime"]) - } -} - var CookButtonFun = function () { - $(".cookButton").on("click", function () { - clicked=true; - model.checkDiv(); - d3.selectAll(".mysteak").remove(); - d3.selectAll(".containers").remove(); - if (model.currentInfo["OKToGraph"]){ - d3.selectAll("svg").remove(); - model.dataClear(); - graph(true,$('.mytog:checked').attr('id')); - }; + }); } - - var timeFun = function (j) { - $("#row" + j + "time").change(function () { - - if (j == 0) { - timeStep = parseInt($("#row" + j + "time").value); - } - - - if (j == 0) { - timeStep = parseInt($("#row" + j + "time").value); - } - - }) - }; - - var flipButtonFun = function (k) { - flipButton.on("click", function () { - side1data = 0 - side1data += parseInt(parseFloat($('#inp1_' + k).val())) || 0; - side2data = parseInt(parseFloat($('#inp2_' + k).val())); - $('#inp1_' + k).val(side2data); - $('#inp2_' + k).val(side1data); - }) - }; + + + var graph=function(isFirst,falseColor){ + d3.selectAll(".mysteak").remove(); + d3.selectAll(".containers").remove(); + model.dataClear(); + + for (var e = 0; e < model.currentInfo["numRows"]; e++) { + var curTime = $("#row" + e + "time").val(); + var cur1 = parseFloat($("#inp1_" + e).val()); + var cur2 = parseFloat($("#inp2_" + e).val()); + + var time=curTime.replace(':','.').split('.'); + if(time.length>1){ + var sumtime=parseFloat(time[1]); + + sumtime+=parseFloat(60*time[0]); + } + else{var sumtime=parseFloat(time[0]);} + + + model.dataAdd([sumtime, cur1, cur2]); + } + var OKtoCook=true; //IF WE HAVE INVALID INPUTS, IT WILL BE CHANGED TO FALSE + + //THIS BIT IS CHECKING WHETHER THE THICKNESS AND INITIAL TEMP INPUTS ARE VALID + $("#tempAlert").remove(); + $("#thickAlert").remove(); + var tempAlert=$("
Temperature is not a valid number
"); + var thicknessAlert=$("
Thickness is not a valid number
"); + if (String(parseInt($("#steakTemp").val()))=='NaN'){ + $("#tempInpDiv").append(tempAlert); + OKtoCook=false; + }else if(parseInt($("#steakTemp").val())<-273||parseInt($("#steakTemp").val())>300){ + $("#tempInpDiv").append(tempAlert); + OKtoCook=false; + }else{ + model.changeMeatTemp(parseFloat($("#steakTemp").val())) + }; + + if (String(parseInt($("#thicknessInp").val()))=='NaN'){ + $("#thickInpDiv").append(thicknessAlert); + OKtoCook=false; + }else if(parseFloat($("#thicknessInp").val())<0.5||parseFloat($("thicknessInp").val())>35){ + $("#thickInpDiv").append(thicknessAlert); + OKtoCook=false; + }else{ + model.changeThickness(parseFloat($("#thicknessInp").val())) + }; + + //add to on click and calculate(blah,blah,blah, meatType) + var meatType = $("input[type='radio'][name='meat']:checked").attr('id'); + if(falseColor=='T') + { + meatType='False'; + } + //THIS WILL COOK THE STEAK IF WE HAVE VALID INPUTS + if (OKtoCook==true){ + var steak = [model.currentInfo["data"][0][1]]; + for (var m = 0; m < parseFloat($("#thicknessInp").val()) * 10; m++) { + steak.push(parseFloat($("#steakTemp").val())) + } + steak.push(model.currentInfo["data"][0][2]); + calculate(model.currentInfo["data"], steak,meatType,isFirst,model.currentInfo["totalTime"]) + } + } + var CookButtonFun = function () { + $(".cookButton").on("click", function () { + clicked=true; + model.checkDiv(); + d3.selectAll(".mysteak").remove(); + d3.selectAll(".containers").remove(); + if (model.currentInfo["OKToGraph"]){ + d3.selectAll("svg").remove(); + model.dataClear(); + graph(true,$('.mytog:checked').attr('id')); + }; + }); + } + + var timeFun = function (j) { + $("#row" + j + "time").change(function () { + + if (j == 0) { + timeStep = parseInt($("#row" + j + "time").value); + } + + + if (j == 0) { + timeStep = parseInt($("#row" + j + "time").value); + } + + }) + }; + + var flipButtonFun = function (k) { + flipButton.on("click", function () { + side1data = 0 + side1data += parseInt(parseFloat($('#inp1_' + k).val())) || 0; + side2data = parseInt(parseFloat($('#inp2_' + k).val())); + $('#inp1_' + k).val(side2data); + $('#inp2_' + k).val(side1data); + }) + }; return { buildDisplay: buildDisplay,