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

Show correct alexa metadata categories for group items #767

Merged
merged 2 commits into from
Jan 8, 2021
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 @@ -36,6 +36,30 @@ const categories = [
'WEARABLE'
]

// Group endpoints are generated from the display categories. Example from the docs: SECURITY_PANEL => Endpoint.SecurityPanel.
const groupEndpoints = categories
.map(category => {
const convertedChars = []
let capitalizeNext = false
for (var i = 0; i < category.length; i++) {
const currentChar = category.charAt(i)
if (i === 0) {
convertedChars.push(currentChar.toUpperCase())
} else if (currentChar === '_') {
capitalizeNext = true
} else if (capitalizeNext) {
convertedChars.push(currentChar.toUpperCase())
capitalizeNext = false
} else {
convertedChars.push(currentChar.toLocaleLowerCase())
}
}
return 'Endpoint.' + convertedChars.join('')
}).reduce((endpoints, endpointName) => {
endpoints[endpointName] = []
return endpoints
}, {})

const labels = {
'Switchable': [],
'Lighting': [],
Expand Down Expand Up @@ -234,6 +258,11 @@ for (let l in labels) {
classes['label:' + l] = labels[l]
}

for (let l in groupEndpoints) {
groupEndpoints[l].unshift(categoryParameter)
classes['endpoint:' + l] = groupEndpoints[l]
}

for (let c in capabilities) {
capabilities[c].unshift(categoryParameter)
classes[c] = capabilities[c]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<template>
<div>
<div style="text-align:right" class="padding-right">
<div style="text-align:right" class="padding-right" v-if="itemType !== 'Group'">
<label @click="toggleMultiple" style="cursor:pointer">Multiple</label> <f7-checkbox :checked="multiple" @change="toggleMultiple"></f7-checkbox>
</div>
<f7-list>
<f7-list-item :key="classSelectKey"
:title="(multiple) ? 'Alexa Classes' : 'Alexa Class'" smart-select :smart-select-params="{ openIn: 'popup', searchbar: true, closeOnSelect: !multiple, scrollToSelectedItem: true }" ref="classes">
<select name="parameters" @change="updateClasses" :multiple="multiple">
<option v-if="!multiple" value=""></option>
<optgroup label="Labels" v-if="!multiple">
<optgroup label="Labels" v-if="!multiple && itemType !== 'Group'">
<option v-for="cl in orderedClasses.filter((c) => c.indexOf('label:') === 0)"
:value="cl.replace('label:', '')" :key="cl"
:selected="isSelected(cl.replace('label:', ''))">
{{cl.replace('label:', '')}}
</option>
</optgroup>
<optgroup label="Capabilities">
<option v-for="cl in orderedClasses.filter((c) => c.indexOf('label:') !== 0)"
:value="cl" :key="cl"
:selected="isSelected(cl)">
{{cl}}
<option v-for="cl in orderedClasses.filter((c) => c.indexOf('label:') !== 0 && c.indexOf('endpoint:') === (itemType === 'Group'? 0 : -1))"
:value="cl.replace('endpoint:', '')" :key="cl"
:selected="isSelected(cl.replace('endpoint:', ''))">
{{cl.replace('endpoint:', '')}}
</option>
</optgroup>
</select>
Expand All @@ -39,14 +39,15 @@ import AlexaDefinitions from '@/assets/definitions/metadata/alexa'
import ConfigSheet from '@/components/config/config-sheet.vue'

export default {
props: ['itemName', 'metadata', 'namespace'],
props: ['item', 'metadata', 'namespace'],
components: {
ConfigSheet
},
data () {
return {
itemType: this.item.type,
classesDefs: Object.keys(AlexaDefinitions),
multiple: !!this.metadata.value && this.metadata.value.indexOf(',') > 0,
multiple: this.item.type !== 'Group' && !!this.metadata.value && this.metadata.value.indexOf(',') > 0,
classSelectKey: this.$f7.utils.id()
}
},
Expand All @@ -63,7 +64,7 @@ export default {
parameters () {
if (!this.classes) return []
if (!this.multiple) {
return AlexaDefinitions['label:' + this.classes] || [...AlexaDefinitions[this.classes]]
return AlexaDefinitions['label:' + this.classes] || AlexaDefinitions['endpoint:' + this.classes] || [...AlexaDefinitions[this.classes]]
}
const params = []
this.classes.forEach((c) => {
Expand Down