fix time presetting algorithm

This commit is contained in:
Joe Tretter
2020-06-06 11:20:54 -05:00
parent 874f77a6ef
commit 9b40f3d281

View File

@@ -126,8 +126,9 @@ let createMasterFilterFrame=()=>{
} }
me.timeChanged=(newTime)=>{ me.timeChanged=(newTime)=>{
if (_filterContext.selectedTime!==newTime){ if ((_filterContext.selectedTime!==newTime) || (_filterContext.theDateOfTime!==_filterContext.theDate)) {
_filterContext.selectedTime=newTime; _filterContext.selectedTime=newTime;
_filterContext.theDateOfTime=_filterContext.theDate;
$("#tbSelectedTime").text(newTime); $("#tbSelectedTime").text(newTime);
console.log("Time changed", newTime); console.log("Time changed", newTime);
} }
@@ -158,22 +159,26 @@ let createMasterFilterFrame=()=>{
let lbTime=$("#lbTime"); let lbTime=$("#lbTime");
lbTime.empty(); lbTime.empty();
allTimes = availableTimes; allTimes = availableTimes;
let presetTime=undefined;
for (let i=0;i<allTimes.length;i++){ for (let i=0;i<allTimes.length;i++){
theTime=allTimes[i].Time; theTime=allTimes[i].Time;
if (_filterContext.selectedTime !== undefined) { if (presetTime===undefined) { // emergency fallback, if nothing else fits fall back to first time seen.
if (_filterContext.selectedTime.substring(0,4) === theTime.substring(0,4)){ presetTime = theTime;
me.timeChanged(theTime); }
if (_filterContext.selectedTime !== undefined) { // try to stay at the same time
if (_filterContext.selectedTime.substring(0,4) >= theTime.substring(0,4)){
presetTime = theTime;
} }
} else { } else {
if (i==4) { if (i==4) { // this is usually upon open - initializing the selected time...
// select the 4th time in the day... that's usually around 9:30 // select the 4th time in the day... that's usually around 9:30
me.timeChanged(theTime); presetTime = theTime;
} }
} }
//lbTime.append($(`<option ${selectedFlag}>${theTime}</option>`)) //lbTime.append($(`<option ${selectedFlag}>${theTime}</option>`))
lbTime.append($(`<button onclick="myMasterFilter.timeChanged('${theTime}');" class="dropdown-item" type="button">${theTime.substring(0,5)}</button>`)) lbTime.append($(`<button onclick="myMasterFilter.timeChanged('${theTime}');" class="dropdown-item" type="button">${theTime.substring(0,5)}</button>`))
} }
me.timeChanged(presetTime);
$("#lbTime").change(); $("#lbTime").change();
$("#spinner-time").hide(); $("#spinner-time").hide();
}); });