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

Add Inbox approve menu to add Thing of binding page #2973

Merged
merged 1 commit into from
Jan 4, 2025
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
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 @@ -86,9 +86,13 @@

<script>
import ConfigSheet from '@/components/config/config-sheet.vue'
import ThingInboxMixin from '@/pages/settings/things/thing-inbox-mixin'

export default {
components: { ConfigSheet },
mixins: [ThingInboxMixin],
components: {
ConfigSheet
},
props: ['bindingId'],
data () {
return {
Expand Down Expand Up @@ -224,28 +228,25 @@ export default {
Promise.reject('Failed to load inbox: ' + e)
})
},
approve (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)
openEntryActions (entry) {
let actions = this.$f7.actions.create({
convertToPopover: true,
closeOnEscape: true,
buttons: [
[
{
text: entry.label,
label: true
}
],
[
this.entryActionsAddAsThingButton(entry, this.loadInbox),
this.entryActionsAddAsThingWithCustomIdButton(entry, this.loadInbox)
]
]
})

actions.open()
},
approveAll () {
this.$f7.dialog.confirm('Add all discovered Things?', 'Add Things', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@
</style>

<script>
import ThingInboxMixin from '@/pages/settings/things/thing-inbox-mixin'

export default {
mixins: [ThingInboxMixin],
components: {
'empty-state-placeholder': () => import('@/components/empty-state-placeholder.vue')
},
Expand Down Expand Up @@ -256,40 +259,8 @@ export default {
}
],
[
{
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))
}
},
this.entryActionsAddAsThingButton(entry, this.load),
this.entryActionsAddAsThingWithCustomIdButton(entry, this.load),
{
text: (!ignored) ? 'Ignore' : 'Unignore',
color: (!ignored) ? 'orange' : 'blue',
Expand Down Expand Up @@ -318,23 +289,6 @@ export default {

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()
this.load()
}).catch((err) => {
this.$f7.toast.create({
text: 'Error during thing creation: ' + err,
destroyOnClose: true,
closeTimeout: 2000
}).open()
this.load()
})
},
ignoreEntry (entry) {
this.$oh.api.postPlain(`/rest/inbox/${entry.thingUID}/ignore`).then((res) => {
this.$f7.toast.create({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
export default {
methods: {
/**
* Approve the given entry from the inbox.
*
* @param {object} entry Thing inbox entry
* @param {string} label Thing label
* @param {string} [newThingId] Optional custom Thing ID
* @return {Promise<void>}
*/
approveEntry (entry, label, newThingId) {
return this.$oh.api.postPlain(`/rest/inbox/${entry.thingUID}/approve${newThingId ? '?newThingId=' + newThingId : ''}`, label).then(() => {
this.$f7.toast.create({
text: 'Entry approved',
destroyOnClose: true,
closeTimeout: 2000
}).open()
return Promise.resolve()
}).catch((err) => {
this.$f7.toast.create({
text: 'Error during thing creation: ' + err,
destroyOnClose: true,
closeTimeout: 2000
}).open()
return Promise.reject(err)
})
},
entryActionsAddAsThingButton (entry, loadFn) {
return {
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 label:`,
'Add as Thing',
(label) => {
this.approveEntry(entry, label).finally(() => {
loadFn()
})
},
null,
entry.label)
}
}
},
entryActionsAddAsThingWithCustomIdButton (entry, loadFn) {
return {
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 label of the new Thing:',
'Add as Thing',
(label) => {
this.approveEntry(entry, label, newThingId).finally(() => {
loadFn()
})
},
null,
entry.label)
},
null,
entry.thingUID.substring(entry.thingUID.lastIndexOf(':') + 1))
}
}
}
}
}
Loading