Раньше зона в списке была просто строкой без возможности провалиться внутрь — все устройства смотрелись только через общий плоский список /devices с колонкой "Зона". Теперь клик по зоне открывает её страницу с карточками устройств (иконка по категории, статус online/offline/ unknown точкой с пульсацией для online, external_id) — ровно то, что просили: все устройства и их статус на одном экране при выборе зоны. Заодно список зон переведён с голой таблицы на карточки для консистентности с новой страницей — вся карточка кликабельна и ведёт на show, кнопки изменить/удалить остаются только у owner. ZonePolicy::view уже был публичным (true всем) — новый роут zones.show использует его без изменений.
51 lines
2.0 KiB
PHP
51 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\AutomationRuleController;
|
|
use App\Http\Controllers\DeviceController;
|
|
use App\Http\Controllers\ProfileController;
|
|
use App\Http\Controllers\ZoneController;
|
|
use App\Models\AutomationRule;
|
|
use App\Models\Device;
|
|
use App\Models\Zone;
|
|
use App\Services\DeviceShadow;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Inertia\Inertia;
|
|
|
|
Route::get('/', function () {
|
|
return view('welcome');
|
|
});
|
|
|
|
Route::get('/dashboard', function (DeviceShadow $shadow) {
|
|
$devices = Device::all();
|
|
$onlineCount = collect($shadow->statuses($devices->pluck('external_id')->all()))
|
|
->filter(fn (string $status) => $status === 'online')
|
|
->count();
|
|
|
|
return Inertia::render('Dashboard', [
|
|
'zonesCount' => Zone::count(),
|
|
'devicesCount' => $devices->count(),
|
|
'onlineDevicesCount' => $onlineCount,
|
|
'activeRulesCount' => AutomationRule::where('is_active', true)->count(),
|
|
]);
|
|
})->middleware(['auth', 'verified'])->name('dashboard');
|
|
|
|
Route::middleware(['auth', 'verified'])->group(function () {
|
|
Route::resource('zones', ZoneController::class);
|
|
Route::resource('devices', DeviceController::class);
|
|
Route::resource('automation-rules', AutomationRuleController::class)
|
|
->except('show')
|
|
->parameters(['automation-rules' => 'automation_rule']);
|
|
|
|
Route::post('/devices/{device}/turn-on', [DeviceController::class, 'turnOn'])->name('devices.turn-on');
|
|
Route::post('/devices/{device}/turn-off', [DeviceController::class, 'turnOff'])->name('devices.turn-off');
|
|
Route::post('/devices/{device}/set-level', [DeviceController::class, 'setLevel'])->name('devices.set-level');
|
|
});
|
|
|
|
Route::middleware('auth')->group(function () {
|
|
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
|
|
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
|
|
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
|
|
});
|
|
|
|
require __DIR__.'/auth.php';
|