From b41fffb9ccc1247bdcfbdf14363d127228ee01ff Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Mon, 4 Jan 2016 15:38:09 -0500 Subject: [PATCH] Huge dashboard refactor + preselect of the watch on call to actions #36 --- application/controllers/Measures.php | 27 ++- application/models/Measure.php | 79 ++++--- application/models/Watch.php | 3 +- application/views/measure/all.php | 196 ------------------ application/views/measure/dashboard.php | 87 ++++++++ .../measure/dashboard/call-to-action.php | 38 ++++ .../measure/dashboard/check-accuracy.php | 6 + .../measure/dashboard/delete-measure.php | 6 + .../views/measure/dashboard/delete-watch.php | 5 + .../measure/dashboard/end-action-button.php | 2 + .../measure/dashboard/start-action-button.php | 6 + .../measure/dashboard/start-new-measure.php | 5 + application/views/measure/dashboard/steps.php | 16 ++ application/views/measure/new-measure.php | 16 +- assets/js/application.js | 9 + 15 files changed, 247 insertions(+), 254 deletions(-) delete mode 100644 application/views/measure/all.php create mode 100644 application/views/measure/dashboard.php create mode 100644 application/views/measure/dashboard/call-to-action.php create mode 100644 application/views/measure/dashboard/check-accuracy.php create mode 100644 application/views/measure/dashboard/delete-measure.php create mode 100644 application/views/measure/dashboard/delete-watch.php create mode 100644 application/views/measure/dashboard/end-action-button.php create mode 100644 application/views/measure/dashboard/start-action-button.php create mode 100644 application/views/measure/dashboard/start-new-measure.php create mode 100644 application/views/measure/dashboard/steps.php diff --git a/application/controllers/Measures.php b/application/controllers/Measures.php index 2db8ac68..8f113fb1 100644 --- a/application/controllers/Measures.php +++ b/application/controllers/Measures.php @@ -42,12 +42,10 @@ private function constructMeasurePage(){ $this->_headerData['headerClass'] = 'blue'; $this->load->view('header', $this->_headerData); - $this->_bodyData['watches'] = $this->watch->getWatches( - $this->session->userdata('userId')); $this->_bodyData['allMeasure'] = $this->measure->getMeasuresByUser( - $this->session->userdata('userId'), $this->_bodyData['watches']); + $this->session->userdata('userId')); - $this->load->view('measure/all', $this->_bodyData); + $this->load->view('measure/dashboard', $this->_bodyData); $this->load->view('footer'); } @@ -94,7 +92,7 @@ public function add_watch(){ */ public function delete_watch(){ - if($this->expectsPost(array('deleteWatch'))){ + if($this->expectsPost(array('watchId'))){ if ($this->watch->deleteWatch($this->watchId)) { $this->_bodyData['success'] = 'Watch successfully deleted!'; @@ -148,18 +146,35 @@ public function new_watch() { */ public function new_measure() { + $this->_bodyData['watches'] = $this->watch->getWatches( + $this->session->userdata('userId')); + $this->event->add(MEASURE_LOAD); $this->_headerData['headerClass'] = 'blue'; $this->load->view('header', $this->_headerData); - $this->_bodyData['watches'] = $this->watch->getWatches($this->session->userdata('userId')); $this->load->view('measure/new-measure', $this->_bodyData); $this->load->view('measure/audio.php'); $this->load->view('footer'); } + /** + * Serves the new measure form (1/2) for a watch + * with existing measures. + */ + public function new_measure_for_watch(){ + + if($this->expectsPost(array('watchId'))){ + + $this->_bodyData['selected_watch'] = $this->watchId; + + $this->new_measure(); + + } + } + /** * Serves the new accuracy form (2/2) */ diff --git a/application/models/Measure.php b/application/models/Measure.php index e881a3e6..b184715e 100644 --- a/application/models/Measure.php +++ b/application/models/Measure.php @@ -35,46 +35,17 @@ function __construct() { * Get the last measure of each $userWatches * * @param int $userId id of the user - * @param array $userWatches watches of the user - * @return array The last measure per $userWatches for $userId + * @return array The last measure per of $userId */ - function getMeasuresByUser($userId, $userWatches) { - - $data = array(); - - if (is_array($userWatches) && sizeof($userWatches) > 0) { - - foreach ($userWatches as $watch) { - //Get measure couple that are on measure or accuracy status - $watchMeasures = $this->select() - ->join("watch", "watch.watchId = ".$watch->watchId) - ->where('measure.watchId', $watch->watchId) - ->where('(`statusId` = 1 OR `statusId` = 2)', null, false) - ->find_all(); - - if ($watchMeasures) { - - foreach ($watchMeasures as $watchMeasure) { - - //If the first measure is less than 12 hours old - if ($watchMeasure->statusId === "1" && - (((time()-$watchMeasure->measureReferenceTime)/3600) < 12)) { - - $watchMeasure->statusId = 1.5; - $ellapsedTime = ((time()-$watchMeasure->measureReferenceTime)/3600); - $watchMeasure->accuracy = round(12-round($ellapsedTime, 1)); - if ($watchMeasure->accuracy <= 1) { - $watchMeasure->accuracy = " < 1"; - } - } - - array_push($data, $watchMeasure); - } - } - } - } - - return $data; + function getMeasuresByUser($userId) { + + return $this->select() + ->join("watch", "watch.watchId = measure.watchId + AND measure.statusId < 3", "right") + ->where("watch.userId", $userId) + ->where("watch.status <", 4) + ->group_by("watch.watchId") + ->find_all(); } /** @@ -96,11 +67,31 @@ public function computeAccuracy($watchMeasure) { $wasArray = true; } - $userDelta = $watchMeasure->accuracyUserTime-$watchMeasure->measureUserTime; - $refDelta = $watchMeasure->accuracyReferenceTime-$watchMeasure->measureReferenceTime; - $accuracy = ($userDelta*86400/$refDelta)-86400; - $accuracy = sprintf("%.1f", $accuracy); - $watchMeasure->accuracy = $accuracy; + //Compute the accuracy if all the data are available + //Both measure have been performed + if(is_numeric($watchMeasure->accuracyUserTime) + && is_numeric($watchMeasure->measureUserTime) + && is_numeric($watchMeasure->accuracyReferenceTime) + && is_numeric($watchMeasure->measureReferenceTime)) + { + $userDelta = $watchMeasure->accuracyUserTime-$watchMeasure->measureUserTime; + $refDelta = $watchMeasure->accuracyReferenceTime-$watchMeasure->measureReferenceTime; + $accuracy = ($userDelta*86400/$refDelta)-86400; + $accuracy = sprintf("%.1f", $accuracy); + $watchMeasure->accuracy = $accuracy; + } + + //Compute 1.5 status. When a measure is less than 12 hours old + if ($watchMeasure->statusId === "1" && + (((time()-$watchMeasure->measureReferenceTime)/3600) < 12)) { + + $watchMeasure->statusId = 1.5; + $ellapsedTime = ((time()-$watchMeasure->measureReferenceTime)/3600); + $watchMeasure->accuracy = round(12-round($ellapsedTime, 1)); + if ($watchMeasure->accuracy <= 1) { + $watchMeasure->accuracy = " < 1"; + } + } //If the measure was an array, //I typecast it back to array. diff --git a/application/models/Watch.php b/application/models/Watch.php index 97f22f4b..3a099f03 100644 --- a/application/models/Watch.php +++ b/application/models/Watch.php @@ -62,7 +62,6 @@ function getWatches($userId) { ->where('status', 1) ->order_by('brand', 'asc') ->find_all(); - } /** @@ -89,7 +88,7 @@ function getWatchByMeasureId($measureId){ * Soft delete watch $watchId * * @param int $watchId The watch to delete - * @return boolean + * @return boolean */ function deleteWatch($watchId) { $data = array('status' => 4); diff --git a/application/views/measure/all.php b/application/views/measure/all.php deleted file mode 100644 index 81612f6d..00000000 --- a/application/views/measure/all.php +++ /dev/null @@ -1,196 +0,0 @@ -
-
-

