From 3333d6142308619b6a1f88c9046fc955e347e621 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Sat, 30 Jan 2016 18:13:22 -0500 Subject: [PATCH] The sync button now reads Press this button when the second hand is exactly at 12 #58 --- application/views/measure/get-accuracy.php | 1 - application/views/measure/new-measure.php | 1 - assets/js/input.time.logic.js | 87 +++++++++++++++------- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/application/views/measure/get-accuracy.php b/application/views/measure/get-accuracy.php index 3d2802a2..94680ca1 100644 --- a/application/views/measure/get-accuracy.php +++ b/application/views/measure/get-accuracy.php @@ -100,7 +100,6 @@ class="btn btn-primary btn-lg"> Back to measures - diff --git a/application/views/measure/new-measure.php b/application/views/measure/new-measure.php index e85de1e3..aebf9b00 100644 --- a/application/views/measure/new-measure.php +++ b/application/views/measure/new-measure.php @@ -48,7 +48,6 @@ class="btn btn-primary btn-lg">
-
diff --git a/assets/js/input.time.logic.js b/assets/js/input.time.logic.js index 11ecd09d..39b55126 100644 --- a/assets/js/input.time.logic.js +++ b/assets/js/input.time.logic.js @@ -1,11 +1,16 @@ var offsetedDate; -var timeoutPopup; var clickedDate; var isAccuracy = false; var validateFunction = "validateBaseMeasure();"; +/** + * Link button click + */ $( document ).ready(function() { + // This is shared between the baseMeasure and accuracyMeasure pages. + // Here, we do the difference between both and change the validateFunction + // used in the clicked function; if ($( "#accuracyHolder" ).length){ isAccuracy = true; validateFunction = "validateAccuracyMeasure();"; @@ -28,7 +33,7 @@ $( document ).ready(function() { "for your " + $('select[name="watchId"]').find(":selected").text() ); - getNextQuarterMinute(); + getNextMinute(); } else @@ -36,48 +41,53 @@ $( document ).ready(function() { $('.watch-error').show(); } }); - - $('body').on('click', 'button[name="restartCountdown"]', function(e) - { - e.preventDefault(); - reset(); - }); }); -function getNextQuarterMinute(){ +/** + * Compute the next minute + */ +function getNextMinute(){ var d = new Date(); var seconds = d.getSeconds(); - var offsetSeconds; + var offsetSeconds = 0; - if(seconds < 15){ - offsetSeconds = 30 - seconds; - }else if(seconds < 30){ - offsetSeconds = 45 - seconds; - }else if(seconds < 45){ + // If it's somewhere between xx:xx:51 and xx:xx:60, + // users won't have the time to click. + // So, we add a minute. + if(seconds >= 50){ offsetSeconds = 60 - seconds; - }else if(seconds < 60){ - offsetSeconds = 60 - seconds + 15; + }else{ + offsetSeconds = -seconds; } - offsetedDate = new Date(d.getTime()+offsetSeconds*1000); + offsetedDate = new Date(d.getTime() + offsetSeconds * 1000 + 60 * 1000); + console.log(d.toString()); console.log(seconds); console.log(offsetSeconds); console.log(offsetedDate.toString()); - $("#sync-button").html("Press this button exactly at
" + $("#sync-button").html("Press this button when the second hand
" + '' - + constructoffsetedDateString(offsetedDate) + + 'is exactly​​ at 12' + '' ); $("#sync-button").show(); + //The maximum waiting time is 70 secs. If nothing happens in the next 80 + //sec, we display a popup. timeoutPopup = setTimeout(function(){deadlinePassed();}, - (offsetSeconds + 20) * 1000); + 80 * 1000); } +/** + * Helper function to transform a javascript Date in xx:xx:xx + * + * @param Date date + * @return String + */ function constructoffsetedDateString(date){ var hours = (date.getHours() < 10) ? "0"+date.getHours() : date.getHours(); @@ -91,19 +101,24 @@ function constructoffsetedDateString(date){ return hours + ":" + minutes + ":" + seconds; } +/** + * This function is triggererd by a setTimeout function and displays a + * popop + */ function deadlinePassed(){ console.log("Deadline Passed"); var deadlinePassedText = `
-

Did you missed it ?

+

Is everything ok, doc ?

To begin measuring the accuracy of your watch, we must first synchronize it with Toolwatch's accuracy system.

- You were supposed to click at ` - + constructoffsetedDateString(offsetedDate) - + `. + You were supposed to click when the second hand was + + exactly at 12 + .

Retry
`; @@ -115,12 +130,18 @@ function deadlinePassed(){ }); } - +/** + * Resets everything + */ function reset(){ $('button.close').click(); - getNextQuarterMinute(); + getNextMinute(); } +/** + * Big ass button has been clicked. + * Displays confirmation popup. + */ function clicked(){ clearInterval(timeoutPopup); @@ -170,16 +191,25 @@ function clicked(){ } +/** + * Removes a minute from the offsetedDate + */ function retrieveMinute(){ offsetedDate = new Date(offsetedDate.getTime()-60*1000); $("span#timeSyncAt").text(constructoffsetedDateString(offsetedDate)); } +/** + * Adds a minute from the offsetedDate + */ function addMinute(){ offsetedDate = new Date(offsetedDate.getTime()+60*1000); $("span#timeSyncAt").text(constructoffsetedDateString(offsetedDate)); } +/** + * Validation function fot the accuracyMeasure + */ function validateAccuracyMeasure(){ var measureId = $('input[name="measureId"]').val(); @@ -227,6 +257,9 @@ function validateAccuracyMeasure(){ ); } +/** + * Validation function for the baseMeasure + */ function validateBaseMeasure(){ var watchId = $('select[name="watchId"]').val();