Skip to content

Commit cdabf5b

Browse files
Fix for #6 + Google analytics
1 parent 0b30051 commit cdabf5b

File tree

6 files changed

+50
-31
lines changed

6 files changed

+50
-31
lines changed

app/controllers/RouteController.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,13 @@ public function index(){
1414

1515
switch ($val){
1616
case "text/html":
17-
return View::make('route.planner');
18-
break;
19-
case "application/ld+json":
20-
try{
21-
$from = Input::get('from'); // required
22-
$to = Input::get('to'); // required
23-
$data = json_decode($this::getJSON());
24-
return var_dump($data);
25-
// TODO: format JSON-LD
26-
}
27-
catch(ErrorException $ex){
28-
return "We could not retrieve data. Ensure that you have provided all required parameters: to, from, date, time, timeSel.";
29-
}
17+
return Response::view('route.planner')->header('Content-Type', "text/html")->header('Vary', 'accept');
3018
break;
3119
case "application/json":
32-
return $this::getJSON();
20+
return Response::make($this::getJSON())->header('Content-Type', "text/html")->header('Vary', 'accept');
3321
break;
3422
default:
35-
return View::make('route.planner');
23+
return Response::view('route.planner')->header('Content-Type', "text/html")->header('Vary', 'accept');
3624
break;
3725
}
3826
}