My measures

-
-
-
-
-
-
Step 1
Step 1
Add a watch to the list
-
-
Step 2
Step 2
Synchronize with our accuracy system (first measure)
-
-
Step 2
Step 3
Get your accuracy (second measure)
-
- -
-
- - - '.$error.'
'; - - } - else if(isset($success)) - { - echo ''; - } - var_dump($allMeasure); - ?> - - - - - - - - - - - - '; - echo ''; - echo ''; - - if($measure->statusId == '0') - { - echo ''; - echo ''; - echo ''; - } - else if($measure->statusId == '1') - { - echo ''; - echo ''; - echo ''; - } - else if($measure->statusId == '1.5') - { - echo ''; - echo ''; - echo ''; - } - else if($measure->statusId == '2') - { - if($measure->accuracy > 0) - $accuracy = "+".$measure->accuracy; - else - $accuracy = $measure->accuracy; - - if(($measure->accuracy > 99.9) || (($measure->accuracy < -99.9))) - { - - echo ''; - } - else - { - echo ''; - } - - echo ''; - echo ''; - } - } - } - else - { - echo ''; - } - ?> - -
Watch brandWatch nameAccuracyActions
'.$measure->brand.''.$measure->name.'Measure me!
- - -
Check the accuracy
- - -
Check the accuracy in '.$measure->accuracy.' hour(s)
- - -
'.$accuracy.' seconds a day
Looks like there was an error measuring your watch, why not try another measure?
'.$accuracy.' seconds a day
- - -
You don\'t have any measure yet!
-
-
-
-
-
- Add a watch

