Initial commit for new repo
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 1m4s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 1m4s
This commit is contained in:
150
app/Providers/AppServiceProvider.php
Normal file
150
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\AlertMailRule;
|
||||
use App\Models\User;
|
||||
use App\Policies\PermissionPolicy;
|
||||
use App\Policies\RolePolicy;
|
||||
use Filament\Support\Assets\Js;
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Vite;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
// use Doctrine\DBAL\Types\Type;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
// Gate::before(function ($user, $ability) {
|
||||
// return $user->hasRole('Super Admin') ? true : null;
|
||||
// });
|
||||
// View::composer('filament-panels::pages.auth.login', function ($view) {
|
||||
// $view->with('forgotPasswordUrl', route('password.request'));
|
||||
// });
|
||||
|
||||
Gate::before(function (User $user, string $ability) {
|
||||
return $user->isSuperAdmin() ? true : null;
|
||||
});
|
||||
|
||||
// FilamentAsset::register([
|
||||
// Js::make('chart-js-plugins', Vite::asset('resources/js/filament-chart-js-plugins.js'))->module(),
|
||||
// ]);
|
||||
FilamentAsset::register([
|
||||
Js::make('chart-js-plugins', Vite::asset('resources/js/filament-chart-js-plugins.js'))->module(),
|
||||
]);
|
||||
|
||||
// if (env('APP_MODE') === 'admin') {
|
||||
// FilamentAsset::register([
|
||||
// Js::make('chart-js-plugins', Vite::asset('resources/js/filament-chart-js-plugins.js'))->module(),
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// URL::forceScheme('https');
|
||||
|
||||
// if (!Type::hasType('citext')) {
|
||||
// Type::addType('citext', \Doctrine\DBAL\Platforms\PostgreSqlPlatform::class);
|
||||
// }
|
||||
|
||||
Gate::policy(Role::class, RolePolicy::class);
|
||||
Gate::policy(Permission::class, PermissionPolicy::class);
|
||||
|
||||
ini_set('max_execution_time', 300); // 300 seconds = 5 minutes
|
||||
ini_set('memory_limit', '512M'); // 512MB
|
||||
|
||||
// $schedule = app(Schedule::class);
|
||||
|
||||
// $productionRules = AlertMailRule::where('module', 'ProductionQuantities')
|
||||
// ->where('rule_name', 'ProductionMail')
|
||||
// ->select('plant', 'schedule_type')
|
||||
// ->distinct()
|
||||
// ->get();
|
||||
|
||||
// foreach ($productionRules as $rule) {
|
||||
// $type = $rule->schedule_type;
|
||||
// $plantId = $rule->plant;
|
||||
|
||||
// $command = $schedule->command('send:production-report', [$type, $plantId]);
|
||||
// // ->appendOutputTo(storage_path('logs/scheduler.log'));
|
||||
|
||||
// switch ($type) {
|
||||
// case 'Live':
|
||||
// $command->everyMinute();
|
||||
// break;
|
||||
// case 'Hourly':
|
||||
// $command->hourly();
|
||||
// break;
|
||||
// case 'Daily':
|
||||
// $command->dailyAt('07:59');
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Invoice report scheduling
|
||||
// $invoiceRules = AlertMailRule::where('module', 'InvoiceValidation')
|
||||
// ->select('plant', 'schedule_type')
|
||||
// ->distinct()
|
||||
// ->get();
|
||||
|
||||
// foreach ($invoiceRules as $rule) {
|
||||
// $type = $rule->schedule_type;
|
||||
// $plantId = $rule->plant;
|
||||
|
||||
// $command = $schedule->command('send:invoice-report', [$type, $plantId]);
|
||||
|
||||
// switch ($type) {
|
||||
// case 'Live':
|
||||
// $command->everyMinute();
|
||||
// break;
|
||||
// case 'Hourly':
|
||||
// $command->hourly();
|
||||
// break;
|
||||
// case 'Daily':
|
||||
// $command->dailyAt('07:59');
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Invoice Data Report Scheduling
|
||||
// $invoiceDataRules = AlertMailRule::where('module', 'InvoiceDataReport')
|
||||
// ->select('plant', 'schedule_type')
|
||||
// ->distinct()
|
||||
// ->get();
|
||||
|
||||
// foreach ($invoiceDataRules as $rule) {
|
||||
// $type = $rule->schedule_type;
|
||||
// $plantId = $rule->plant;
|
||||
|
||||
// $command = $schedule->command('send:invoice-data-report', [$type, $plantId]);
|
||||
|
||||
// switch ($type) {
|
||||
// case 'Live':
|
||||
// $command->everyMinute();
|
||||
// break;
|
||||
// case 'Hourly':
|
||||
// $command->hourly();
|
||||
// break;
|
||||
// case 'Daily':
|
||||
// $command->dailyAt('10:00');
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
153
app/Providers/Filament/AdminPanelProvider.php
Normal file
153
app/Providers/Filament/AdminPanelProvider.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?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 App\Filament\Auth\CustomLogin as AuthCustomLogin;
|
||||
use App\Filament\Pages\CustomLogin;
|
||||
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')),
|
||||
// ]);
|
||||
// })
|
||||
// ->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>
|
||||
// '
|
||||
// );
|
||||
|
||||
// FilamentView::registerRenderHook('panels::body.end', function () {
|
||||
// return '<script src="' . asset('js/pwa-install.js') . '"></script>';
|
||||
// });
|
||||
// }
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
FilamentView::registerRenderHook('panels::head.end', function () {
|
||||
// Only inject on the "home" page (or specific route)
|
||||
if (url()->current() == config('app.url') . '/admin') {
|
||||
return '
|
||||
<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>
|
||||
';
|
||||
}
|
||||
|
||||
return ''; // Do not inject on other pages
|
||||
});
|
||||
|
||||
// Only include PWA install script if on home page
|
||||
FilamentView::registerRenderHook('panels::body.end', function () {
|
||||
if (url()->current() == config('app.url') . '/admin') {
|
||||
return '<script src="' . asset('js/pwa-install.js') . '"></script>';
|
||||
}
|
||||
return '';
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user