Skip to content

Commit

Permalink
Merge pull request #112 from MathieuNls/58_new_input
Browse files Browse the repository at this point in the history
New click-based synchronization system #58
  • Loading branch information
MathieuNls committed Feb 13, 2016
2 parents d68a45d + 81a7b53 commit 1b0d805
Show file tree
Hide file tree
Showing 14 changed files with 442 additions and 413 deletions.
22 changes: 10 additions & 12 deletions application/controllers/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,15 @@ function contact() {

$result['success'] = false;

$name = $this->input->post('name');
$email = $this->input->post('email');
$message = $this->input->post('message');
$tags = "contact";

$this->load->library('mandrill');

$messageMandrill = array(
'html' => $message,
'subject' => $subject,
'from_email' => $email,
'from_name' => $name,
'html' => $this->message,
'subject' => "Contact information",
'from_email' => $this->email,
'from_name' => $this->name,
'to' => array(
array(
'email' => '[email protected]',
Expand All @@ -323,7 +321,7 @@ function contact() {
)
),
'headers' => array(
'Reply-To' => $email,
'Reply-To' => $this->email,
),
'important' => false,
'track_opens' => true,
Expand All @@ -341,17 +339,17 @@ function contact() {

$scheduleTime = time();

$send_at = date('Y-', $scheduleTime).date('m-', $scheduleTime)
.(date('d', $scheduleTime)).' '.(date('H', $scheduleTime)-1).':'
.(date('i', $scheduleTime)).date(':s', $scheduleTime);
$returnValue = date('Y-', $scheduleTime).date('m-', $scheduleTime)
.(date('d', $scheduleTime)).' '.(date('H', $scheduleTime)).':'
.(date('i', $scheduleTime)).':'.(date('s', $scheduleTime));

$mandrillResponse = $this->mandrill->messages->send($messageMandrill, $async, $ip_pool, $send_at);
log_message('info', 'Mandrill email: ' . print_r($mandrillResponse, true));


if ($mandrillResponse[0]['status'] === 'sent') {
$result['success'] = true;
}
}

echo json_encode($result);
}
Expand Down
55 changes: 17 additions & 38 deletions application/controllers/Measures.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,12 @@ public function new_measure() {

$this->event->add(MEASURE_LOAD);

array_push($this->_headerData['javaScripts'], "input.time.logic");

$this->_headerData['headerClass'] = 'blue';
$this->load->view('header', $this->_headerData);

$this->load->view('measure/new-measure', $this->_bodyData);
$this->load->view('measure/audio.php');

$this->load->view('footer');
}
Expand Down Expand Up @@ -248,15 +249,17 @@ public function get_accuracy() {

$this->event->add(ACCURACY_LOAD);


$this->_headerData['headerClass'] = 'blue';
array_push($this->_headerData['javaScripts'], "watch.animation");
array_push($this->_headerData['javaScripts'], "input.time.logic",
"watch.animation");

$this->load->view('header', $this->_headerData);

$this->_bodyData['selectedWatch'] = $this->watch->getWatch($this->input->post('watchId'));
$this->_bodyData['measureId'] = $this->input->post('measureId');

$this->load->view('measure/get-accuracy', $this->_bodyData);
$this->load->view('measure/audio.php');

$this->load->view('footer');

Expand All @@ -265,15 +268,6 @@ public function get_accuracy() {
}
}

/**
* getReferenceTime. Set the server time to the user session.
*
* This must to be call by the user before accuracyMeasure or baseMeasure
*/
function getReferenceTime() {
$this->session->set_userdata('referenceTime', time());
}

/**
* Save the base measure (1/2)
*
Expand All @@ -288,21 +282,14 @@ function getReferenceTime() {
*/
function baseMeasure() {

if ($this->expectsPost(array('watchId', 'userTimezone', 'userTime'))) {

$result = array('success' =>false);

$watchId = $this->input->post('watchId');

//Construct user time
$referenceTime = $this->session->userdata('referenceTime');
$userTimezone = $this->input->post('userTimezone');
$tempUserTime = preg_split('/:/', $this->input->post('userTime'));
$userTime = mktime($tempUserTime[0], $tempUserTime[1],
$tempUserTime[2], date("n"), date("j"), date("Y"));
if ($this->expectsPost(array('watchId', 'referenceTimestamp', 'userTimestamp'))) {

//Add the base measure
if ($this->measure->addBaseMesure($watchId, $referenceTime, $userTime)) {
if ($this->measure->addBaseMesure(
$this->watchId,
$this->referenceTimestamp/1000,
$this->userTimestamp/1000)
) {

$result['success'] = true;

Expand All @@ -319,8 +306,6 @@ function baseMeasure() {
* TODO: When this becomes doable from many endpoints (web, mobile, ...)
* I'll to move it to the model.
*
* FIXME: userTimezone parameter isn't used. Should it ?
*
* @param POST String measureId
* @param POST String userTimezone
* @param POST String userTime
Expand All @@ -329,20 +314,14 @@ function baseMeasure() {
*/
function accuracyMeasure() {

if ($this->expectsPost(array('measureId', 'userTimezone', 'userTime'))) {

$result = array('success' =>false);

//Construct the user time
$referenceTime = $this->session->userdata('referenceTime');
$userTimezone = $this->input->post('userTimezone');
$tempUserTime = preg_split('/:/', $this->input->post('userTime'));
$userTime = mktime($tempUserTime[0], $tempUserTime[1], $tempUserTime[2],
date("n"), date("j"), date("Y"));
if ($this->expectsPost(array('measureId', 'referenceTimestamp', 'userTimestamp'))) {

//Add the watch measure
$watchMeasure = $this->measure->addAccuracyMesure(
$this->input->post('measureId'), $referenceTime, $userTime);
$this->measureId,
$this->referenceTimestamp/1000,
$this->userTimestamp/1000
);

// If the computed accuracy makes sense, we return success
if (is_numeric($watchMeasure->accuracy)) {
Expand Down
7 changes: 6 additions & 1 deletion application/libraries/Auto_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,14 @@ private function sendAtString($scheduleTime) {
//sent right away.
$scheduleTime = $scheduleTime-48*60*60;

log_message('info', 'Date ' . print_r($scheduleTime, true));


$returnValue = date('Y-', $scheduleTime).date('m-', $scheduleTime)
.(date('d', $scheduleTime)).' '.(date('H', $scheduleTime)).':'
.(date('i', $scheduleTime)).date(':s', $scheduleTime);
.(date('i', $scheduleTime)).':'.(date('s', $scheduleTime));

log_message('info', 'Date ' . print_r($returnValue, true));

return $returnValue;
}
Expand Down
24 changes: 6 additions & 18 deletions application/tests/controllers/Measures_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function test_newWatch(){

public function test_newMeasure(){
$output = $this->request('GET', ['Measures', 'new_measure']);
$this->assertContains('<h1>New measure</h1>', $output);
$this->assertContains('<h1>New measure', $output);
}

public function test_getAccuracyFail(){
Expand All @@ -191,17 +191,7 @@ public function test_getAccuracy(){
]
);

$this->assertContains('<h1 id="mainTitle">Check the accuracy</h1>', $output);
}

public function test_getReferenceTime() {
$CI = &get_instance();
$CI->load->model('User');
$CI->load->library('Session');

$output = $this->request('GET', ['Measures', 'getReferenceTime']);

$this->assertEquals($CI->session->userdata('referenceTime'), time());
$this->assertContains('<h1 id="mainTitle">Check the accuracy', $output);
}

public function test_baseMesure() {
Expand All @@ -227,8 +217,8 @@ public function test_baseMesure() {
['Measures', 'baseMeasure'],
[
'watchId' => self::$watchId,
'userTime' => '10:13:12',
'userTimezone' => '5'
'referenceTimestamp' => microtime(),
'userTimestamp' => microtime()
]
);

Expand All @@ -242,15 +232,13 @@ public function test_accuracyMeasure() {

$measure = $CI->Measure->find_by('watchId', self::$watchId);

$CI->session->set_userdata('referenceTime', time());

$output = $this->request(
'POST',
['Measures', 'accuracyMeasure'],
[
'measureId' => $measure->id,
'userTime' => '10:16:12',
'userTimezone' => '5'
'referenceTimestamp' => microtime(),
'userTimestamp' => microtime()
]
);

Expand Down
36 changes: 18 additions & 18 deletions application/views/home/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@

<div id="demo" class="col-sm-12">

<div class=" col-sm-offset-2 col-sm-3" >
<div style="margin-top:60px;" class=" col-sm-offset-2 col-sm-3" >
<canvas id="canvas_animated_watch" width="250" height="250"></canvas>
<img style="display:none" id="watch" src="<?php echo img_url('flatwatch-blank.png');?>">
</div>

<div id="demo-second-step" class="col-sm-5" >
<center id="demo-sync-time">5</center>
</div>

<div id="demo-third-step" class="col-sm-5" >
<br />
<br />
<br />
<input type="text" id="inputUserTime" name="userTime" class="form-control" placeholder="ex: 12:34:56">
<br>Please use the 24-hour clock format
<span class="signup-error time-error">Your time should be hours:minutes:seconds (like 11:22:33).</span>
<button id="demo-cta" class="btn btn-primary btn-lg" name="startSync">Check now!</button>
<img id='demo-pointer' src="<?php echo img_url('pointer.png');?>">

<div id="demo-first-step" class="form-group">
<div class="col-sm-offset-1 col-sm-4">
<center>
<br />
<br />
<br />
<a
style="display:none; background-color:#1763A5"
id="sync-button"
class="btn btn-primary btn-lg" disabled="disabled">
</a>
</center>
</div>
</div>

<div id="demo-fourth-step" class="col-sm-5" >

<div style="margin-top:90px;" id="demo-second-step" class="col-sm-5" >
<div class="col-sm-12">
<h1>Congratulations!</h1> <br/> <p class="accuracy-subtitle"> The accuracy of your <strong><span class="watch-brand">watch</span></strong> is </p>
</div>
<div class="col-sm-12">
<strong><span class="watch-accuracy"></span> seconds a day!</strong>
<strong><span class="watch-accuracy"></span> seconds a day!</strong>
</div>
</div>

</div>

</div>
</div>
12 changes: 6 additions & 6 deletions application/views/home/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

<div class="home-picto">
<div id="demo-screen" class="container container-fluid">
<?php
$this->load->view('home/demo');
$this->load->view('home/slogan');

<?php
$this->load->view('home/demo');
$this->load->view('home/slogan');
?>

</div>
</div>

<?php $this->load->view('home/mosa'); ?>
<?php $this->load->view('home/mosa'); ?>
36 changes: 0 additions & 36 deletions application/views/measure/audio.php

This file was deleted.

2 changes: 1 addition & 1 deletion application/views/measure/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<div class="col-md-12">
<center>
<a class="btn btn-success btn-lg col-md-2 col-md-offset-5" href="/measures/new-watch/">Add a watch</a><br><br>
<?php if($watches != null) { ?>
<?php if($allMeasure != null) { ?>

<a class="btn btn-primary btn-lg col-md-2 col-md-offset-5" href="/measures/new-measure/">Start a new measure</a>

Expand Down
Loading

0 comments on commit 1b0d805

Please sign in to comment.