Skip to content

Commit ad5c296

Browse files
add acknowledge
1 parent bf3aca7 commit ad5c296

File tree

2 files changed

+132
-25
lines changed

2 files changed

+132
-25
lines changed

app/callbacks/display_callbacks.py

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -423,36 +423,59 @@ def update_map_and_alert_info(sequence_on_display, cameras):
423423

424424

425425
@app.callback(
426-
Output("to_acknowledge", "data"),
427-
[Input("acknowledge-button", "n_clicks")],
426+
[Output("confirmation-modal", "style"), Output("to_acknowledge", "data")],
428427
[
429-
State("sequence_id_on_display", "data"),
430-
State("user_token", "data"),
428+
Input("acknowledge-button", "n_clicks"),
429+
Input("confirm-wildfire", "n_clicks"),
430+
Input("confirm-non-wildfire", "n_clicks"),
431+
Input("cancel-confirmation", "n_clicks"),
431432
],
433+
[State("sequence_id_on_display", "data"), State("user_token", "data")],
432434
prevent_initial_call=True,
433435
)
434-
def acknowledge_event(n_clicks, sequence_id_on_display, user_token):
435-
"""
436-
Acknowledges the selected event and updates the state to reflect this.
437-
438-
Parameters:
439-
- n_clicks (int): Number of clicks on the acknowledge button.
440-
- sequence_id_on_display (int): Currently displayed event ID.
441-
- user_token (dict): User authorization headers for API requests.
442-
443-
Returns:
444-
- int: The ID of the event that has been acknowledged.
445-
"""
446-
if sequence_id_on_display == 0 or n_clicks == 0:
447-
raise PreventUpdate
448-
449-
if cfg.SAFE_DEV_MODE == "True":
450-
raise PreventUpdate
451-
452-
api_client.token = user_token
453-
# call_api(api_client.acknowledge_event, user_credentials)(event_id=int(sequence_id_on_display))
436+
def acknowledge_event(
437+
acknowledge_clicks, confirm_wildfire, confirm_non_wildfire, cancel, sequence_id_on_display, user_token
438+
):
439+
ctx = dash.callback_context
454440

455-
return sequence_id_on_display
441+
if not ctx.triggered:
442+
raise dash.exceptions.PreventUpdate
443+
444+
triggered_id = ctx.triggered[0]["prop_id"].split(".")[0]
445+
446+
# Modal styles
447+
modal_visible_style = {
448+
"position": "fixed",
449+
"top": "50%",
450+
"left": "50%",
451+
"transform": "translate(-50%, -50%)",
452+
"z-index": "1000",
453+
"background-color": "rgba(0, 0, 0, 0.5)",
454+
}
455+
modal_hidden_style = {"display": "none"}
456+
457+
if triggered_id == "acknowledge-button":
458+
# Show the modal
459+
if acknowledge_clicks > 0:
460+
return modal_visible_style, dash.no_update
461+
462+
elif triggered_id == "confirm-wildfire":
463+
# Send wildfire confirmation to the API
464+
api_client.token = user_token
465+
api_client.label_sequence(sequence_id_on_display, True)
466+
return modal_hidden_style, sequence_id_on_display
467+
468+
elif triggered_id == "confirm-non-wildfire":
469+
# Send non-wildfire confirmation to the API
470+
api_client.token = user_token
471+
api_client.label_sequence(sequence_id_on_display, False)
472+
return modal_hidden_style, sequence_id_on_display
473+
474+
elif triggered_id == "cancel-confirmation":
475+
# Cancel action
476+
return modal_hidden_style, dash.no_update
477+
478+
raise dash.exceptions.PreventUpdate
456479

457480

458481
# Modal issue let's add this later

app/layouts/main_layout.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,89 @@ def get_main_layout():
7070
# [TEMPORARY FIX] Storing the user's credentials to refresh the token when needed
7171
dcc.Store(id="to_acknowledge", data=0),
7272
dcc.Store(id="trigger_no_detections", data=False),
73+
html.Div(
74+
id="confirmation-modal",
75+
style={
76+
"display": "none", # Hidden by default
77+
"position": "fixed",
78+
"top": "0",
79+
"left": "0",
80+
"width": "100%",
81+
"height": "100%",
82+
"background-color": "rgba(0, 0, 0, 0.5)",
83+
"z-index": "1000",
84+
"justify-content": "center",
85+
"align-items": "center",
86+
},
87+
children=[
88+
html.Div(
89+
[
90+
html.H4(
91+
"Est-ce une fumée suspecte ? ",
92+
style={
93+
"margin-bottom": "20px",
94+
"font-size": "20px",
95+
"font-weight": "bold",
96+
},
97+
),
98+
html.Div(
99+
[
100+
html.Button(
101+
"Oui, c'est une fumée",
102+
id="confirm-wildfire",
103+
n_clicks=0,
104+
style={
105+
"margin-right": "10px",
106+
"padding": "10px 20px",
107+
"background-color": "#4CAF50",
108+
"color": "white",
109+
"border": "none",
110+
"border-radius": "5px",
111+
"cursor": "pointer",
112+
},
113+
),
114+
html.Button(
115+
"No, c'est un faux positif",
116+
id="confirm-non-wildfire",
117+
n_clicks=0,
118+
style={
119+
"margin-right": "10px",
120+
"padding": "10px 20px",
121+
"background-color": "#f44336",
122+
"color": "white",
123+
"border": "none",
124+
"border-radius": "5px",
125+
"cursor": "pointer",
126+
},
127+
),
128+
html.Button(
129+
"Cancel",
130+
id="cancel-confirmation",
131+
n_clicks=0,
132+
style={
133+
"padding": "10px 20px",
134+
"background-color": "#555",
135+
"color": "white",
136+
"border": "none",
137+
"border-radius": "5px",
138+
"cursor": "pointer",
139+
},
140+
),
141+
],
142+
style={"display": "flex", "justify-content": "center"},
143+
),
144+
],
145+
style={
146+
"background-color": "white",
147+
"padding": "30px",
148+
"border-radius": "10px",
149+
"box-shadow": "0 4px 8px rgba(0, 0, 0, 0.2)",
150+
"max-width": "400px",
151+
"width": "100%",
152+
"text-align": "center",
153+
},
154+
),
155+
],
156+
),
73157
]
74158
)

0 commit comments

Comments
 (0)