Now saving gerty screen display preferences as JSON in a single db field i 🙂

This commit is contained in:
Black Coffee 2022-09-29 12:13:12 +01:00
parent 2d18153b1d
commit 45dcd7f21f
4 changed files with 79 additions and 138 deletions

View file

@ -17,26 +17,9 @@ async def create_gerty(wallet_id: str, data: Gerty) -> Gerty:
lnbits_wallets, lnbits_wallets,
mempool_endpoint, mempool_endpoint,
exchange, exchange,
show_lnbits_wallets_balance, display_preferences
show_sats_quote,
show_pieter_wuille_facts,
show_exchange_market_rate,
show_onchain_difficulty_epoch_progress,
show_onchain_difficulty_retarget_date,
show_onchain_difficulty_blocks_remaining,
show_onchain_difficulty_epoch_time_remaining,
show_onchain_mempool_recommended_fees,
show_onchain_mempool_number_of_tx,
show_mining_current_hash_rate,
show_mining_current_difficulty,
show_lightning_channel_count,
show_lightning_node_count,
show_lightning_tor_node_count,
show_lightning_clearnet_nodes,
show_lightning_unannounced_nodes,
show_lightning_average_channel_capacity
) )
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?)
""", """,
( (
gerty_id, gerty_id,
@ -45,24 +28,7 @@ async def create_gerty(wallet_id: str, data: Gerty) -> Gerty:
data.lnbits_wallets, data.lnbits_wallets,
data.mempool_endpoint, data.mempool_endpoint,
data.exchange, data.exchange,
data.show_lnbits_wallets_balance, data.display_preferences
data.show_sats_quote,
data.show_pieter_wuille_facts,
data.show_exchange_market_rate,
data.show_onchain_difficulty_epoch_progress,
data.show_onchain_difficulty_retarget_date,
data.show_onchain_difficulty_blocks_remaining,
data.show_onchain_difficulty_epoch_time_remaining,
data.show_onchain_mempool_recommended_fees,
data.show_onchain_mempool_number_of_tx,
data.show_mining_current_hash_rate,
data.show_mining_current_difficulty,
data.show_lightning_channel_count,
data.show_lightning_node_count,
data.show_lightning_tor_node_count,
data.show_lightning_clearnet_nodes,
data.show_lightning_unannounced_nodes,
data.show_lightning_average_channel_capacity
), ),
) )

View file

@ -1,6 +1,6 @@
async def m001_initial(db): async def m001_initial(db):
""" """
Initial gertys table. Initial Gertys table.
""" """
await db.execute( await db.execute(
""" """
@ -11,24 +11,7 @@ async def m001_initial(db):
lnbits_wallets TEXT, lnbits_wallets TEXT,
mempool_endpoint TEXT, mempool_endpoint TEXT,
exchange TEXT, exchange TEXT,
show_lnbits_wallets_balance BOOL, display_preferences TEXT
show_sats_quote BOOL,
show_pieter_wuille_facts BOOL,
show_exchange_market_rate BOOL,
show_onchain_difficulty_epoch_progress BOOL,
show_onchain_difficulty_retarget_date BOOL,
show_onchain_difficulty_blocks_remaining BOOL,
show_onchain_difficulty_epoch_time_remaining BOOL,
show_onchain_mempool_recommended_fees BOOL,
show_onchain_mempool_number_of_tx BOOL,
show_mining_current_hash_rate BOOL,
show_mining_current_difficulty BOOL,
show_lightning_channel_count BOOL,
show_lightning_node_count BOOL,
show_lightning_tor_node_count BOOL,
show_lightning_clearnet_nodes BOOL,
show_lightning_unannounced_nodes BOOL,
show_lightning_average_channel_capacity BOOL
); );
""" """
) )

View file

