Skip to content

Commit

Permalink
Merge pull request #10 from vatsimnetwork/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mbozwood authored Feb 16, 2022
2 parents 018e0f4 + fa9d852 commit 2054f68
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 52 deletions.
4 changes: 2 additions & 2 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Handler extends ExceptionHandler
*/
public function report(Throwable $e)
{
if (app()->bound('sentry') && $this->shouldReport($exception)) {
app('sentry')->captureException($exception);
if (app()->bound('sentry') && $this->shouldReport($e)) {
app('sentry')->captureException($e);
}

parent::report($e);
Expand Down
47 changes: 2 additions & 45 deletions app/Http/Controllers/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,60 +37,17 @@ public function getBookings($order): array

foreach ($dbBookings as $dbBooking) {
$bookings[] = [
'x' => $dbBooking->callsign,
'x' => format_callsign($dbBooking->callsign, $dbBooking->type),
'y' => [
strtotime($dbBooking->start)*1000, strtotime($dbBooking->end)*1000
],
'fillColor' => $this->colourFromProgress(time(), strtotime($dbBooking->start), strtotime($dbBooking->end), $dbBooking->type),
'fillColor' => colour_from_progress(time(), strtotime($dbBooking->start), strtotime($dbBooking->end), $dbBooking->type),
];
}

return $bookings;
}

protected function colourFromProgress($now, $start, $end, $type): string
{
// future
if ($now < $start) {
if($type == 'booking') {
return '#8981FFCC';
} else if ($type == 'exam') {
return '#7BFF5ECC';
} else if ($type == 'training') {
return '#FF7AFFCC';
} else if ($type == 'event') {
return '#FFFF62CC';
} else {
return '#8981FFCC';
}
}
// past
if ($now > $end) {
if($type == 'booking') {
return '#0000B3CC';
} else if ($type == 'exam') {
return '#007F00CC';
} else if ($type == 'training') {
return '#A3007ACC';
} else if ($type == 'event') {
return '#A36900CC';
} else {
return '#0000B3CC';
}
}
if($type == 'booking') {
return '#3C34FFCC';
} else if ($type == 'exam') {
return '#2ECB11CC';
} else if ($type == 'training') {
return '#ED2DC6CC';
} else if ($type == 'event') {
return '#EFB515CC';
} else {
return '#3C34FFCC';
}
}

/**
* @return View
*/
Expand Down
64 changes: 64 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,67 @@ function response_unauth($data = []): JsonResponse
return response()->json($data, 401);
}
}

if (!function_exists('adjust_brightness')) {
function adjust_brightness($hex_code, $time): string
{
$adjust_float = $time == 'current' ? 0 : ($time == 'past' ? -0.3 : 0.3);
$hexCode = ltrim($hex_code, '#');

if (strlen($hexCode) == 3) {
$hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
}

$hexCode = array_map('hexdec', str_split($hexCode, 2));

foreach ($hexCode as & $color) {
$adjustableLimit = $adjust_float < 0 ? $color : 255 - $color;
$adjustAmount = ceil($adjustableLimit * $adjust_float);

$color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
}

return '#' . implode($hexCode);
}
}

if (!function_exists('colour_from_progress')) {
function colour_from_progress($now, $start, $end, $type): string
{
$booking = '#3C34FF';
$exam = '#3C34FF';
$training = '#ED2DC6';
$event = '#EFB515';

$time = $now < $start ? 'future' : ($now > $end ? 'past' : 'current');

return match($type) {
'exam' => adjust_brightness($exam, $time),
'training' => adjust_brightness($training, $time),
'event' => adjust_brightness($event, $time),
default => adjust_brightness($booking, $time),
};
}
}

if (!function_exists('format_callsign')) {
function format_callsign($callsign, $type = 'booking'): string
{
return match($type) {
'event' => format_event_callsign($callsign),
default => $callsign,
};
}
}

if (!function_exists('format_event_callsign')) {
function format_event_callsign($callsign): string
{
$count = substr_count($callsign,'_');
if($count > 1) {
$explode = explode('_', $callsign);
return $explode[0] . '_' . $explode[count($explode) - 1];
}
return $callsign;
}
}
10 changes: 5 additions & 5 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="alert alert-info" role="alert">
While controllers are able to book positions on their local facility websites, this serves as no
ultimate guarantee that the position will be open at the published time. Remember that this is a
voluntary network and members are providing this service in their spare time.
voluntary network and members are providing this service in their spare time.
</div>
</div>
</div>
Expand All @@ -22,10 +22,10 @@
</div>
</div>
<div class="col">
<span class="badge rounded-pill" style="background-color: #3C34FFCC !important;">Booking</span>
<span class="badge rounded-pill" style="background-color: #ED2DC6CC !important;">Training</span>
<span class="badge rounded-pill" style="background-color: #EFB515CC !important;">Event</span>
<span class="badge rounded-pill" style="background-color: #2ECB11CC !important;">Exam</span>
<span class="badge rounded-pill" style="background-color: #3C34FF !important;">Booking</span>
<span class="badge rounded-pill" style="background-color: #ED2DC6 !important;">Training</span>
<span class="badge rounded-pill" style="background-color: #EFB515 !important;">Event</span>
<span class="badge rounded-pill" style="background-color: #2ECB11 !important;">Exam</span>
</div>
</div>
<div class="row">
Expand Down

0 comments on commit 2054f68

Please sign in to comment.