@@ -13,17 +13,23 @@ use tuirealm::{
1313use crate :: {
1414 app:: {
1515 ids:: Id ,
16- messages:: { CscsMsg , ErrorPopupMsg , InfoPopupMsg , JobMsg , LoginPopupMsg , MenuMsg , Msg , SystemSelectMsg , View } ,
16+ messages:: {
17+ CscsMsg , DownloadPopupMsg , ErrorPopupMsg , InfoPopupMsg , JobMsg , LoginPopupMsg , MenuMsg , Msg ,
18+ SystemSelectMsg , View ,
19+ } ,
1720 user_events:: { CscsEvent , UserEvent } ,
1821 } ,
1922 components:: {
20- context_menu:: ContextMenu , error_popup :: ErrorPopup , info_popup :: InfoPopup , login_popup :: LoginPopup ,
21- system_select_popup:: SystemSelectPopup , workload_list:: WorkloadList ,
23+ context_menu:: ContextMenu , download_popup :: DownloadTargetInput , error_popup :: ErrorPopup , info_popup :: InfoPopup ,
24+ login_popup :: LoginPopup , system_select_popup:: SystemSelectPopup , workload_list:: WorkloadList ,
2225 workload_log:: WorkloadLog ,
2326 } ,
24- cscs:: handlers:: { cscs_login, cscs_system_set} ,
27+ cscs:: {
28+ handlers:: { cscs_login, cscs_system_set} ,
29+ ports:: TreeAction ,
30+ } ,
2531 trace_dbg,
26- util:: ui:: draw_area_in_absolute,
32+ util:: ui:: { draw_area_in_absolute, draw_area_in_absolute_fixed_height } ,
2733} ;
2834
2935pub struct Model < T >
5460
5561 /// Allows creating user events based on messages
5662 pub user_event_tx : mpsc:: Sender < UserEvent > ,
63+
64+ /// Allows interacting with the file Api
65+ pub file_tree_tx : mpsc:: Sender < TreeAction > ,
5766}
5867
5968impl < T > Model < T >
6776 select_system_tx : mpsc:: Sender < ( ) > ,
6877 job_log_tx : mpsc:: Sender < Option < usize > > ,
6978 user_event_tx : mpsc:: Sender < UserEvent > ,
79+ file_tree_tx : mpsc:: Sender < TreeAction > ,
7080 ) -> Self {
7181 Self {
7282 app,
7888 select_system_tx,
7989 job_log_tx,
8090 user_event_tx,
91+ file_tree_tx,
8192 }
8293 }
8394
@@ -125,6 +136,10 @@ where
125136 let popup = draw_area_in_absolute( f. area( ) , 10 ) ;
126137 f. render_widget( Clear , popup) ;
127138 app. view( & Id :: SystemSelectPopup , f, popup) ;
139+ } else if app. mounted( & Id :: DownloadPopup ) {
140+ let popup = draw_area_in_absolute_fixed_height( f. area( ) , 10 , 3 ) ;
141+ f. render_widget( Clear , popup) ;
142+ app. view( & Id :: DownloadPopup , f, popup) ;
128143 }
129144 } )
130145 . is_ok( )
@@ -227,6 +242,38 @@ where
227242 }
228243 }
229244 }
245+ fn handle_download_popup_msg ( & mut self , msg : DownloadPopupMsg ) -> Option < Msg > {
246+ match msg {
247+ DownloadPopupMsg :: Opened ( remote_path) => {
248+ if self . app . mounted ( & Id :: DownloadPopup ) {
249+ assert ! ( self . app. umount( & Id :: DownloadPopup ) . is_ok( ) ) ;
250+ }
251+ assert ! (
252+ self . app
253+ . mount(
254+ Id :: DownloadPopup ,
255+ Box :: new( DownloadTargetInput :: new( remote_path) ) ,
256+ vec![ ]
257+ )
258+ . is_ok( )
259+ ) ;
260+ assert ! ( self . app. active( & Id :: DownloadPopup ) . is_ok( ) ) ;
261+ None
262+ }
263+ DownloadPopupMsg :: PathSet ( remote, local) => {
264+ assert ! ( self . app. umount( & Id :: DownloadPopup ) . is_ok( ) ) ;
265+ let file_tx = self . file_tree_tx . clone ( ) ;
266+ tokio:: spawn ( async move {
267+ file_tx. send ( TreeAction :: Download ( remote, local) ) . await . unwrap ( ) ;
268+ } ) ;
269+ None
270+ }
271+ DownloadPopupMsg :: Closed => {
272+ assert ! ( self . app. umount( & Id :: DownloadPopup ) . is_ok( ) ) ;
273+ None
274+ }
275+ }
276+ }
230277 fn handle_menu_msg ( & mut self , msg : MenuMsg ) -> Option < Msg > {
231278 match msg {
232279 MenuMsg :: Opened => {
@@ -328,6 +375,7 @@ where
328375 Msg :: Menu ( menu_msg) => self . handle_menu_msg ( menu_msg) ,
329376 Msg :: ErrorPopup ( popup_msg) => self . handle_error_popup_msg ( popup_msg) ,
330377 Msg :: InfoPopup ( popup_msg) => self . handle_info_popup_msg ( popup_msg) ,
378+ Msg :: DownloadPopup ( popup_msg) => self . handle_download_popup_msg ( popup_msg) ,
331379 Msg :: Cscs ( CscsMsg :: Login ( client_id, client_secret) ) => {
332380 let event_tx = self . user_event_tx . clone ( ) ;
333381 let error_tx = self . error_tx . clone ( ) ;
0 commit comments