Files
pds/app/Providers/Filament/AdminPanelProvider.php

186 lines
7.8 KiB
PHP

<?php
namespace App\Providers\Filament;
use Althinect\FilamentSpatieRolesPermissions\FilamentSpatieRolesPermissionsPlugin;
use App\Filament\Pages\InvoiceDashboard;
use Filament\Facades\Filament;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\AuthenticateSession;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Navigation\MenuItem;
use Filament\Navigation\NavigationGroup;
use Filament\Navigation\NavigationItem;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Althinect\FilamentSpatieRolesPermissions\Middleware\SyncSpatiePermissionsWithFilamentTenants;
use Filament\View\PanelsRenderHook;
use Filament\Support\Facades\FilamentView;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
// ->maxContentWidth(MaxWidth::Small)
//->simplePageMaxContentWidth(MaxWidth::Medium)
// ->login(Login::class, function (Login $login) {
// $login->formActions([
// ...$login->getFormActions(),
// Action::make('forgotPassword')
// ->label('Forgot your password?')
// ->url(route('password.request')),
// ]);
// })
// ->forgotPassword()
// ->favicon(asset('/assets/crilogo1.png'))
->favicon(asset('/assets/crilogo1.png'))
->colors([
'primary' => Color::Amber,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
// ->widgets([
// Widgets\AccountWidget::class,
// Widgets\FilamentInfoWidget::class,
// ])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
])
->tenantMiddleware([
SyncSpatiePermissionsWithFilamentTenants::class,
], isPersistent: true)
->databaseNotifications()
// ->renderHook(PanelsRenderHook::AUTH_LOGIN_FORM_AFTER, function () {
// // Use Filament panel helper for login URL and custom route for forgot password
// return '<div class="mt-4 text-center">
// <a href="' . route('filament.admin.forgot-password') . '" class="text-primary-600 hover:underline">
// Forgot your password?
// </a>
// </div>';
// })
//->renderHook('panels::body.end', fn () => view('components.pages.folder-picker-script'))
->renderHook(
PanelsRenderHook::SIDEBAR_NAV_START,
fn () => view('components.navigation-filter')
)
->plugin(FilamentSpatieRolesPermissionsPlugin::make());
}
// public function boot(): void
// {
// FilamentView::registerRenderHook(
// 'panels::head.end',
// fn() => '
// <link rel="manifest" href="' . asset('manifest.json') . '">
// <meta name="theme-color" content="#007bff">
// <script>
// if ("serviceWorker" in navigator) {
// navigator.serviceWorker.register("/sw.js")
// .then(reg => console.log("Service Worker registered:", reg.scope))
// .catch(err => console.error("Service Worker registration failed:", err));
// }
// </script>
// '
// );
// /**
// * ✅ 2. Add install popup for mobile/desktop
// */
// FilamentView::registerRenderHook(
// 'panels::body.end',
// fn() => '
// <script>
// let deferredPrompt;
// window.addEventListener("beforeinstallprompt", (e) => {
// e.preventDefault();
// deferredPrompt = e;
// if (document.getElementById("install-banner")) return;
// const banner = document.createElement("div");
// banner.id = "install-banner";
// banner.innerHTML = `
// <div style="
// position: fixed;
// bottom: 20px;
// left: 20px;
// right: 20px;
// background: var(--fi-color-primary, #007bff);
// color: white;
// padding: 15px;
// border-radius: 10px;
// text-align: center;
// font-family: system-ui, sans-serif;
// box-shadow: 0 4px 10px rgba(0,0,0,0.3);
// z-index: 99999;
// ">
// <span style="font-size: 16px;">📱 Install <b>Quality Dashboard</b> App?</span><br>
// <button id="installBtn" style="
// margin-top: 10px;
// background: white;
// color: var(--fi-color-primary, #007bff);
// border: none;
// padding: 8px 16px;
// border-radius: 6px;
// font-weight: 600;
// cursor: pointer;
// ">Install</button>
// </div>
// `;
// document.body.appendChild(banner);
// document.getElementById("installBtn").addEventListener("click", async () => {
// banner.remove();
// deferredPrompt.prompt();
// const { outcome } = await deferredPrompt.userChoice;
// console.log("User install choice:", outcome);
// deferredPrompt = null;
// });
// });
// window.addEventListener("appinstalled", () => {
// console.log("🎉 PWA installed successfully!");
// const banner = document.getElementById("install-banner");
// if (banner) banner.remove();
// });
// </script>
// '
// );
// }
}