@ -4,8 +4,6 @@ from typing import Optional
from fastapi import Query from fastapi import Query
from pydantic import BaseModel from pydantic import BaseModel
class Gerty(BaseModel): class Gerty(BaseModel):
id: str = Query(None) id: str = Query(None)
name: str name: str
@ -13,25 +11,7 @@ class Gerty(BaseModel):
lnbits_wallets: str = Query(None) # Wallets to keep an eye on, {"wallet-id": "wallet-read-key, etc"} lnbits_wallets: str = Query(None) # Wallets to keep an eye on, {"wallet-id": "wallet-read-key, etc"}
mempool_endpoint: str = Query(None) # Mempool endpoint to use mempool_endpoint: str = Query(None) # Mempool endpoint to use
exchange: str = Query(None) # BTC <-> Fiat exchange rate to pull ie "USD", in 0.0001 and sats exchange: str = Query(None) # BTC <-> Fiat exchange rate to pull ie "USD", in 0.0001 and sats
show_lnbits_wallets_balance: bool = Query(False) display_preferences: str = Query(None)
show_sats_quote: bool = Query(False)
show_pieter_wuille_facts: bool = Query(False)
show_exchange_market_rate: bool = Query(False)
show_onchain_difficulty_epoch_progress: bool = Query(False)
show_onchain_difficulty_retarget_date: bool = Query(False)
show_onchain_difficulty_blocks_remaining: bool = Query(False)
show_onchain_difficulty_epoch_time_remaining: bool = Query(False)
show_onchain_mempool_recommended_fees: bool = Query(False)
show_onchain_mempool_number_of_tx: bool = Query(False)
show_mining_current_hash_rate: bool = Query(False)
show_mining_current_difficulty: bool = Query(False)
show_lightning_channel_count: bool = Query(False)
show_lightning_node_count: bool = Query(False)
show_lightning_tor_node_count: bool = Query(False)
show_lightning_clearnet_nodes: bool = Query(False)
show_lightning_unannounced_nodes: bool = Query(False)
show_lightning_average_channel_capacity: bool = Query(False)
@classmethod @classmethod
def from_row(cls, row: Row) -> "Gerty": def from_row(cls, row: Row) -> "Gerty":

View file