- - - Start a new measure - - - - -
-
-
- diff --git a/application/views/measure/dashboard.php b/application/views/measure/dashboard.php new file mode 100644 index 00000000..79d6ade5 --- /dev/null +++ b/application/views/measure/dashboard.php @@ -0,0 +1,87 @@ +
+ + load->view("measure/dashboard/steps"); ?> + +
+
+ + + '.$error.'
'; + + } + else if(isset($success)) + { + echo ''; + } + var_dump($allMeasure); + ?> + + + + + + + + + + + + '; + echo ''; + echo ''; + + $this->load->view("measure/dashboard/call-to-action.php", $measure); + + $this->load->view("measure/dashboard/start-action-button"); + + if($measure->statusId === "1"){ + $this->load->view("measure/dashboard/check-accuracy", $measure); + } + + if($measure->statusId > 0){ + $this->load->view("measure/dashboard/delete-measure", $measure); + } + + $this->load->view("measure/dashboard/start-new-measure", $measure); + + + $this->load->view("measure/dashboard/delete-watch", $measure); + $this->load->view("measure/dashboard/end-action-button"); + + } + } + else + { + echo ''; + } + ?> + +
Watch brandWatch nameAccuracyActions
'.$measure->brand.''.$measure->name.'
You don\'t have any measure yet!
+
+
+
+
+
+ Add a watch

+ + + Start a new measure + + + + +
+
+
+ diff --git a/application/views/measure/dashboard/call-to-action.php b/application/views/measure/dashboard/call-to-action.php new file mode 100644 index 00000000..50d61f68 --- /dev/null +++ b/application/views/measure/dashboard/call-to-action.php @@ -0,0 +1,38 @@ +Measure me! +
+ +
'; + +}else if($statusId == '1'){ + + echo 'Check the accuracy'; + +}else if($statusId == '1.5'){ + + echo 'Check the accuracy in + '.$accuracy.' hour(s) '; + +}else if($statusId == '2'){ + + if($accuracy > 0){ + $accuracy = "+".$accuracy; + }else{ + $accuracy = $accuracy; + } + + if(($accuracy > 99.9) || (($accuracy < -99.9))) + { + + echo ''.$accuracy.' seconds a day
Looks like there was + an error measuring your watch, why not try another measure?'; + } + else + { + echo ''.$accuracy.' seconds a day'; + } +} +?> diff --git a/application/views/measure/dashboard/check-accuracy.php b/application/views/measure/dashboard/check-accuracy.php new file mode 100644 index 00000000..faa3a6d6 --- /dev/null +++ b/application/views/measure/dashboard/check-accuracy.php @@ -0,0 +1,6 @@ +
  • Check the accuracy +
    + + +
    +
  • diff --git a/application/views/measure/dashboard/delete-measure.php b/application/views/measure/dashboard/delete-measure.php new file mode 100644 index 00000000..76be74e7 --- /dev/null +++ b/application/views/measure/dashboard/delete-measure.php @@ -0,0 +1,6 @@ +
  • + Delete this measure +
    + +
    +
  • diff --git a/application/views/measure/dashboard/delete-watch.php b/application/views/measure/dashboard/delete-watch.php new file mode 100644 index 00000000..dad61e72 --- /dev/null +++ b/application/views/measure/dashboard/delete-watch.php @@ -0,0 +1,5 @@ +
  • + Delete watch +
    +
    +
  • diff --git a/application/views/measure/dashboard/end-action-button.php b/application/views/measure/dashboard/end-action-button.php new file mode 100644 index 00000000..78aedd48 --- /dev/null +++ b/application/views/measure/dashboard/end-action-button.php @@ -0,0 +1,2 @@ + + diff --git a/application/views/measure/dashboard/start-action-button.php b/application/views/measure/dashboard/start-action-button.php new file mode 100644 index 00000000..cb5d50d4 --- /dev/null +++ b/application/views/measure/dashboard/start-action-button.php @@ -0,0 +1,6 @@ + +
    + +
    - \ No newline at end of file + diff --git a/assets/js/application.js b/assets/js/application.js index ca378c47..eefdf199 100644 --- a/assets/js/application.js +++ b/assets/js/application.js @@ -470,6 +470,15 @@ $(document).ready(function() } }); + $('body').on('click', '.submitNewMeasure', function(e) + { + e.preventDefault(); + var watchId = $(this).attr('data-watch'); + + $('form[name="start-new-measure-'+watchId+'"]').submit(); + + }); + $('body').on('click', '.submitDeleteMeasures', function(e) { e.preventDefault();