Add tests and fix issues

This commit is contained in:
2026-04-25 10:38:21 +02:00
parent a0bdf9e37e
commit d84a0eed3f
18 changed files with 911 additions and 567 deletions

View File

@@ -1,32 +1,35 @@
import streamlit as st
from streamlit import dialog
from queries import crud, daily_stats, weekly_stats, monthly_stats, yearly_stats
from enums import CounterType
@st.dialog("Add New Counter", icon=":material/add_box:")
@dialog("Add New Counter", icon=":material/add_box:")
def _add_counter():
colors = crud.get_colors(1)
with st.form(key="add_counter", border=False, clear_on_submit=True):
title = st.text_input("Title:")
counter_type_name = st.selectbox("Type", options=[e.name for e in CounterType])
color = st.radio("Color",
key="color-selector",
title = st.text_input("Title:", key="new_counter_title")
counter_type_name = st.selectbox("Type", options=[e.name for e in CounterType], key="new_counter_type")
selected_color = st.radio("Color",
key="new_counter_color_selector",
width="stretch",
options=[colors[key][0] for key in colors],
format_func=lambda c: f"#{c}")
with st.container(horizontal=True, width="stretch", horizontal_alignment="center"):
if st.form_submit_button(label="Create", icon=":material/save:"):
crud.create_counter(title, CounterType[counter_type_name], color)
if st.form_submit_button(label="Create", icon=":material/save:", key="create_counter_submit_btn"):
if not title:
raise ValueError("Title cannot be empty")
crud.create_counter(title, CounterType[counter_type_name], selected_color)
st.rerun()
@st.dialog("Remove Counter", icon=":material/delete:")
def _remove_counter(counter_id:int):
@dialog("Remove Counter", icon=":material/delete:")
def _remove_counter(remove_counter_id:int):
with st.form(key="remove_counter", border=False, clear_on_submit=True):
st.subheader("Are you sure?")
with st.container(horizontal=True, width="stretch", horizontal_alignment="center"):
if st.form_submit_button("Confirm", icon=":material/delete:"):
crud.remove_counter(counter_id)
if st.form_submit_button("Confirm", icon=":material/delete:", key="remove_counter_submit_btn"):
crud.remove_counter(remove_counter_id)
st.rerun()
df = crud.get_counters()
@@ -89,7 +92,7 @@ with st.container(key="counter-table"):
</style>
""")
if st.button("Add Counter", width="stretch", icon=":material/add_box:"):
if st.button("Add Counter", width="stretch", icon=":material/add_box:", key="new_counter_button"):
_add_counter()