Browse Source

Merge pull request #6 from sebsel/feature/default-timezone

Add timezone and metric options
pull/13/head
Aaron Parecki 7 years ago
committed by GitHub
parent
commit
1d1d4932e5
5 changed files with 49 additions and 4 deletions
  1. +9
    -1
      compass/app/Http/Controllers/Controller.php
  2. +2
    -0
      compass/database/schema.sql
  3. +12
    -2
      compass/public/assets/speed.js
  4. +2
    -1
      compass/resources/views/map.blade.php
  5. +24
    -0
      compass/resources/views/settings.blade.php

+ 9
- 1
compass/app/Http/Controllers/Controller.php View File

@ -96,7 +96,7 @@ class Controller extends BaseController
], ],
'range_from' => $request->input('from') ?: '', 'range_from' => $request->input('from') ?: '',
'range_to' => $request->input('to') ?: '', 'range_to' => $request->input('to') ?: '',
'range_tz' => $request->input('tz') ?: 'America/Los_Angeles'
'range_tz' => $request->input('tz') ?: $db->timezone
]); ]);
} }
@ -188,6 +188,14 @@ class Controller extends BaseController
'ping_urls' => $request->input('ping_urls'), 'ping_urls' => $request->input('ping_urls'),
]); ]);
return redirect('/settings/'.$db->name);
} else if($request->input('timezone')) {
DB::table('databases')->where('id', $db->id)
->update([
'timezone' => $request->input('timezone'),
'metric' => $request->input('metric'),
]);
return redirect('/settings/'.$db->name); return redirect('/settings/'.$db->name);
} }
} }

+ 2
- 0
compass/database/schema.sql View File

@ -15,6 +15,8 @@ CREATE TABLE `databases` (
`micropub_endpoint` varchar(255) NOT NULL, `micropub_endpoint` varchar(255) NOT NULL,
`micropub_token` varchar(1024) NOT NULL, `micropub_token` varchar(1024) NOT NULL,
`ping_urls` varchar(1024) NOT NULL, `ping_urls` varchar(1024) NOT NULL,
`timezone` varchar(100) NOT NULL DEFAULT 'UTC',
`metric` boolean NOT NULL DEFAULT 1,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `read_token` (`read_token`), KEY `read_token` (`read_token`),
KEY `write_token` (`write_token`) KEY `write_token` (`write_token`)

+ 12
- 2
compass/public/assets/speed.js View File

@ -2,6 +2,16 @@ function speedSeries(response) {
var data = response.linestring; var data = response.linestring;
var system = {
label: 'mph',
multiplier: 2.23694
};
if(document.getElementById('is-metric').value == true) {
system.label = 'km/h';
system.multiplier = 3.6;
}
var series = { var series = {
name: "Speed", name: "Speed",
yAxis: 1, yAxis: 1,
@ -9,7 +19,7 @@ function speedSeries(response) {
animation: true, animation: true,
pointFormatter: function(){ pointFormatter: function(){
moveMarkerToPosition(this); moveMarkerToPosition(this);
return '<b>'+this.y+'mph</b>';
return '<b>'+this.y+system.label+'</b>';
} }
}, },
lineWidth: 1, lineWidth: 1,
@ -27,7 +37,7 @@ function speedSeries(response) {
series.data = data.properties.map(function(d,i){ series.data = data.properties.map(function(d,i){
return { return {
x: new Date(d.unixtime*1000), x: new Date(d.unixtime*1000),
y: ('speed' in d && d.speed >= 0 ? Math.round(d.speed * 2.23694) : null),
y: ('speed' in d && d.speed >= 0 ? Math.round(d.speed * system.multiplier) : null),
location: data.coordinates[i] location: data.coordinates[i]
} }
}); });

+ 2
- 1
compass/resources/views/map.blade.php View File

@ -35,7 +35,7 @@
$days = array_fill(1,31,['#']); $days = array_fill(1,31,['#']);
$start = new DateTime('2008-05-30T00:00:00-0800'); $start = new DateTime('2008-05-30T00:00:00-0800');
$end = new DateTime(); $end = new DateTime();
$end->setTimeZone(new DateTimeZone('America/Los_Angeles'));
$end->setTimeZone(new DateTimeZone($database->timezone));
$i = clone $start; $i = clone $start;
while((int)$i->format('Y') <= (int)$end->format('Y') && (int)$i->format('M') <= (int)$end->format('M')) { while((int)$i->format('Y') <= (int)$end->format('Y') && (int)$i->format('M') <= (int)$end->format('M')) {
?> ?>
@ -57,6 +57,7 @@
<div id="map"></div> <div id="map"></div>
<div id="graphs"> <div id="graphs">
<input id="is-metric" type="hidden" value="{{ $database->metric }}">
<div id="battery-chart" width="800" height="160"></div> <div id="battery-chart" width="800" height="160"></div>
</div> </div>

+ 24
- 0
compass/resources/views/settings.blade.php View File

@ -60,6 +60,30 @@
<br> <br>
<h2>Settings</h2>
<p>Here you can pick a default timezone and system of measurement to display this database in.</p>
<div class="panel">
<form action="/settings/{{ $database->name }}" method="post" class="ui form">
<div class="field">
<label for="timezone">Timezone</label>
<input name="timezone" type="text" class="pure-input-1" value="{{ $database->timezone }}">
</div>
<div class="field">
<label for="metric">System</label>
<select name="metric" class="pure-input-1">
<option value="0" {{ $database->metric ? '' : 'selected' }}>Imperial (miles)</option>
<option value="1" {{ $database->metric ? 'selected' : '' }}>Metric (kilometer)</option>
</select>
</div>
<button type="submit" class="ui button primary">Save</button>
</form>
</div>
<br>
<h2>Realtime Micropub Export</h2> <h2>Realtime Micropub Export</h2>
<p>Enter a Micropub endpoint and token below and any trips that are written to this database will be sent to the endpoint as well.</p> <p>Enter a Micropub endpoint and token below and any trips that are written to this database will be sent to the endpoint as well.</p>

Loading…
Cancel
Save