From fd71c8218348f97ea03f6b797a50b281bebe733b Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 25 Jan 2023 20:28:05 +0000 Subject: [PATCH] gave up on seperate js install file --- lnbits/core/static/js/install.js | 161 ----------------- lnbits/core/templates/admin/_tab_server.html | 4 +- lnbits/core/templates/core/install.html | 177 ++++++++++++++++++- 3 files changed, 174 insertions(+), 168 deletions(-) delete mode 100644 lnbits/core/static/js/install.js diff --git a/lnbits/core/static/js/install.js b/lnbits/core/static/js/install.js deleted file mode 100644 index 2d24109d3..000000000 --- a/lnbits/core/static/js/install.js +++ /dev/null @@ -1,161 +0,0 @@ -new Vue({ - el: '#vue', - data: function () { - return { - searchTerm: '', - tab: 'all', - filteredExtensions: null, - showUninstallDialog: false, - showUpgradeDialog: false, - selectedExtension: null, - selectedExtensionRepos: null, - maxStars: 5 - } - }, - watch: { - searchTerm(term) { - this.filterExtensions(term, this.tab) - } - }, - methods: { - handleTabChanged: function (tab) { - this.filterExtensions(this.searchTerm, tab) - }, - filterExtensions(term, tab) { - // Filter the extensions list - function extensionNameContains(searchTerm) { - return function (extension) { - return ( - extension.name.toLowerCase().includes(searchTerm.toLowerCase()) || - extension.shortDescription - ?.toLowerCase() - .includes(searchTerm.toLowerCase()) - ) - } - } - - this.filteredExtensions = this.extensions - .filter(e => (tab === 'installed' ? e.isInstalled : true)) - .filter(e => (tab === 'featured' ? e.isFeatured : true)) - .filter(extensionNameContains(term)) - }, - async installExtension(release) { - const extension = this.selectedExtension - try { - extension.inProgress = true - this.showUpgradeDialog = false - await LNbits.api.request( - 'POST', - `/api/v1/extension?usr=${this.g.user.id}`, - this.g.user.wallets[0].adminkey, - { - ext_id: extension.id, - archive: release.archive, - source_repo: release.source_repo - } - ) - window.location.href = [ - "{{ url_for('install.extensions') }}", - '?usr=', - this.g.user.id - ].join('') - } catch (error) { - LNbits.utils.notifyApiError(error) - extension.inProgress = false - } - }, - async uninstallExtension() { - const extension = this.selectedExtension - this.showUpgradeDialog = false - this.showUninstallDialog = false - try { - extension.inProgress = true - await LNbits.api.request( - 'DELETE', - `/api/v1/extension/${extension.id}?usr=${this.g.user.id}`, - this.g.user.wallets[0].adminkey - ) - window.location.href = [ - "{{ url_for('install.extensions') }}", - '?usr=', - this.g.user.id - ].join('') - } catch (error) { - LNbits.utils.notifyApiError(error) - extension.inProgress = false - } - }, - toggleExtension: function (extension) { - const action = extension.isActive ? 'activate' : 'deactivate' - window.location.href = [ - "{{ url_for('install.extensions') }}", - '?usr=', - this.g.user.id, - `&${action}=`, - extension.id - ].join('') - }, - - showUninstall() { - this.showUpgradeDialog = false - this.showUninstallDialog = true - }, - - async showUpgrade(extension) { - this.selectedExtension = extension - this.showUpgradeDialog = true - this.selectedExtensionRepos = null - try { - const {data} = await LNbits.api.request( - 'GET', - `/api/v1/extension/${extension.id}/releases?usr=${this.g.user.id}`, - this.g.user.wallets[0].adminkey - ) - - this.selectedExtensionRepos = data.reduce((repos, release) => { - repos[release.source_repo] = repos[release.source_repo] || { - releases: [], - isInstalled: false - } - release.isInstalled = this.isInstalledVersion( - this.selectedExtension, - release - ) - if (release.isInstalled) { - repos[release.source_repo].isInstalled = true - } - repos[release.source_repo].releases.push(release) - return repos - }, {}) - } catch (error) { - LNbits.utils.notifyApiError(error) - extension.inProgress = false - } - }, - hasNewVersion: function (extension) { - if (extension.installedRelease && extension.latestRelease) { - return ( - extension.installedRelease.version !== extension.latestRelease.version - ) - } - }, - isInstalledVersion: function (extension, release) { - if (extension.installedRelease) { - return ( - extension.installedRelease.source_repo === release.source_repo && - extension.installedRelease.version === release.version - ) - } - } - }, - created() { - console.log(window.extensions) - console.log(window.user) - this.extensions = JSON.parse(window.extensions).map(e => ({ - ...e, - inProgress: false - })) - this.filteredExtensions = this.extensions.concat([]) - }, - mixins: [windowMixin] -}) diff --git a/lnbits/core/templates/admin/_tab_server.html b/lnbits/core/templates/admin/_tab_server.html index 715a90b90..09abb8a1f 100644 --- a/lnbits/core/templates/admin/_tab_server.html +++ b/lnbits/core/templates/admin/_tab_server.html @@ -97,13 +97,13 @@
-

Extensions Manifests

+

Extension Sources

diff --git a/lnbits/core/templates/core/install.html b/lnbits/core/templates/core/install.html index 69487495d..03c0aaeca 100644 --- a/lnbits/core/templates/core/install.html +++ b/lnbits/core/templates/core/install.html @@ -1,11 +1,9 @@ {% extends "base.html" %} {% from "macros.jinja" import window_vars with context -%} {{ window_vars(user, extensions) }} {% block scripts %} - -{% endblock %} {% block page %} +%} {{ window_vars(user, extensions) }}{% block page %}

- Add Extensions (admin only) + Add Extensions(admin only)

@@ -65,7 +63,7 @@
@@ -317,3 +315,172 @@
{% endblock %} +{% block scripts %} + +{% endblock %} \ No newline at end of file