@ -31,7 +31,7 @@
<template v-slot:header="props"> <template v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">
<q-th auto-width></q-th> <q-th auto-width></q-th>
<q-th v-for="col in props.cols" :key="col.name" :props="props"> <q-th v-for="col in props.cols" :key="col.name" :props="props" :class="`col__${col.name} text-truncate elipsis`">
{{ col.label }} {{ col.label }}
</q-th> </q-th>
<q-th auto-width></q-th> <q-th auto-width></q-th>
@ -164,15 +164,17 @@
</q-input> </q-input>
<p>Use the toggles below to control what your Gerty will display</p> <p>Use the toggles below to control what your Gerty will display</p>
<q-expansion-item <q-expansion-item
expand-separator expand-separator
icon="perm_identity" icon="perm_identity"
label="LNbits wallets" label="LNbits Wallets"
> >
<q-toggle <q-toggle
v-model="formDialog.data.show_lnbits_wallets_balance" v-model="formDialog.data.display_preferences.lnbits_wallets_balance"
label="Show LNbits wallet balances" label="Show LNbits wallet balances"
></q-toggle> ></q-toggle>
</q-expansion-item> </q-expansion-item>
<q-expansion-item <q-expansion-item
expand-separator expand-separator
@ -180,19 +182,19 @@
label="The Fun Stuff" label="The Fun Stuff"
> >
<q-toggle <q-toggle
v-model="formDialog.data.show_sats_quote" v-model="formDialog.data.display_preferences.satoshi_quotes"
label="Satoshi Quotes" label="Satoshi Quotes"
> >
<q-tooltip>Displays random quotes from Satoshi</q-tooltip> <q-tooltip>Displays random quotes from Satoshi</q-tooltip>
</q-toggle> </q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_pieter_wuille_facts" v-model="formDialog.data.display_preferences.pieter_wuille_facts"
label="Pieter Wuille Facts" label="Pieter Wuille Facts"
> >
<q-tooltip>Show accurate facts about Pieter Wuille</q-tooltip> <q-tooltip>Show accurate facts about Pieter Wuille</q-tooltip>
</q-toggle> </q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_exchange_market_rate" v-model="formDialog.data.display_preferences.exchange_market_rate"
label="Current dirty fiat to BTC price" label="Current dirty fiat to BTC price"
></q-toggle> ></q-toggle>
</q-expansion-item> </q-expansion-item>
@ -202,22 +204,22 @@
label="Onchain Information" label="Onchain Information"
> >
<q-toggle <q-toggle
v-model="formDialog.data.show_onchain_difficulty_epoch_progress" v-model="formDialog.data.display_preferences.onchain_difficulty_epoch_progress"
label="Percent of current difficulty epoch complete" label="Percent of current difficulty epoch complete"
></q-toggle> ></q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_onchain_difficulty_retarget_date" v-model="formDialog.data.display_preferences.onchain_difficulty_retarget_date"
label="Estimated retarget date" label="Estimated retarget date"
></q-toggle> ></q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_onchain_difficulty_blocks_remaining" v-model="formDialog.data.display_preferences.onchain_difficulty_blocks_remaining"
label="Blocks until next difficulty adjustment" label="Blocks until next difficulty adjustment"
></q-toggle> ></q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_onchain_difficulty_epoch_time_remaining" v-model="formDialog.data.display_preferences.onchain_difficulty_epoch_time_remaining"
label="Estimated time until next difficulty adjustment" label="Estimated time until next difficulty adjustment"
></q-toggle> ></q-toggle>
</q-expansion-item> </q-expansion-item>
@ -228,12 +230,12 @@
> >
<q-toggle <q-toggle
v-model="formDialog.data.show_onchain_mempool_recommended_fees" v-model="formDialog.data.display_preferences.onchain_mempool_recommended_fees"
label="Recommended fees" label="Recommended fees"
></q-toggle> ></q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_onchain_mempool_number_of_tx" v-model="formDialog.data.display_preferences.mempool_tx_count"
label="Number of transactions in the mempool" label="Number of transactions in the mempool"
></q-toggle> ></q-toggle>
</q-expansion-item> </q-expansion-item>
@ -244,12 +246,12 @@
label="Mining Data" label="Mining Data"
> >
<q-toggle <q-toggle
v-model="formDialog.data.show_mining_current_hash_rate" v-model="formDialog.data.display_preferences.mining_current_hash_rate"
label="Current mining hashrate" label="Current mining hashrate"
></q-toggle> ></q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_mining_current_difficulty" v-model="formDialog.data.display_preferences.mining_current_difficulty"
label="Current mining difficulty" label="Current mining difficulty"
></q-toggle> ></q-toggle>
</q-expansion-item> </q-expansion-item>
@ -260,32 +262,32 @@
label="Lightning Network" label="Lightning Network"
> >
<q-toggle <q-toggle
v-model="formDialog.data.show_lightning_channel_count" v-model="formDialog.data.display_preferences.lightning_channel_count"
label="Channel count" label="Channel count"
></q-toggle> ></q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_lightning_node_count" v-model="formDialog.data.display_preferences.lightning_node_count"
label="Number of nodes" label="Number of nodes"
></q-toggle> ></q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_lightning_tor_node_count" v-model="formDialog.data.display_preferences.lightning_tor_node_count"
label="Number of Tor nodes" label="Number of Tor nodes"
></q-toggle> ></q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_lightning_clearnet_nodes" v-model="formDialog.data.display_preferences.lightning_clearnet_nodes"
label="Number of clearnet nodes" label="Number of clearnet nodes"
></q-toggle> ></q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_lightning_unannounced_nodes" v-model="formDialog.data.display_preferences.lightning_unannounced_nodes"
label="Number of unannounced nodes" label="Number of unannounced nodes"
></q-toggle> ></q-toggle>
<q-toggle <q-toggle
v-model="formDialog.data.show_lightning_average_channel_capacity" v-model="formDialog.data.display_preferences.lightning_average_channel_capacity"
label="Average channel capacity" label="Average channel capacity"
></q-toggle> ></q-toggle>
</q-expansion-item> </q-expansion-item>
@ -524,31 +526,13 @@
name: 'exchange', name: 'exchange',
align: 'left', align: 'left',
label: 'Exchange', label: 'Exchange',
field: 'exchange' field: 'exchange',
},
{
name: 'sats_quote',
align: 'left',
label: 'Sats Quote',
field: 'sats_quote'
}, },
{ {
name: 'mempool_endpoint', name: 'mempool_endpoint',
align: 'left', align: 'left',
label: 'Mempool Endpoint', label: 'Mempool Endpoint',
field: 'mempool_endpoint' field: 'mempool_endpoint'
},
{
name: 'onchain_stats',
align: 'left',
label: 'Onchain Stats',
field: 'onchain_stats'
},
{
name: 'ln_stats',
align: 'left',
label: 'LN Stats',
field: 'ln_stats'
} }
], ],
pagination: { pagination: {
@ -558,23 +542,42 @@
formDialog: { formDialog: {
show: false, show: false,
data: { data: {
sats_quote: false, display_preferences: {
onchain_stats: false, lnbits_wallets_balance: true,
ln_stats: false, satoshi_quotes: true,
pieter_wuille_facts: true,
exchange_market_rate: true,
onchain_difficulty_epoch_progress: true,
onchain_difficulty_retarget_date: true,
onchain_difficulty_blocks_remaining: true,
onchain_difficulty_epoch_time_remaining: true,
onchain_mempool_recommended_fees: true,
mempool_tx_count: true,
mining_current_hash_rate: true,
mining_current_difficulty: true,
lightning_channel_count: true,
lightning_node_count: true,
lightning_tor_node_count: true,
lightning_clearnet_nodes: true,
lightning_unannounced_nodes: true,
lightning_average_channel_capacity: true,
},
lnbits_wallets: [], lnbits_wallets: [],
mempool_endpoint: "https://mempool.space" mempool_endpoint: "https://mempool.space",
} }
} }
} }
}, },
mounted() {
console.log('this.formDialog', this.formDialog.data.display_preferences)
},
methods: { methods: {
closeFormDialog: function () { closeFormDialog: function () {
this.formDialog.data = { this.formDialog.data = {
sats_quote: false,
onchain_stats: false,
ln_stats: false,
lnbits_wallets: [], lnbits_wallets: [],
mempool_endpoint: "https://mempool.space" mempool_endpoint: "https://mempool.space",
display_preferences: {},
} }
}, },
getGertys: function () { getGertys: function () {
@ -593,28 +596,29 @@
}, },
updateformDialog: function (formId) { updateformDialog: function (formId) {
var gerty = _.findWhere(this.gertys, {id: formId}) var gerty = _.findWhere(this.gertys, {id: formId})
console.log('gerty.display_preferences', gerty.display_preferences)
this.formDialog.data.id = gerty.id this.formDialog.data.id = gerty.id
this.formDialog.data.name = gerty.name this.formDialog.data.name = gerty.name
this.formDialog.data.wallet = gerty.wallet this.formDialog.data.wallet = gerty.wallet
this.formDialog.data.lnbits_wallets = JSON.parse(gerty.lnbits_wallets) this.formDialog.data.lnbits_wallets = JSON.parse(gerty.lnbits_wallets)
this.formDialog.data.exchange = gerty.exchange, this.formDialog.data.exchange = gerty.exchange,
this.formDialog.data.mempool_endpoint = gerty.mempool_endpoint, this.formDialog.data.mempool_endpoint = gerty.mempool_endpoint,
this.formDialog.data.sats_quote = Boolean(gerty.sats_quote) this.formDialog.data.display_preferences = JSON.parse(gerty.display_preferences),
this.formDialog.data.onchain_stats = Boolean(gerty.onchain_stats)
this.formDialog.data.ln_stats = Boolean(gerty.ln_stats)
this.formDialog.show = true this.formDialog.show = true
console.log('updateformDialog', this.formDialog.data)
}, },
sendFormDataGerty: function () { sendFormDataGerty: function () {
var self = this if (this.formDialog.data.id) {
if (self.formDialog.data.id) {
this.updateGerty( this.updateGerty(
self.g.user.wallets[0].adminkey, this.g.user.wallets[0].adminkey,
self.formDialog.data this.formDialog.data
) )
} else { } else {
{#console.log('sendFormDataGerty', this.formDialog.data)#}
this.createGerty( this.createGerty(
self.g.user.wallets[0].adminkey, this.g.user.wallets[0].adminkey,
self.formDialog.data this.formDialog.data
) )
} }
}, },
@ -623,12 +627,11 @@
name: this.formDialog.data.name, name: this.formDialog.data.name,
wallet: this.formDialog.data.wallet, wallet: this.formDialog.data.wallet,
lnbits_wallets: JSON.stringify(this.formDialog.data.lnbits_wallets), lnbits_wallets: JSON.stringify(this.formDialog.data.lnbits_wallets),
sats_quote: this.formDialog.data.sats_quote,
exchange: this.formDialog.data.exchange, exchange: this.formDialog.data.exchange,
mempool_endpoint: this.formDialog.data.mempool_endpoint, mempool_endpoint: this.formDialog.data.mempool_endpoint,
onchain_stats: this.formDialog.data.onchain_stats, display_preferences: JSON.stringify(this.formDialog.data.display_preferences)
ln_stats: this.formDialog.data.ln_stats
} }
console.log('createGerty', data)
var self = this var self = this
LNbits.api LNbits.api
@ -650,6 +653,7 @@
updateGerty: function (wallet, data) { updateGerty: function (wallet, data) {
var self = this var self = this
data.lnbits_wallets = JSON.stringify(this.formDialog.data.lnbits_wallets) data.lnbits_wallets = JSON.stringify(this.formDialog.data.lnbits_wallets)
data.display_preferences = JSON.stringify(this.formDialog.data.display_preferences)
LNbits.api LNbits.api
.request( .request(
'PUT', 'PUT',
@ -703,3 +707,11 @@
}) })
</script> </script>
{% endblock %} {% endblock %}
{% block styles %}
<style>
.col__display_preferences {
border: 1px solid red
}
</style>
{% endblock %}