Skip to content

Commit bf19f52

Browse files
authored
Merge pull request #75 from AdvancedPhotonSource/41-update-new-recon-and-new-index-buttons-in-scans-table-page
Issue #41
2 parents 023b01c + af6fb06 commit bf19f52

2 files changed

Lines changed: 86 additions & 59 deletions

File tree

laue_portal/pages/scans.py

Lines changed: 85 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,36 @@
1515

1616
layout = html.Div([
1717
navbar.navbar,
18-
dcc.Location(id='url', refresh=False),
18+
dcc.Location(id='url', refresh=True),
1919

2020
# Secondary action bar aligned to right
2121
dbc.Row([
2222
dbc.Col([
2323
dbc.Nav([
24-
dbc.NavItem(
25-
dbc.NavLink(
26-
"New Recon",
27-
href="/create-wire-reconstruction",
28-
active=False,
29-
id="scans-page-wire-recon"
30-
)
24+
dbc.Button(
25+
"New Recon",
26+
id="scans-page-wire-recon-btn",
27+
style={"backgroundColor": "#6c757d", "borderColor": "#6c757d"},
28+
className="me-2"
3129
),
32-
html.Span("|", className="mx-2 text-muted"),
33-
dbc.NavItem(
34-
dbc.NavLink(
35-
"New Index",
36-
href="/create-peakindexing",
37-
active=False,
38-
id="scans-page-peakindex"
39-
)
30+
dbc.Button(
31+
"New Index",
32+
id="scans-page-peakindex-btn",
33+
style={"backgroundColor": "#6c757d", "borderColor": "#6c757d"},
34+
className="me-2"
35+
),
36+
dbc.Button(
37+
"New Recon + Index",
38+
id="scans-page-recon-index-btn-placeholder",
39+
style={"backgroundColor": "#6c757d", "borderColor": "#6c757d"},
40+
className="me-2"
41+
),
42+
dbc.Button(
43+
"Energy to K-space",
44+
id="scans-page-energy-kspace-btn-placeholder",
45+
style={"backgroundColor": "#6c757d", "borderColor": "#6c757d"},
46+
className="me-2"
4047
),
41-
html.Span("|", className="mx-2 text-muted"),
42-
dbc.NavItem(dbc.NavLink("New Recon with selected (only 1 sel)", href="#", active=False)),
43-
html.Span("|", className="mx-2 text-muted"),
44-
dbc.NavItem(dbc.NavLink("Stop ALL", href="#", active=False)),
45-
html.Span("|", className="mx-2 text-muted"),
46-
dbc.NavItem(dbc.NavLink("Stop Selected", href="#", active=False)),
47-
html.Span("|", className="mx-2 text-muted"),
48-
dbc.NavItem(dbc.NavLink("Set high Priority for selected (only 1 sel)", href="#", active=False)),
4948
],
5049
className="bg-light px-2 py-2 d-flex justify-content-end w-100")
5150
], width=12)
@@ -95,6 +94,7 @@
9594
'time': 'Date',
9695
}
9796

97+
9898
def _get_metadatas():
9999
with Session(session_utils.get_engine()) as session:
100100
# Query with JOINs to get scan count and catalog info for each metadata record
@@ -189,27 +189,14 @@ def _get_metadatas():
189189
'unSortIcon': True,
190190
})
191191

192-
# Add the custom actions column
193-
cols.insert(-1, {
194-
'headerName': 'Actions',
195-
'field': 'actions', # This field doesn't need to exist in the data
196-
'cellRenderer': 'ActionButtonsRenderer',
197-
'sortable': False,
198-
'filter': False,
199-
'resizable': True, # Or False, depending on preference
200-
'suppressMenu': True, # Or False
201-
'width': 200, # Adjusted width for DBC buttons
202-
})
203-
204192
return cols, metadatas.to_dict('records')
205193

206194

207-
208195
@dash.callback(
209196
Output('metadata-table', 'columnDefs', allow_duplicate=True),
210197
Output('metadata-table', 'rowData', allow_duplicate=True),
211198
Input('url','pathname'),
212-
prevent_initial_call=True,
199+
prevent_initial_call='initial_duplicate',
213200
)
214201
def get_metadatas(path):
215202
if path == '/scans':
@@ -218,15 +205,52 @@ def get_metadatas(path):
218205
else:
219206
raise PreventUpdate
220207

208+
@dash.callback(
209+
Output('scans-page-wire-recon-btn', 'disabled'),
210+
Output('scans-page-wire-recon-btn', 'style'),
211+
Output('scans-page-peakindex-btn', 'disabled'),
212+
Output('scans-page-peakindex-btn', 'style'),
213+
Output('scans-page-recon-index-btn-placeholder', 'disabled'),
214+
Output('scans-page-recon-index-btn-placeholder', 'style'),
215+
Output('scans-page-energy-kspace-btn-placeholder', 'disabled'),
216+
Output('scans-page-energy-kspace-btn-placeholder', 'style'),
217+
Input('metadata-table', 'selectedRows'),
218+
prevent_initial_call=False,
219+
)
220+
def update_button_states(selected_rows):
221+
enabled_style = {"backgroundColor": "#1abc9c", "borderColor": "#1abc9c"}
222+
disabled_style = {"backgroundColor": "#6c757d", "borderColor": "#6c757d"}
223+
224+
has_selection = selected_rows and len(selected_rows) > 0
225+
226+
if has_selection:
227+
return (
228+
False, enabled_style, # New Recon
229+
False, enabled_style, # New Index
230+
True, disabled_style, # New Recon + Index (placeholder)
231+
True, disabled_style, # Energy to K-space (placeholder)
232+
)
233+
else:
234+
return (
235+
True, disabled_style, # New Recon
236+
True, disabled_style, # New Index
237+
True, disabled_style, # New Recon + Index (placeholder)
238+
True, disabled_style, # Energy to K-space (placeholder)
239+
)
240+
221241

222242
@dash.callback(
223-
Output('scans-page-wire-recon', 'href'),
224-
Input('metadata-table','selectedRows'),
225-
State('scans-page-wire-recon', 'href'),
243+
Output('url', 'href'),
244+
Input('scans-page-wire-recon-btn', 'n_clicks'),
245+
State('metadata-table', 'selectedRows'),
226246
prevent_initial_call=True,
227247
)
228-
def selected_recon_href(rows,href):
229-
base_href = href.split("?")[0]
248+
def handle_recon_button(n_clicks, rows):
249+
if not n_clicks:
250+
return dash.no_update
251+
252+
base_href = "/create-wire-reconstruction"
253+
230254
if not rows:
231255
return base_href
232256

@@ -237,44 +261,47 @@ def selected_recon_href(rows,href):
237261
if row.get('scanNumber'):
238262
scan_ids.append(str(row['scanNumber']))
239263
else:
240-
return base_href
264+
return dash.no_update
241265

242266
if row.get('aperture'):
243267
aperture = str(row['aperture']).lower()
244268
if aperture == 'none':
245-
return base_href # Conflict condition: cannot be reconstructed
269+
return dash.no_update
246270
if 'wire' in aperture:
247271
any_wire_scans = True
248272
else:
249273
any_nonwire_scans = True
250-
251-
# Conflict condition: mixture of wirerecon and recon
274+
252275
if any_wire_scans and any_nonwire_scans:
253-
return base_href
276+
return dash.no_update
254277

255278
if any_nonwire_scans:
256279
base_href = "/create-reconstruction"
257-
258-
return f"{base_href}?scan_id={','.join(scan_ids)}"
280+
281+
url = f"{base_href}?scan_id={','.join(scan_ids)}"
282+
return url
259283

260284

261285
@dash.callback(
262-
Output('scans-page-peakindex', 'href'),
263-
Input('metadata-table','selectedRows'),
264-
State('scans-page-peakindex', 'href'),
286+
Output('url', 'href', allow_duplicate=True),
287+
Input('scans-page-peakindex-btn', 'n_clicks'),
288+
State('metadata-table', 'selectedRows'),
265289
prevent_initial_call=True,
266290
)
267-
def selected_peakindex_href(rows,href):
268-
base_href = href.split("?")[0]
291+
def handle_peakindex_button(n_clicks, rows):
292+
if not n_clicks:
293+
return dash.no_update
294+
295+
base_href = "/create-peakindexing"
296+
269297
if not rows:
270298
return base_href
271-
299+
272300
scan_ids = []
273-
274301
for row in rows:
275302
if row.get('scanNumber'):
276303
scan_ids.append(str(row['scanNumber']))
277304
else:
278305
return base_href
279-
306+
280307
return f"{base_href}?scan_id={','.join(scan_ids)}"

tests/test_metadata_retrievers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ def test_get_metadatas_empty_database_smoke(self, empty_metadata_database):
130130

131131
# Verify specific expected columns are present
132132
column_fields = [col['field'] for col in cols]
133-
expected_columns = ['scanNumber', 'sample_name', 'aperture', 'user_name', 'time', 'scan_dim', 'actions', 'notes']
133+
expected_columns = ['checkbox', 'scanNumber', 'sample_name', 'aperture', 'scan_dim', 'technique', 'user_name', 'time', 'notes']
134134
for expected_col in expected_columns:
135135
assert expected_col in column_fields, f"Column {expected_col} should be present in column definitions"

0 commit comments

Comments
 (0)