feat: let user filter its own extensions (#2774)

This commit is contained in:
Vlad Stan 2024-11-12 15:17:05 +02:00 committed by GitHub
parent fa18170ed7
commit 09b1623bb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -67,19 +67,34 @@ window.app.component('lnbits-extension-list', {
data: function () {
return {
extensions: [],
user: null
user: null,
userExtensions: [],
searchTerm: ''
}
},
computed: {
userExtensions: function () {
watch: {
searchTerm(term) {
this.userExtensions = this.updateUserExtensions(term)
}
},
methods: {
updateUserExtensions: function (filterBy) {
if (!this.user) return []
var path = window.location.pathname
var userExtensions = this.user.extensions
const path = window.location.pathname
const userExtensions = this.user.extensions
return this.extensions
.filter(function (obj) {
return userExtensions.indexOf(obj.code) !== -1
.filter(function (o) {
return userExtensions.indexOf(o.code) !== -1
})
.filter(function (o) {
if (!filterBy) return true
return (
`${o.code} ${o.name} ${o.short_description} ${o.url}`
.toLocaleLowerCase()
.indexOf(filterBy.toLocaleLowerCase()) !== -1
)
})
.map(function (obj) {
obj.isActive = path.startsWith(obj.url)
@ -101,6 +116,7 @@ window.app.component('lnbits-extension-list', {
.sort(function (a, b) {
return a.name.localeCompare(b.name)
})
this.userExtensions = this.updateUserExtensions()
} catch (error) {
LNbits.utils.notifyApiError(error)
}

View File

@ -96,11 +96,21 @@
<template id="lnbits-extension-list">
<q-list
v-if="user && userExtensions.length > 0"
v-if="user && (userExtensions.length > 0 || !!searchTerm)"
dense
class="lnbits-drawer__q-list"
>
<q-item-label header v-text="$t('extensions')"></q-item-label>
<q-item>
<q-item-section>
<q-input
v-model="searchTerm"
dense
borderless
:label="$t('extensions')"
>
</q-input>
</q-item-section>
</q-item>
<q-item
v-for="extension in userExtensions"
:key="extension.code"