From 1bc6b50727cbe243fb58f14ed0aa9ee6b4f80181 Mon Sep 17 00:00:00 2001 From: Notoric Date: Tue, 11 Jun 2024 01:17:06 +0100 Subject: [PATCH] Added graphing and heatmap --- .../Http/Controllers/ShortlinkController.php | 4 +- laravel/app/Models/Link_interaction.php | 13 ++- laravel/public/css/default.css | 19 +++- laravel/resources/views/details.blade.php | 100 +++++++++++++++++- 4 files changed, 129 insertions(+), 7 deletions(-) diff --git a/laravel/app/Http/Controllers/ShortlinkController.php b/laravel/app/Http/Controllers/ShortlinkController.php index ee8ecf9..886f293 100644 --- a/laravel/app/Http/Controllers/ShortlinkController.php +++ b/laravel/app/Http/Controllers/ShortlinkController.php @@ -74,7 +74,9 @@ class ShortlinkController extends Controller return response()->json(['error' => 'Unauthorized'], 401); } $countrylist = (new Link_interactionController)->getCountryArray($id); - return view('details', ['shortlink' => $shortlink, 'countrylist' => $countrylist]); + $coordinates = Link_interaction::getCoordinates($id); + $timestamps = Link_interaction::getTimes($id); + return view('details', ['shortlink' => $shortlink, 'countrylist' => $countrylist, 'coordinates' => $coordinates, 'timestamps' => $timestamps]); } catch (\Exception $e) { return response()->json(['error' => $e->getMessage()], 404); } diff --git a/laravel/app/Models/Link_interaction.php b/laravel/app/Models/Link_interaction.php index c65c8f6..a3e9ec1 100644 --- a/laravel/app/Models/Link_interaction.php +++ b/laravel/app/Models/Link_interaction.php @@ -78,16 +78,21 @@ class Link_interaction extends Model return $link_interaction; } - public function getTimes(string $link) { + public static function getTimes(string $link) { $link_interaction = []; $link_interaction = Link_interaction::where('link', $link)->select('created_at')->get()->toArray(); return $link_interaction; } - public function getCoordinates(string $link) { - $link_interaction = []; + public static function getCoordinates(string $link) { + $coordinates = []; $link_interaction = Link_interaction::where('link', $link)->select('latitude', 'longitude')->get()->toArray(); - return $link_interaction; + foreach ($link_interaction as $interaction) { + if ($interaction['latitude'] != null && $interaction['longitude'] != null) { + array_push($coordinates, $interaction); + } + } + return $coordinates; } } diff --git a/laravel/public/css/default.css b/laravel/public/css/default.css index 0f53747..5ce09a9 100644 --- a/laravel/public/css/default.css +++ b/laravel/public/css/default.css @@ -10,6 +10,7 @@ body { margin: 0; overflow: hidden; + overflow-y: scroll; font-family: 'Roboto', sans-serif; background-color: var(--background); color: white; @@ -363,4 +364,20 @@ a button { align-self: center; font-size: 0.8em; cursor: pointer; -} \ No newline at end of file +} + +#graphs { + display: flex; + flex-direction: row; + justify-content: space-between; +} + +#graphs h2 { + margin-bottom: 20px; +} + +#map { + width: 540px; + height: 400px; +} + diff --git a/laravel/resources/views/details.blade.php b/laravel/resources/views/details.blade.php index 6e4c52e..46eb230 100644 --- a/laravel/resources/views/details.blade.php +++ b/laravel/resources/views/details.blade.php @@ -4,6 +4,10 @@ Details & Logs @endsection +@section('head') + +@endsection + @section('content')
- +
+

Heatmap

+
+
+
+

Timeline

+ +

Link Clicks

@@ -87,4 +98,91 @@ @section('scripts') + + + + + + + @endsection \ No newline at end of file