Browse Source

Merge remote-tracking branch 'aaronpk/master'

pull/8/head
sebsel 6 years ago
parent
commit
7152579d01
6 changed files with 82 additions and 4 deletions
  1. +9
    -1
      compass/app/Http/Controllers/Controller.php
  2. +33
    -0
      compass/database/migrations/2017_07_10_231240_database_settings.php
  3. +2
    -0
      compass/database/schema.sql
  4. +12
    -2
      compass/public/assets/speed.js
  5. +2
    -1
      compass/resources/views/map.blade.php
  6. +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_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'),
]);
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);
}
}

+ 33
- 0
compass/database/migrations/2017_07_10_231240_database_settings.php View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DatabaseSettings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('databases', function (Blueprint $table) {
$table->string('timezone', 100)->default('UTC');
$table->boolean('metric')->default(true);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('databases', function (Blueprint $table) {
$table->dropColumn('timezone');
$table->dropColumn('metric');
});
}
}

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

@ -15,6 +15,8 @@ CREATE TABLE `databases` (
`micropub_endpoint` varchar(255) NOT NULL,
`micropub_token` 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`),
KEY `read_token` (`read_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 system = {
label: 'mph',
multiplier: 2.23694
};
if(document.getElementById('is-metric').value == true) {
system.label = 'km/h';
system.multiplier = 3.6;
}
var series = {
name: "Speed",
yAxis: 1,
@ -9,7 +19,7 @@ function speedSeries(response) {
animation: true,
pointFormatter: function(){
moveMarkerToPosition(this);
return '<b>'+this.y+'mph</b>';
return '<b>'+this.y+system.label+'</b>';
}
},
lineWidth: 1,
@ -27,7 +37,7 @@ function speedSeries(response) {
series.data = data.properties.map(function(d,i){
return {
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]
}
});

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

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

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

@ -60,6 +60,30 @@
<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>
<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