Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MainUI] Add thing action menu to add new thing page #2921

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<f7-list-item v-for="entry in scanResults"
:key="entry.thingUID"
:link="true"
@click="approve(entry)"
@click="openEntryActions(entry)"
media-item
:title="entry.label"
:subtitle="entry.representationProperty ? entry.properties[entry.representationProperty] : ''"
Expand Down Expand Up @@ -224,29 +224,99 @@ export default {
Promise.reject('Failed to load inbox: ' + e)
})
},
approve (entry) {

openEntryActions (entry) {
console.log(`Add ${entry.thingUID} as thing`)
this.$f7.dialog.prompt(`This will create a new Thing of type ${entry.thingTypeUID} with the following name:`,
'Add as Thing',
(name) => {
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)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove this from this PR? See #2920 (review).

I would also suggest to refactor the openEntryActions and approveEntry actions to a mixin, which then both inbox-list.vue and choose-thing-type.vue can import. This reduces code duplication and avoids further issues where those two provide different options.

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 <code>Thing</code> with <code>Bridge</code>' +
'<p>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.</p>'
let content = `<p><code>Thing ${entry.thingUID} "${entry.label}" [ ${properties} ]</code></p>`
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))
Expand Down
Loading