Skip to content

Commit

Permalink
Page: Add ability to edit current tab of tabbed page (#2953)
Browse files Browse the repository at this point in the history
Closes #2899.

Signed-off-by: Florian Hotze <dev@florianhotze.com>
  • Loading branch information
florian-h05 authored Dec 28, 2024
1 parent 1f4673f commit 512ecce
Showing 1 changed file with 47 additions and 17 deletions.
64 changes: 47 additions & 17 deletions bundles/org.openhab.ui/web/src/pages/page/page-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</f7-nav-left>
<f7-nav-title>{{ (page) ? page.config.label : '' }}</f7-nav-title>
<f7-nav-right>
<f7-link v-if="isAdmin" icon-md="material:edit" :href="'/settings/pages/' + pageType + '/' + uid">
<f7-link v-if="isAdmin" icon-md="material:edit" @click="editPage" class="edit-page-button">
{{ $theme.md ? '' : $t('page.navbar.edit') }}
</f7-link>
<f7-link v-if="fullscreenIcon" class="fullscreen-icon-navbar" :icon-f7="fullscreenIcon" @click="toggleFullscreen" />
Expand Down Expand Up @@ -95,22 +95,7 @@ export default {
return this.$store.getters.page(this.uid)
},
pageType () {
if (!this.page) return null
switch (this.page.component) {
case 'oh-layout-page':
return 'layout'
case 'oh-map-page':
return 'map'
case 'oh-tabs-page':
return 'tabs'
case 'oh-plan-page':
return 'plan'
case 'oh-chart-page':
return 'chart'
default:
console.warn('Unknown page type!')
return 'unknown'
}
return this.getPageType(this.page)
},
isAdmin () {
return this.page && this.$store.getters.isAdmin
Expand Down Expand Up @@ -149,6 +134,24 @@ export default {
onCommand (itemName, command) {
this.$store.dispatch('sendCommand', { itemName, command })
},
getPageType (page) {
if (!page) return null
switch (page.component) {
case 'oh-layout-page':
return 'layout'
case 'oh-map-page':
return 'map'
case 'oh-tabs-page':
return 'tabs'
case 'oh-plan-page':
return 'plan'
case 'oh-chart-page':
return 'chart'
default:
console.warn('Unknown page type!')
return 'unknown'
}
},
tabContext (tab) {
const page = tab.config.page ? this.$store.getters.page(tab.config.page.replace('page:', '')) : tab.component
const context = {
Expand Down Expand Up @@ -180,6 +183,33 @@ export default {
const ctx = this.tabContext(tab)
return this.evaluateExpression('tab-' + idx + '-' + key, tab.config[key], ctx, ctx.props)
},
editPage () {
if (this.pageType === 'tabs') {
const action = this.$f7.actions.create({
buttons: [
{
text: 'Edit Tabbed Page',
onClick: () => {
this.$f7router.navigate('/settings/pages/' + this.pageType + '/' + this.uid)
}
},
{
text: 'Edit Current Tab',
onClick: () => {
const tabPageUid = this.page.slots.default[this.currentTab].config.page.replace('page:', '')
const tabPage = this.$store.getters.page(tabPageUid)
const tabPageType = this.getPageType(tabPage)
this.$f7router.navigate('/settings/pages/' + tabPageType + '/' + tabPageUid)
}
}
],
targetEl: this.$el.querySelector('.edit-page-button')
})
action.open()
} else {
this.$f7router.navigate('/settings/pages/' + this.pageType + '/' + this.uid)
}
},
toggleFullscreen () {
this.$fullscreen.toggle(document.body, {
wrap: false,
Expand Down

0 comments on commit 512ecce

Please sign in to comment.