Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
russellporter committed May 2, 2014
1 parent e5af3af commit 0ee240f
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 94 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*.php]
indent_style = space
indent_size = 4

[*.ctp]
indent_style = space
indent_size = 4

[*.js]
indent_style = space
indent_size = 2
96 changes: 59 additions & 37 deletions app/Model/AppModel.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
<?php
/**
* Application model for Cake.
*
* This file is application-wide model file. You can put all
* application-wide model-related methods here.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Model
* @subpackage cake.cake.libs.model
* @since CakePHP(tm) v 0.2.9
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
* Application model for Cake.
*
* This file is application-wide model file. You can put all
* application-wide model-related methods here.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Model
* @subpackage cake.cake.libs.model
* @since CakePHP(tm) v 0.2.9
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('Model', 'Model');

/**
* Application model for Cake.
*
* This is a placeholder class.
* Create the same file in app/app_model.php
* Add your application-wide methods to the class, your models will inherit them.
*
* @package Cake.Model
* @subpackage cake.cake.libs.model
*/
* Application model for Cake.
*
* This is a placeholder class.
* Create the same file in app/app_model.php
* Add your application-wide methods to the class, your models will inherit them.
*
* @package Cake.Model
* @subpackage cake.cake.libs.model
*/
class AppModel extends Model {
protected $clubSpecific = true;

/**
* Select data only for this club
*/
* Select data only for this club
*/
function beforeFind($queryData) {
if($this->clubSpecific) {
$key = $this->name.".club_id";
Expand All @@ -57,29 +57,51 @@ function beforeFind($queryData) {
}

/**
* Convert date fields to/from UTC seamlessly!
* Extended from: http://stackoverflow.com/questions/3775038/converting-dates-between-timezones-in-appmodel-afterfind-cakephp
*/
* Convert date fields to/from UTC seamlessly!
* Extended from: http://stackoverflow.com/questions/3775038/converting-dates-between-timezones-in-appmodel-afterfind-cakephp
*/
function afterFind($results, $primary){
// Only bother converting if the local timezone is set.
$from = new DateTimeZone("UTC");
$to = Configure::read("Club.timezone");
if($primary && $to)
if ($primary && $to) {
$this->replaceDateRecursive($results, $from, $to);
}
return $results;
}

function beforeSave() {
$from = Configure::read("Club.timezone");
$to = new DateTimeZone("UTC");
if($from)
if ($from) {
$this->replaceDateRecursive($this->data, $from, $to);
if($this->clubSpecific && empty($this->data[$this->name]['club_id'])) {
}
if ($this->clubSpecific && empty($this->data[$this->name]['club_id'])) {
$this->data[$this->name]['club_id'] = Configure::read("Club.id");
}
return true;
}

function save($data = null, $validate = true, $fieldList = array()) {
// Wonderful CakePHP.
if (isset($this->modificationFields) && $this->modificationFields) {
$now = date('Y-m-d H:i:s');
// set created_at field before creation
if (isset($data[$this->alias])) {
if (!$data[$this->alias]['id']) {
$data[$this->alias]['created_at'] = $now;
}
$data[$this->alias]['updated_at'] = $now;
} else {
if (!$data['id']) {
$data['created_at'] = $now;
}
$data['updated_at'] = $now;
}
}
return parent::save($data, $validate, $fieldList);
}

function replaceDateRecursive(&$results, $from, $to){
foreach($results as $key => &$value){
if(is_array($value)){
Expand Down
3 changes: 2 additions & 1 deletion app/Model/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Resource extends AppModel {
public $displayField = 'caption';
public $clubSpecific = false; // in general, not club specific, though *some* resources belong to a club directly (header image, logo, etc)
public $thumbnailableFiles = array('jpg', 'jpeg', 'gif', 'png', 'pdf');
public $modificationFields = true;

public $belongsTo = array('Club');

Expand Down Expand Up @@ -126,7 +127,7 @@ private function absolutePathForResource($resource, $thumbnail = null) {
}

private function urlForResource($resource, $thumbnail = null) {
return Configure::read('Club.dataUrl') . $this->relativePathForResource($resource, $thumbnail);
return Configure::read('Club.dataUrl') . $this->relativePathForResource($resource, $thumbnail) . '?' . hash('md5', $resource['updated_at']);
}

private function relativePathForResource($resource, $thumbnail = null) {
Expand Down
94 changes: 48 additions & 46 deletions app/View/Elements/Events/knockout_result_list.ctp
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
<?php
// Params: mode (either 'normal', or 'live')
?>
<?php if ($mode == 'live') { ?>
<p>Results produced on <span data-bind="text: creationDate"></span></p>
<?php } ?>
<div data-bind="foreach: courses">
<h3 data-bind="text: name"></h3>
<div data-bind="if: results().length == 0">
<p><b>No results</b></p>
</div>
<div data-bind="if: results().length > 0">
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>#</th>
<th>Participant</th>
<th data-bind="visible: isScore">Score Points</th>
<th>Time</th>
<th data-bind="visible: hasWhyJustRunPoints">Points</th>
<th data-bind="visible: hasComments" style="width: 35px"></th>
</tr>
</thead>
<tbody data-bind="foreach: results">
<tr>
<td>
<span data-bind="text: position || friendlyStatus"></span>
</td>
<td>
<span data-bind="visible: person.profileUrl">
<a data-bind="attr: { href: person.profileUrl }"><span data-bind="text: person.givenName + ' ' + person.familyName"></span></a>
</span>
<div data-bind="if: resultList">
<?php if ($mode == 'live') { ?>
<p>Results produced on <span data-bind="text: resultList().creationDate"></span></p>
<?php } ?>
<div data-bind="foreach: resultList().courses">
<h3 data-bind="text: name"></h3>
<div data-bind="if: results().length == 0">
<p><b>No results</b></p>
</div>
<div data-bind="if: results().length > 0">
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>#</th>
<th>Participant</th>
<th data-bind="visible: isScore">Score Points</th>
<th>Time</th>
<th data-bind="visible: hasWhyJustRunPoints">Points</th>
<th data-bind="visible: hasComments" style="width: 35px"></th>
</tr>
</thead>
<tbody data-bind="foreach: results">
<tr>
<td>
<span data-bind="text: position || friendlyStatus"></span>
</td>
<td>
<span data-bind="visible: person.profileUrl">
<a data-bind="attr: { href: person.profileUrl }"><span data-bind="text: person.givenName + ' ' + person.familyName"></span></a>
</span>

<span data-bind="visible: !person.profileUrl, text: person.givenName + ' ' + person.familyName"></span>
</td>
<td data-bind="visible: $parent.isScore, text: scores['Points']"></td>
<td>
<span data-bind="text: time != null ? hours + ':' + minutes + ':' + seconds + ($parent.millisecondTiming ? '.' + milliseconds : '' ) : ''"></span>
</td>
<td data-bind="visible: $parent.hasWhyJustRunPoints, text: scores['WhyJustRun']"></td>
<td data-bind="visible: $parent.hasComments">
<div class="btn-group" data-bind="visible: officialComment">
<button class="btn btn-xs btn-default" data-bind="tooltip: { title: officialComment, trigger: 'hover' }">
<span class="glyphicon glyphicon-comment"></span>
</button>
</div>
</td>
</tr>
</tbody>
</table>
<span data-bind="visible: !person.profileUrl, text: person.givenName + ' ' + person.familyName"></span>
</td>
<td data-bind="visible: $parent.isScore, text: scores['Points']"></td>
<td>
<span data-bind="text: time != null ? hours + ':' + minutes + ':' + seconds + ($parent.millisecondTiming ? '.' + milliseconds : '' ) : ''"></span>
</td>
<td data-bind="visible: $parent.hasWhyJustRunPoints, text: scores['WhyJustRun']"></td>
<td data-bind="visible: $parent.hasComments">
<div class="btn-group" data-bind="visible: officialComment">
<button class="btn btn-xs btn-default" data-bind="tooltip: { title: officialComment, trigger: 'hover' }">
<span class="glyphicon glyphicon-comment"></span>
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
17 changes: 14 additions & 3 deletions app/webroot/js/wjr/iof.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@
define(['jquery', 'underscore', 'knockout', 'moment', './utils', './binding'], function ($, _, ko, moment, utils) {
'use strict';
var IOF = {};
IOF.Event = function (id, name, startTime) {
IOF.ResultList = function (event, creationTime) {
this.event = ko.observable(event);
this.creationTime = ko.observable(creationTime);
this.formattedCreationTime = ko.computed(function () {
var time = this.creationTime();
return time ? time.format("dddd, MMMM Do YYYY [at] h:mm:ss a") : null;
}, this);
};

IOF.Event = function (id, name, startTime, courses) {
this.id = id;
this.name = name;
this.startTime = startTime;
this.courses = courses;
};

IOF.Course = function (id, name, results, scoringType, millisecondTiming) {
Expand Down Expand Up @@ -76,7 +86,7 @@ define(['jquery', 'underscore', 'knockout', 'moment', './utils', './binding'], f
};

IOF.loadResultsList = function (xml) {
var resultList, date, event, courses;
var resultList, date, event, courses, iofEvent;

resultList = $(xml.documentElement);
date = moment(resultList.attr('createTime'));
Expand Down Expand Up @@ -124,7 +134,8 @@ define(['jquery', 'underscore', 'knockout', 'moment', './utils', './binding'], f
courses.push(new IOF.Course(courseId, courseName, results, scoringType, millisecondTiming));
});

return [new IOF.Event(event.children("Id").text(), event.children("Name").text(), null), courses, date];
iofEvent = new IOF.Event(event.children("Id").text(), event.children("Name").text(), null, courses);
return new IOF.ResultList(iofEvent, date);
};

return IOF;
Expand Down
10 changes: 3 additions & 7 deletions app/webroot/js/wjr/result-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ define(['jquery', './iof', 'knockout', 'bootstrap'], function ($, IOF, ko) {
var viewModel, fetchResults, url;

viewModel = {
event: ko.observable(),
courses: ko.observableArray(),
creationDate: ko.observable()
resultList: ko.observable()
};

fetchResults = function () {
Expand All @@ -19,10 +17,8 @@ define(['jquery', './iof', 'knockout', 'bootstrap'], function ($, IOF, ko) {
dataType: "xml",
ifModified: true,
success: function (xml) {
var result = IOF.loadResultsList(xml);
viewModel.event(result[0]);
viewModel.courses(result[1]);
viewModel.creationDate(result[2].format("dddd, MMMM Do YYYY [at] h:mm:ss a"));
var resultList = IOF.loadResultsList(xml);
viewModel.resultList(resultList);
}
});
};
Expand Down

0 comments on commit 0ee240f

Please sign in to comment.