checklist / pages /dashboard.py
Abimael Torcate
Initial commit: Complete checklist management app with AI reporting
d54ba19
"""Página do dashboard para visualizar e interagir com o checklist"""
import streamlit as st
from utils.database import get_checklist_with_items, toggle_item as toggle_item_db
st.set_page_config(
page_title="Dashboard do Checklist",
page_icon="✅",
layout="centered"
)
def get_progress(items):
if not items:
return 0
checked_count = sum(1 for item in items if item['is_checked'])
return (checked_count / len(items)) * 100
def main():
if 'current_checklist_id' not in st.session_state or st.session_state.current_checklist_id is None:
st.error("Nenhum checklist selecionado!")
if st.button("← Voltar para Início"):
st.switch_page("app.py")
return
checklist_id = st.session_state.current_checklist_id
try:
# Buscar checklist do banco
checklist = get_checklist_with_items(checklist_id)
if not checklist:
st.error("Checklist não encontrado!")
if st.button("← Voltar para Início"):
st.switch_page("app.py")
return
col1, col2, col3 = st.columns([4, 1, 1])
with col1:
st.title(f"📋 {checklist['name']}")
if checklist['numero_processo']:
st.caption(f"🔢 Processo: {checklist['numero_processo']}")
with col2:
if st.button("📊 Análises"):
st.switch_page("pages/analytics.py")
with col3:
if st.button("← Voltar"):
st.switch_page("app.py")
st.markdown("---")
progress = get_progress(checklist['items'])
col1, col2 = st.columns([3, 1])
with col1:
st.progress(progress / 100)
with col2:
st.metric("Progresso", f"{progress:.0f}%")
st.markdown("### Items do Checklist")
if not checklist['items']:
st.info("Este checklist não possui items.")
else:
for item in checklist['items']:
col1, col2 = st.columns([10, 1])
with col1:
current_state = item['is_checked']
new_state = st.checkbox(
item['text'],
value=current_state,
key=f"check_{item['id']}"
)
# Se o estado mudou, atualizar no banco
if new_state != current_state:
try:
toggle_item_db(item['id'], checklist_id, new_state)
st.rerun()
except Exception as e:
st.error(f"Erro ao atualizar item: {str(e)}")
items_total = len(checklist['items'])
items_checked = sum(1 for item in checklist['items'] if item['is_checked'])
items_remaining = items_total - items_checked
st.markdown("---")
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Total de Items", items_total)
with col2:
st.metric("Concluídos", items_checked, delta=f"{items_checked}/{items_total}")
with col3:
st.metric("Restantes", items_remaining)
if progress == 100:
st.success("🎉 Parabéns! Você completou todo o checklist!")
st.balloons()
except Exception as e:
st.error(f"Erro ao carregar checklist: {str(e)}")
if st.button("← Voltar para Início"):
st.switch_page("app.py")
if __name__ == "__main__":
main()