1- use crate :: models:: { block_group:: BlockGroup , node:: Node , path:: Path , traits:: Query } ;
1+ use crate :: graph:: { GenGraph , GraphNode } ;
2+ use crate :: models:: {
3+ block_group:: BlockGroup , node:: Node , node:: PATH_START_NODE_ID , path:: Path , traits:: Query ,
4+ } ;
25use crate :: progress_bar:: { get_handler, get_time_elapsed_bar} ;
36use crate :: views:: block_group_viewer:: { PlotParameters , Viewer } ;
47use crate :: views:: collection:: { CollectionExplorer , CollectionExplorerState , FocusZone } ;
@@ -21,9 +24,20 @@ use std::time::{Duration, Instant};
2124// Frequency by which we check for external updates to the db
2225const REFRESH_INTERVAL : u64 = 3 ; // seconds
2326
27+ fn get_empty_graph ( ) -> GenGraph {
28+ let mut g = GenGraph :: new ( ) ;
29+ g. add_node ( GraphNode {
30+ block_id : -1 ,
31+ node_id : PATH_START_NODE_ID ,
32+ sequence_start : 0 ,
33+ sequence_end : 0 ,
34+ } ) ;
35+ g
36+ }
37+
2438pub fn view_block_group (
2539 conn : & Connection ,
26- name : & str ,
40+ name : Option < String > ,
2741 sample_name : Option < String > ,
2842 collection_name : & str ,
2943 position : Option < String > , // Node ID and offset
@@ -32,27 +46,6 @@ pub fn view_block_group(
3246 let bar = progress_bar. add ( get_time_elapsed_bar ( ) ) ;
3347 let _ = progress_bar. println ( "Loading block group" ) ;
3448
35- // Get the block group for two cases: with and without a sample
36- let block_group = if let Some ( ref sample_name) = sample_name {
37- BlockGroup :: get ( conn, "select * from block_groups where collection_name = ?1 AND sample_name = ?2 AND name = ?3" ,
38- params ! [ collection_name, sample_name, name] )
39- } else {
40- // modified version:
41- BlockGroup :: get ( conn, "select * from block_groups where collection_name = ?1 AND sample_name is null AND name = ?2" , params ! [ collection_name, name] )
42- } ;
43-
44- if block_group. is_err ( ) {
45- panic ! (
46- "No block group found with name {} and sample {:?} in collection {} " ,
47- name,
48- sample_name. clone( ) . unwrap_or_else( || "null" . to_string( ) ) ,
49- collection_name
50- ) ;
51- }
52-
53- let block_group = block_group. unwrap ( ) ;
54- let block_group_id = block_group. id ;
55-
5649 // Get the node object corresponding to the position given by the user
5750 let origin = if let Some ( position_str) = position {
5851 let parts = position_str. split ( ":" ) . collect :: < Vec < & str > > ( ) ;
@@ -68,12 +61,51 @@ pub fn view_block_group(
6861 } else {
6962 None
7063 } ;
64+
65+ // Create explorer and its state that persists across frames
66+ let mut explorer = CollectionExplorer :: new ( conn, collection_name) ;
67+ let mut explorer_state = CollectionExplorerState :: new ( ) ;
68+ if let Some ( ref s) = sample_name {
69+ explorer_state. toggle_sample ( s) ;
70+ }
71+
72+ let mut block_graph;
73+ let mut block_group_id: Option < i64 > = None ;
74+ let mut focus_zone = FocusZone :: Sidebar ;
75+
76+ if let Some ( name) = name {
77+ // Get the block group for two cases: with and without a sample
78+ let block_group = if let Some ( ref sample_name) = sample_name {
79+ BlockGroup :: get ( conn, "select * from block_groups where collection_name = ?1 AND sample_name = ?2 AND name = ?3" ,
80+ params ! [ collection_name, sample_name, name] )
81+ } else {
82+ // modified version:
83+ BlockGroup :: get ( conn, "select * from block_groups where collection_name = ?1 AND sample_name is null AND name = ?2" , params ! [ collection_name, name] )
84+ } ;
85+
86+ if block_group. is_err ( ) {
87+ panic ! (
88+ "No block group found with name {:?} and sample {:?} in collection {} " ,
89+ name,
90+ sample_name. clone( ) . unwrap_or_else( || "null" . to_string( ) ) ,
91+ collection_name
92+ ) ;
93+ }
94+
95+ let block_group = block_group. unwrap ( ) ;
96+ block_group_id = Some ( block_group. id ) ;
97+ block_graph = BlockGroup :: get_graph ( conn, block_group. id ) ;
98+ explorer_state. selected_block_group_id = Some ( block_group. id ) ;
99+ focus_zone = FocusZone :: Canvas ;
100+ } else {
101+ block_graph = get_empty_graph ( ) ;
102+ }
103+
71104 bar. finish ( ) ;
72105
73106 // Create the viewer and the initial graph
74107 let bar = progress_bar. add ( get_time_elapsed_bar ( ) ) ;
75108 let _ = progress_bar. println ( "Pre-computing layout in chunks" ) ;
76- let mut block_graph = BlockGroup :: get_graph ( conn, block_group_id) ;
77109
78110 let mut viewer = if let Some ( origin) = origin {
79111 Viewer :: with_origin ( & block_graph, conn, PlotParameters :: default ( ) , origin)
@@ -96,19 +128,8 @@ pub fn view_block_group(
96128 let show_sidebar = true ;
97129 let mut tui_layout_change = false ;
98130
99- // Focus management
100- let mut focus_zone = FocusZone :: Canvas ;
101-
102- // Create explorer and its state that persists across frames
103- let mut explorer = CollectionExplorer :: new ( conn, collection_name) ;
104- let mut explorer_state =
105- CollectionExplorerState :: with_selected_block_group ( Some ( block_group_id) ) ;
106- if let Some ( ref s) = sample_name {
107- explorer_state. toggle_sample ( s) ;
108- }
109-
110131 // Track the last selected block group to detect changes
111- let mut last_selected_block_group_id = Some ( block_group_id) ;
132+ let mut last_selected_block_group_id = block_group_id;
112133 // Track if we're loading a new block group
113134 let mut is_loading = false ;
114135 let mut last_refresh = Instant :: now ( ) ;
0 commit comments