Раньше device_types заводились только через сидер — теперь owner может посмотреть все типы (карточки: иконка по категории, capabilities тегами, число устройств этого типа) и добавить новый прямо из интерфейса: код, категория, возможности вводятся тегами (можно вписать вручную и добавить по Enter/кнопке). Ссылка на список — со страницы устройств. DeviceTypePolicy зеркалит остальные Policy (view — всем, create — только owner). DeviceTypeResource получил devices_count через whenCounted — опционально, не ломает существующий API-эндпоинт (там withCount не вызывается, поле просто не появляется).
77 lines
3.7 KiB
Vue
77 lines
3.7 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>
|
|
<div class="flex items-center gap-3">
|
|
<Link :href="routes.deviceTypes.index" class="text-sm text-gray-500 hover:text-gray-700">Типы устройств</Link>
|
|
<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>
|
|
</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>
|