Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISS: Refactor sidebar menu #631

Merged
merged 14 commits into from
Sep 9, 2024
24 changes: 24 additions & 0 deletions app/Http/Controllers/ControllerDash.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,37 @@ public function dash() {

$flights = Overflight::where('dep', '!=', '')->where('arr', '!=', '')->take(15)->get();

$training_metrics = $top_trainers = [];
$training_stats = TrainingDash::generateTrainingStats($now->format('y'), $now->format('n'), 'stats');
$training_metrics[] = (object)['title' => 'Total', 'metric' => $training_stats['sessionsCompletePerMonth']];
$training_metrics[] = (object)['title' => 'S1', 'metric' => $training_stats['sessionsByType']['S1']];
$training_metrics[] = (object)['title' => 'S2', 'metric' => $training_stats['sessionsByType']['S2']];
$training_metrics[] = (object)['title' => 'S3', 'metric' => $training_stats['sessionsByType']['S3']];
$training_metrics[] = (object)['title' => 'C1', 'metric' => $training_stats['sessionsByType']['C1']];
$trainer_by_total = $trainer_by_cid = [];
foreach($training_stats['trainerSessions'] as $t) {
$trainer_by_total[] = [$t['cid']] = $t['total'];
$trainer_by_cid[] = [$t['cid']] = $t['name'];
}
rsort($trainer_by_total);
foreach($trainer_by_total as $tt) {
if($tt == 0) {
break;
}
$top_trainers[] = (object)['name' => $trainer_by_cid[key($trainer_by_total)], 'sessions_given' => $tt];
if(count($top_trainers) == 3) {
break;
}
}

return view('dashboard.dashboard')->with('calendar', $calendar)->with('news', $news)->with('announcement', $announcement)
->with('winner', $winner_bronze)->with('pwinner', $prev_winner_bronze)->with('month_words', $last_month->format('F'))->with('pmonth_words', $prev_month->format('F'))
->with('controllers', $controllers)
->with('events', $events)
->with('pyrite', $pyrite)->with('lyear', $last_year->format('Y'))
->with('winner_local', $winner_local)->with('pwinner_local', $prev_winner_local)
->with('month_challenge_description', $month_challenge_description)->with('pmonth_challenge_description', $pmonth_challenge_description)
->with('training_metrics', $training_metrics)->with('top_trainers', $top_trainers)
->with('flights', $flights)->with('stats', $stats)->with('home', $home);
}

Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/TrainingDash.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public function statistics(Request $request) {
return view('dashboard.training.statistics')->with('stats', $stats);
}

