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

Feature/admin statistics #36

Merged
merged 14 commits into from
Jan 24, 2024
Merged
29 changes: 21 additions & 8 deletions src/app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@

namespace App\Http\Controllers;

use App\Enums\ModifiedEnum;
use App\Models\Fine;
use App\Models\Item;
use App\Models\Reservation;
use App\Models\User;
use App\Enums\ModifiedEnum;
use Inertia\Inertia;

class AdminController extends Controller
{
public function index()
{
$userData = auth()->user();

if (!$userData) {
return redirect('/');
}

// Get the Statistics
$items = Item::count();
$customers = User::count();
$reservations = Reservation::count();
$invoices = Fine::count();

return Inertia::render('admin/index', [
'userData' => [
'name' => 'John Doe',
],
'userData' => $userData,
'count' => [
'items' => 10,
'customers' => 20,
'reservations' => 30,
'invoices' => 40,
'items' => $items,
'customers' => $customers,
'reservations' => $reservations,
'invoices' => $invoices,
],
'chart1' => [
'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'],
Expand Down
63 changes: 32 additions & 31 deletions src/app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,42 @@
namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Middleware;

class HandleInertiaRequests extends Middleware
{
/**
* The root template that's loaded on the first page visit.
*
* @see https://inertiajs.com/server-side-setup#root-template
* @var string
*/
protected $rootView = 'app';
/**
* The root template that's loaded on the first page visit.
*
* @see https://inertiajs.com/server-side-setup#root-template
* @var string
*/
protected $rootView = 'app';

/**
* Determines the current asset version.
*
* @see https://inertiajs.com/asset-versioning
* @param \Illuminate\Http\Request $request
* @return string|null
*/
public function version(Request $request): ?string
{
return parent::version($request);
}
/**
* Determines the current asset version.
*
* @see https://inertiajs.com/asset-versioning
* @param \Illuminate\Http\Request $request
* @return string|null
*/
public function version(Request $request): ?string
{
return parent::version($request);
}

/**
* Defines the props that are shared by default.
*
* @see https://inertiajs.com/shared-data
* @param \Illuminate\Http\Request $request
* @return array
*/
public function share(Request $request): array
{
return array_merge(parent::share($request), [
//
]);
}
/**
* Defines the props that are shared by default.
*
* @see https://inertiajs.com/shared-data
* @param \Illuminate\Http\Request $request
* @return array
*/
public function share(Request $request): array
{
return array_merge(parent::share($request), [
//
]);
}
}
12 changes: 10 additions & 2 deletions src/resources/vue/components/admin/Siderbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<div class="dropdown">
<a href="#" class="d-flex align-items-center link-light text-decoration-none dropdown-toggle" id="dropdownUser2" data-bs-toggle="dropdown" aria-expanded="false">
<Icon icon="full-person" size="24" color="white" />
<strong class="p-1">{{ userData.name }}</strong>
<strong class="p-1">{{ name }}</strong>
</a>
<ul class="dropdown-menu text-small shadow" aria-labelledby="dropdownUser2">
<li><a class="dropdown-item" href="#">Profile</a></li>
Expand All @@ -55,10 +55,18 @@
import Icon from "@/icon.vue"
export default {
name: "AdminSidebar",
props: ["userData"],
props: {
userData: {
type: Object,
required: true,
},
},
components: {
Icon
},
created() {
this.name = this.userData.first_name + " " + this.userData.last_name.charAt(0) + "."
},
}
</script>

Expand Down
3 changes: 0 additions & 3 deletions src/resources/vue/layouts/admin-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
userData: {
type: Object,
required: true,
default: () => ({
name: "John Doe",
}),
},
},
};
Expand Down
13 changes: 5 additions & 8 deletions src/resources/vue/pages/admin/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<AdminLayout :user-data="{name: 'John Doe'}">
<AdminLayout :user-data="userData">
<div class="admin-content">
<div class="dashboard">
<span class="dashboard-title">Dashboard</span>
Expand Down Expand Up @@ -49,18 +49,15 @@ export default {
userData: {
type: Object,
required: true,
default: () => ({
name: "John Doe",
}),
},
count: {
type: Object,
required: true,
default: () => ({
items: 1,
customers: 1,
reservations: 1,
openInvoices: 1,
items: 0,
customers: 0,
reservations: 0,
openInvoices: 0,
}),
},
chart1: {
Expand Down
Loading