From 0b5de50bd5f4111225611ca346a16ded9ae90c9a Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Fri, 26 Jan 2024 09:39:09 +0100 Subject: [PATCH 01/21] feat: add devices dialog in editor WIP Signed-off-by: Stefan Dej --- src/components/TheEditor.vue | 13 ++- src/components/dialogs/DevicesDialog.vue | 97 +++++++++++++++++++ .../dialogs/DevicesDialogSerial.vue | 59 +++++++++++ .../dialogs/DevicesDialogSerialDevice.vue | 40 ++++++++ src/components/dialogs/DevicesDialogUsb.vue | 70 +++++++++++++ .../dialogs/DevicesDialogUsbDevice.vue | 55 +++++++++++ src/locales/en.json | 6 ++ 7 files changed, 338 insertions(+), 2 deletions(-) create mode 100644 src/components/dialogs/DevicesDialog.vue create mode 100644 src/components/dialogs/DevicesDialogSerial.vue create mode 100644 src/components/dialogs/DevicesDialogSerialDevice.vue create mode 100644 src/components/dialogs/DevicesDialogUsb.vue create mode 100644 src/components/dialogs/DevicesDialogUsbDevice.vue diff --git a/src/components/TheEditor.vue b/src/components/TheEditor.vue index 4d0974c67..df97f93ce 100644 --- a/src/components/TheEditor.vue +++ b/src/components/TheEditor.vue @@ -13,6 +13,10 @@ :icon="isWriteable ? mdiFileDocumentEditOutline : mdiFileDocumentOutline" :title="title"> @@ -135,14 +140,17 @@ import { mdiHelp, mdiHelpCircle, mdiRestart, + mdiUsb, } from '@mdi/js' import type Codemirror from '@/components/inputs/Codemirror.vue' +import DevicesDialog from '@/components/dialogs/DevicesDialog.vue' @Component({ - components: { Panel, CodemirrorAsync }, + components: { DevicesDialog, Panel, CodemirrorAsync }, }) export default class TheEditor extends Mixins(BaseMixin) { - private dialogConfirmChange = false + dialogConfirmChange = false + dialogDevices = false formatFilesize = formatFilesize @@ -157,6 +165,7 @@ export default class TheEditor extends Mixins(BaseMixin) { mdiHelpCircle = mdiHelpCircle mdiFileDocumentEditOutline = mdiFileDocumentEditOutline mdiFileDocumentOutline = mdiFileDocumentOutline + mdiUsb = mdiUsb private scrollbarOptions = { scrollbars: { autoHide: 'never' } } diff --git a/src/components/dialogs/DevicesDialog.vue b/src/components/dialogs/DevicesDialog.vue new file mode 100644 index 000000000..e93f563ea --- /dev/null +++ b/src/components/dialogs/DevicesDialog.vue @@ -0,0 +1,97 @@ + + + + + diff --git a/src/components/dialogs/DevicesDialogSerial.vue b/src/components/dialogs/DevicesDialogSerial.vue new file mode 100644 index 000000000..a2d24939f --- /dev/null +++ b/src/components/dialogs/DevicesDialogSerial.vue @@ -0,0 +1,59 @@ + + + + + diff --git a/src/components/dialogs/DevicesDialogSerialDevice.vue b/src/components/dialogs/DevicesDialogSerialDevice.vue new file mode 100644 index 000000000..b9ddeb4c4 --- /dev/null +++ b/src/components/dialogs/DevicesDialogSerialDevice.vue @@ -0,0 +1,40 @@ + + + diff --git a/src/components/dialogs/DevicesDialogUsb.vue b/src/components/dialogs/DevicesDialogUsb.vue new file mode 100644 index 000000000..3fb1318bd --- /dev/null +++ b/src/components/dialogs/DevicesDialogUsb.vue @@ -0,0 +1,70 @@ + + + + + diff --git a/src/components/dialogs/DevicesDialogUsbDevice.vue b/src/components/dialogs/DevicesDialogUsbDevice.vue new file mode 100644 index 000000000..58458994c --- /dev/null +++ b/src/components/dialogs/DevicesDialogUsbDevice.vue @@ -0,0 +1,55 @@ + + + diff --git a/src/locales/en.json b/src/locales/en.json index 8cb6bda38..5c5752dea 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -146,6 +146,11 @@ "SendCode": "Send code...", "SetupConsole": "Setup Console" }, + "DevicesDialog": { + "Headline": "Devices", + "HideSystemEntries": "Hide system entries", + "Refresh": "refresh" + }, "Dialogs": { "StartPrint": { "Cancel": "Cancel", @@ -158,6 +163,7 @@ }, "Editor": { "ConfigReference": "Config Reference", + "DeviceDialog": "Devices", "DontSave": "Don't save", "Downloading": "Downloading", "FailedSave": "{filename} could not be uploaded!", From a09c8fc630c8039561a33db42d605da3026c9b49 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Fri, 26 Jan 2024 19:58:00 +0100 Subject: [PATCH 02/21] feat: add serial devices Signed-off-by: Stefan Dej --- .../dialogs/DevicesDialogSerial.vue | 23 +++++- .../dialogs/DevicesDialogSerialDevice.vue | 81 +++++++++++++------ src/locales/en.json | 5 ++ 3 files changed, 82 insertions(+), 27 deletions(-) diff --git a/src/components/dialogs/DevicesDialogSerial.vue b/src/components/dialogs/DevicesDialogSerial.vue index a2d24939f..e18b043fc 100644 --- a/src/components/dialogs/DevicesDialogSerial.vue +++ b/src/components/dialogs/DevicesDialogSerial.vue @@ -1,11 +1,11 @@ @@ -35,6 +45,8 @@ export interface SerialDevice { @Component export default class DevicesDialogSerial extends Mixins(BaseMixin) { devices: SerialDevice[] = [] + loading = false + loaded = false @Prop({ type: Boolean, default: false }) hideSystemEntries!: boolean @@ -49,9 +61,14 @@ export default class DevicesDialogSerial extends Mixins(BaseMixin) { } async refresh() { + this.loading = true + this.devices = await fetch(this.apiUrl + '/machine/peripherals/serial') .then((res) => res.json()) .then((res) => res.result?.serial_devices ?? []) + + this.loading = false + this.loaded = true } } diff --git a/src/components/dialogs/DevicesDialogSerialDevice.vue b/src/components/dialogs/DevicesDialogSerialDevice.vue index b9ddeb4c4..0001aaac2 100644 --- a/src/components/dialogs/DevicesDialogSerialDevice.vue +++ b/src/components/dialogs/DevicesDialogSerialDevice.vue @@ -1,40 +1,73 @@ diff --git a/src/locales/en.json b/src/locales/en.json index 5c5752dea..a6973b514 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -147,8 +147,13 @@ "SetupConsole": "Setup Console" }, "DevicesDialog": { + "ClickRefresh": "Click on the refresh button to search for devices.", + "DevicePath": "Device path", "Headline": "Devices", "HideSystemEntries": "Hide system entries", + "NoDeviceFound": "No device found. Please check the connection and click on the refresh button.", + "PathByHardware": "Path by hardware", + "PathById": "Path by ID", "Refresh": "refresh" }, "Dialogs": { From 2f108a59c2df024ce3d9e4e8247d300faa0f9262 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Fri, 26 Jan 2024 19:58:18 +0100 Subject: [PATCH 03/21] refactor: refactor tabs and add can devices Signed-off-by: Stefan Dej --- src/components/dialogs/DevicesDialog.vue | 60 ++++++++++------- src/components/dialogs/DevicesDialogCan.vue | 71 +++++++++++++++++++++ src/components/dialogs/DevicesDialogUsb.vue | 46 +++++++------ 3 files changed, 134 insertions(+), 43 deletions(-) create mode 100644 src/components/dialogs/DevicesDialogCan.vue diff --git a/src/components/dialogs/DevicesDialog.vue b/src/components/dialogs/DevicesDialog.vue index e93f563ea..191311961 100644 --- a/src/components/dialogs/DevicesDialog.vue +++ b/src/components/dialogs/DevicesDialog.vue @@ -30,18 +30,22 @@ - {{ tab.content }} + {{ tab.title }} - - - - - - - - can - video - + + + + + + + + + + + + video + + @@ -61,31 +65,39 @@ export default class DevicesDialog extends Mixins(BaseMixin) { mdiUsb = mdiUsb mdiCloseThick = mdiCloseThick - tab = 'usb' + tab = 'serial' hideSystemEntries = true @Prop({ type: Boolean, default: false }) showDialog!: boolean get tabs() { - return [ + const output: { tab: string; title: string }[] = [ { - name: 'usb', - content: 'USB', + tab: 'serial', + title: 'Serial', }, { - name: 'serial', - content: 'Serial', + tab: 'usb', + title: 'USB', }, - // only show CAN, when a device exists { - name: 'can', - content: 'CAN', - }, - { - name: 'video', - content: 'Video', + tab: 'video', + title: 'Video', }, ] + + this.canInterfaces.forEach((name) => { + output.push({ + tab: name, + title: name.toUpperCase(), + }) + }) + + return output.sort((a, b) => a.title.localeCompare(b.title)) + } + + get canInterfaces() { + return Object.keys(this.$store.state.server.system_info?.canbus ?? {}) } closePrompt() { diff --git a/src/components/dialogs/DevicesDialogCan.vue b/src/components/dialogs/DevicesDialogCan.vue new file mode 100644 index 000000000..144ae5d11 --- /dev/null +++ b/src/components/dialogs/DevicesDialogCan.vue @@ -0,0 +1,71 @@ + + + + + diff --git a/src/components/dialogs/DevicesDialogUsb.vue b/src/components/dialogs/DevicesDialogUsb.vue index 3fb1318bd..5c1b2b611 100644 --- a/src/components/dialogs/DevicesDialogUsb.vue +++ b/src/components/dialogs/DevicesDialogUsb.vue @@ -1,21 +1,29 @@ From 9ffcf357643186d114eb5b6e9b5044f203a125ce Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Fri, 26 Jan 2024 22:49:24 +0100 Subject: [PATCH 04/21] feat: add video devices Signed-off-by: Stefan Dej --- src/components/dialogs/DevicesDialog.vue | 4 +- src/components/dialogs/DevicesDialogVideo.vue | 94 +++++++++++++++++++ .../DevicesDialogVideoDeviceLibcamera.vue | 47 ++++++++++ .../dialogs/DevicesDialogVideoDeviceV4l2.vue | 69 ++++++++++++++ 4 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 src/components/dialogs/DevicesDialogVideo.vue create mode 100644 src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue create mode 100644 src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue diff --git a/src/components/dialogs/DevicesDialog.vue b/src/components/dialogs/DevicesDialog.vue index 191311961..10555aaeb 100644 --- a/src/components/dialogs/DevicesDialog.vue +++ b/src/components/dialogs/DevicesDialog.vue @@ -43,7 +43,9 @@ - video + + + diff --git a/src/components/dialogs/DevicesDialogVideo.vue b/src/components/dialogs/DevicesDialogVideo.vue new file mode 100644 index 000000000..29dbdd90d --- /dev/null +++ b/src/components/dialogs/DevicesDialogVideo.vue @@ -0,0 +1,94 @@ + + + + + diff --git a/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue b/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue new file mode 100644 index 000000000..98f1c3c31 --- /dev/null +++ b/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue @@ -0,0 +1,47 @@ + + + diff --git a/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue b/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue new file mode 100644 index 000000000..2a95b7d59 --- /dev/null +++ b/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue @@ -0,0 +1,69 @@ + + + From 6493d13f916ca5dd1b425da2184cf94d3e7f4567 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Fri, 26 Jan 2024 23:21:48 +0100 Subject: [PATCH 05/21] feat: add filter to show csi cam, when libcamera array is empty Signed-off-by: Stefan Dej --- src/components/dialogs/DevicesDialogVideo.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/dialogs/DevicesDialogVideo.vue b/src/components/dialogs/DevicesDialogVideo.vue index 29dbdd90d..6c7f191fe 100644 --- a/src/components/dialogs/DevicesDialogVideo.vue +++ b/src/components/dialogs/DevicesDialogVideo.vue @@ -66,6 +66,8 @@ export default class DevicesDialogVideo extends Mixins(BaseMixin) { get filteredV4l2Devices() { return this.v4l2Devices.filter((device) => { if (this.hideSystemEntries) { + if (this.libcameraDevices.length === 0 && device.hardware_bus.endsWith('csi')) return true + return !device.hardware_bus.startsWith('platform:') } @@ -83,8 +85,6 @@ export default class DevicesDialogVideo extends Mixins(BaseMixin) { this.v4l2Devices = result.v4l2_devices ?? [] this.libcameraDevices = result.libcamera_devices ?? [] - window.console.log(result) - this.loading = false this.loaded = true } From 1facbd4f66ea9b3908791f47a2950ac253cab01a Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 28 Jan 2024 21:07:41 +0100 Subject: [PATCH 06/21] fix: fix identical keys for webcams Signed-off-by: Stefan Dej --- src/components/dialogs/DevicesDialogVideo.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/dialogs/DevicesDialogVideo.vue b/src/components/dialogs/DevicesDialogVideo.vue index 6c7f191fe..b40d8ec92 100644 --- a/src/components/dialogs/DevicesDialogVideo.vue +++ b/src/components/dialogs/DevicesDialogVideo.vue @@ -8,12 +8,12 @@ From af1edd8a11bcb30436c6622df144eb6343392329 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 28 Jan 2024 21:08:22 +0100 Subject: [PATCH 07/21] feat: display alt_name in v4l2 webcams when it is different to camera_name Signed-off-by: Stefan Dej --- src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue b/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue index 2a95b7d59..1ca543732 100644 --- a/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue +++ b/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue @@ -4,6 +4,7 @@
V4L2
{{ device.camera_name }} + {{ device.alt_name }}
@@ -62,6 +63,12 @@ export default class DevicesDialogVideoDeviceLibcamera extends Mixins(BaseMixin) @Prop({ type: Object, required: true }) device!: V4l2Device + get show_alt_name() { + if (this.device.alt_name === null) return false + + return this.device.alt_name !== this.device.camera_name + } + copy(text: string) { navigator.clipboard.writeText(text) } From 3628baff0373d2c4449dd0ceda2117bb403e1b49 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Wed, 31 Jan 2024 21:05:20 +0100 Subject: [PATCH 08/21] refactor: refactor format and resolution output for libcameras Signed-off-by: Stefan Dej --- .../DevicesDialogVideoDeviceLibcamera.vue | 33 ++++++++++++++++--- src/locales/en.json | 4 ++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue b/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue index 98f1c3c31..4066a65c8 100644 --- a/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue +++ b/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue @@ -20,10 +20,22 @@ @click:append="copy(device.libcamera_id)" /> - - {{ mode.format }} - {{ mode.resolutions.join(', ') }} - + + @@ -40,6 +52,19 @@ export default class DevicesDialogVideoDeviceLibcamera extends Mixins(BaseMixin) @Prop({ type: Object, required: true }) device!: LibcameraDevice + get identicalResolutions() { + const resolutions = this.device.modes.map((mode) => mode.resolutions.join(',')) + return resolutions.every((resolution) => resolution === resolutions[0]) + } + + get resolutions() { + return this.device.modes[0].resolutions.join(', ') + } + + get formats() { + return this.device.modes.map((mode) => mode.format).join(', ') + } + copy(text: string) { navigator.clipboard.writeText(text) } diff --git a/src/locales/en.json b/src/locales/en.json index 9216f95e2..c007557d0 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -149,12 +149,14 @@ "DevicesDialog": { "ClickRefresh": "Click on the refresh button to search for devices.", "DevicePath": "Device path", + "Formats": "Formats", "Headline": "Devices", "HideSystemEntries": "Hide system entries", "NoDeviceFound": "No device found. Please check the connection and click on the refresh button.", "PathByHardware": "Path by hardware", "PathById": "Path by ID", - "Refresh": "refresh" + "Refresh": "refresh", + "Resolutions": "Resolutions" }, "Dialogs": { "StartPrint": { From d5a76b30656993543eef091b3e520a87563b0bc1 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Wed, 31 Jan 2024 21:06:55 +0100 Subject: [PATCH 09/21] locale: add LibcameraId to device path locale Signed-off-by: Stefan Dej --- src/locales/en.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/locales/en.json b/src/locales/en.json index c007557d0..8128eb008 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -152,6 +152,7 @@ "Formats": "Formats", "Headline": "Devices", "HideSystemEntries": "Hide system entries", + "LibcameraId": "Libcamera ID", "NoDeviceFound": "No device found. Please check the connection and click on the refresh button.", "PathByHardware": "Path by hardware", "PathById": "Path by ID", From 72a97036b35d0137efdd8c063358413acce69b7a Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Wed, 31 Jan 2024 21:07:43 +0100 Subject: [PATCH 10/21] fix: fix margin between formats and resolutions Signed-off-by: Stefan Dej --- src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue b/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue index 4066a65c8..f6e0a5424 100644 --- a/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue +++ b/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue @@ -21,11 +21,11 @@ @@ -29,6 +48,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator' import BaseMixin from '@/components/mixins/base' import DevicesDialogCanDevice from '@/components/dialogs/DevicesDialogCanDevice.vue' +import { mdiInformationVariantCircle } from '@mdi/js' export interface CanDevice { application: string @@ -39,6 +59,8 @@ export interface CanDevice { components: { DevicesDialogCanDevice }, }) export default class DevicesDialogCan extends Mixins(BaseMixin) { + mdiInformationVariantCircle = mdiInformationVariantCircle + devices: CanDevice[] = [] loading = false loaded = false diff --git a/src/locales/en.json b/src/locales/en.json index 8128eb008..d39e80a86 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -147,6 +147,7 @@ "SetupConsole": "Setup Console" }, "DevicesDialog": { + "CanBusInfo": "Only unassigned nodes can be detected. It’s recommended to have only one unassigned device connected to the can bus to avoid communication issues. For more details, please click on the link:", "ClickRefresh": "Click on the refresh button to search for devices.", "DevicePath": "Device path", "Formats": "Formats", From 5c35ecc59b7358a1219f1a740901c6ad34d6fe0b Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 4 Feb 2024 15:36:55 +0100 Subject: [PATCH 16/21] feat: add format & resolutions to V4L2 video devices Signed-off-by: Stefan Dej --- src/components/dialogs/DevicesDialogVideo.vue | 1 + .../DevicesDialogVideoDeviceLibcamera.vue | 4 +-- .../dialogs/DevicesDialogVideoDeviceV4l2.vue | 35 ++++++++++++++++++- src/plugins/helpers.ts | 7 ++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/components/dialogs/DevicesDialogVideo.vue b/src/components/dialogs/DevicesDialogVideo.vue index b40d8ec92..e52d30de7 100644 --- a/src/components/dialogs/DevicesDialogVideo.vue +++ b/src/components/dialogs/DevicesDialogVideo.vue @@ -46,6 +46,7 @@ export interface V4l2Device { path_by_hardware: string | null path_by_id: string | null usb_location: string | null + modes: { description: string; format: string; flags: string[]; resolutions: string[] }[] } export interface LibcameraDevice { diff --git a/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue b/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue index 9042fd19e..2cdc3470e 100644 --- a/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue +++ b/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue @@ -45,7 +45,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator' import BaseMixin from '@/components/mixins/base' import { mdiContentCopy } from '@mdi/js' import { LibcameraDevice } from '@/components/dialogs/DevicesDialogVideo.vue' -import { copyToClipboard } from '@/plugins/helpers' +import { copyToClipboard, sortResolutions } from '@/plugins/helpers' @Component export default class DevicesDialogVideoDeviceLibcamera extends Mixins(BaseMixin) { @@ -54,7 +54,7 @@ export default class DevicesDialogVideoDeviceLibcamera extends Mixins(BaseMixin) @Prop({ type: Object, required: true }) device!: LibcameraDevice get identicalResolutions() { - const resolutions = this.device.modes.map((mode) => mode.resolutions.join(',')) + const resolutions = this.device.modes.map((mode) => mode.resolutions.sort(sortResolutions).join(',')) return resolutions.every((resolution) => resolution === resolutions[0]) } diff --git a/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue b/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue index d2127c3ba..242bb5255 100644 --- a/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue +++ b/src/components/dialogs/DevicesDialogVideoDeviceV4l2.vue @@ -47,6 +47,26 @@ @click:append="copy(device.path_by_hardware)" /> + + @@ -56,7 +76,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator' import BaseMixin from '@/components/mixins/base' import { mdiContentCopy } from '@mdi/js' import { V4l2Device } from '@/components/dialogs/DevicesDialogVideo.vue' -import { copyToClipboard } from '@/plugins/helpers' +import { copyToClipboard, sortResolutions } from '@/plugins/helpers' @Component export default class DevicesDialogVideoDeviceLibcamera extends Mixins(BaseMixin) { @@ -64,6 +84,19 @@ export default class DevicesDialogVideoDeviceLibcamera extends Mixins(BaseMixin) @Prop({ type: Object, required: true }) device!: V4l2Device + get identicalResolutions() { + const resolutions = this.device.modes.map((mode) => mode.resolutions.sort(sortResolutions).join(',')) + return resolutions.every((resolution) => resolution === resolutions[0]) + } + + get resolutions() { + return this.device.modes[0].resolutions.join(', ') + } + + get formats() { + return this.device.modes.map((mode) => `${mode.description} (${mode.format})`).join(', ') + } + get show_alt_name() { if (this.device.alt_name === null) return false diff --git a/src/plugins/helpers.ts b/src/plugins/helpers.ts index cbd900d31..8cbd54a94 100644 --- a/src/plugins/helpers.ts +++ b/src/plugins/helpers.ts @@ -275,3 +275,10 @@ export function copyToClipboard(text: string) { } textArea.remove() } + +export function sortResolutions(a: string, b: string) { + const aSplit = parseInt(a.split('x')[0]) + const bSplit = parseInt(b.split('x')[0]) + + return aSplit - bSplit +} From 7288dd934ac51ad70d8d7ea3e4d614254dfd0531 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 11 Feb 2024 14:29:18 +0100 Subject: [PATCH 17/21] feat: add tooltip after copy function Signed-off-by: Stefan Dej --- .../dialogs/DevicesDialogCanDevice.vue | 23 ++------ .../dialogs/DevicesDialogSerialDevice.vue | 43 +++------------ .../DevicesDialogVideoDeviceLibcamera.vue | 24 +++------ .../dialogs/DevicesDialogVideoDeviceV4l2.vue | 44 +++------------- src/components/inputs/TextfieldWithCopy.vue | 52 +++++++++++++++++++ src/locales/en.json | 3 ++ 6 files changed, 81 insertions(+), 108 deletions(-) create mode 100644 src/components/inputs/TextfieldWithCopy.vue diff --git a/src/components/dialogs/DevicesDialogCanDevice.vue b/src/components/dialogs/DevicesDialogCanDevice.vue index 96a5e37cb..163362ce3 100644 --- a/src/components/dialogs/DevicesDialogCanDevice.vue +++ b/src/components/dialogs/DevicesDialogCanDevice.vue @@ -10,15 +10,7 @@ - + @@ -28,18 +20,13 @@ diff --git a/src/components/dialogs/DevicesDialogSerialDevice.vue b/src/components/dialogs/DevicesDialogSerialDevice.vue index aab768347..b3293ee33 100644 --- a/src/components/dialogs/DevicesDialogSerialDevice.vue +++ b/src/components/dialogs/DevicesDialogSerialDevice.vue @@ -13,41 +13,17 @@ - + - + - + @@ -58,17 +34,12 @@ import { Component, Mixins, Prop } from 'vue-property-decorator' import BaseMixin from '@/components/mixins/base' import { SerialDevice } from '@/components/dialogs/DevicesDialogSerial.vue' -import { mdiContentCopy } from '@mdi/js' -import { copyToClipboard } from '@/plugins/helpers' +import TextfieldWithCopy from '@/components/inputs/TextfieldWithCopy.vue' -@Component +@Component({ + components: { TextfieldWithCopy }, +}) export default class DevicesDialogSerialDevice extends Mixins(BaseMixin) { - mdiContentCopy = mdiContentCopy - @Prop({ type: Object, required: true }) device!: SerialDevice - - copy(text: string) { - copyToClipboard(text) - } } diff --git a/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue b/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue index 2cdc3470e..22091d0dc 100644 --- a/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue +++ b/src/components/dialogs/DevicesDialogVideoDeviceLibcamera.vue @@ -9,15 +9,7 @@ - +