mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-07 08:52:35 +00:00
2.x - databases
This commit is contained in:
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Traits;
|
||||
|
||||
use App\Models\Server;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
trait BelongsToServers
|
||||
{
|
||||
public static function getUrl(string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string
|
||||
{
|
||||
if (! isset($parameters['server'])) {
|
||||
$parameters['server'] = request()->route('server') ?? 0;
|
||||
}
|
||||
|
||||
return parent::getUrl($name, $parameters, $isAbsolute, $panel, $tenant);
|
||||
}
|
||||
|
||||
public static function getServerFromRoute(): Server
|
||||
{
|
||||
$server = request()->route('server');
|
||||
|
||||
if (! $server) {
|
||||
$server = Route::getRoutes()->match(Request::create(url()->previous()))->parameter('server');
|
||||
}
|
||||
|
||||
if (! $server instanceof Server) {
|
||||
$server = Server::query()->find($server);
|
||||
}
|
||||
|
||||
if (! $server) {
|
||||
$server = new Server;
|
||||
}
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
return static::can('viewAny');
|
||||
|
||||
return auth()->user()->can('viewAny', [static::getModel(), static::getServerFromRoute()]);
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return auth()->user()->can('create', [static::getModel(), static::getServerFromRoute()]);
|
||||
}
|
||||
|
||||
public static function authorizeViewAny(): void
|
||||
{
|
||||
Gate::authorize('viewAny', [static::getModel(), static::getServerFromRoute()]);
|
||||
}
|
||||
|
||||
public static function authorizeCreate(): void
|
||||
{
|
||||
Gate::authorize('create', [static::getModel(), static::getServerFromRoute()]);
|
||||
}
|
||||
|
||||
public static function authorizeEdit(Model $record): void
|
||||
{
|
||||
Gate::authorize('update', [$record, static::getServerFromRoute()]);
|
||||
}
|
||||
|
||||
public static function authorizeView(Model $record): void
|
||||
{
|
||||
Gate::authorize('view', [$record, static::getServerFromRoute()]);
|
||||
}
|
||||
}
|
38
app/Web/Traits/HasWidgets.php
Normal file
38
app/Web/Traits/HasWidgets.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Traits;
|
||||
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
trait HasWidgets
|
||||
{
|
||||
protected ?string $live = '5s';
|
||||
|
||||
protected array $extraAttributes = [];
|
||||
|
||||
protected function getExtraAttributes(): array
|
||||
{
|
||||
$attributes = $this->extraAttributes;
|
||||
|
||||
if ($this->getLive()) {
|
||||
$attributes['wire:poll.'.$this->getLive()] = '$dispatch(\'$refresh\')';
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
public function getExtraAttributesBag(): ComponentAttributeBag
|
||||
{
|
||||
return new ComponentAttributeBag($this->getExtraAttributes());
|
||||
}
|
||||
|
||||
public function getLive(): ?string
|
||||
{
|
||||
return $this->live;
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Traits;
|
||||
|
||||
trait PageHasCluster
|
||||
{
|
||||
// public function getMaxContentWidth(): ?string
|
||||
// {
|
||||
// return 'full';
|
||||
// }
|
||||
|
||||
public function getSubNavigation(): array
|
||||
{
|
||||
if (filled($cluster = static::getCluster())) {
|
||||
return $this->generateNavigationItems($cluster::getClusteredComponents());
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace App\Web\Traits;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Web\Pages\Servers\Databases\Index as DatabasesIndex;
|
||||
use App\Web\Pages\Servers\Logs\Index as LogsIndex;
|
||||
use App\Web\Pages\Servers\PHP\Index as PHPIndex;
|
||||
use App\Web\Pages\Servers\Settings as ServerSettings;
|
||||
@ -26,35 +27,42 @@ public function getSubNavigation(): array
|
||||
$items = [];
|
||||
|
||||
if (ServerView::canAccess()) {
|
||||
$items[] = NavigationItem::make('Overview')
|
||||
$items[] = NavigationItem::make(ServerView::getNavigationLabel())
|
||||
->icon('heroicon-o-chart-pie')
|
||||
->isActiveWhen(fn () => request()->routeIs(ServerView::getRouteName()))
|
||||
->url(ServerView::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (SitesIndex::canAccess()) {
|
||||
$items[] = NavigationItem::make('Sites')
|
||||
$items[] = NavigationItem::make(SitesIndex::getNavigationLabel())
|
||||
->icon('heroicon-o-globe-alt')
|
||||
->isActiveWhen(fn () => request()->routeIs(SitesIndex::getRouteName().'*'))
|
||||
->url(SitesIndex::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (DatabasesIndex::canAccess()) {
|
||||
$items[] = NavigationItem::make(DatabasesIndex::getNavigationLabel())
|
||||
->icon('heroicon-o-circle-stack')
|
||||
->isActiveWhen(fn () => request()->routeIs(DatabasesIndex::getRouteName().'*'))
|
||||
->url(DatabasesIndex::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (PHPIndex::canAccess()) {
|
||||
$items[] = NavigationItem::make('PHP')
|
||||
$items[] = NavigationItem::make(PHPIndex::getNavigationLabel())
|
||||
->icon('heroicon-o-code-bracket')
|
||||
->isActiveWhen(fn () => request()->routeIs(PHPIndex::getRouteName().'*'))
|
||||
->url(PHPIndex::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (LogsIndex::canAccess()) {
|
||||
$items[] = NavigationItem::make('Logs')
|
||||
$items[] = NavigationItem::make(LogsIndex::getNavigationLabel())
|
||||
->icon('heroicon-o-square-3-stack-3d')
|
||||
->isActiveWhen(fn () => request()->routeIs(LogsIndex::getRouteName().'*'))
|
||||
->url(LogsIndex::getUrl(parameters: ['server' => $this->server]));
|
||||
}
|
||||
|
||||
if (ServerSettings::canAccess()) {
|
||||
$items[] = NavigationItem::make('Settings')
|
||||
$items[] = NavigationItem::make(ServerSettings::getNavigationLabel())
|
||||
->icon('heroicon-o-cog-6-tooth')
|
||||
->isActiveWhen(fn () => request()->routeIs(ServerSettings::getRouteName().'*'))
|
||||
->url(ServerSettings::getUrl(parameters: ['server' => $this->server]));
|
||||
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Traits;
|
||||
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
trait PageHasWidgets
|
||||
{
|
||||
protected array $extraAttributes = [
|
||||
'wire:poll.5s' => '$dispatch(\'$refresh\')',
|
||||
];
|
||||
|
||||
protected function getExtraAttributes(): array
|
||||
{
|
||||
return $this->extraAttributes;
|
||||
}
|
||||
|
||||
public function getView(): string
|
||||
{
|
||||
return 'web.components.page';
|
||||
}
|
||||
|
||||
public function getExtraAttributesBag(): ComponentAttributeBag
|
||||
{
|
||||
return new ComponentAttributeBag($this->getExtraAttributes());
|
||||
}
|
||||
|
||||
abstract public function getWidgets(): array;
|
||||
}
|
Reference in New Issue
Block a user