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

Addon config page: Use dirty mixin & Add Ctrl-S shortcut #2314

Merged
merged 1 commit into from
Feb 6, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions bundles/org.openhab.ui/web/src/js/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export default [
{
path: ':addonId',
beforeEnter: [enforceAdminForRoute],
beforeLeave: [checkDirtyBeforeLeave],
async: loadAsync(AddonsConfigureBindingPage)
}
]
Expand Down
35 changes: 32 additions & 3 deletions bundles/org.openhab.ui/web/src/pages/addons/addon-config.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<f7-page>
<f7-page @page:afterin="onPageAfterIn" @page:beforeout="onPageBeforeOut">
<f7-navbar :title="'Configure ' + addon.label" back-link="Back">
<f7-nav-right>
<f7-link @click="save()" v-if="$theme.md" icon-md="material:save" icon-only />
<f7-link @click="save()" v-if="!$theme.md">
Save
Save<span v-if="$device.desktop">&nbsp;(Ctrl-S)</span>
</f7-link>
</f7-nav-right>
</f7-navbar>
Expand Down Expand Up @@ -76,8 +76,10 @@

<script>
import ConfigSheet from '@/components/config/config-sheet.vue'
import DirtyMixin from '@/pages/settings/dirty-mixin'

export default {
mixins: [DirtyMixin],
components: {
ConfigSheet
},
Expand All @@ -101,6 +103,16 @@ export default {
return this.addonId.split('-')[1]
}
},
watch: {
config: {
handler: function () {
if (!this.loading) {
this.dirty = true
}
},
deep: true
}
},
methods: {
save () {
let promises = []
Expand All @@ -127,8 +139,25 @@ export default {
closeTimeout: 2000
}).open()
})

this.dirty = false
this.$f7router.back()
},
onPageAfterIn () {
if (window) {
window.addEventListener('keydown', this.keyDown)
}
},
onPageBeforeOut () {
if (window) {
window.removeEventListener('keydown', this.keyDown)
}
},
keyDown (ev) {
if (ev.keyCode === 83 && (ev.ctrlKey || ev.metaKey) && !(ev.altKey || ev.shiftKey)) {
this.save()
ev.stopPropagation()
ev.preventDefault()
}
}
},
created () {
Expand Down