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

Addon suggestions #2150

Merged
merged 4 commits into from
Nov 25, 2023
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 @@ -12,7 +12,10 @@
<div class="addons-cards">
<addon-card v-for="addon in featuredAddons" :key="addon.uid" :addon="addon" :install-action-text="installActionText" :headline="'Featured'" @addonButtonClick="addonButtonClick" />
</div>
<div v-if="showAsCards" class="addons-cards">
<div v-if="suggested" class="addons-cards">
<addon-card v-for="addon in addonsList" :key="addon.uid" :addon="addon" :install-action-text="installActionText" :headline="'Suggested'" @addonButtonClick="addonButtonClick" />
</div>
<div v-else-if="showAsCards" class="addons-cards">
<addon-card v-for="addon in addonsList" :key="addon.uid" :addon="addon" :install-action-text="installActionText" @addonButtonClick="addonButtonClick" />
</div>
<f7-list v-else media-list ref="addonlist" class="addons-table-list" no-chevron no-hairlines>
Expand Down Expand Up @@ -95,7 +98,7 @@ import AddonCard from './addon-card.vue'
import { compareAddons } from '@/assets/addon-store'

export default {
props: ['addons', 'title', 'subtitle', 'showAll', 'featured', 'showAsCards', 'installActionText'],
props: ['addons', 'title', 'subtitle', 'showAll', 'featured', 'showAsCards', 'suggested', 'installActionText'],
components: {
AddonListItem,
AddonCard
Expand Down
35 changes: 31 additions & 4 deletions bundles/org.openhab.ui/web/src/pages/addons/addons-store.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
</f7-block>
<f7-tabs>
<f7-tab :tab-active="currentTab === 'bindings'">
<addons-section
v-if="suggestedAddons" :show-all="true"
@addonButtonClick="addonButtonClick"
:addons="suggestedAddons.filter((a) => a.type === 'binding')"
:suggested="true"
:title="'Binding Suggestions'"
:subtitle="'Suggested bindings from network scan'" />
<addons-section
v-if="officialAddons"
@addonButtonClick="addonButtonClick"
Expand All @@ -58,7 +65,7 @@
<addons-section
v-if="addons && addons.marketplace"
@addonButtonClick="addonButtonClick"
:addons="addons.marketplace.filter((a) => a.type === 'binding')"
:addons="marketplaceAddons.filter((a) => a.type === 'binding')"
:title="'Community Marketplace'"
:subtitle="'Bindings independently released by the community'" />
<addons-section
Expand Down Expand Up @@ -107,10 +114,17 @@
:subtitle="'Alternative user interfaces and icon sets'" />
</f7-tab>
<f7-tab :tab-active="currentTab === 'other'">
<addons-section
v-if="suggestedAddons" :show-all="true"
@addonButtonClick="addonButtonClick"
:suggested="true"
:addons="suggestedAddons.filter((a) => a.type === 'misc')"
:title="'System Integrations Suggestions'"
:subtitle="'Suggested system integrations from network scan'" />
<addons-section
v-if="addons && officialAddons" :show-all="true"
@addonButtonClick="addonButtonClick"
:addons="allAddons.filter((a) => a.type === 'misc')"
:addons="unsuggestedAddons.filter((a) => a.type === 'misc')"
:title="'System Integrations'"
:featured="['misc-openhabcloud', 'misc-homekit', 'misc-metrics']"
:subtitle="'Integrate openHAB with external systems'" />
Expand Down Expand Up @@ -181,6 +195,7 @@ export default {
return {
currentTab: this.initialTab || 'bindings',
services: null,
suggestions: [],
ready: false,
searchResults: []
}
Expand All @@ -189,11 +204,20 @@ export default {
allAddons () {
return Object.keys(this.addons).flatMap((k) => this.addons[k])
},
suggestedAddons () {
return Object.keys(this.addons).flatMap((k) => this.addons[k]).filter((a) => this.suggestions.some((s) => s.id === a.id))
},
unsuggestedAddons () {
return Object.keys(this.addons).flatMap((k) => this.addons[k]).filter((a) => !this.suggestedAddons.includes(a))
},
officialAddons () {
return Object.keys(this.addons).filter((k) => k === 'eclipse' || k === 'karaf').flatMap((k) => this.addons[k])
return Object.keys(this.addons).filter((k) => k === 'eclipse' || k === 'karaf').flatMap((k) => this.addons[k]).filter((a) => !this.suggestedAddons.includes(a))
},
marketplaceAddons () {
return this.addons.marketplace.filter((a) => !this.suggestedAddons.includes(a))
},
otherAddons () {
return Object.keys(this.addons).filter((k) => k !== 'eclipse' && k !== 'karaf' && k !== 'marketplace').flatMap((k) => this.addons[k])
return Object.keys(this.addons).filter((k) => k !== 'eclipse' && k !== 'karaf' && k !== 'marketplace').flatMap((k) => this.addons[k]).filter((a) => !this.suggestedAddons.includes(a))
}
},
methods: {
Expand All @@ -206,6 +230,9 @@ export default {
},
load () {
this.stopEventSource()
this.$oh.api.get('/rest/addons/suggestions').then((data) => {
this.$set(this, 'suggestions', data)
})
this.$oh.api.get('/rest/addons/services').then((data) => {
this.services = data
Promise.all(this.services.map((s) => this.$oh.api.get('/rest/addons?serviceId=' + s.id))).then((data2) => {
Expand Down
54 changes: 29 additions & 25 deletions bundles/org.openhab.ui/web/src/pages/wizards/setup-wizard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -415,31 +415,35 @@ export default {
this.i18nReady = true
}
})
this.$oh.api.get('/rest/addons').then((data) => {
this.addons = data.sort((a, b) => a.label.toUpperCase().localeCompare(b.label.toUpperCase()))
this.selectedAddons = this.addons.filter((a) => this.recommendedAddons.includes(a.uid) && !a.installed)
const self = this
this.autocompleteAddons = this.$f7.autocomplete.create({
openIn: 'popup',
pageTitle: this.$t('setupwizard.addons.selectAddons'),
searchbarPlaceholder: this.$t('setupwizard.addons.selectAddons.placeholder'),
openerEl: this.$refs.selectAddons,
multiple: true,
requestSourceOnOpen: true,
source: (query, render) => {
if (query.length === 0) {
render(self.addons.filter((a) => !a.installed).map((a) => a.label))
} else {
render(self.addons.filter((a) => !a.installed && (a.label.toLowerCase().indexOf(query.toLowerCase()) >= 0 || a.uid.toLowerCase().indexOf(query.toLowerCase()) >= 0)).map((a) => a.label))
}
},
on: {
change (value) {
const selected = value.map((label) => self.addons.find((a) => a.label === label))
self.$set(self, 'selectedAddons', selected)
}
},
value: this.addons.filter((a) => this.recommendedAddons.includes(a.uid)).map((a) => a.label)
this.$oh.api.get('/rest/addons/suggestions').then((suggestedAddons) => {
let suggestions = suggestedAddons.flatMap((s) => s.id)
this.$oh.api.get('/rest/addons').then((data) => {
this.addons = data.sort((a, b) => a.label.toUpperCase().localeCompare(b.label.toUpperCase()))
this.selectedAddons = this.addons.filter((a) => (this.recommendedAddons.includes(a.uid) || suggestions.includes(a.id)) && !a.installed).sort((a, b) => a.label.toUpperCase().localeCompare(b.label.toUpperCase()))
const sortedAddons = this.selectedAddons.concat(this.addons.filter((a) => (!this.selectedAddons.includes(a))))
const self = this
this.autocompleteAddons = this.$f7.autocomplete.create({
openIn: 'popup',
pageTitle: this.$t('setupwizard.addons.selectAddons'),
searchbarPlaceholder: this.$t('setupwizard.addons.selectAddons.placeholder'),
openerEl: this.$refs.selectAddons,
multiple: true,
requestSourceOnOpen: true,
source: (query, render) => {
if (query.length === 0) {
render(sortedAddons.filter((a) => !a.installed).map((a) => a.label))
} else {
render(sortedAddons.filter((a) => !a.installed && (a.label.toLowerCase().indexOf(query.toLowerCase()) >= 0 || a.uid.toLowerCase().indexOf(query.toLowerCase()) >= 0)).map((a) => a.label))
}
},
on: {
change (value) {
const selected = value.map((label) => self.addons.find((a) => a.label === label))
self.$set(self, 'selectedAddons', selected)
}
},
value: this.addons.filter((a) => this.recommendedAddons.includes(a.uid) || suggestions.includes(a.id)).map((a) => a.label)
})
})
})
}
Expand Down