From e22e16e7a32a8e2c714e0deb1634fede9ae41d64 Mon Sep 17 00:00:00 2001 From: Arne Seime Date: Sat, 14 Dec 2024 10:08:32 +0100 Subject: [PATCH] [MainUI] Add thing action menu to add new thing page Signed-off-by: Arne Seime --- .../settings/things/add/choose-thing-type.vue | 114 ++++++++++++++---- 1 file changed, 92 insertions(+), 22 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/pages/settings/things/add/choose-thing-type.vue b/bundles/org.openhab.ui/web/src/pages/settings/things/add/choose-thing-type.vue index dc8d6d6819..6a5adb4ad1 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/things/add/choose-thing-type.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/things/add/choose-thing-type.vue @@ -34,7 +34,7 @@ { - this.$oh.api.postPlain(`/rest/inbox/${entry.thingUID}/approve`, name).then((res) => { - this.$f7.toast.create({ - text: 'Entry approved', - destroyOnClose: true, - closeTimeout: 2000 - }).open() - setTimeout(() => { this.$f7router.navigate('/settings/things/', { reloadCurrent: true }) }, 300) - }).catch((err) => { - this.$f7.toast.create({ - text: 'Error during thing creation: ' + err, - destroyOnClose: true, - closeTimeout: 2000 - }).open() - }) - }, - null, - entry.label) + let actions = this.$f7.actions.create({ + convertToPopover: true, + closeOnEscape: true, + buttons: [ + [ + { + text: entry.label, + label: true + } + ], + [ + { + text: 'Add as Thing', + color: 'green', + bold: true, + onClick: () => { + this.$f7.dialog.prompt(`This will create a new Thing of type ${entry.thingTypeUID} with the following name:`, + 'Add as Thing', + (name) => { + this.approveEntry(entry, name) + }, + null, + entry.label) + } + }, + { + text: 'Add as Thing (with custom ID)', + color: 'blue', + bold: true, + onClick: () => { + this.$f7.dialog.prompt(`This will create a new Thing of type ${entry.thingTypeUID}. You can change the suggested thing ID below:`, + 'Add as Thing', + (newThingId) => { + this.$f7.dialog.prompt('Enter the desired name of the new Thing:', + 'Add as Thing', + (name) => { + this.approveEntry(entry, name, newThingId) + }, + null, + entry.label) + }, + null, + entry.thingUID.substring(entry.thingUID.lastIndexOf(':') + 1)) + } + }, + { + text: 'Show equivalent Thing file configuration (basic properties)', + color: 'blue', + bold: true, + onClick: () => { + let properties = Object.entries(entry.properties).map(([k, v]) => `${k}="${v}"`) + let explanatoryText = 'NOTE: If this is a bridge, substitute Thing with Bridge' + + '

All properties are show here, but you may not want to include them all in the file configuraiton. Refer to binding docs for this particular binding for more details.

' + let content = `

Thing ${entry.thingUID} "${entry.label}" [ ${properties} ]

` + this.$f7.dialog.create({ + title: 'Equivalent Thing file configuration', + text: explanatoryText + content, + cssClass: 'thing-file-configuration-dialog', + buttons: [ + { + text: 'Close', + color: 'orange' + } + ] + }).open() + } + } + ] + ] + }) + + actions.open() }, + approveEntry (entry, name, newThingId) { + this.$oh.api.postPlain(`/rest/inbox/${entry.thingUID}/approve${newThingId ? '?newThingId=' + newThingId : ''}`, name).then((res) => { + this.$f7.toast.create({ + text: 'Entry approved', + destroyOnClose: true, + closeTimeout: 2000 + }).open() + setTimeout(() => { this.$f7router.navigate('/settings/things/', { reloadCurrent: true }) }, 300) + }).catch((err) => { + this.$f7.toast.create({ + text: 'Error during thing creation: ' + err, + destroyOnClose: true, + closeTimeout: 2000 + }).open() + }) + }, + approveAll () { this.$f7.dialog.confirm('Add all discovered Things?', 'Add Things', () => { const promises = this.scanResults.map((i) => this.$oh.api.postPlain('/rest/inbox/' + i.thingUID + '/approve', i.label))