1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-03-13 09:40:18 +01:00

feat: Riorganizzazione delle views Blade in componenti

This commit is contained in:
Maicol Battistini 2022-03-07 12:11:29 +01:00
parent ae968a31a6
commit 2fc288566c
No known key found for this signature in database
GPG Key ID: 4FDB0F87CDB1D34A
13 changed files with 124 additions and 106 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Inertia\Middleware;
class HandleInertiaRequests extends Middleware
@ -30,7 +31,10 @@ class HandleInertiaRequests extends Middleware
final public function rootView(Request $request): string
{
if (in_array($request->route()?->uri(), ['setup', 'login', 'setup/admin'], true)) {
/** @var array{external?: bool}|null $route_props */
$route_props = $request->route('props');
if (Arr::get($route_props, 'external', false)) {
return 'external';
}

View File

@ -2,6 +2,7 @@
namespace App\Providers;
use App\Http\Controllers\Controller;
use Exception;
use Illuminate\Support\ServiceProvider;
use Nette\Utils\Json;
@ -19,11 +20,13 @@ class AppServiceProvider extends ServiceProvider
* Bootstrap any application services.
* @throws Exception
*/
public function boot(): void
public function boot(Controller $controller): void
{
cache()->rememberForever(
'translations_'.app()->getLocale(),
fn () => Json::decode(file_get_contents(resource_path('lang/'.app()->getLocale().'.json')))
'translations_' . app()->getLocale(),
fn() => Json::decode(file_get_contents(resource_path('lang/' . app()->getLocale() . '.json')))
);
view()->share('modules', $controller->getModules(request()));
}
}

View File

@ -1,39 +1,5 @@
<!DOCTYPE html>
<html lang="{{app()->getLocale()}}">
@include('layouts.head')
<body class="mdc-typography @if(session('high-contrast')) mdc-high-contrast @endif">
@php
$modules = app(\App\Http\Controllers\Controller::class)
->getModules(request());
@endphp
<top-app-bar>
@include('layouts.top-app-bar')
<material-drawer @mobile type="modal" @elsenotmobile type="dismissible" open @endmobile>
<x-drawer :modules="$modules"></x-drawer>
<div slot="appContent">
<main>
@inertia
</main>
</div>
</material-drawer>
<footer class="@if(session('high-contrast')) mdc-high-contrast @endif">
<div class="left-footer">
<span>
<a href="https://openstamanager.com">
@lang('OpenSTAManager')
</a>
</span>
</div>
<div class="right-footer">
<strong>@lang('Versione')</strong> {{trim(file_get_contents(base_path('VERSION')))}}
<small>(<code>{{trim(file_get_contents(base_path('REVISION')))}}</code>)</small>
</div>
</footer>
</top-app-bar>
@extends('layouts.base')
@include('layouts.top-app-bar-menus')
@include('layouts.footer')
</body>
</html>
@section('contents')
<x-top-app-bar></x-top-app-bar>
@endsection

View File

@ -1,26 +1,9 @@
<mwc-list activatable>
@php
assert($modules instanceof \Illuminate\Support\Collection);
$entries = $modules->pluck('config.drawer_entries')
->collapse()
->prepend([
'icon' => 'view-dashboard-outline',
'text' => __('Dashboard')
], 'dashboard');
@endphp
@foreach($entries as $route => $details)
@switch($route)
@case('hr')
<li divider padded role="separator"></li>
@break
@default
<a class="drawer-item" href="{{Route::has($route) ? route($route) : ''}}">
<mwc-list-item graphic="icon" @if(request()->routeIs($route)) activated @endif>
<i class="mdi mdi-{{$details['icon']}}"
slot="graphic" aria-hidden="true"></i>
<span class="mdc-typography--subtitle2">{{$details['text']}}</span>
</mwc-list-item>
</a>
@endswitch
@endforeach
</mwc-list>
<material-drawer @mobile type="modal" @elsenotmobile type="dismissible" open @endmobile>
<x-drawer.entries></x-drawer.entries>
<div slot="appContent">
<main>
@inertia
</main>
</div>
</material-drawer>

View File

@ -0,0 +1,26 @@
<mwc-list activatable>
@php
assert($modules instanceof \Illuminate\Support\Collection);
$entries = $modules->pluck('config.drawer_entries')
->collapse()
->prepend([
'icon' => 'view-dashboard-outline',
'text' => __('Dashboard')
], 'dashboard');
@endphp
@foreach($entries as $route => $details)
@switch($route)
@case('hr')
<li divider padded role="separator"></li>
@break
@default
<a class="drawer-item" href="{{Route::has($route) ? route($route) : ''}}">
<mwc-list-item graphic="icon" @if(request()->routeIs($route)) activated @endif>
<i class="mdi mdi-{{$details['icon']}}"
slot="graphic" aria-hidden="true"></i>
<span class="mdc-typography--subtitle2">{{$details['text']}}</span>
</mwc-list-item>
</a>
@endswitch
@endforeach
</mwc-list>

View File

@ -0,0 +1,13 @@
<footer class="@if(session('high-contrast')) mdc-high-contrast @endif">
<div class="left-footer">
<span>
<a href="https://openstamanager.com">
@lang('OpenSTAManager')
</a>
</span>
</div>
<div class="right-footer">
<strong>@lang('Versione')</strong> {{trim(file_get_contents(base_path('VERSION')))}}
<small>(<code>{{trim(file_get_contents(base_path('REVISION')))}}</code>)</small>
</div>
</footer>

View File

@ -0,0 +1,20 @@
<top-app-bar>
<!-- Menu icon and logo -->
<mwc-icon-button slot="navigationIcon">
<i class="mdi mdi-menu"></i>
</mwc-icon-button>
<div slot="title" style="display: flex; align-items: center;">
<img src="{{asset('images/logo.png')}}" alt="@lang('OpenSTAManager')" style="height: 50px; margin-right: 8px;">
<span>@lang('OpenSTAManager')</span>
</div>
<x-top-app-bar.actions></x-top-app-bar.actions>
<!-- Drawer -->
<x-drawer></x-drawer>
<!-- Footer -->
<x-footer></x-footer>
</top-app-bar>
<x-top-app-bar.menus></x-top-app-bar.menus>

View File

@ -1,9 +1,3 @@
<mwc-icon-button slot="navigationIcon"><i class="mdi mdi-menu"></i></mwc-icon-button>
<div slot="title" style="display: flex; align-items: center;">
<img src="{{asset('images/logo.png')}}" alt="@lang('OpenSTAManager')" style="height: 50px; margin-right: 8px;">
<span>@lang('OpenSTAManager')</span>
</div>
<mwc-icon-button id="navbar-notifications" slot="actionItems" label="@lang('Notifiche')">
<i class="mdi mdi-bell-outline"></i>
</mwc-icon-button>

View File

@ -1,12 +1,5 @@
<!DOCTYPE html>
<html lang="{{app()->getLocale()}}">
@include('layouts.head')
<body>
@php
$modules = app(\App\Http\Controllers\Controller::class)
->getModules(request());
@endphp
@inertia
@include('layouts.footer')
</body>
</html>
@extends('layouts.base')
@section('contents')
@inertia
@endsection

View File

@ -1,3 +1,5 @@
<!DOCTYPE html>
<html lang="{{app()->getLocale()}}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
@ -19,3 +21,29 @@
@tag('styles')
@tag('_material')
</head>
<body class="mdc-typography @if(session('high-contrast')) mdc-high-contrast @endif">
@php
/** @var $modules */
assert($modules instanceof Illuminate\Support\Collection);
/** @var string $translations */
$translations = cache('translations_' . app()->getLocale());
@endphp
@yield('contents')
<script>
window.modules = @js($modules->pluck('modules')->collapse()->all());
window.translations = @js($translations);
window.user = @js(auth()->user());
window.version = @js(trim(file_get_contents(base_path('VERSION'))));
window.revision = @js(trim(file_get_contents(base_path('REVISION'))));
window.theme = @js(session('high-contrast') ? 'high-contrast' : 'light');
</script>
@routes
@tag('app')
</body>
</html>

View File

@ -1,13 +0,0 @@
@php
/** @var string $translations */
$translations = cache('translations_' . app()->getLocale());
/** @var \Illuminate\Support\Collection $modules */
@endphp
<script>
window.modules = @js($modules->pluck('modules')->collapse()->all());
window.translations = @js($translations);
</script>
@routes
@tag('app')

View File

@ -26,7 +26,7 @@ Route::get('/', static fn () => redirect()->route('auth.login'))
Route::name('auth.')
->middleware('guest')
->group(static function () {
Route::inertia('login', 'LoginPage')
Route::inertia('login', 'LoginPage', ['external' => true])
->name('login');
Route::post('login', [AuthController::class, 'login'])
@ -44,7 +44,7 @@ Route::name('password.')
Route::post('forgot', [PasswordController::class, 'forgotPassword'])
->name('forgot');
Route::inertia('reset', 'ResetPasswordPage')
Route::inertia('reset', 'ResetPasswordPage', ['external' => true])
->name('reset');
Route::post('reset', [PasswordController::class, 'resetPassword'])
@ -53,15 +53,16 @@ Route::name('password.')
Route::name('setup.')->middleware(CheckConfigurationMiddleware::class)->group(static function () {
Route::inertia('setup', 'SetupPage', [
'languages' => cache()->rememberForever('app.languages', fn () => array_map(
static fn ($file) => basename($file, '.json'),
glob(resource_path('lang').'/*.json', GLOB_NOSORT)
'languages' => cache()->rememberForever('app.languages', fn() => array_map(
static fn($file) => basename($file, '.json'),
glob(resource_path('lang') . '/*.json', GLOB_NOSORT)
)),
'license' => cache()->rememberForever('app.license', fn () => file_get_contents(base_path('LICENSE'))),
'license' => cache()->rememberForever('app.license', fn() => file_get_contents(base_path('LICENSE'))),
'external' => true,
])
->name('index');
Route::inertia('setup/admin', 'AdminSetupPage')
Route::inertia('setup/admin', 'AdminSetupPage', ['external' => true])
->name('admin');
Route::options('setup/test', [SetupController::class, 'testDatabase'])