Skip to content

Commit

Permalink
Merge branch 'issue/353' into 353
Browse files Browse the repository at this point in the history
  • Loading branch information
Poseidon281 committed Jul 28, 2024
2 parents ed1f618 + 080f066 commit 52b8bd3
Show file tree
Hide file tree
Showing 24 changed files with 957 additions and 742 deletions.
51 changes: 51 additions & 0 deletions app/Filament/App/Pages/Dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Filament\App\Pages;

use Filament\Facades\Filament;
use Filament\Pages\Page;
use Illuminate\Contracts\Support\Htmlable;

class Dashboard extends Page
{
protected static string $routePath = '/';

protected static ?int $navigationSort = -2;

protected static string $view = 'filament-panels::pages.dashboard';

public static function getNavigationLabel(): string
{
return 'Dashboard';
}

public static function getNavigationIcon(): string|Htmlable|null
{
return 'tabler-home';
}

public static function getRoutePath(): string
{
return static::$routePath;
}

public function getWidgets(): array
{
return Filament::getWidgets();
}

public function getVisibleWidgets(): array
{
return $this->filterVisibleWidgets($this->getWidgets());
}

public function getColumns(): int|string|array
{
return 2;
}

public function getTitle(): string|Htmlable
{
return 'Welcome, '. auth()->user()->username;
}
}
74 changes: 74 additions & 0 deletions app/Filament/App/Pages/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Filament\App\Pages;

use Filament\Actions\Action;
use Filament\Facades\Filament;
use Filament\Pages\Page;

class Index extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.app.pages.index';

public array $history = [];
public int $historyIndex = 0;
public string $input = '';

protected function getViewData(): array
{
return [
'server' => Filament::getTenant(),
'user' => auth()->user(),
];
}

protected function getHeaderActions(): array
{
return [
Action::make('start')
->color('primary')
->action(fn () => $this->dispatch('setServerState', state: 'start')),

Action::make('restart')
->color('gray')
->action(fn () => $this->dispatch('setServerState', state: 'restart')),

Action::make('stop')
->color('danger')
->action(fn () => $this->dispatch('setServerState', state: 'stop')),
];
}

public function up()
{
$this->historyIndex = min($this->historyIndex + 1, count($this->history) - 1);

// e.currentTarget.value = history![newIndex] || '';
//
// // By default up arrow will also bring the cursor to the start of the line, so we'll preventDefault to keep it at the end.
// e.preventDefault();
}

public function down()
{
$this->historyIndex = max($this->historyIndex - 1, -1);

// e.currentTarget.value = history![newIndex] || '';
}

public function enter()
{
$this->dispatch('sendServerCommand', command: $this->input);

$this->input = '';

// setHistory((prevHistory) => [command, ...prevHistory!].slice(0, 32));
// setHistoryIndex(-1);
//
// instance && instance.send('send command', command);
// e.currentTarget.value = '';
}

}
102 changes: 0 additions & 102 deletions app/Filament/App/Resources/BackupResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,120 +4,18 @@

use App\Filament\App\Resources\BackupResource\Pages;
use App\Models\Backup;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;

class BackupResource extends Resource
{
protected static ?string $model = Backup::class;

protected static ?string $navigationIcon = 'tabler-download';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('server_id')
->relationship('server', 'name')
->required(),
Forms\Components\TextInput::make('uuid')
->label('UUID')
->required(),
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\Textarea::make('ignored_files')
->required()
->columnSpanFull(),
Forms\Components\TextInput::make('disk')
->required(),
Forms\Components\TextInput::make('checksum'),
Forms\Components\TextInput::make('bytes')
->required()
->numeric()
->default(0),
Forms\Components\DateTimePicker::make('completed_at'),
Forms\Components\Toggle::make('is_successful')
->required(),
Forms\Components\Textarea::make('upload_id')
->columnSpanFull(),
Forms\Components\TextInput::make('is_locked')
->required()
->numeric()
->default(0),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('server.name')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('uuid')
->label('UUID')
->searchable(),
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('disk')
->searchable(),
Tables\Columns\TextColumn::make('checksum')
->searchable(),
Tables\Columns\TextColumn::make('bytes')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('completed_at')
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\IconColumn::make('is_successful')
->boolean(),
Tables\Columns\TextColumn::make('is_locked')
->numeric()
->sortable(),
])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListBackups::route('/'),
'create' => Pages\CreateBackup::route('/create'),
'view' => Pages\ViewBackup::route('/{record}'),
'edit' => Pages\EditBackup::route('/{record}/edit'),
];
}
}
11 changes: 0 additions & 11 deletions app/Filament/App/Resources/BackupResource/Pages/CreateBackup.php

This file was deleted.

20 changes: 0 additions & 20 deletions app/Filament/App/Resources/BackupResource/Pages/EditBackup.php

This file was deleted.

62 changes: 62 additions & 0 deletions app/Filament/App/Resources/BackupResource/Pages/ListBackups.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,79 @@
namespace App\Filament\App\Resources\BackupResource\Pages;

use App\Filament\App\Resources\BackupResource;
use App\Http\Controllers\Api\Client\Servers\BackupController;
use App\Models\Backup;
use App\Services\Backups\DownloadLinkService;
use Filament\Actions;
use Filament\Facades\Filament;
use Filament\Forms\Form;
use Filament\Resources\Pages\ListRecords;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Http\Request;

class ListBackups extends ListRecords
{
protected static string $resource = BackupResource::class;

public function form(Form $form): Form
{
return $form
->schema([
//TODO
]);
}

public function table(Table $table): Table
{
$server = Filament::getTenant();

return $table
->columns([
TextColumn::make('name')
->searchable(),
TextColumn::make('bytes')
->label('Size')
->formatStateUsing(fn ($state) => $this->convertToReadableSize($state)),
TextColumn::make('created_at')
->dateTime()
->sortable(),
IconColumn::make('is_successful')
->label('Successful')
->boolean(),
IconColumn::make('is_locked')
->label('Lock Status')
->icon(fn (Backup $backup) => !$backup->is_locked ? 'tabler-lock-open' : 'tabler-lock'),
])
->actions([
Action::make('lock')
->label(fn (Backup $backup) => !$backup->is_locked ? 'Lock' : 'Unlock')
->action(fn (BackupController $backupController, Backup $backup, Request $request) => $backupController->toggleLock($request, $server, $backup)),
Action::make('download')
->url(function (DownloadLinkService $downloadLinkService, Backup $backup, Request $request) {
return $downloadLinkService->handle($backup, $request->user());
}, true),
Action::make('restore'),
Action::make('delete')
->action(fn (BackupController $backupController, Backup $backup, Request $request) => $backupController->delete($request, $server, $backup)),
]);
}

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}

public function convertToReadableSize($size)
{
$base = log($size) / log(1024);
$suffix = ['', 'KB', 'MB', 'GB', 'TB'];
$f_base = floor($base);

return round(pow(1024, $base - floor($base)), 2) . $suffix[$f_base];
}
}
19 changes: 0 additions & 19 deletions app/Filament/App/Resources/BackupResource/Pages/ViewBackup.php

This file was deleted.

Loading

0 comments on commit 52b8bd3

Please sign in to comment.