From f40303ff95f0c8722e493dfb7ed528e913a40ad6 Mon Sep 17 00:00:00 2001 From: sebsel Date: Mon, 10 Jul 2017 23:59:28 +0200 Subject: [PATCH 1/3] first take at default timezone option --- compass/app/Http/Controllers/Controller.php | 10 ++++++++- compass/database/schema.sql | 2 ++ compass/resources/views/map.blade.php | 2 +- compass/resources/views/settings.blade.php | 24 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/compass/app/Http/Controllers/Controller.php b/compass/app/Http/Controllers/Controller.php index 77b4f7f..a4ccb5f 100644 --- a/compass/app/Http/Controllers/Controller.php +++ b/compass/app/Http/Controllers/Controller.php @@ -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); } } diff --git a/compass/database/schema.sql b/compass/database/schema.sql index 12c5d9b..5e5d275 100644 --- a/compass/database/schema.sql +++ b/compass/database/schema.sql @@ -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`) diff --git a/compass/resources/views/map.blade.php b/compass/resources/views/map.blade.php index d120a04..2eadcba 100644 --- a/compass/resources/views/map.blade.php +++ b/compass/resources/views/map.blade.php @@ -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')) { ?> diff --git a/compass/resources/views/settings.blade.php b/compass/resources/views/settings.blade.php index b334d00..59d64f2 100644 --- a/compass/resources/views/settings.blade.php +++ b/compass/resources/views/settings.blade.php @@ -60,6 +60,30 @@
+

Settings

+ +

Here you can pick a default timezone and system of measurement to display this database in.

+ +
+
+
+ + +
+ +
+ + +
+ + +
+
+
+

Realtime Micropub Export

Enter a Micropub endpoint and token below and any trips that are written to this database will be sent to the endpoint as well.

From d7d41f85910af79ab8a9a8e6fed235e32de3c8e5 Mon Sep 17 00:00:00 2001 From: Sebastiaan Andeweg Date: Tue, 11 Jul 2017 00:57:25 +0200 Subject: [PATCH 2/3] display speed in metric or imperial --- compass/public/assets/speed.js | 14 ++++++++++++-- compass/resources/views/map.blade.php | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compass/public/assets/speed.js b/compass/public/assets/speed.js index 1d80b50..4039af4 100644 --- a/compass/public/assets/speed.js +++ b/compass/public/assets/speed.js @@ -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 ''+this.y+'mph'; + return ''+this.y+system.label+''; } }, 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] } }); diff --git a/compass/resources/views/map.blade.php b/compass/resources/views/map.blade.php index 2eadcba..cb4855f 100644 --- a/compass/resources/views/map.blade.php +++ b/compass/resources/views/map.blade.php @@ -57,6 +57,7 @@
+
From 4e8d9729b79b032d47becf6e7cc07772aba3163a Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Mon, 10 Jul 2017 16:13:52 -0700 Subject: [PATCH 3/3] add database migrations for #6 --- .../2017_07_10_231240_database_settings.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 compass/database/migrations/2017_07_10_231240_database_settings.php diff --git a/compass/database/migrations/2017_07_10_231240_database_settings.php b/compass/database/migrations/2017_07_10_231240_database_settings.php new file mode 100644 index 0000000..45cf0cd --- /dev/null +++ b/compass/database/migrations/2017_07_10_231240_database_settings.php @@ -0,0 +1,33 @@ +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'); + }); + } +}