Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/DeviceNameAndGroup.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import type { Device } from '@/model/devices-management/Device'
import DeviceGroupsButton from './DeviceGroupsButton.vue'
import { useGroupsStore } from '@/stores/groups'

defineProps<{
id: string
Expand All @@ -10,7 +11,15 @@ defineProps<{

<template>
<span class="grid grid-cols-1 sm:grid-cols-7 gap-1">
<span class="sm:col-span-3"> {{ device.name }}</span>
<span
:class="
useGroupsStore().getGroupsOfDevice(device.id).length === 0
? 'col-span-full'
: 'sm:col-span-3'
"
>
{{ device.name }}</span
>
<DeviceGroupsButton :id="id" :device="device" class="sm:col-span-4" />
</span>
</template>
23 changes: 20 additions & 3 deletions src/components/tasks-automations/TriggerComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
formatDateForDatetimeLocalInput,
formatDuration,
} from './timeUtils'
import type { Device } from '@/model/devices-management/Device'
import type { Device, DeviceId } from '@/model/devices-management/Device'
import { useDevicesStore } from '@/stores/devices'
import DeviceNameAndGroup from '../DeviceNameAndGroup.vue'
import { useGroupsStore } from '@/stores/groups'

const props = defineProps<{
trigger?: Trigger
Expand Down Expand Up @@ -151,6 +153,18 @@ function closeDialog() {
onMounted(() => {
devices.value = useDevicesStore().devices
})

function groupsToString(deviceId: DeviceId) {
const deviceGroups = useGroupsStore().getGroupsOfDevice(deviceId)
return deviceGroups.length > 0
? '(' +
deviceGroups[0].name +
(deviceGroups.length > 1
? ', ' + deviceGroups[1].name + (deviceGroups.length > 2 ? ', ...' : '')
: '') +
')'
: ''
}
</script>

<template>
Expand Down Expand Up @@ -204,10 +218,12 @@ onMounted(() => {
</template>
<!-- Device Event trigger -->
<template v-else-if="isDeviceEventTrigger(trigger) && selectedDevice">
<p class="col-span-full font-bold text-center">{{ selectedDevice.name }}</p>
<p class="col-span-full font-bold justify-self-center w-55 text-center">
<DeviceNameAndGroup :id="selectedDevice.id" :device="selectedDevice" />
</p>
<select
v-model="selectedEvent"
class="col-span-full select h-7 w-45 select-primary justify-self-center text-center"
class="col-span-full select h-7 w-50 select-primary justify-self-center text-center"
v-if="edit"
>
<option selected disabled>Pick an event</option>
Expand Down Expand Up @@ -239,6 +255,7 @@ onMounted(() => {
<template v-for="device in devices" :key="device.id">
<option :value="device" v-if="device.events.length !== 0">
{{ device.name }}
{{ groupsToString(device.id) }}
</option>
</template>
</select>
Expand Down