Skip to content

Commit

Permalink
Add Dashboard Card (Component Base)
Browse files Browse the repository at this point in the history
  • Loading branch information
Miyunecadz committed Sep 13, 2021
1 parent abed5b8 commit 2160858
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 19 deletions.
45 changes: 30 additions & 15 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,35 @@ class DashboardController extends Controller
{
public function index()
{
$customers = Customer::all();
$customerCount = $customers->count();

$users = User::all();
$usersCount = $users->count();

$pending_services = Service::where('status' , '<>', 'ready');
$pending_services_count = $pending_services->count();

$pending_services_not_paid = Service::where('status', 'pending_for_payment');
$pending_services_not_paid_count = $pending_services_not_paid->count();

dd([$customerCount,$usersCount,$pending_services_count, $pending_services_not_paid_count]);

return view('pages.dashboard');
$customerCount = Customer::count();

$userCount = User::count();

$servicePendingCount = Service::countNotReady();

$servicePendingForPaymentCount = Service::countWithStatus('pending_for_payment');

$data = [
'customer' =>[
'title' => 'Number of Customer',
'count' => $customerCount
] ,
'user' =>[
'title' => 'Number of User',
'count' => $userCount
],
'service_pending' =>[
'title' => 'Number of Pending Services',
'count' => $servicePendingCount
],
'service_pending_for_payment' => [
'title' => 'Number of Pending for Payment',
'count' => $servicePendingForPaymentCount
]
];

return view('pages.dashboard', [
'data' => $data
]);
}
}
4 changes: 4 additions & 0 deletions app/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ public function hasActiveConnection()
{
return $this->connection_status==="active";
}

public static function count(){
return self::all()->count();
}
}
16 changes: 13 additions & 3 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function getServiceTypes()
{
return self::$serviceTypes;
}


public static function getInitialStatus($serviceType)
{
Expand Down Expand Up @@ -111,12 +111,12 @@ public function isDeniable()

return true;
}

private function getNextFlow($flag="prev")
{
$flowIndex=0;
foreach($this->processFlow as $flow)
{
{
if($this->status==$flow)
{
break;
Expand Down Expand Up @@ -171,4 +171,14 @@ public function serviceType()
{
return StringHelper::toReadableService($this->type_of_service);
}

public static function countNotReady()
{
return self::where('status', '<>', 'ready')->count();
}

public static function countWithStatus($status)
{
return self::where('status', $status)->count();
}
}
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,9 @@ public function user_role()
{
return self::validRoles()[$this->role];
}

public static function count()
{
return self::all()->count();
}
}
33 changes: 33 additions & 0 deletions app/View/Components/DashboardCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\View\Components;

use Illuminate\View\Component;

class DashboardCard extends Component
{

public $title;
public $count;

/**
* Create a new component instance.
*
* @return void
*/
public function __construct($title, $count)
{
$this->title = $title;
$this->count = $count;
}

/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.dashboard-card');
}
}
7 changes: 7 additions & 0 deletions resources/views/components/dashboard-card.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="col-12 col-md-5 col-lg-2 card my-1 mt-2 me-md-2">
<!-- Very little is needed to make a happy life. - Marcus Antoninus -->
<div class="card-body text-end">
<h3 class="card-title">{{ $count }}</h3>
<p class="card-text">{{ $title }}</p>
</div>
</div>
8 changes: 7 additions & 1 deletion resources/views/pages/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
@section('title', 'Dashboard')

@section('content')
Dashboard Section

<div class="row justify-content-center mx-3 ms-lg-0">
@foreach ($data as $datum)
<x-dashboard-card :title="$datum['title']" :count="$datum['count']"/>
@endforeach

</div>

@endsection

0 comments on commit 2160858

Please sign in to comment.