private function generateTrainingStats($year, $month, $dataType) {
public static function generateTrainingStats($year, $month, $dataType) {
$retArr = [];
$retArr['dateSelect'] = ['month' => $month, 'year' => $year];
// Set date range
Expand All @@ -629,7 +629,7 @@ private function generateTrainingStats($year, $month, $dataType) {
$retArr['sessionsCompletePreviousMonth'] = $sessionsPrevious->where('type', 12)->count();
}
// Training sessions per month by type
if ($dataType == 'graph') {
if (($dataType == 'graph')||($dataType == 'stats')) {
$sessionsS1 = $sessions->where('position', '<', 105)->count();
$sessionsS2 = $sessions->where('position', '>', 105)->where('position', '<', 115)->count();
$sessionsS3 = $sessions->whereIn('position', [115, 116, 117, 118, 119, 123])->count();
Expand All @@ -650,6 +650,7 @@ private function generateTrainingStats($year, $month, $dataType) {
$mtr = 0;
foreach ($trainers as $trainer) {
$trainerStats = [];
$trainerStats['cid'] = $trainer->id;
$trainerStats['name'] = explode(' ', $trainer->getFullNameAttribute())[1];
$trainerSesh = $sessions->where('trainer_id', $trainer->id);
$trainerStats['total'] = $trainerSesh->count();
Expand Down
78 changes: 17 additions & 61 deletions resources/assets/js/mix/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,30 @@
var coll = document.getElementsByClassName("collapsible-controllers");
var i;
var iconc = document.getElementById("caret-controllers");

var coll = document.getElementsByClassName("collapsible-sidebar");
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function () {
iconc.classList.toggle("open");
this.getElementsByClassName("caret")[0].classList.toggle("open");
this.classList.toggle("active");

var content = this.nextElementSibling;

let content = this.nextElementSibling;
if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
});

for (i = 0; i < coll.length; i++) {
if (coll[i].nextElementSibling.innerHTML.indexOf("active") !== -1) {
coll[i].click();
}
}
}

var coll = document.getElementsByClassName("collapsible-train");
var i;
var icont = document.getElementById("caret-train");

for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function () {
icont.classList.toggle("open");
this.classList.toggle("active");

var content = this.nextElementSibling;

if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
for (j = 0; j < coll.length; j++) {
let e = coll[j];
if (
e.getAttribute("name") !== this.getAttribute("name") &&
e.classList.contains("active")
) {
e.getElementsByClassName("caret")[0].classList.toggle("open");
e.classList.toggle("active");
e.nextElementSibling.style.maxHeight = null;
}
}
});

for (i = 0; i < coll.length; i++) {
if (coll[i].nextElementSibling.innerHTML.indexOf("active") !== -1) {
coll[i].click();
}
}
}

var coll = document.getElementsByClassName("collapsible-admin");
var i;
var icona = document.getElementById("caret-admin");

for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function () {
icona.classList.toggle("open");
this.classList.toggle("active");

var content = this.nextElementSibling;

if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
});

for (i = 0; i < coll.length; i++) {
if (coll[i].nextElementSibling.innerHTML.indexOf("active") !== -1) {
coll[i].click();
}
for (j = 0; j < coll.length; j++) {
if (coll[j].nextElementSibling.innerHTML.indexOf("active") !== -1) {
coll[j].click();
break;
}
}
10 changes: 9 additions & 1 deletion resources/assets/sass/mix/sidebar.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
.collapsible {
.sidebar-container {
margin-left: 20px;
}

[class^="collapsible"] {
cursor: pointer;
}

.collapsible-sidebar {
margin-left: -20px;
}

.content {
text-align: left;
overflow: hidden;
Expand Down
53 changes: 45 additions & 8 deletions resources/views/inc/sidebar.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="card bg-light card-body" id="pill-sidebar">
<div class="nav flex-column nav-pills" role="tablist" aria-orientation="vertical" style="margin-left:20px;">
<div class="nav flex-column nav-pills sidebar-container" role="tablist" aria-orientation="vertical">
<div class="dropdown-divider"></div>
<p class="collapsible-controllers" style="margin-left:-20px; cursor:pointer">
<p class="collapsible-sidebar" name="controllers">
ZTL CONTROLLERS
<b id="caret-controllers" class="float-right fas fa-caret-left"></b>
<b class="caret float-right fas fa-caret-left"></b>
</p>
<div class="content">
@if(Auth::user()->rating_id == 1)
Expand All @@ -24,14 +24,14 @@
</div>
@if(Auth::user()->canTrain == 1 || Auth::user()->isAbleTo('train'))
<div class="dropdown-divider"></div>
<p class="collapsible-train" style="margin-left:-20px; cursor:pointer">
<p class="collapsible-sidebar" name="training">
TRAINING
<b id="caret-train" class="float-right fas fa-caret-left"></b>
<b class="caret float-right fas fa-caret-left"></b>
</p>
<div class="content">
<a class="nav-link" href="https://scheduling.ztlartcc.org?first_name={{ Auth::user()->fname }}&last_name={{ Auth::user()->lname }}&email={{ Auth::user()->email }}&cid={{ Auth::id() }}" target="_blank">Schedule a Training Session</a>
<a class="nav-link {{ Nav::urlDoesContain('dashboard/training/info') }}" href="/dashboard/training/info">Training Information</a>
<a class="nav-link {{ Nav::urlDoesContain('/dashboard/training/atcast') }}" href="/dashboard/training/atcast">ATCast Videos</a>
<a class="nav-link {{ Nav::urlDoesContain('dashboard/training/atcast') }}" href="/dashboard/training/atcast">ATCast Videos</a>
@if(Auth::user()->isAbleTo('train'))
<a class="nav-link {{ Nav::urlDoesContain('dashboard/training/tickets') }}" href="/dashboard/training/tickets">Training Tickets</a>
<a class="nav-link" href="https://scheduling.ztlartcc.org/index.php/user/login" target="_blank">Schedule Management</a>
Expand All @@ -46,9 +46,9 @@
@endif
@if(Auth::user()->isAbleTo('staff') || Auth::user()->isAbleTo('email') || Auth::user()->isAbleTo('scenery') || Auth::user()->isAbleTo('files'))
<div class="dropdown-divider"></div>
<p class="collapsible-admin" style="margin-left:-20px; cursor:pointer">
<p class="collapsible-sidebar" name="administration">
ADMINISTRATION
<b id="caret-admin" class="float-right fas fa-caret-left"></b>
<b class="caret float-right fas fa-caret-left"></b>
</p>
<div class="content">
@if(Auth::user()->isAbleTo('staff'))
Expand Down Expand Up @@ -116,6 +116,42 @@
</div>
</div>
<br/>
<div class="card">
<div class="card-body p-2">
<h5 class="card-title">
{{ Carbon\Carbon::now()->translatedFormat('F') }} Training&nbsp;<i class="fa-solid fa-graduation-cap"></i><br>
<small class="text-muted">Sessions Given</small>
</h5>
<table class="table table-sm table-borderless table-striped pb-0 mb-0">
@if(count($training_metrics) > 0)
@foreach($training_metrics as $t)
<tr class="p-3 m-0"><td class="py-0 pl-1 pr-2 m-0"><strong>{{ $t->title }}</strong></td><td class="py-0 px-2 m-0">&nbsp;{{ $t->metric }}</td></tr>
@endforeach
@else
<tr class="p-3 m-0"><td class="py-0 pl-1 pr-2 m-0"><i>Unavailable</i></td></tr>
@endif
</table>
</div>
</div>
<br/>
<div class="card">
<div class="card-body p-2">
<h5 class="card-title">
Top Trainers&nbsp;<i class="fa-solid fa-person-chalkboard"></i><br>
<small class="text-muted">Sessions Given</small>
</h5>
<table class="table table-sm table-borderless table-striped pb-0 mb-0">
@if(count($top_trainers) > 0)
@foreach($top_trainers as $m)
<tr class="p-3 m-0"><td class="py-0 pl-1 pr-2 m-0"><strong>{{ $m->name }}</strong></td><td class="py-0 px-2 m-0">&nbsp;{{ $m->sessions_given }}</td></tr>
@endforeach
@else
<tr class="p-3 m-0"><td class="py-0 pl-1 pr-2 m-0"><i>So empty...</i></td></tr>
@endif
</table>
</div>
</div>
<br/>
<div class="card">
<div class="card-body p-2">
<h5 class="card-title">Online Now&nbsp;<i class="fas fa-broadcast-tower"></i></h5>
Expand All @@ -130,5 +166,6 @@
</table>
</div>
</div>

@endif
<script src="{{asset('js/sidebar.js')}}"></script>