You've already forked Atomcms-edit
Initial commit
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Articles\WebsiteArticle;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Flowframe\Trend\Trend;
|
||||
use Flowframe\Trend\TrendValue;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class ArticlesAggregateChart extends ChartWidget
|
||||
{
|
||||
#[\Override]
|
||||
protected static ?int $sort = 2;
|
||||
|
||||
#[\Override]
|
||||
protected ?string $maxHeight = '300px';
|
||||
|
||||
#[\Override]
|
||||
protected string $color = 'primary';
|
||||
|
||||
#[\Override]
|
||||
public function getHeading(): string|Htmlable|null
|
||||
{
|
||||
return __('filament::resources.stats.articles_chart.title');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getDescription(): string|Htmlable|null
|
||||
{
|
||||
return __('filament::resources.stats.articles_chart.description');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = Trend::model(WebsiteArticle::class)
|
||||
->between(
|
||||
start: now()->startOfMonth(),
|
||||
end: now()->endOfMonth(),
|
||||
)
|
||||
->perDay()
|
||||
->count();
|
||||
|
||||
$label = __('filament::resources.stats.articles_chart.label');
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => $label,
|
||||
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
|
||||
],
|
||||
],
|
||||
'labels' => $data->map(fn (TrendValue $value) => $value->date),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\ItemDefinition;
|
||||
use App\Models\Miscellaneous\CameraWeb;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use App\Models\WebsiteBadge;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
class TopDashboardOverview extends BaseWidget
|
||||
{
|
||||
#[\Override]
|
||||
protected static ?int $sort = 1;
|
||||
|
||||
#[\Override]
|
||||
protected function getStats(): array
|
||||
{
|
||||
return [
|
||||
Stat::make(__('filament::resources.stats.users_count.title'), Number::format(User::query()->count(), 0))
|
||||
->description(__('filament::resources.stats.users_count.description'))
|
||||
->chart([20, 20])
|
||||
->descriptionIcon('heroicon-m-user-group', IconPosition::Before)
|
||||
->color('success'),
|
||||
|
||||
Stat::make(__('filament::resources.stats.furniture_count.title'), Number::format(ItemDefinition::query()->count(), 0))
|
||||
->description(__('filament::resources.stats.furniture_count.description'))
|
||||
->descriptionIcon('heroicon-m-cube', IconPosition::Before)
|
||||
->chart([20, 20])
|
||||
->color('success'),
|
||||
|
||||
Stat::make(__('filament::resources.stats.rooms_count.title'), Number::format(Room::query()->count(), 0))
|
||||
->description(__('filament::resources.stats.rooms_count.description'))
|
||||
->descriptionIcon('heroicon-m-building-storefront', IconPosition::Before)
|
||||
->chart([20, 20])
|
||||
->color('success'),
|
||||
|
||||
Stat::make(__('filament::resources.stats.photos_count.title'), Number::format(CameraWeb::query()->count(), 0))
|
||||
->description(__('filament::resources.stats.photos_count.description'))
|
||||
->descriptionIcon('heroicon-m-camera', IconPosition::Before)
|
||||
->chart([20, 20])
|
||||
->color('success'),
|
||||
|
||||
Stat::make(__('filament::resources.stats.badge_count.title'), Number::format(WebsiteBadge::query()->count(), 0))
|
||||
->description(__('filament::resources.stats.badge_count.description'))
|
||||
->descriptionIcon('heroicon-m-gif', IconPosition::Before)
|
||||
->chart([20, 20])
|
||||
->color('success'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+343
@@ -0,0 +1,343 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Services\EmulatorUpdateService;
|
||||
use App\Services\NitroUpdateService;
|
||||
use App\Services\RconService;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Widgets\Widget;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdateCheckerWidget extends Widget
|
||||
{
|
||||
#[\Override]
|
||||
protected string $view = 'filament.widgets.update-checker';
|
||||
|
||||
#[\Override]
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
#[\Override]
|
||||
protected static ?int $sort = 0;
|
||||
|
||||
public ?string $emulatorVersion = null;
|
||||
|
||||
public ?string $latestEmulatorVersion = null;
|
||||
|
||||
public bool $emulatorUpdate = false;
|
||||
|
||||
public ?string $nitroVersion = null;
|
||||
|
||||
public ?string $latestNitroVersion = null;
|
||||
|
||||
public bool $nitroUpdate = false;
|
||||
|
||||
public int $onlineUsers = 0;
|
||||
|
||||
public string $dbSize = '0 MB';
|
||||
|
||||
public bool $hasAnyUpdate = false;
|
||||
|
||||
public int $sqlApplied = 0;
|
||||
|
||||
public int $sqlPending = 0;
|
||||
|
||||
public bool $sqlTableExists = false;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->emulatorVersion = setting('emulator_version', '?');
|
||||
$this->nitroVersion = setting('nitro_client_version', '?');
|
||||
|
||||
try {
|
||||
$this->onlineUsers = (int) DB::connection('mysql')->table('users')->where('online', '1')->count();
|
||||
$sizeResult = DB::connection('mysql')->select('SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) as db_size FROM information_schema.tables WHERE table_schema = DATABASE()');
|
||||
$this->dbSize = ($sizeResult[0]->db_size ?? '0') . ' MB';
|
||||
} catch (\Exception) {
|
||||
$this->dbSize = '? MB';
|
||||
}
|
||||
|
||||
$this->loadSqlStatus();
|
||||
|
||||
$cached = Cache::get('all_updates_check');
|
||||
|
||||
if ($cached !== null) {
|
||||
$this->emulatorUpdate = $cached['emulator'] ?? false;
|
||||
$this->latestEmulatorVersion = $cached['emulator_version'] ?? null;
|
||||
$this->nitroUpdate = $cached['nitro'] ?? false;
|
||||
$this->latestNitroVersion = $cached['nitro_version'] ?? null;
|
||||
$this->hasAnyUpdate = $this->emulatorUpdate || $this->nitroUpdate;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->performCheck();
|
||||
}
|
||||
|
||||
private function loadSqlStatus(): void
|
||||
{
|
||||
try {
|
||||
$updateService = new EmulatorUpdateService;
|
||||
$sqlDiagnosis = $updateService->diagnoseSqlUpdates();
|
||||
|
||||
$this->sqlTableExists = $sqlDiagnosis['table_exists'] ?? false;
|
||||
$this->sqlApplied = $sqlDiagnosis['applied_count'] ?? 0;
|
||||
$this->sqlPending = $sqlDiagnosis['pending_count'] ?? 0;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[UpdateChecker] SQL status failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function performCheck(): void
|
||||
{
|
||||
try {
|
||||
$updateService = new EmulatorUpdateService;
|
||||
$check = $updateService->checkForUpdates();
|
||||
$this->emulatorUpdate = $check['update_available'] ?? false;
|
||||
$this->latestEmulatorVersion = $check['latest_version'] ?? null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[UpdateChecker] Emulator check failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$nitroService = new NitroUpdateService;
|
||||
$nitroCheck = $nitroService->checkForUpdates();
|
||||
$this->nitroUpdate = $nitroCheck['has_updates'] ?? false;
|
||||
if ($this->nitroUpdate) {
|
||||
$parts = [];
|
||||
if ($nitroCheck['client_update'] ?? false) {
|
||||
$parts[] = 'Client';
|
||||
}
|
||||
if ($nitroCheck['renderer_update'] ?? false) {
|
||||
$parts[] = 'Renderer';
|
||||
}
|
||||
$this->latestNitroVersion = implode(' + ', $parts);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[UpdateChecker] Nitro check failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$this->hasAnyUpdate = $this->emulatorUpdate || $this->nitroUpdate;
|
||||
|
||||
Cache::put('all_updates_check', [
|
||||
'emulator' => $this->emulatorUpdate,
|
||||
'emulator_version' => $this->latestEmulatorVersion,
|
||||
'nitro' => $this->nitroUpdate,
|
||||
'nitro_version' => $this->latestNitroVersion,
|
||||
], now()->addMinutes(15));
|
||||
}
|
||||
|
||||
public function forceCheck(): void
|
||||
{
|
||||
try {
|
||||
Cache::forget('all_updates_check');
|
||||
$updateService = new EmulatorUpdateService;
|
||||
$updateService->resetInstalledDate();
|
||||
$this->performCheck();
|
||||
|
||||
if ($this->hasAnyUpdate) {
|
||||
Notification::make()->success()->title('Updates Gevonden!')->body('Klik op "Alles Updaten" om te installeren')->send();
|
||||
} else {
|
||||
Notification::make()->info()->title('Geen Updates')->body('Alles is al up-to-date')->send();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()->danger()->title('Fout')->body($e->getMessage())->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function repairSystem(): void
|
||||
{
|
||||
try {
|
||||
Cache::forget('all_updates_check');
|
||||
|
||||
$messages = [];
|
||||
$errors = [];
|
||||
|
||||
try {
|
||||
$emuService = new EmulatorUpdateService;
|
||||
$repairResult = $emuService->repairEmulator();
|
||||
|
||||
if ($repairResult['success']) {
|
||||
$messages[] = '🖥️ Emulator: ' . ($repairResult['message'] ?? 'Gerepareerd');
|
||||
} else {
|
||||
$errors[] = 'Emulator: ' . ($repairResult['error'] ?? 'Onbekende fout');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = 'Emulator: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try {
|
||||
$nitroService = new NitroUpdateService;
|
||||
$repairResult = $nitroService->repair();
|
||||
|
||||
if ($repairResult['success']) {
|
||||
$messages[] = '🎮 Nitro: ' . ($repairResult['message'] ?? 'Gerepareerd');
|
||||
} else {
|
||||
$errors[] = 'Nitro: ' . ($repairResult['error'] ?? 'Onbekende fout');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = 'Nitro: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
if ($messages !== []) {
|
||||
Notification::make()->success()->title('Reparatie Voltooid!')->body(implode(' | ', $messages))->send();
|
||||
}
|
||||
|
||||
if ($errors !== []) {
|
||||
Notification::make()->danger()->title('Reparatie Fout')->body(implode(' | ', $errors))->send();
|
||||
}
|
||||
|
||||
Cache::forget('all_updates_check');
|
||||
$this->mount();
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()->danger()->title('Fout')->body($e->getMessage())->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function diagnoseSystem(): void
|
||||
{
|
||||
try {
|
||||
$emuService = new EmulatorUpdateService;
|
||||
$nitroService = new NitroUpdateService;
|
||||
|
||||
$emuDiagnosis = $emuService->diagnose();
|
||||
$nitroDiagnosis = $nitroService->diagnose();
|
||||
|
||||
$issues = array_merge(
|
||||
$emuDiagnosis['issues'] ?? [],
|
||||
$nitroDiagnosis['issues'] ?? [],
|
||||
);
|
||||
|
||||
$recommendations = array_merge(
|
||||
$emuDiagnosis['recommendations'] ?? [],
|
||||
$nitroDiagnosis['recommendations'] ?? [],
|
||||
);
|
||||
|
||||
if ($issues === []) {
|
||||
Notification::make()->info()->title('Diagnose')->body('Geen problemen gevonden')->send();
|
||||
} else {
|
||||
$body = 'Problemen: ' . implode(', ', $issues);
|
||||
if ($recommendations !== []) {
|
||||
$body .= "\n\nAanbevelingen: " . implode(', ', $recommendations);
|
||||
}
|
||||
Notification::make()->warning()->title('Diagnose Resultaat')->body($body)->send();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()->danger()->title('Fout')->body($e->getMessage())->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAll(): void
|
||||
{
|
||||
try {
|
||||
Cache::forget('all_updates_check');
|
||||
Cache::forget('website_settings');
|
||||
|
||||
$messages = [];
|
||||
$errors = [];
|
||||
$updateService = new EmulatorUpdateService;
|
||||
|
||||
try {
|
||||
$result = $updateService->updateEmulator();
|
||||
if ($result['success']) {
|
||||
$messages[] = '🖥️ ' . ($result['message'] ?? 'Emulator geüpdatet');
|
||||
} else {
|
||||
$error = $result['error'] ?? '';
|
||||
if (str_contains($error, 'al up-to-date')) {
|
||||
$messages[] = '🖥️ Emulator al up-to-date';
|
||||
} else {
|
||||
$errors[] = 'Emulator: ' . $error;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = 'Emulator: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try {
|
||||
$nitroService = new NitroUpdateService;
|
||||
$nitroCheck = $nitroService->checkForUpdates();
|
||||
|
||||
if ($nitroCheck['has_updates'] ?? false) {
|
||||
$result = $nitroService->updateNitro();
|
||||
if ($result['success']) {
|
||||
$parts = [];
|
||||
if ($result['renderer_updated'] ?? false) {
|
||||
$parts[] = 'Renderer';
|
||||
}
|
||||
if ($result['client_updated'] ?? false) {
|
||||
$parts[] = 'Client';
|
||||
}
|
||||
if ($result['built'] ?? false) {
|
||||
$parts[] = 'Build';
|
||||
}
|
||||
if ($result['deployed'] ?? false) {
|
||||
$parts[] = 'Deploy';
|
||||
}
|
||||
if ($parts !== []) {
|
||||
$messages[] = '🎮 Nitro: ' . implode(', ', $parts);
|
||||
}
|
||||
} elseif (! empty($result['errors'] ?? [])) {
|
||||
$errors = array_merge($errors, $result['errors']);
|
||||
}
|
||||
} else {
|
||||
$messages[] = '🎮 Nitro al up-to-date';
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = 'Nitro: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try {
|
||||
$sqlResult = $updateService->runSqlUpdates();
|
||||
if ($sqlResult['sql_updated'] ?? false) {
|
||||
$count = count($sqlResult['files_run'] ?? []);
|
||||
if ($count > 0) {
|
||||
$messages[] = "📊 {$count} SQL updates";
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = 'SQL: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try {
|
||||
$updateService->restartEmulator();
|
||||
$messages[] = '🔄 Emulator herstart';
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[UpdateChecker] Restart failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$rcon = new RconService;
|
||||
$rcon->sendCommand('updatecatalog');
|
||||
$rcon->sendCommand('updatewordfilter');
|
||||
$messages[] = '📚 Catalogus + filter vernieuwd';
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[UpdateChecker] RCON failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($messages !== []) {
|
||||
Notification::make()->success()->title('Updates Voltooid!')->body(implode(' | ', $messages))->send();
|
||||
}
|
||||
|
||||
if ($errors !== []) {
|
||||
Notification::make()->danger()->title('Sommige Updates Mislukt')->body(implode(' | ', $errors))->send();
|
||||
}
|
||||
|
||||
if ($messages === [] && $errors === []) {
|
||||
Notification::make()->info()->title('Geen Updates')->body('Alles was al up-to-date')->send();
|
||||
}
|
||||
|
||||
Cache::forget('all_updates_check');
|
||||
$this->mount();
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()->danger()->title('Fout')->body($e->getMessage())->send();
|
||||
}
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function canView(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user