Дашборд, зоны, устройства, правила автоматизации и профиль теперь Vue 3 + Inertia вместо Blade+Alpine — гостевые страницы Breeze (логин/регистрация) сознательно оставлены на Blade, чтобы не трогать уже протестированную аутентификацию. Контроллеры возвращают Inertia::render() вместо view(), переиспользуют существующие API Resources и FormRequest. Ключевой нюанс: Resource/ResourceCollection, переданные напрямую в проп Inertia, заворачиваются в ключ "data" (Inertia вызывает toResponse() у Responsable-объектов) — везде используется ->resolve() и явное резолвление вложенных ресурсов (zone/device_type внутри Device и т.п.), иначе вложенные поля тоже задваивались бы обёрткой. Alpine.js и все Blade-вьюхи защищённой части удалены как мёртвый код. Тесты (ZoneControllerTest/DeviceControllerTest) переведены на assertInertia(). UserFactory теперь явно задаёт role=owner — без этого Eloquent не подтягивает DB-default обратно в модель после create(), что уронило бы общий auth.user проп на любой странице.
74 lines
3.4 KiB
Vue
74 lines
3.4 KiB
Vue
<script setup>
|
|
import { computed } from 'vue';
|
|
import { Link, router, usePage } from '@inertiajs/vue3';
|
|
import AppLayout from '@/Layouts/AppLayout.vue';
|
|
import StatusBadge from '@/Components/StatusBadge.vue';
|
|
import { routes } from '@/routes';
|
|
|
|
defineProps({
|
|
devices: { type: Array, required: true },
|
|
});
|
|
|
|
const isOwner = computed(() => usePage().props.auth.user?.role === 'owner');
|
|
|
|
function destroy(device) {
|
|
if (confirm('Удалить устройство?')) {
|
|
router.delete(routes.devices.destroy(device.id));
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<AppLayout>
|
|
<template #header>
|
|
<div class="flex justify-between items-center">
|
|
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Устройства</h2>
|
|
<Link
|
|
v-if="isOwner"
|
|
:href="routes.devices.create"
|
|
class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700"
|
|
>
|
|
Добавить устройство
|
|
</Link>
|
|
</div>
|
|
</template>
|
|
|
|
<div class="py-12">
|
|
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
|
<table class="w-full text-left text-sm">
|
|
<thead>
|
|
<tr class="border-b">
|
|
<th class="py-2">Название</th>
|
|
<th class="py-2">Зона</th>
|
|
<th class="py-2">Тип</th>
|
|
<th class="py-2">Статус</th>
|
|
<th class="py-2">External ID</th>
|
|
<th class="py-2" />
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-if="devices.length === 0">
|
|
<td colspan="6" class="py-4 text-gray-500">Устройств пока нет.</td>
|
|
</tr>
|
|
<tr v-for="device in devices" :key="device.id" class="border-b">
|
|
<td class="py-2">
|
|
<Link :href="routes.devices.show(device.id)" class="text-indigo-600 hover:underline">{{ device.name }}</Link>
|
|
</td>
|
|
<td class="py-2">{{ device.zone.name }}</td>
|
|
<td class="py-2">{{ device.device_type.code }}</td>
|
|
<td class="py-2"><StatusBadge :status="device.status" /></td>
|
|
<td class="py-2 font-mono text-xs">{{ device.external_id }}</td>
|
|
<td class="py-2 text-right space-x-2">
|
|
<Link v-if="isOwner" :href="routes.devices.edit(device.id)" class="text-indigo-600 hover:underline">Изменить</Link>
|
|
<button v-if="isOwner" type="button" class="text-red-600 hover:underline" @click="destroy(device)">Удалить</button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</AppLayout>
|
|
</template>
|