@@ -4,45 +4,17 @@ use crate::client;
44use crate :: token:: get_smb_token:: get_smb_token;
55use crate :: {
66 cli:: CommandResult ,
7- ui:: { fail_message, fail_symbol, succeed_message, succeed_symbol} ,
7+ ui:: {
8+ fail_message, fail_symbol, project_detail_view:: show_project_detail_tui,
9+ project_table:: show_projects_tui, succeed_message, succeed_symbol,
10+ } ,
811} ;
912use anyhow:: { anyhow, Result } ;
1013use log:: debug;
1114use smbcloud_model:: project:: { Config , Project } ;
1215use smbcloud_network:: environment:: Environment ;
1316use smbcloud_networking_project:: crud_project_read:: { get_project, get_projects} ;
1417use spinners:: Spinner ;
15- use tabled:: { Table , Tabled } ;
16-
17- #[ derive( Tabled ) ]
18- struct ProjectRow {
19- #[ tabled( rename = "ID" ) ]
20- id : i32 ,
21- #[ tabled( rename = "Name" ) ]
22- name : String ,
23- #[ tabled( rename = "Runner" ) ]
24- runner : String ,
25- #[ tabled( rename = "Repository" ) ]
26- repository : String ,
27- #[ tabled( rename = "Description" ) ]
28- description : String ,
29- }
30-
31- #[ derive( Tabled ) ]
32- struct ProjectDetailRow {
33- #[ tabled( rename = "ID" ) ]
34- id : i32 ,
35- #[ tabled( rename = "Name" ) ]
36- name : String ,
37- #[ tabled( rename = "Repository" ) ]
38- repository : String ,
39- #[ tabled( rename = "Description" ) ]
40- description : String ,
41- #[ tabled( rename = "Created at" ) ]
42- created_at : String ,
43- #[ tabled( rename = "Updated at" ) ]
44- updated_at : String ,
45- }
4618
4719pub async fn process_project_list ( env : Environment ) -> Result < CommandResult > {
4820 let mut spinner = Spinner :: new (
@@ -56,9 +28,9 @@ pub async fn process_project_list(env: Environment) -> Result<CommandResult> {
5628 let msg = if projects. is_empty ( ) {
5729 succeed_message ( "No projects found." )
5830 } else {
59- succeed_message ( "Showing all projects ." )
31+ succeed_message ( "Done ." )
6032 } ;
61- show_projects ( projects) ;
33+ show_projects ( projects) ? ;
6234 Ok ( CommandResult {
6335 spinner : Spinner :: new (
6436 spinners:: Spinners :: SimpleDotsScrolling ,
@@ -89,7 +61,7 @@ pub async fn process_project_show(env: Environment, id: String) -> Result<Comman
8961 Ok ( project) => {
9062 spinner. stop_and_persist ( & succeed_symbol ( ) , succeed_message ( "Loaded." ) ) ;
9163 let message = succeed_message ( & format ! ( "Showing project {}." , & project. name) ) ;
92- show_project_detail ( & project) ;
64+ show_project_detail ( & project) ? ;
9365 Ok ( CommandResult {
9466 spinner : Spinner :: new (
9567 spinners:: Spinners :: SimpleDotsScrolling ,
@@ -106,35 +78,15 @@ pub async fn process_project_show(env: Environment, id: String) -> Result<Comman
10678 }
10779}
10880
109- pub ( crate ) fn show_projects ( projects : Vec < Project > ) {
81+ pub ( crate ) fn show_projects ( projects : Vec < Project > ) -> Result < ( ) > {
11082 if projects. is_empty ( ) {
111- return ;
83+ return Ok ( ( ) ) ;
11284 }
113- let rows: Vec < ProjectRow > = projects
114- . into_iter ( )
115- . map ( |p| ProjectRow {
116- id : p. id ,
117- name : p. name ,
118- runner : p. runner . to_string ( ) ,
119- repository : p. repository . unwrap_or ( "-" . to_string ( ) ) ,
120- description : p. description . unwrap_or ( "-" . to_owned ( ) ) ,
121- } )
122- . collect ( ) ;
123- let table = Table :: new ( rows) ;
124- println ! ( "{table}" ) ;
85+ show_projects_tui ( projects) . map_err ( |e| anyhow ! ( e) )
12586}
12687
127- pub ( crate ) fn show_project_detail ( project : & Project ) {
128- let row = ProjectDetailRow {
129- id : project. id ,
130- name : project. name . clone ( ) ,
131- repository : project. repository . clone ( ) . unwrap_or ( "-" . to_owned ( ) ) ,
132- description : project. description . clone ( ) . unwrap_or ( "-" . to_owned ( ) ) ,
133- created_at : project. created_at . date_naive ( ) . to_string ( ) ,
134- updated_at : project. updated_at . date_naive ( ) . to_string ( ) ,
135- } ;
136- let table = Table :: new ( vec ! [ row] ) ;
137- println ! ( "{table}" ) ;
88+ pub ( crate ) fn show_project_detail ( project : & Project ) -> Result < ( ) > {
89+ show_project_detail_tui ( project) . map_err ( |e| anyhow ! ( e) )
13890}
13991
14092pub ( crate ) async fn process_project_use ( env : Environment , id : String ) -> Result < CommandResult > {
0 commit comments