app/controllers/StationController.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class StationController extends \BaseController {
44

5-
public function index(){
5+
public function index(){
66
// TODO: content delegation with list of all stations
77
return View::make('stations.search');
88
}
@@ -17,9 +17,7 @@ public function liveboard($id){
1717
$acceptHeader = Request::header('accept');
1818
$priorities = array('text/html', 'application/json', '*/*');
1919
$result = $negotiator->getBest($acceptHeader, $priorities);
20-
2120
$val = $result->getValue();
22-
2321
switch ($val){
2422
case "text/html":
2523
$station = \hyperRail\StationString::convertToString($id);
@@ -34,8 +32,23 @@ public function liveboard($id){
3432
$jsonLD = (string)json_encode($newData);
3533
return Response::make($jsonLD, 200)->header('Content-Type', 'application/ld+json')->header('Vary', 'accept');
3634
break;
35+
/*case "text/turtle":
36+
$stationStringName = \hyperRail\StationString::convertToString($id);
37+
$URL = "http://api.irail.be/liveboard/?station=" . $stationStringName->name . "&fast=true&lang=nl&format=json";
38+
$data = file_get_contents($URL);
39+
$newData = \hyperRail\iRailFormatConverter::convertLiveboardData($data, $id);
40+
$jsonLD = (string)json_encode($newData);
41+
$graph = new EasyRdf_Graph();
42+
// NO PARSER YET IN STABLE :(
43+
$graph->parse($jsonLD, EasyRdf_Format::getFormat('json-ld'));
44+
$output = $graph->serialise(EasyRdf_Format::getFormat('turtle'));
45+
return Response::make($output, 200)->header('Content-Type', 'text/turtle')->header('Vary', 'accept');
46+
break;
47+
*/
3748
default:
38-
return Response::view('stations.liveboard')->header('Content-Type', "text/html")->header('Vary', 'accept');
49+
$station = \hyperRail\StationString::convertToString($id);
50+
$data = array('station' => $station);
51+
return Response::view('stations.liveboard', $data)->header('Content-Type', "text/html")->header('Vary', 'accept');
3952
break;
4053
}
4154
}

app/views/core/footer.blade.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<footer class="footer container">
22
<hr/>
33
<p class="small"><a href="{{ URL::to('language') }}">{{Lang::get('client.language')}}</a> | &copy; 2014, OKFN Belgium. {{Lang::get('client.isPartOf')}} <a href="http://okfn.be/" target="_blank">Open Knowledge Foundation Belgium</a>. </p>
4-
</footer>
4+
</footer>
5+
<script>
6+
var _gaq = [['_setAccount', 'UA-263695-8'], ['_trackPageview']];
7+
(function(d, t) {
8+
var g = d.createElement(t),
9+
s = d.getElementsByTagName(t)[0];
10+
g.src = '//www.google-analytics.com/ga.js';
11+
s.parentNode.insertBefore(g, s);
12+
}(document, 'script'));
13+
</script>

app/views/route/planner.blade.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@
1616
<div class="form-group">
1717
<label for="departure">{{Lang::get('client.fromStation')}}</label>
1818
<div class="input-group">
19-
<input type="text" ng-model="departure" placeholder="{{Lang::get('client.typeFromStation')}}" typeahead="station as station.name for station in stations.stations | filter:{name:$viewValue} | limitTo:5" typeahead-template-url="customTemplate.html" class="form-control input-lg" tabindex=1>
19+
<input type="text" ng-model="departure" placeholder="{{Lang::get('client.typeFromStation')}}" typeahead="station as station.name for station in stations.stations | filter:{name:$viewValue} | limitTo:5" typeahead-template-url="customTemplate.html" class="form-control input-lg">
2020
<a class="input-group-addon" ng-show="departure.id" href="stations/NMBS/@{{departure.id}}" target="_blank" data-toggle="tooltip" data-placement="left" title="{{Lang::get('client.viewLiveboard')}}"><i class="fa fa-clock-o"></i></a>
2121
<span class="input-group-addon" ng-hide="departure.id"></span>
2222
</div>
2323
</div>
2424
<div class="form-group">
2525
<label for="destination">{{Lang::get('client.toStation')}}</label>
2626
<div class="input-group">
27-
<input type="text" ng-model="destination" placeholder="{{Lang::get('client.typeToStation')}}" typeahead="station as station.name for station in stations.stations | filter:{name:$viewValue} | limitTo:5" typeahead-template-url="customTemplate.html" class="form-control input-lg" tabindex=2>
27+
<input type="text" ng-model="destination" placeholder="{{Lang::get('client.typeToStation')}}" typeahead="station as station.name for station in stations.stations | filter:{name:$viewValue} | limitTo:5" typeahead-template-url="customTemplate.html" typeahead-on-select='focusOnConfirm()' class="form-control input-lg">
2828
<a class="input-group-addon btn" ng-show="destination.id" href="stations/NMBS/@{{destination.id}}" target="_blank" data-toggle="tooltip" data-placement="left" title="{{Lang::get('client.viewLiveboard')}}"><i class="fa fa-clock-o"></i></a>
2929
<span class="input-group-addon" ng-hide="destination.id"></span>
3030
</div>
3131
</div>
3232
<label for="destination">{{Lang::get('client.chooseDate')}}</label>
3333
<div class="datepicker">
34-
<datepicker ng-class="time" ng-model="mydate" show-weeks="false" tabindex=3></datepicker>
34+
<datepicker ng-class="time" ng-model="mydate" show-weeks="false" ></datepicker>
3535
</div>
3636
<br/>
3737
</div>
3838
<div class="col-sm-6">
3939
<label for="destination">{{Lang::get('client.chooseTime')}}</label>
40-
<select class="form-control input-lg timepicker" ng-model="timeoption" tabindex=4>
40+
<select class="form-control input-lg timepicker" ng-model="timeoption">
4141
<option value="depart">{{Lang::get('client.departureAtHour')}}</option>
4242
<option value="arrive">{{Lang::get('client.arrivalAtHour')}}</option>
4343
</select>
44-
<timepicker ng-model="mytime" ng-change="changed()" minute-step="15" show-meridian="ismeridian" tabindex=5></timepicker>
44+
<timepicker ng-model="mytime" ng-change="changed()" minute-step="15" show-meridian="ismeridian"></timepicker>
4545
<br/>
46-
<input type="submit" class="btn btn-default btn-lg btn-primary btn-wide" ng-click="save()" value="{{Lang::get('client.confirmSearch')}}" ng-hide="departure == destination" tabindex=6>
46+
<input type="submit" id="submit" class="btn btn-default btn-lg btn-primary btn-wide" ng-click="save()" value="{{Lang::get('client.confirmSearch')}}" ng-hide="departure == destination">
4747
<div class="alert alert-danger" ng-show="data === null">
4848
<p ng-show="stationnotfound === true">{{Lang::get('client.errorCheckInput')}}</p>
4949
</div>

app/views/stations/search.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
</script>
1616
<div class="form-group">
1717
<label for="departure">{{Lang::get('client.stationName')}}</label>
18-
<input type="text" ng-model="departure" placeholder="{{Lang::get('client.stationSearchPlaceholder')}}" typeahead="station as station.name for station in stations.stations | filter:{name:$viewValue} | limitTo:5" typeahead-template-url="customTemplate.html" class="form-control input-lg">
18+
<input type="text" ng-model="departure" placeholder="{{Lang::get('client.stationSearchPlaceholder')}}" typeahead="station as station.name for station in stations.stations | filter:{name:$viewValue} | limitTo:5" typeahead-template-url="customTemplate.html" class="form-control input-lg" typeahead-on-select='focus()'>
1919
</div>
20-
<a href="{{ URL::to('stations/NMBS') }}/@{{departure.id}}" ng-show="departure.id" class="btn btn-primary btn-wide btn-lg bounceIn">{{Lang::get('client.viewLiveboard')}}</a>
20+
<a id="confirm" href="{{ URL::to('stations/NMBS') }}/@{{departure.id}}" ng-show="departure.id" class="btn btn-primary btn-wide btn-lg bounceIn">{{Lang::get('client.viewLiveboard')}}</a>
2121
</div>
2222
</div>
2323
</div>

public/js/irailapp/app.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616
// Init departure and destination as undefined
1717
$scope.departure = undefined;
1818
$scope.destination = undefined;
19-
2019
// Time and date are automatically set
2120
$scope.mytime = new Date();
2221
$scope.mydate = new Date();
2322
// Timeoption defaults to arrive at set hour
2423
$scope.timeoption = 'depart';
25-
2624
// Default states
27-
// TODO: unless &auto is set (which automatically searches)
2825
$scope.planning = true; // When planning is set to true, you can enter stations and set time
2926
$scope.loading = false; // When loading is set to true, you see a spinner
3027
$scope.results = false; // When results is set to true, results are displayed
@@ -33,6 +30,12 @@
3330
* FUNCTIONS THAT CAN BE CALLED
3431
*-------------------------------------------------------*/
3532

33+
$(document).keypress(function(e) {
34+
if(e.which == 13 && $scope.planning == true){
35+
$scope.confirmRouteSearch();
36+
}
37+
});
38+
3639
/**
3740
* Check if we can dump the data
3841
*/
@@ -251,6 +254,12 @@
251254
$scope.stations = data;
252255
});
253256

257+
$(document).keypress(function(e) {
258+
if(e.which == 13){
259+
$('#confirm').focus();
260+
}
261+
});
262+
254263
$scope.resetplanner = function(){
255264
// Should not do anything
256265
}

0 commit comments

Comments
 (0)