Skip to content

Commit

Permalink
Merge 97a20ef into f601eb2
Browse files Browse the repository at this point in the history
  • Loading branch information
crnjan authored Mar 11, 2021
2 parents f601eb2 + 97a20ef commit 1ec3222
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ export default {
}
},
map () {
return this.query.map((item) => this.store[item.name].state).filter((state) => Number.isFinite(Number.parseFloat(state.split(' ')[0])))
return this.query.map((item) => this.store[item.name].state).filter((state) => Number.isFinite(Number.parseFloat(state)))
},
mapAux () {
return this.queryAux.map((item) => this.store[item.name].state).filter((state) => Number.isFinite(Number.parseFloat(state.split(' ')[0])))
return this.queryAux.map((item) => this.store[item.name].state).filter((state) => Number.isFinite(Number.parseFloat(state)))
},
reduce () {
const ret = this.map.reduce((avg, state, arr, { length }) => {
const value = Number.parseFloat(state.split(' ')[0])
const value = Number.parseFloat(state)
if (Number.isFinite(value)) {
return avg + value / length
}
Expand All @@ -92,7 +92,7 @@ export default {
reduceAux () {
if (this.type !== 'temperature') return undefined
const ret = this.mapAux.reduce((avg, state, arr, { length }) => {
const value = Number.parseFloat(state.split(' ')[0])
const value = Number.parseFloat(state)
if (Number.isFinite(value)) {
return avg + value / length
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@

<script>
import { findEquipment, allEquipmentPoints, findPoints } from '../glance-helpers'
import expr from 'expression-eval'
export default {
props: ['element', 'type', 'customConfig', 'invertColor', 'store'],
props: ['element', 'type', 'badgeOverrides', 'invertColor', 'store'],
data () {
return {
badgeConfigs: {
Expand All @@ -52,11 +53,18 @@ export default {
screens: { icon: 'f7:tv' },
projectors: { icon: 'f7:videocam_fill' },
speakers: { icon: 'f7:speaker_2_fill' }
}
},
exprAst: null
}
},
computed: {
config () {
if (this.badgeOverrides) {
const override = this.badgeOverrides[this.type]
if (override && override.badge) {
return Object.assign(this.badgeConfigs[this.type], override.badge)
}
}
return this.badgeConfigs[this.type]
},
query () {
Expand Down Expand Up @@ -171,6 +179,10 @@ export default {
return this.query.map((item) => this.store[item.name].state)
},
reduce () {
const ast = this.overrideExpression()
if (ast) {
return this.map.filter((state) => expr.eval(ast, { state: state, Number: Number })).length
}
switch (this.type) {
case 'lights':
return this.map.filter((state) => state === 'ON' || (state.split(',').length === 3 && state.split(',')[2] !== '0') || (state.indexOf(',') < 0 && Number.parseInt(state) > 0)).length
Expand All @@ -180,6 +192,17 @@ export default {
return this.map.filter((state) => state === 'ON' || state === 'OPEN').length
}
}
},
methods: {
overrideExpression () {
if (this.badgeOverrides && !this.exprAst) {
const override = this.badgeOverrides[this.type]
if (override && override.expression) {
this.exprAst = expr.parse(override.expression)
}
}
return this.exprAst
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="location-stats margin-top" :class="config.invertText ? 'invert-text' : ''" v-if="!config.disableBadges">
<span v-for="badgeType in ['alarms', 'lights', 'windows', 'doors', 'garagedoors', 'blinds', 'presence', 'lock', 'climate', 'screens', 'projectors', 'speakers']" :key="badgeType">
<status-badge v-if="!config.badges || !config.badges.length || config.badges.indexOf(badgeType) >= 0"
:store="context.store" :element="element" :type="badgeType" :invert-color="config.invertText" />
:store="context.store" :element="element" :type="badgeType" :invert-color="config.invertText" :badgeOverrides="badgeOverrides" />
</span>
</div>
<div class="location-stats margin-top-half" v-if="!config.disableBadges">
Expand Down Expand Up @@ -66,9 +66,10 @@ export default {
activeTab: (this.element.equipment.length === 0 && this.element.properties.length > 0) ? 'properties' : 'equipment'
}
},
methods: {
},
computed: {
badgeOverrides () {
return this.config.badges || this.context.badgeOverrides
},
propertiesListContext () {
return {
store: this.$store.getters.trackedItems,
Expand Down
8 changes: 7 additions & 1 deletion bundles/org.openhab.ui/web/src/pages/home/model-tab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,19 @@ export default {
return excludedIdx >= 0
},
cardContext (element) {
return {
let context = {
component: element.card || {
component: (this.type === 'locations') ? 'oh-location-card' : (this.type === 'equipment') ? 'oh-equipment-card' : 'oh-property-card',
config: {}
},
store: this.$store.getters.trackedItems
}
const page = this.page
const type = this.type
if (page && page.slots && page.slots[type] && page.slots[type][0] && page.slots[type][0].config && page.slots[type][0].config.badges) {
context.badgeOverrides = page.slots[type][0].config.badges
}
return context
},
parentLocationName (item) {
if (item.metadata.semantics.config && item.metadata.semantics.config.isPartOf) {
Expand Down

0 comments on commit 1ec3222

Please sign in to comment.