Skip to content

Commit

Permalink
Merge 685ed00 into 65df3b3
Browse files Browse the repository at this point in the history
  • Loading branch information
hubsif authored May 11, 2021
2 parents 65df3b3 + 685ed00 commit 45b1533
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ export default {
return labelA.localeCompare(labelB)
})
if (this.filterType) {
this.preparedItems = this.preparedItems.filter((i) => i.type === this.filterType)
if (Array.isArray(this.filterType)) {
this.preparedItems = this.preparedItems.filter((i) => this.filterType.includes(i.type.split(':', 1)[0]))
} else {
this.preparedItems = this.preparedItems.filter((i) => i.type === this.filterType)
}
}
if (this.editableOnly) {
this.preparedItems = this.preparedItems.filter((i) => i.editable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<f7-list-item media-item class="channel-item"
:title="channel.label || channelType.label"
:footer="channel.description || channelType.description"
:subtitle="channel.uid" />
:subtitle="channel.uid + ' (' + getItemType(channel) + ')'" />
</f7-list>
</f7-col>

Expand All @@ -36,8 +36,8 @@
<!-- Choose item to link -->
<f7-col v-if="!createItem">
<f7-list>
<!-- TODO: filter with compatible item types -->
<item-picker key="itemLink" title="Item to Link" name="item" :value="selectedItemName" :multiple="false" :items="items" @input="(value) => selectedItemName = value" />
<item-picker key="itemLink" title="Item to Link" name="item" :value="selectedItemName" :multiple="false" :items="items" :filterType="getCompatibleItemTypes()"
@input="(value) => selectedItemName = value" />
</f7-list>
</f7-col>

Expand Down Expand Up @@ -70,17 +70,13 @@
</div>
</f7-col>

<!-- <f7-block v-if="!itemTypeCompatible()" class="text-color-red">
The channel and the item type are not compatible.
</f7-block> -->

<f7-block v-if="!ready && !(!item && !items)" class="text-align-center">
<f7-preloader />
<div>Loading...</div>
</f7-block>

<!-- Profile configuration -->
<f7-col v-else-if="profileTypes.length">
<f7-col v-else-if="profileTypes.length && currentItem">
<f7-block-title>Profile</f7-block-title>
<f7-block-footer class="padding-left padding-right">
Profiles define how Channels and Items work together. Install transformation add-ons to get additional profiles.
Expand All @@ -89,9 +85,8 @@
</f7-link>
</f7-block-footer>
<f7-list>
<f7-list-item radio :checked="!currentProfileType" value="" @change="onProfileTypeChange()" title="(No Profile)" name="profile-type" />
<f7-list-item radio v-for="profileType in profileTypes"
:value="profileType.uid"
<f7-list-item radio v-for="profileType in compatibleProfileTypes"
:checked="!currentProfileType && profileType.uid === 'system:default' || currentProfileType && profileType.uid === currentProfileType.uid"
@change="onProfileTypeChange(profileType.uid)"
:key="profileType.uid" :title="profileType.label" name="profile-type" />
</f7-list>
Expand Down Expand Up @@ -173,6 +168,15 @@ export default {
})
}
},
computed: {
currentItem () {
return this.item ? this.item : this.createItem ? this.newItem : this.selectedItemName
},
compatibleProfileTypes () {
let currentItemType = this.currentItem ? this.currentItem.type : null
return this.profileTypes.filter(p => !p.supportedItemTypes.length || p.supportedItemTypes.includes(currentItemType))
}
},
methods: {
onPageAfterIn (event) {
if (!this.channel) return
Expand All @@ -195,6 +199,7 @@ export default {
const getProfileTypes = this.$oh.api.get('/rest/profile-types?channelTypeUID=' + channel.channelTypeUID)
getProfileTypes.then((data) => {
this.profileTypes = data
this.profileTypes.unshift(data.splice(data.findIndex(p => p.uid === 'system:default'), 1)[0]) // move default to be first
this.ready = true
})
},
Expand All @@ -214,30 +219,16 @@ export default {
this.profileTypeConfiguration = null
})
},
itemTypeCompatible () {
// debugger
// TODO move to testable .js file
let item = this.item
if (!item) item = (this.createItem) ? this.newItem : this.selectedItem
if (!item) return true
if (!item.type) return true
if (!this.selectedChannel) return true
if (!this.selectedChannel.itemType) return false
if (this.currentProfileType && this.currentProfileType.supportedItemTypes && this.currentProfileType.supportedItemTypes.length > 0) {
return (this.currentProfileType.supportedItemTypes.indexOf(this.item.type) >= 0)
}
const channelItemType = this.selectedChannel.itemType
if (channelItemType === item.type) return true
// Exceptions
if (item.type.indexOf('Number') === 0 && channelItemType.indexOf('Number') === 0) return true
if (item.type.indexOf('Number') === 0 && channelItemType === 'Dimmer') return true
if (channelItemType === 'Color' && (item.type === 'Dimmer' || item.type === 'Switch')) return true
if (channelItemType === 'Dimmer' && item.type === 'Switch') return true
return false
getItemType (channel) {
if (channel && channel.kind === 'TRIGGER') return 'Trigger'
if (!channel || !channel.itemType) return '?'
return channel.itemType
},
getCompatibleItemTypes () {
let compatibleItemTypes = this.channel.itemType.split(':', 1)
if (this.channel.itemType === 'Color') { compatibleItemTypes.push('Switch', 'Dimmer') }
if (this.channel.itemType === 'Dimmer') { compatibleItemTypes.push('Switch') }
return compatibleItemTypes
},
save () {
const link = {}
Expand Down Expand Up @@ -277,11 +268,6 @@ export default {
this.$f7.dialog.alert('Please review the profile configuration and correct validation errors')
return
}
// temporarily disabled
// if (!this.itemTypeCompatible()) {
// this.$f7.dialog.alert('The channel and item type are not compatible')
// return
// }
if (this.createItem) {
this.$oh.api.put('/rest/items/' + this.newItem.name, this.newItem).then((data) => {
Expand Down Expand Up @@ -327,6 +313,11 @@ export default {
this.ready = true
})
})
},
currentItem () {
if (this.currentProfileType && !this.compatibleProfileTypes.find(p => p.uid === this.currentProfileType.uid)) {
this.currentProfileType = null
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<f7-list-item divider title="Channel" />
<f7-list-item media-item class="channel-item"
:title="channel.label || channelType.label"
:footer="channel.uid"
:footer="channel.uid + ' (' + getItemType(channel) + ')'"
:subtitle="thing.label"
:badge="thingStatusBadgeText(thing.statusInfo)"
:badge-color="thingStatusBadgeColor(thing.statusInfo)">
Expand Down Expand Up @@ -56,9 +56,8 @@
<div>Loading...</div>
</f7-block>
<f7-list v-else>
<f7-list-item radio :checked="!currentProfileType" value="" @change="onProfileTypeChange()" title="(No Profile)" name="profile-type" :disabled="!link.editable" />
<f7-list-item radio v-for="profileType in profileTypes"
:checked="currentProfileType && profileType.uid === currentProfileType.uid"
:checked="!currentProfileType && profileType.uid === 'system:default' || currentProfileType && profileType.uid === currentProfileType.uid"
:disabled="!link.editable"
@change="onProfileTypeChange(profileType.uid)"
:key="profileType.uid" :title="profileType.label" name="profile-type" />
Expand Down Expand Up @@ -123,9 +122,10 @@ export default {
const itemName = this.item.name
const itemType = this.item.type
const channelUID = this.channel.uid.replace('#', '%23')
const getProfileTypes = this.$oh.api.get('/rest/profile-types?channelTypeUID=' + this.channel.channelTypeUID + '&itemType=' + itemType)
getProfileTypes.then((data) => {
this.$oh.api.get('/rest/profile-types?channelTypeUID=' + this.channel.channelTypeUID + '&itemType=' + itemType).then((data) => {
this.profileTypes = data
this.profileTypes.unshift(data.splice(data.findIndex(p => p.uid === 'system:default'), 1)[0]) // move default to be first
.filter(p => !p.supportedItemTypes.length || p.supportedItemTypes.includes(this.item.type)) // only show compatible profile types
this.$oh.api.get('/rest/links/' + itemName + '/' + channelUID).then((data2) => {
this.link = data2
Expand Down Expand Up @@ -155,6 +155,11 @@ export default {
this.profileTypeConfiguration = null
})
},
getItemType (channel) {
if (channel && channel.kind === 'TRIGGER') return 'Trigger'
if (!channel || !channel.itemType) return '?'
return channel.itemType
},
unlink () {
this.$f7.dialog.confirm(
`Are you sure you want to unlink ${this.item.name} from ${this.thing.label}?`,
Expand Down

0 comments on commit 45b1533

Please sign in to comment.