move admin js to own file
This commit is contained in:
parent
be3d4b9e5c
commit
c9a7c41e1f
2 changed files with 84 additions and 85 deletions
81
static/js/admin.js
Normal file
81
static/js/admin.js
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
window.app = Vue.createApp({
|
||||||
|
el: "#vue",
|
||||||
|
mixins: [windowMixin],
|
||||||
|
delimiters: ["${", "}"],
|
||||||
|
data: function () {
|
||||||
|
return {
|
||||||
|
entries: [],
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
name: "key",
|
||||||
|
required: true,
|
||||||
|
label: "Key",
|
||||||
|
align: "left",
|
||||||
|
field: (row) => row.key,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "value",
|
||||||
|
required: true,
|
||||||
|
label: "Value",
|
||||||
|
align: "left",
|
||||||
|
field: (row) => row.value,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
fetchConfig() {
|
||||||
|
this.entries = [];
|
||||||
|
LNbits.api
|
||||||
|
.request(
|
||||||
|
"GET",
|
||||||
|
"/nwcprovider/api/v1/config",
|
||||||
|
this.g.user.wallets[0].adminkey,
|
||||||
|
)
|
||||||
|
.then((response) => {
|
||||||
|
const newEntries = [];
|
||||||
|
for (const [key, value] of Object.entries(response.data)) {
|
||||||
|
newEntries.push({
|
||||||
|
key: key,
|
||||||
|
value: value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.entries = newEntries;
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.error("Error fetching config:", error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async saveConfig() {
|
||||||
|
const data = {};
|
||||||
|
for (const entry of this.entries) {
|
||||||
|
data[entry.key] = entry.value;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await LNbits.api.request(
|
||||||
|
"POST",
|
||||||
|
"/nwcprovider/api/v1/config",
|
||||||
|
this.g.user.wallets[0].adminkey,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
this.$q.notify({
|
||||||
|
message: "Config saved, please restart the server",
|
||||||
|
color: "positive",
|
||||||
|
position: "top",
|
||||||
|
timeout: 2000,
|
||||||
|
actions: [{ icon: "close", color: "white" }],
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error saving config:", error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
created: function () {
|
||||||
|
this.fetchConfig();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
{% extends "base.html" %} {% from "macros.jinja" import window_vars with context
|
{% extends "base.html" %} {% from "macros.jinja" import window_vars with context
|
||||||
%} {% block page %}
|
%} {% block scripts %} {{ window_vars(user) }}
|
||||||
|
<script src="{{ static_url_for('nwcprovider/static', path='js/admin.js') }}"></script>
|
||||||
|
{% endblock %} {% block page %}
|
||||||
<div class="row q-col-gutter-md" id="configTable">
|
<div class="row q-col-gutter-md" id="configTable">
|
||||||
<div class="col-12 q-gutter-y-md">
|
<div class="col-12 q-gutter-y-md">
|
||||||
<q-card>
|
<q-card>
|
||||||
|
|
@ -36,88 +38,4 @@
|
||||||
</q-card>
|
</q-card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %} {% block scripts %} {{ window_vars(user) }}
|
|
||||||
<script>
|
|
||||||
window.app = Vue.createApp({
|
|
||||||
el: "#vue",
|
|
||||||
mixins: [windowMixin],
|
|
||||||
delimiters: ["${", "}"],
|
|
||||||
data: function () {
|
|
||||||
return {
|
|
||||||
entries: [],
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
name: "key",
|
|
||||||
required: true,
|
|
||||||
label: "Key",
|
|
||||||
align: "left",
|
|
||||||
field: (row) => row.key,
|
|
||||||
sortable: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "value",
|
|
||||||
required: true,
|
|
||||||
label: "Value",
|
|
||||||
align: "left",
|
|
||||||
field: (row) => row.value,
|
|
||||||
sortable: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
fetchConfig() {
|
|
||||||
this.entries = [];
|
|
||||||
LNbits.api
|
|
||||||
.request(
|
|
||||||
"GET",
|
|
||||||
"/nwcprovider/api/v1/config",
|
|
||||||
this.g.user.wallets[0].adminkey,
|
|
||||||
)
|
|
||||||
.then((response) => {
|
|
||||||
const newEntries = [];
|
|
||||||
for (const [key, value] of Object.entries(response.data)) {
|
|
||||||
newEntries.push({
|
|
||||||
key: key,
|
|
||||||
value: value,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.entries = newEntries;
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
console.error("Error fetching config:", error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
async saveConfig() {
|
|
||||||
const data = {};
|
|
||||||
for (const entry of this.entries) {
|
|
||||||
data[entry.key] = entry.value;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const response = await LNbits.api.request(
|
|
||||||
"POST",
|
|
||||||
"/nwcprovider/api/v1/config",
|
|
||||||
this.g.user.wallets[0].adminkey,
|
|
||||||
data,
|
|
||||||
);
|
|
||||||
this.$q.notify({
|
|
||||||
message: "Config saved, please restart the server",
|
|
||||||
color: "positive",
|
|
||||||
position: "top",
|
|
||||||
timeout: 2000,
|
|
||||||
actions: [{ icon: "close", color: "white" }],
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error saving config:", error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
created: function () {
|
|
||||||
this.fetchConfig();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue