Show count of pending pilot registrations; pagination

This commit is contained in:
Nabeel Shahzad
2017-12-22 14:48:15 -06:00
parent 7103278bb8
commit 50ede116ca
9 changed files with 70 additions and 52 deletions

View File

@@ -2,17 +2,21 @@
namespace App\Http\Controllers\Admin;
use App\Repositories\PirepRepository;
use Illuminate\Http\Request;
use App\Repositories\PirepRepository;
use App\Repositories\UserRepository;
class DashboardController extends BaseController
{
private $pirepRepo;
private $pirepRepo, $userRepo;
public function __construct(
PirepRepository $pirepRepo
PirepRepository $pirepRepo,
UserRepository $userRepo
) {
$this->pirepRepo = $pirepRepo;
$this->userRepo = $userRepo;
}
/**
@@ -28,6 +32,7 @@ class DashboardController extends BaseController
return view('admin.dashboard.index', [
'feed' => $feed,
'pending_pireps' => $this->pirepRepo->getPendingCount(),
'pending_users' => $this->userRepo->getPendingCount(),
]);
}
}

View File

@@ -36,19 +36,15 @@ class UserController extends BaseController
$this->userRepo = $userRepo;
}
/**
* Display a listing of the User.
*
* @param Request $request
* @return Response
*/
public function index(Request $request)
{
$this->userRepo->pushCriteria(new RequestCriteria($request));
$Users = $this->userRepo->all();
$users = $this->userRepo
->orderBy('created_at', 'desc')
->paginate();
return view('admin.users.index', [
'users' => $Users,
'users' => $users,
]);
}

View File

@@ -2,6 +2,7 @@
namespace App\Repositories;
use App\Models\Enums\PirepState;
use App\Models\Pirep;
use App\Models\User;
use App\Repositories\Traits\CacheableRepository;
@@ -15,6 +16,7 @@ class PirepRepository extends BaseRepository implements CacheableInterface
'user_id',
'flight_id',
'status',
'state',
];
public function model()
@@ -46,7 +48,10 @@ class PirepRepository extends BaseRepository implements CacheableInterface
*/
public function getPendingCount(User $user = null)
{
$where = [];
$where = [
'state' => PirepState::PENDING,
];
if ($user !== null) {
$where['user_id'] = $user->id;
}

View File

@@ -1,6 +1,7 @@
<?php
namespace App\Repositories;
use App\Models\Enums\PilotState;
use App\Models\User;
use App\Repositories\Traits\CacheableRepository;
use Prettus\Repository\Contracts\CacheableInterface;
@@ -14,10 +15,25 @@ class UserRepository extends BaseRepository implements CacheableInterface
'email' => 'like',
'home_airport_id',
'curr_airport_id',
'state'
];
public function model()
{
return User::class;
}
/**
* Number of PIREPs that are pending
* @return mixed
*/
public function getPendingCount()
{
$where = [
'state' => PilotState::PENDING,
];
$users = $this->orderBy('created_at', 'desc')->findWhere($where)->count();
return $users;
}
}

View File

@@ -119,6 +119,7 @@ return [
# ENUMS
'PilotState' => App\Models\Enums\PilotState::class,
'PirepSource' => App\Models\Enums\PirepSource::class,
'PirepState' => App\Models\Enums\PirepState::class,
'PirepStatus' => App\Models\Enums\PirepStatus::class,

View File

@@ -10,11 +10,11 @@
<div class="numbers">
<p>{{$type}}</p>
@if(isset($link))
<a href="{!! @link !!}">
<a href="{!! $link !!}">
@endif
{{$pending}} pending
@if(isset($link))
</a>
</a>
@endif
</div>
</div>

View File

@@ -4,45 +4,31 @@
<div class="content">
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-6">
@component('admin.components.infobox')
@slot('icon', 'pe-7s-users')
@slot('type', 'Pilots')
@slot('pending', 5)
@slot('total', 60)
@endcomponent
@component('admin.components.infobox')
@slot('icon', 'pe-7s-cloud-upload')
@slot('type', 'PIREPs')
@slot('pending', $pending_pireps)
@slot('link', route('admin.pireps.index').'?search=status:0')
@endcomponent
</div>
<div class="col-md-6">
@component('admin.components.infobox')
@slot('icon', 'pe-7s-users')
@slot('type', 'Pilots')
@slot('pending', 5)
@slot('total', 60)
@endcomponent
@component('admin.components.infobox')
@slot('icon', 'pe-7s-cloud-upload')
@slot('type', 'PIREPs')
@slot('pending', $pending_pireps)
@slot('link', route('admin.pireps.index').'?search=status:0')
@endcomponent
</div>
</div>
<div class="col-md-7">
@include('admin.dashboard.announcements')
</div>
<div class="col-md-5">
@component('admin.components.infobox')
@slot('icon', 'pe-7s-users')
@slot('type', 'Pilots')
@slot('pending', $pending_users)
@slot('link', route('admin.users.index').'?search=state:0')
@endcomponent
@component('admin.components.infobox')
@slot('icon', 'pe-7s-cloud-upload')
@slot('type', 'PIREPs')
@slot('pending', $pending_pireps)
@slot('link', route('admin.pireps.index').'?search=state:0')
@endcomponent
</div>
</div>
<div class="row">
<div class="col-md-6">
@include('admin.dashboard.pirep_chart')
{{--@include('admin.dashboard.pirep_chart')--}}
</div>
<div class="col-md-6">
</div>
{{--<div class="col-md-3 col-sm-6 col-xs-12">

View File

@@ -13,5 +13,11 @@
<div class="card">
@include('admin.users.table')
</div>
<div class="row">
<div class="col-12 text-center">
{{ $users->links('admin.pagination.default') }}
</div>
</div>
@endsection

View File

@@ -11,11 +11,14 @@
<td>{!! $user->name !!}</td>
<td>{!! $user->email !!}</td>
<td class="text-center">
@if($user->active == 1)
<span class="label label-success">Active</span>
@if($user->state == PilotState::ACTIVE)
<span class="label label-success">
@elseif($user->state == PilotState::PENDING)
<span class="label label-warning">
@else
<span class="label label-default">Inactive</span>
<span class="label label-default">
@endif
{!! PilotState::label($user->state) !!}</span>
</td>
<td class="text-right">
{!! Form::open(['route' => ['admin.users.destroy', $user->id], 'method' => 'delete']) !!}