-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
home.vue
218 lines (212 loc) · 9.55 KB
/
home.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<template>
<f7-page stacked name="HomePage" class="page-home" :class="{ 'standard-background': $f7.data.themeOptions.homeBackground === 'standard' }" @page:init="onPageInit" @page:beforein="onPageBeforeIn" @page:afterin="onPageAfterIn" @page:beforeout="onPageBeforeOut">
<f7-navbar :large="$f7.data.themeOptions.homeNavbar !== 'simple'" :large-transparent="$f7.data.themeOptions.homeNavbar !== 'simple'" class="home-nav disable-user-select">
<f7-nav-left>
<f7-link icon-ios="f7:menu" icon-aurora="f7:menu" icon-md="material:menu" panel-open="left" />
</f7-nav-left>
<f7-nav-title-large v-if="$f7.data.themeOptions.homeNavbar !== 'simple'" class="home-title-large">
<span class="today">{{ new Date().toLocaleString($store.getters.locale, { weekday: 'long', day: 'numeric', month: 'long' }) }}</span>
{{ title }}
</f7-nav-title-large>
<f7-nav-title>
{{ title }}
</f7-nav-title>
<f7-nav-right>
<f7-link v-if="(this.$store.getters.isAdmin && $store.state.developerDock && $f7.width >= 1280)" icon-f7="question_circle_fill" @click="$f7.emit('toggleDeveloperDock')" />
<f7-link v-else-if="(this.$store.getters.isAdmin && !$store.state.developerDock && $f7.width >= 1280)" icon-f7="question_circle" @click="$f7.emit('selectDeveloperDock',{'dock':'help','helpTab':'current'})" />
<f7-link v-if="this.$store.getters.isAdmin" icon-ios="f7:pencil" icon-aurora="f7:pencil" icon-md="material:edit" :tooltip="$t('home.editHome')" :href="(homePageComponent) ? '/settings/pages/home/home' : '/settings/pages/home/add'" />
<f7-link v-if="showPinToHome" icon-ios="f7:pin_fill" icon-aurora="f7:pin_fill" icon-md="material:add_location" :tooltip="$t('home.pinToHome')" @click="pinToHome" />
<f7-link v-if="showExitToApp" icon-ios="f7:square_arrow_right" icon-aurora="f7:square_arrow_right" icon-md="material:exit_to_app" :tooltip="$t('home.exitToApp')" @click="exitToApp" />
<f7-link v-else icon-ios="f7:sidebar_right" icon-aurora="f7:sidebar_right" icon-md="material:exit_to_app" :tooltip="$t('home.otherApps')" panel-open="right" @click="($store.state.developerDock) ? $f7.emit('toggleDeveloperDock') : ''" />
</f7-nav-right>
</f7-navbar>
<f7-toolbar tabbar labels bottom v-if="tabsVisible">
<f7-link tab-link @click="switchTab('overview')" :tab-link-active="currentTab === 'overview'" icon-ios="f7:house_fill" icon-aurora="f7:house_fill" icon-md="material:home" :text="$t('home.overview.tab')" />
<f7-link tab-link v-if="tabVisible('locations')" @click="switchTab('locations')" :tab-link-active="currentTab === 'locations'" icon-ios="f7:placemark_fill" icon-aurora="f7:placemark_fill" icon-md="material:place" :text="$t('home.locations.tab')" />
<f7-link tab-link v-if="tabVisible('equipment')" @click="switchTab('equipment')" :tab-link-active="currentTab === 'equipment'" icon-ios="f7:cube_box_fill" icon-aurora="f7:cube_box_fill" icon-md="material:payments" :text="$t('home.equipment.tab')" />
<f7-link tab-link v-if="tabVisible('properties')" @click="switchTab('properties')" :tab-link-active="currentTab === 'properties'" icon-ios="f7:bolt_fill" icon-aurora="f7:bolt_fill" icon-md="material:flash_on" :text="$t('home.properties.tab')" />
</f7-toolbar>
<f7-block v-if="!ready || (currentTab !== 'overview' && !modelReady)" class="text-align-center padding-top margin-top">
<f7-block-title>
<f7-preloader :size="30" />
<div>Loading...</div>
</f7-block-title>
<f7-block v-if="loopError">
<f7-block-title>
<div>Error!</div>
</f7-block-title>
{{ loopError }}. Please correct and refresh.
</f7-block>
</f7-block>
<f7-tabs v-else>
<f7-tab id="tab-overview" :tab-active="currentTab === 'overview'" @tab:show="() => this.currentTab = 'overview'">
<overview-tab v-if="currentTab === 'overview'" :context="context" :key="overviewPageKey" :allow-chat="allowChat" />
</f7-tab>
<f7-tab id="tab-locations" :tab-active="currentTab === 'locations'" @tab:show="() => this.currentTab = 'locations'">
<model-tab v-if="currentTab === 'locations'" :context="context" type="locations" :model="model" :page="homePageComponent" />
</f7-tab>
<f7-tab id="tab-equipment" :tab-active="currentTab === 'equipment'" @tab:show="() => this.currentTab = 'equipment'">
<model-tab v-if="currentTab === 'equipment'" :context="context" type="equipment" :model="model" :page="homePageComponent" />
</f7-tab>
<f7-tab id="tab-properties" :tab-active="currentTab === 'properties'" @tab:show="() => this.currentTab = 'properties'">
<model-tab v-if="currentTab === 'properties'" :context="context" type="properties" :model="model" :page="homePageComponent" />
</f7-tab>
</f7-tabs>
</f7-page>
</template>
<style lang="stylus">
.theme-filled .home-nav .home-title-large .title-large-text
color var(--f7-text-color)
.theme-filled .home-nav.navbar-large:not(.navbar-large-collapsed) .link.icon-only
color var(--f7-theme-color)
transition color 0.3s
.theme-filled .home-nav.navbar-large.navbar-large-collapsed .link.icon-only
color var(--f7-navbar-link-color)
transition color 0.3s
.home-nav .home-title-large .title-large-text
line-height 0.98
.today
position absolute
font-size 8pt
font-weight normal
text-transform uppercase
top -6px
letter-spacing 1px
color var(--f7-list-item-footer-text-color)
.edit-home-button
float right
display absolute
z-index 9000
</style>
<script>
import OverviewTab from './home/overview-tab.vue'
import ModelTab from './home/model-tab.vue'
import HomeCards from './home/homecards-mixin'
export default {
props: ['initialTab'],
mixins: [HomeCards],
components: {
OverviewTab,
ModelTab
},
data () {
return {
showSetup: true,
showTasks: true,
showCards: false,
showPinToHome: false,
showExitToApp: false,
currentTab: this.initialTab || 'overview',
overviewPageKey: this.$utils.id(),
items: []
}
},
computed: {
ready () {
return this.$store.state.apiVersion > 0
},
context () {
return {
store: this.$store.getters.trackedItems
}
},
homePageComponent () {
const page = this.$store.getters.page('home')
if (!page) return null
if (page.component !== 'oh-home-page') return null
return page
},
tabsVisible () {
// Show the tabs bar if the home page component is unavailable
if (!this.homePageComponent) return true
// Hide the tabs bar if all model tabs are hidden
if (this.homePageComponent.config?.hiddenModelTabs?.length === 3) return false
// Hide the tabs bar if model cards are restricted to a role and/or users and the current users doesn't satisfy the requirements
// Note: User configuration takes precedence over role configuration
const visibleTo = this.homePageComponent.config.displayModelCardsTo
if (visibleTo === undefined || !visibleTo.length) return true
const user = this.$store.getters.user
if (!user) return false
if (user.roles && user.roles.some(r => visibleTo.indexOf('role:' + r) >= 0)) return true
if (visibleTo.indexOf('user:' + user.name) >= 0) return true
return false
},
allowChat () {
if (!this.homePageComponent) return true
const visibleTo = this.homePageComponent.config.allowChatInputTo
if (visibleTo === undefined || !visibleTo.length) return true
const user = this.$store.getters.user
if (!user) return false
if (user.roles && user.roles.some(r => visibleTo.indexOf('role:' + r) >= 0)) return true
if (visibleTo.indexOf('user:' + user.name) >= 0) return true
return false
},
title () {
switch (this.currentTab) {
case 'overview':
return this.$t('home.overview.title')
case 'locations':
return this.$t('home.locations.title')
case 'equipment':
return this.$t('home.equipment.title')
case 'properties':
return this.$t('home.properties.title')
default:
return this.$t('home.overview.title')
}
}
},
watch: {
ready (val, oldVal) {
if (val && !oldVal) {
this.$store.dispatch('startTrackingStates')
}
}
},
methods: {
onPageBeforeIn () {
this.$f7router.updateCurrentUrl('/' + this.currentTab)
this.$f7router.url = '/' + this.currentTab
this.overviewPageKey = this.$utils.id()
},
onPageAfterIn () {
if (this.ready) {
this.loadModel()
this.$store.dispatch('startTrackingStates')
}
},
onPageBeforeOut () {
this.$store.dispatch('stopTrackingStates')
},
onPageInit () {
this.$store.subscribe((mutation, state) => {
if (mutation.type === 'setSemantics') {
this.loadModel()
}
})
if (window.OHApp) {
if (window.OHApp.pinToHome) this.showPinToHome = true
if (window.OHApp.exitToApp) this.showExitToApp = true
}
},
pinToHome () {
window.OHApp.pinToHome()
},
exitToApp () {
window.OHApp.exitToApp()
},
switchTab (tab) {
this.currentTab = tab
this.$f7router.updateCurrentUrl('/' + this.currentTab)
this.$f7router.url = '/' + this.currentTab
},
tabVisible (tab) {
if (!this.tabsVisible) return false
if (!this.homePageComponent) return true
const hiddenTabs = this.homePageComponent.config.hiddenModelTabs
if (hiddenTabs === undefined || !hiddenTabs.length) return true
return hiddenTabs.indexOf(tab) < 0
}
}
}
</script>