diff --git a/src-tauri/src/db.rs b/src-tauri/src/db.rs index d7e384d..abb47f0 100644 --- a/src-tauri/src/db.rs +++ b/src-tauri/src/db.rs @@ -11,6 +11,8 @@ pub struct Project { pub status: String, pub start_date: Option, pub end_date: Option, + pub hus_count: Option, + pub epics_count: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -155,7 +157,7 @@ async fn get_conn(db_path: &str) -> Result { let conn = db.connect().map_err(|e| format!("Connect: {e}"))?; conn.execute_batch( - "CREATE TABLE IF NOT EXISTS projects ( + " CREATE TABLE IF NOT EXISTS projects ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, key TEXT, @@ -163,6 +165,8 @@ async fn get_conn(db_path: &str) -> Result { status TEXT DEFAULT 'active', start_date TEXT, end_date TEXT, + hus_count INTEGER DEFAULT 0, + epics_count INTEGER DEFAULT 0, created_at TEXT DEFAULT (datetime('now')) ); @@ -325,7 +329,7 @@ pub mod commands { let conn = get_conn(&db_path).await?; let mut rows = conn - .query("SELECT id, name, key, description, status, start_date, end_date FROM projects ORDER BY name", ()) + .query("SELECT id, name, key, description, status, start_date, end_date, hus_count, epics_count FROM projects ORDER BY name", ()) .await .map_err(|e| format!("Query: {e}"))?; @@ -339,6 +343,8 @@ pub mod commands { status: row.get::(4).unwrap_or_else(|_| "active".into()), start_date: row.get::(5).ok(), end_date: row.get::(6).ok(), + hus_count: row.get::(7).ok(), + epics_count: row.get::(8).ok(), }); } Ok(projects) @@ -350,8 +356,8 @@ pub mod commands { let conn = get_conn(&db_path).await?; conn.execute( - "INSERT OR REPLACE INTO projects (id, name, key, description, status, start_date, end_date) - VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)", + "INSERT OR REPLACE INTO projects (id, name, key, description, status, start_date, end_date, hus_count, epics_count) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)", libsql::params![ project.id, project.name, @@ -360,6 +366,8 @@ pub mod commands { project.status, project.start_date, project.end_date, + project.hus_count, + project.epics_count, ], ) .await @@ -368,6 +376,24 @@ pub mod commands { Ok(conn.last_insert_rowid()) } + #[tauri::command] + pub async fn update_project_counts(state: State<'_, Mutex>, initiative_id: i64) -> Result<(), String> { + let db_path = state.lock().map_err(|e| e.to_string())?.clone(); + let conn = get_conn(&db_path).await?; + + conn.execute( + "UPDATE projects SET + hus_count = (SELECT COUNT(*) FROM user_stories WHERE initiative_id = ?1), + epics_count = (SELECT COUNT(*) FROM epics WHERE initiative_id = ?1) + WHERE id = ?1", + libsql::params![initiative_id], + ) + .await + .map_err(|e| format!("Update counts: {e}"))?; + + Ok(()) + } + #[tauri::command] pub async fn delete_project(state: State<'_, Mutex>, id: i64) -> Result<(), String> { let db_path = state.lock().map_err(|e| e.to_string())?.clone(); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 476ccc7..56bc4dc 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -22,6 +22,7 @@ fn main() { .invoke_handler(tauri::generate_handler![ commands::get_projects, commands::save_project, + commands::update_project_counts, commands::delete_project, commands::get_work_items, commands::save_work_item, diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index c3792e5..9466467 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -41,7 +41,7 @@ "common": { "loading": "Loading...", "retry": "Retry", - "backToProjects": "← Back to Projects", + "backToProjects": "Back to Projects", "noDescription": "No description" }, "sidebar": { @@ -79,6 +79,8 @@ "selectProject": "Select a project from the sidebar" }, "status": { + "active": "Active", + "inactive": "Inactive", "backlog": "Backlog", "todo": "To do", "inProgress": "In progress", diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index 6562d28..c377ac1 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -41,7 +41,7 @@ "common": { "loading": "Cargando...", "retry": "Reintentar", - "backToProjects": "← Volver a Proyectos", + "backToProjects": "Volver a Proyectos", "noDescription": "Sin descripción" }, "sidebar": { @@ -79,6 +79,8 @@ "selectProject": "Seleccioná un proyecto del panel lateral" }, "status": { + "active": "Activo", + "inactive": "Inactivo", "backlog": "Backlog", "todo": "Por hacer", "inProgress": "En progreso", diff --git a/src/services/tauri-db.ts b/src/services/tauri-db.ts index 7972cb1..1170de7 100644 --- a/src/services/tauri-db.ts +++ b/src/services/tauri-db.ts @@ -18,6 +18,8 @@ export interface ProjectRecord { status: string start_date: string | null end_date: string | null + hus_count: number | null + epics_count: number | null } export interface EpicRecord { @@ -141,6 +143,9 @@ export const tauriDb = { saveProject(project: ProjectRecord): Promise { return safeInvoke('save_project', { project }) }, + updateProjectCounts(initiativeId: number): Promise { + return safeInvoke('update_project_counts', { initiativeId }) + }, deleteProject(id: number): Promise { return safeInvoke('delete_project', { id }) }, diff --git a/src/stores/projects.ts b/src/stores/projects.ts index 285608a..05c54bc 100644 --- a/src/stores/projects.ts +++ b/src/stores/projects.ts @@ -49,6 +49,8 @@ export const useProjectsStore = defineStore('projects', () => { status: p.status || 'active', start_date: p.start_date ?? null, end_date: p.end_date ?? null, + hus_count: null, + epics_count: null, }).catch(() => {}) } } diff --git a/src/stores/workitems.ts b/src/stores/workitems.ts index df71cc0..dbab267 100644 --- a/src/stores/workitems.ts +++ b/src/stores/workitems.ts @@ -114,6 +114,8 @@ export const useWorkItemsStore = defineStore('workitems', () => { if (isFirstVisit || newEpics.length > 0) { await syncEpicsToTurso(id, isFirstVisit ? epicData : newEpics) } + // Actualizar contadores en projects + await tauriDb.updateProjectCounts(id).catch(() => {}) firstVisit.value.add(id) } catch (e: any) { diff --git a/src/views/DashboardView.vue b/src/views/DashboardView.vue index 04c63fd..6d5df0c 100644 --- a/src/views/DashboardView.vue +++ b/src/views/DashboardView.vue @@ -84,7 +84,7 @@ const statusLabel = (status: unknown) => { -
{{ workItems.totalHUs }}
+
{{ workItems.totalHUs }}

{{ t('dashboard.husSubtitle') }}

diff --git a/src/views/NewDashboardView.vue b/src/views/NewDashboardView.vue index a2dd77e..dd8519c 100644 --- a/src/views/NewDashboardView.vue +++ b/src/views/NewDashboardView.vue @@ -136,7 +136,7 @@ const tabContent: Record
-
+