Перевод защищённой части приложения на Vue.js + Inertia
Дашборд, зоны, устройства, правила автоматизации и профиль теперь 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 проп на любой странице.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<script setup>
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import Form from '@/Pages/AutomationRules/Form.vue';
|
||||
|
||||
defineProps({
|
||||
zones: { type: Array, required: true },
|
||||
devices: { type: Array, required: true },
|
||||
actionTypeOptions: { type: Array, required: true },
|
||||
sensorTypeOptions: { type: Array, required: true },
|
||||
conditionOperatorOptions: { type: Array, required: true },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout>
|
||||
<template #header>
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Новое правило</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||
<Form
|
||||
:zones="zones"
|
||||
:devices="devices"
|
||||
:action-type-options="actionTypeOptions"
|
||||
:sensor-type-options="sensorTypeOptions"
|
||||
:condition-operator-options="conditionOperatorOptions"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import Form from '@/Pages/AutomationRules/Form.vue';
|
||||
|
||||
defineProps({
|
||||
rule: { type: Object, required: true },
|
||||
zones: { type: Array, required: true },
|
||||
devices: { type: Array, required: true },
|
||||
actionTypeOptions: { type: Array, required: true },
|
||||
sensorTypeOptions: { type: Array, required: true },
|
||||
conditionOperatorOptions: { type: Array, required: true },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout>
|
||||
<template #header>
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Изменить правило</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||
<Form
|
||||
:rule="rule"
|
||||
:zones="zones"
|
||||
:devices="devices"
|
||||
:action-type-options="actionTypeOptions"
|
||||
:sensor-type-options="sensorTypeOptions"
|
||||
:condition-operator-options="conditionOperatorOptions"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,176 @@
|
||||
<script setup>
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import { routes } from '@/routes';
|
||||
|
||||
const props = defineProps({
|
||||
rule: { type: Object, default: null },
|
||||
zones: { type: Array, required: true },
|
||||
devices: { type: Array, required: true },
|
||||
actionTypeOptions: { type: Array, required: true },
|
||||
sensorTypeOptions: { type: Array, required: true },
|
||||
conditionOperatorOptions: { type: Array, required: true },
|
||||
});
|
||||
|
||||
const isEdit = !!props.rule;
|
||||
|
||||
const form = useForm({
|
||||
zone_id: props.rule?.zone_id ?? '',
|
||||
condition_source_device_id: props.rule?.condition_source_device_id ?? '',
|
||||
condition_sensor_type: props.rule?.condition_sensor_type ?? '',
|
||||
condition_operator: props.rule?.condition_operator ?? '',
|
||||
condition_value: props.rule?.condition_value ?? '',
|
||||
target_device_id: props.rule?.target_device_id ?? '',
|
||||
action_type: props.rule?.action_type ?? '',
|
||||
level: props.rule?.level ?? '',
|
||||
is_active: props.rule?.is_active ?? true,
|
||||
});
|
||||
|
||||
function submit() {
|
||||
if (isEdit) {
|
||||
form.put(routes.automationRules.update(props.rule.id));
|
||||
} else {
|
||||
form.post(routes.automationRules.store);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<form @submit.prevent="submit">
|
||||
<div>
|
||||
<label for="zone_id" class="block font-medium text-sm text-gray-700">Зона</label>
|
||||
<select
|
||||
id="zone_id"
|
||||
v-model="form.zone_id"
|
||||
required
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<option value="">— выбрать —</option>
|
||||
<option v-for="zone in zones" :key="zone.id" :value="zone.id">{{ zone.name }}</option>
|
||||
</select>
|
||||
<div v-if="form.errors.zone_id" class="mt-2 text-sm text-red-600">{{ form.errors.zone_id }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<label for="condition_source_device_id" class="block font-medium text-sm text-gray-700">Устройство-источник показания</label>
|
||||
<select
|
||||
id="condition_source_device_id"
|
||||
v-model="form.condition_source_device_id"
|
||||
required
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<option value="">— выбрать —</option>
|
||||
<option v-for="device in devices" :key="device.id" :value="device.id">
|
||||
{{ device.zone.name }} — {{ device.name }} ({{ device.device_type.code }})
|
||||
</option>
|
||||
</select>
|
||||
<div v-if="form.errors.condition_source_device_id" class="mt-2 text-sm text-red-600">{{ form.errors.condition_source_device_id }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label for="condition_sensor_type" class="block font-medium text-sm text-gray-700">Тип показания</label>
|
||||
<input
|
||||
id="condition_sensor_type"
|
||||
v-model="form.condition_sensor_type"
|
||||
list="sensor-types"
|
||||
type="text"
|
||||
required
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<datalist id="sensor-types">
|
||||
<option v-for="option in sensorTypeOptions" :key="option" :value="option" />
|
||||
</datalist>
|
||||
<div v-if="form.errors.condition_sensor_type" class="mt-2 text-sm text-red-600">{{ form.errors.condition_sensor_type }}</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="condition_operator" class="block font-medium text-sm text-gray-700">Оператор</label>
|
||||
<select
|
||||
id="condition_operator"
|
||||
v-model="form.condition_operator"
|
||||
required
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<option value="">— выбрать —</option>
|
||||
<option v-for="op in conditionOperatorOptions" :key="op" :value="op">{{ op }}</option>
|
||||
</select>
|
||||
<div v-if="form.errors.condition_operator" class="mt-2 text-sm text-red-600">{{ form.errors.condition_operator }}</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="condition_value" class="block font-medium text-sm text-gray-700">Порог</label>
|
||||
<input
|
||||
id="condition_value"
|
||||
v-model="form.condition_value"
|
||||
type="number"
|
||||
step="any"
|
||||
required
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.condition_value" class="mt-2 text-sm text-red-600">{{ form.errors.condition_value }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<label for="target_device_id" class="block font-medium text-sm text-gray-700">Устройство-исполнитель</label>
|
||||
<select
|
||||
id="target_device_id"
|
||||
v-model="form.target_device_id"
|
||||
required
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<option value="">— выбрать —</option>
|
||||
<option v-for="device in devices" :key="device.id" :value="device.id">
|
||||
{{ device.zone.name }} — {{ device.name }} ({{ device.device_type.code }})
|
||||
</option>
|
||||
</select>
|
||||
<div v-if="form.errors.target_device_id" class="mt-2 text-sm text-red-600">{{ form.errors.target_device_id }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label for="action_type" class="block font-medium text-sm text-gray-700">Действие</label>
|
||||
<select
|
||||
id="action_type"
|
||||
v-model="form.action_type"
|
||||
required
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<option value="">— выбрать —</option>
|
||||
<option v-for="option in actionTypeOptions" :key="option" :value="option">{{ option }}</option>
|
||||
</select>
|
||||
<div v-if="form.errors.action_type" class="mt-2 text-sm text-red-600">{{ form.errors.action_type }}</div>
|
||||
</div>
|
||||
|
||||
<div v-show="form.action_type === 'set_level'">
|
||||
<label for="level" class="block font-medium text-sm text-gray-700">Уровень</label>
|
||||
<input
|
||||
id="level"
|
||||
v-model="form.level"
|
||||
type="number"
|
||||
step="any"
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.level" class="mt-2 text-sm text-red-600">{{ form.errors.level }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<label class="inline-flex items-center">
|
||||
<input v-model="form.is_active" type="checkbox" class="rounded border-gray-300 text-indigo-600 shadow-sm">
|
||||
<span class="ms-2 text-sm text-gray-600">Правило активно</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex items-center gap-4">
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="form.processing"
|
||||
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 disabled:opacity-50"
|
||||
>
|
||||
Сохранить
|
||||
</button>
|
||||
<a :href="routes.automationRules.index" class="text-sm text-gray-600 hover:underline">Отмена</a>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
@@ -0,0 +1,78 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { Link, router, usePage } from '@inertiajs/vue3';
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import { routes } from '@/routes';
|
||||
|
||||
defineProps({
|
||||
rules: { type: Array, required: true },
|
||||
});
|
||||
|
||||
const isOwner = computed(() => usePage().props.auth.user?.role === 'owner');
|
||||
|
||||
function destroy(rule) {
|
||||
if (confirm('Удалить правило?')) {
|
||||
router.delete(routes.automationRules.destroy(rule.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.automationRules.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" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="rules.length === 0">
|
||||
<td colspan="5" class="py-4 text-gray-500">Правил пока нет.</td>
|
||||
</tr>
|
||||
<tr v-for="rule in rules" :key="rule.id" class="border-b">
|
||||
<td class="py-2">{{ rule.zone.name }}</td>
|
||||
<td class="py-2">
|
||||
{{ rule.condition_source_device.name }}:
|
||||
{{ rule.condition_sensor_type }}
|
||||
{{ rule.condition_operator }}
|
||||
{{ rule.condition_value }}
|
||||
</td>
|
||||
<td class="py-2">
|
||||
{{ rule.target_device.name }}: {{ rule.action_type }}
|
||||
<template v-if="Object.keys(rule.action_params ?? {}).length">
|
||||
({{ JSON.stringify(rule.action_params) }})
|
||||
</template>
|
||||
</td>
|
||||
<td class="py-2">{{ rule.is_active ? 'да' : 'нет' }}</td>
|
||||
<td class="py-2 text-right space-x-2">
|
||||
<Link v-if="isOwner" :href="routes.automationRules.edit(rule.id)" class="text-indigo-600 hover:underline">Изменить</Link>
|
||||
<button v-if="isOwner" type="button" class="text-red-600 hover:underline" @click="destroy(rule)">Удалить</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,41 @@
|
||||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import { routes } from '@/routes';
|
||||
|
||||
defineProps({
|
||||
zonesCount: Number,
|
||||
devicesCount: Number,
|
||||
onlineDevicesCount: Number,
|
||||
activeRulesCount: Number,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout>
|
||||
<template #header>
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Dashboard</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 grid grid-cols-1 sm:grid-cols-4 gap-6">
|
||||
<Link :href="routes.zones.index" class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6 hover:shadow-md transition">
|
||||
<div class="text-sm text-gray-500">Зоны</div>
|
||||
<div class="text-3xl font-semibold text-gray-900">{{ zonesCount }}</div>
|
||||
</Link>
|
||||
<Link :href="routes.devices.index" class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6 hover:shadow-md transition">
|
||||
<div class="text-sm text-gray-500">Устройства</div>
|
||||
<div class="text-3xl font-semibold text-gray-900">{{ devicesCount }}</div>
|
||||
</Link>
|
||||
<Link :href="routes.devices.index" class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6 hover:shadow-md transition">
|
||||
<div class="text-sm text-gray-500">Онлайн</div>
|
||||
<div class="text-3xl font-semibold text-green-600">{{ onlineDevicesCount }}</div>
|
||||
</Link>
|
||||
<Link :href="routes.automationRules.index" class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6 hover:shadow-md transition">
|
||||
<div class="text-sm text-gray-500">Активных правил</div>
|
||||
<div class="text-3xl font-semibold text-gray-900">{{ activeRulesCount }}</div>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,25 @@
|
||||
<script setup>
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import Form from '@/Pages/Devices/Form.vue';
|
||||
|
||||
defineProps({
|
||||
zones: { type: Array, required: true },
|
||||
deviceTypes: { type: Array, required: true },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout>
|
||||
<template #header>
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Новое устройство</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||
<Form :zones="zones" :device-types="deviceTypes" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup>
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import Form from '@/Pages/Devices/Form.vue';
|
||||
|
||||
defineProps({
|
||||
device: { type: Object, required: true },
|
||||
zones: { type: Array, required: true },
|
||||
deviceTypes: { type: Array, required: true },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout>
|
||||
<template #header>
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Изменить устройство</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||
<Form :device="device" :zones="zones" :device-types="deviceTypes" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,108 @@
|
||||
<script setup>
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import { routes } from '@/routes';
|
||||
|
||||
const props = defineProps({
|
||||
device: { type: Object, default: null },
|
||||
zones: { type: Array, required: true },
|
||||
deviceTypes: { type: Array, required: true },
|
||||
});
|
||||
|
||||
const isEdit = !!props.device;
|
||||
|
||||
const form = useForm({
|
||||
name: props.device?.name ?? '',
|
||||
zone_id: props.device?.zone_id ?? '',
|
||||
device_type_id: props.device?.device_type_id ?? '',
|
||||
external_id: props.device?.external_id ?? '',
|
||||
protocol: props.device?.protocol ?? 'mqtt',
|
||||
});
|
||||
|
||||
function submit() {
|
||||
if (isEdit) {
|
||||
form.put(routes.devices.update(props.device.id));
|
||||
} else {
|
||||
form.post(routes.devices.store);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<form @submit.prevent="submit">
|
||||
<div>
|
||||
<label for="name" class="block font-medium text-sm text-gray-700">Название</label>
|
||||
<input
|
||||
id="name"
|
||||
v-model="form.name"
|
||||
type="text"
|
||||
required
|
||||
autofocus
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.name" class="mt-2 text-sm text-red-600">{{ form.errors.name }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<label for="zone_id" class="block font-medium text-sm text-gray-700">Зона</label>
|
||||
<select
|
||||
id="zone_id"
|
||||
v-model="form.zone_id"
|
||||
required
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<option value="">— выбрать —</option>
|
||||
<option v-for="zone in zones" :key="zone.id" :value="zone.id">{{ zone.name }}</option>
|
||||
</select>
|
||||
<div v-if="form.errors.zone_id" class="mt-2 text-sm text-red-600">{{ form.errors.zone_id }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<label for="device_type_id" class="block font-medium text-sm text-gray-700">Тип устройства</label>
|
||||
<select
|
||||
id="device_type_id"
|
||||
v-model="form.device_type_id"
|
||||
required
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<option value="">— выбрать —</option>
|
||||
<option v-for="type in deviceTypes" :key="type.id" :value="type.id">{{ type.code }} ({{ type.category }})</option>
|
||||
</select>
|
||||
<div v-if="form.errors.device_type_id" class="mt-2 text-sm text-red-600">{{ form.errors.device_type_id }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<label for="external_id" class="block font-medium text-sm text-gray-700">External ID (идентификатор физического устройства)</label>
|
||||
<input
|
||||
id="external_id"
|
||||
v-model="form.external_id"
|
||||
type="text"
|
||||
required
|
||||
class="mt-1 block w-full font-mono border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.external_id" class="mt-2 text-sm text-red-600">{{ form.errors.external_id }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<label for="protocol" class="block font-medium text-sm text-gray-700">Протокол</label>
|
||||
<input
|
||||
id="protocol"
|
||||
v-model="form.protocol"
|
||||
type="text"
|
||||
required
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.protocol" class="mt-2 text-sm text-red-600">{{ form.errors.protocol }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex items-center gap-4">
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="form.processing"
|
||||
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 disabled:opacity-50"
|
||||
>
|
||||
Сохранить
|
||||
</button>
|
||||
<a :href="routes.devices.index" class="text-sm text-gray-600 hover:underline">Отмена</a>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
@@ -0,0 +1,73 @@
|
||||
<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>
|
||||
@@ -0,0 +1,132 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { useForm, usePage } from '@inertiajs/vue3';
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import StatusBadge from '@/Components/StatusBadge.vue';
|
||||
import { routes } from '@/routes';
|
||||
|
||||
const props = defineProps({
|
||||
device: { type: Object, required: true },
|
||||
shadow: { type: Object, required: true },
|
||||
telemetry: { type: Array, required: true },
|
||||
});
|
||||
|
||||
const isOwner = computed(() => usePage().props.auth.user?.role === 'owner');
|
||||
const capabilities = computed(() => props.device.device_type.capabilities ?? []);
|
||||
const hasControls = computed(() => capabilities.value.some((c) => ['turn_on', 'turn_off', 'set_level'].includes(c)));
|
||||
|
||||
const lastSeenLabel = computed(() => (
|
||||
props.shadow.last_seen ? new Date(props.shadow.last_seen).toLocaleString('ru-RU') : 'нет данных'
|
||||
));
|
||||
|
||||
const levelForm = useForm({ level: '' });
|
||||
|
||||
function turnOn() {
|
||||
useForm({}).post(routes.devices.turnOn(props.device.id));
|
||||
}
|
||||
|
||||
function turnOff() {
|
||||
useForm({}).post(routes.devices.turnOff(props.device.id));
|
||||
}
|
||||
|
||||
function setLevel() {
|
||||
levelForm.post(routes.devices.setLevel(props.device.id));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout>
|
||||
<template #header>
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">{{ device.name }}</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-4xl mx-auto sm:px-6 lg:px-8 space-y-6">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||
<h3 class="font-semibold mb-4">Живое состояние (Redis device shadow)</h3>
|
||||
<dl class="grid grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<dt class="text-gray-500">Статус</dt>
|
||||
<dd class="mt-1"><StatusBadge :status="device.status" /></dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-gray-500">Последняя активность</dt>
|
||||
<dd>{{ lastSeenLabel }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-gray-500">Желаемое состояние (desired)</dt>
|
||||
<dd class="font-mono text-xs">{{ JSON.stringify(shadow.desired_state) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-gray-500">Подтверждённое состояние (reported)</dt>
|
||||
<dd class="font-mono text-xs">{{ JSON.stringify(shadow.reported_state) }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div v-if="isOwner && hasControls" class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||
<h3 class="font-semibold mb-4">Ручное управление</h3>
|
||||
<div class="flex items-center gap-4 flex-wrap">
|
||||
<button
|
||||
v-if="capabilities.includes('turn_on')"
|
||||
type="button"
|
||||
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"
|
||||
@click="turnOn"
|
||||
>
|
||||
Включить
|
||||
</button>
|
||||
<button
|
||||
v-if="capabilities.includes('turn_off')"
|
||||
type="button"
|
||||
class="inline-flex items-center px-4 py-2 bg-white border border-gray-300 rounded-md font-semibold text-xs text-gray-700 uppercase tracking-widest hover:bg-gray-50"
|
||||
@click="turnOff"
|
||||
>
|
||||
Выключить
|
||||
</button>
|
||||
<form v-if="capabilities.includes('set_level')" class="flex items-center gap-2" @submit.prevent="setLevel">
|
||||
<input
|
||||
v-model="levelForm.level"
|
||||
type="number"
|
||||
step="any"
|
||||
required
|
||||
placeholder="уровень"
|
||||
class="border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm text-sm"
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
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"
|
||||
>
|
||||
Установить уровень
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="device.device_type.category === 'sensor'" class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||
<h3 class="font-semibold mb-4">Последние показания (ClickHouse)</h3>
|
||||
<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>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="telemetry.length === 0">
|
||||
<td colspan="3" class="py-4 text-gray-500">Показаний пока нет.</td>
|
||||
</tr>
|
||||
<tr v-for="(row, i) in telemetry" :key="i" class="border-b">
|
||||
<td class="py-2">{{ row.sensor_type }}</td>
|
||||
<td class="py-2">{{ row.value }}</td>
|
||||
<td class="py-2">{{ row.recorded_at }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<a :href="routes.devices.index" class="text-sm text-gray-600 hover:underline">← Назад к устройствам</a>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script setup>
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import UpdateProfileInformationForm from '@/Pages/Profile/Partials/UpdateProfileInformationForm.vue';
|
||||
import UpdatePasswordForm from '@/Pages/Profile/Partials/UpdatePasswordForm.vue';
|
||||
import DeleteUserForm from '@/Pages/Profile/Partials/DeleteUserForm.vue';
|
||||
|
||||
defineProps({
|
||||
user: { type: Object, required: true },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout>
|
||||
<template #header>
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Профиль</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
|
||||
<div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
|
||||
<div class="max-w-xl">
|
||||
<UpdateProfileInformationForm :user="user" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
|
||||
<div class="max-w-xl">
|
||||
<UpdatePasswordForm />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
|
||||
<div class="max-w-xl">
|
||||
<DeleteUserForm />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,88 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import { routes } from '@/routes';
|
||||
|
||||
const confirmingDeletion = ref(false);
|
||||
|
||||
const form = useForm({ password: '' });
|
||||
|
||||
function confirmDeletion() {
|
||||
confirmingDeletion.value = true;
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
confirmingDeletion.value = false;
|
||||
form.reset();
|
||||
form.clearErrors();
|
||||
}
|
||||
|
||||
function submit() {
|
||||
form.delete(routes.profile.destroy, {
|
||||
preserveScroll: true,
|
||||
errorBag: 'userDeletion',
|
||||
onSuccess: () => closeModal(),
|
||||
onError: () => {},
|
||||
onFinish: () => form.reset('password'),
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="space-y-6">
|
||||
<header>
|
||||
<h2 class="text-lg font-medium text-gray-900">Удаление аккаунта</h2>
|
||||
<p class="mt-1 text-sm text-gray-600">
|
||||
После удаления аккаунта все связанные данные будут безвозвратно удалены.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center px-4 py-2 bg-red-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-red-500"
|
||||
@click="confirmDeletion"
|
||||
>
|
||||
Удалить аккаунт
|
||||
</button>
|
||||
|
||||
<div v-if="confirmingDeletion" class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4">
|
||||
<div class="bg-white rounded-lg shadow-xl max-w-lg w-full p-6">
|
||||
<form @submit.prevent="submit">
|
||||
<h2 class="text-lg font-medium text-gray-900">Точно удалить аккаунт?</h2>
|
||||
<p class="mt-1 text-sm text-gray-600">
|
||||
Это необратимо. Введите пароль, чтобы подтвердить удаление.
|
||||
</p>
|
||||
|
||||
<div class="mt-6">
|
||||
<label for="delete-password" class="sr-only">Пароль</label>
|
||||
<input
|
||||
id="delete-password"
|
||||
v-model="form.password"
|
||||
type="password"
|
||||
placeholder="Пароль"
|
||||
class="mt-1 block w-3/4 border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.password" class="mt-2 text-sm text-red-600">{{ form.errors.password }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center px-4 py-2 bg-white border border-gray-300 rounded-md font-semibold text-xs text-gray-700 uppercase tracking-widest hover:bg-gray-50"
|
||||
@click="closeModal"
|
||||
>
|
||||
Отмена
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="form.processing"
|
||||
class="inline-flex items-center px-4 py-2 bg-red-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-red-500 disabled:opacity-50"
|
||||
>
|
||||
Удалить аккаунт
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,82 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { useForm, usePage } from '@inertiajs/vue3';
|
||||
import { routes } from '@/routes';
|
||||
|
||||
const form = useForm({
|
||||
current_password: '',
|
||||
password: '',
|
||||
password_confirmation: '',
|
||||
});
|
||||
|
||||
const flashStatus = computed(() => usePage().props.flash.status);
|
||||
|
||||
function submit() {
|
||||
form.put(routes.password.update, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => form.reset(),
|
||||
onError: () => {
|
||||
if (form.errors.password) form.reset('password', 'password_confirmation');
|
||||
if (form.errors.current_password) form.reset('current_password');
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<header>
|
||||
<h2 class="text-lg font-medium text-gray-900">Смена пароля</h2>
|
||||
<p class="mt-1 text-sm text-gray-600">Длинный случайный пароль надёжнее короткого запоминающегося.</p>
|
||||
</header>
|
||||
|
||||
<form class="mt-6 space-y-6" @submit.prevent="submit">
|
||||
<div>
|
||||
<label for="current_password" class="block font-medium text-sm text-gray-700">Текущий пароль</label>
|
||||
<input
|
||||
id="current_password"
|
||||
v-model="form.current_password"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.current_password" class="mt-2 text-sm text-red-600">{{ form.errors.current_password }}</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="password" class="block font-medium text-sm text-gray-700">Новый пароль</label>
|
||||
<input
|
||||
id="password"
|
||||
v-model="form.password"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.password" class="mt-2 text-sm text-red-600">{{ form.errors.password }}</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="password_confirmation" class="block font-medium text-sm text-gray-700">Подтверждение пароля</label>
|
||||
<input
|
||||
id="password_confirmation"
|
||||
v-model="form.password_confirmation"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.password_confirmation" class="mt-2 text-sm text-red-600">{{ form.errors.password_confirmation }}</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="form.processing"
|
||||
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 disabled:opacity-50"
|
||||
>
|
||||
Сохранить
|
||||
</button>
|
||||
<p v-if="flashStatus === 'password-updated'" class="text-sm text-gray-600">Сохранено.</p>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { useForm, usePage } from '@inertiajs/vue3';
|
||||
import { routes } from '@/routes';
|
||||
|
||||
const props = defineProps({
|
||||
user: { type: Object, required: true },
|
||||
});
|
||||
|
||||
const form = useForm({
|
||||
name: props.user.name,
|
||||
email: props.user.email,
|
||||
});
|
||||
|
||||
const flashStatus = computed(() => usePage().props.flash.status);
|
||||
|
||||
function submit() {
|
||||
form.patch(routes.profile.update);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<header>
|
||||
<h2 class="text-lg font-medium text-gray-900">Данные профиля</h2>
|
||||
<p class="mt-1 text-sm text-gray-600">Имя и email аккаунта.</p>
|
||||
</header>
|
||||
|
||||
<form class="mt-6 space-y-6" @submit.prevent="submit">
|
||||
<div>
|
||||
<label for="name" class="block font-medium text-sm text-gray-700">Имя</label>
|
||||
<input
|
||||
id="name"
|
||||
v-model="form.name"
|
||||
type="text"
|
||||
required
|
||||
autofocus
|
||||
autocomplete="name"
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.name" class="mt-2 text-sm text-red-600">{{ form.errors.name }}</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="email" class="block font-medium text-sm text-gray-700">Email</label>
|
||||
<input
|
||||
id="email"
|
||||
v-model="form.email"
|
||||
type="email"
|
||||
required
|
||||
autocomplete="username"
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.email" class="mt-2 text-sm text-red-600">{{ form.errors.email }}</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="form.processing"
|
||||
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 disabled:opacity-50"
|
||||
>
|
||||
Сохранить
|
||||
</button>
|
||||
<p v-if="flashStatus === 'profile-updated'" class="text-sm text-gray-600">Сохранено.</p>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script setup>
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import Form from '@/Pages/Zones/Form.vue';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout>
|
||||
<template #header>
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Новая зона</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||
<Form />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup>
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import Form from '@/Pages/Zones/Form.vue';
|
||||
|
||||
defineProps({
|
||||
zone: { type: Object, required: true },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout>
|
||||
<template #header>
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Изменить зону</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||
<Form :zone="zone" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,62 @@
|
||||
<script setup>
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import { routes } from '@/routes';
|
||||
|
||||
const props = defineProps({
|
||||
zone: { type: Object, default: null },
|
||||
});
|
||||
|
||||
const isEdit = !!props.zone;
|
||||
|
||||
const form = useForm({
|
||||
name: props.zone?.name ?? '',
|
||||
description: props.zone?.description ?? '',
|
||||
});
|
||||
|
||||
function submit() {
|
||||
if (isEdit) {
|
||||
form.put(routes.zones.update(props.zone.id));
|
||||
} else {
|
||||
form.post(routes.zones.store);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<form @submit.prevent="submit">
|
||||
<div>
|
||||
<label for="name" class="block font-medium text-sm text-gray-700">Название</label>
|
||||
<input
|
||||
id="name"
|
||||
v-model="form.name"
|
||||
type="text"
|
||||
required
|
||||
autofocus
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<div v-if="form.errors.name" class="mt-2 text-sm text-red-600">{{ form.errors.name }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<label for="description" class="block font-medium text-sm text-gray-700">Описание</label>
|
||||
<textarea
|
||||
id="description"
|
||||
v-model="form.description"
|
||||
rows="3"
|
||||
class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
/>
|
||||
<div v-if="form.errors.description" class="mt-2 text-sm text-red-600">{{ form.errors.description }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex items-center gap-4">
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="form.processing"
|
||||
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 disabled:opacity-50"
|
||||
>
|
||||
Сохранить
|
||||
</button>
|
||||
<a :href="routes.zones.index" class="text-sm text-gray-600 hover:underline">Отмена</a>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
@@ -0,0 +1,66 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { Link, router, usePage } from '@inertiajs/vue3';
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import { routes } from '@/routes';
|
||||
|
||||
defineProps({
|
||||
zones: { type: Array, required: true },
|
||||
});
|
||||
|
||||
const isOwner = computed(() => usePage().props.auth.user?.role === 'owner');
|
||||
|
||||
function destroy(zone) {
|
||||
if (confirm('Удалить зону?')) {
|
||||
router.delete(routes.zones.destroy(zone.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.zones.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" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="zones.length === 0">
|
||||
<td colspan="4" class="py-4 text-gray-500">Зон пока нет.</td>
|
||||
</tr>
|
||||
<tr v-for="zone in zones" :key="zone.id" class="border-b">
|
||||
<td class="py-2">{{ zone.name }}</td>
|
||||
<td class="py-2 text-gray-500">{{ zone.description }}</td>
|
||||
<td class="py-2">{{ zone.devices_count }}</td>
|
||||
<td class="py-2 text-right space-x-2">
|
||||
<Link v-if="isOwner" :href="routes.zones.edit(zone.id)" class="text-indigo-600 hover:underline">Изменить</Link>
|
||||
<button v-if="isOwner" type="button" class="text-red-600 hover:underline" @click="destroy(zone)">Удалить</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
Reference in New Issue
Block a user