Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions app/callbacks/display_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import ast
import json
import urllib
from datetime import date
from io import StringIO

import dash
import logging_config
import pandas as pd
from dash.dependencies import ALL, Input, Output, State
from dash.exceptions import PreventUpdate
from dateutil.relativedelta import relativedelta # type: ignore
from main import app

import config as cfg
Expand Down Expand Up @@ -58,23 +60,6 @@ def update_blinking_alarm_language(search):
return [translate[lang]["blinking_alarm"]]


@app.callback(Output("datepicker_button_text", "children"), Input("url", "search"))
def update_datepicker_language(search):
translate = {
"fr": {
"select_date": "Historique",
},
"es": {
"select_date": "Historial",
},
}

params = dict(urllib.parse.parse_qsl(search.lstrip("?"))) if search else {}
lang = params.get("lang", cfg.DEFAULT_LANGUAGE)

return translate.get(lang, {}).get("select_date", "Select Date")


@app.callback(Output("url", "search"), [Input("btn-fr", "n_clicks"), Input("btn-es", "n_clicks")])
def update_language_url(fr_clicks, es_clicks):
# Check which button has been clicked
Expand Down Expand Up @@ -168,7 +153,6 @@ def select_event_with_button(n_clicks, button_ids, api_sequences, sequence_id_on
"""
logger.info("select_event_with_button")
ctx = dash.callback_context

api_sequences = pd.read_json(StringIO(api_sequences), orient="split")
if api_sequences.empty:
return [[], 0, 1, "reset_zoom"]
Expand Down Expand Up @@ -629,10 +613,27 @@ def toggle_datepicker_modal(open_click, close_click, is_open):


@app.callback(
Output("open-datepicker-modal", "children"),
Output("my-date-picker-single", "min_date_allowed"),
Output("my-date-picker-single", "max_date_allowed"),
Output("my-date-picker-single", "initial_visible_month"),
Output("datepicker_button_text", "children"),
Input("open-datepicker-modal", "n_clicks"),
Input("my-date-picker-single", "date"),
prevent_initial_call=True,
)
def update_datepicker_button(selected_date):
if selected_date:
return f"📅 {selected_date}"
return "📅"
def update_datepicker(open_clicks, selected_date):
ctx = dash.callback_context
triggered_id = ctx.triggered_id
today = date.today()
min_date = today - relativedelta(months=3)

if triggered_id == "open-datepicker-modal":
return min_date, today, today, dash.no_update

if triggered_id == "my-date-picker-single":
if selected_date:
return dash.no_update, dash.no_update, dash.no_update, f"{selected_date}"
else:
return dash.no_update, dash.no_update, dash.no_update, ""

return dash.no_update, dash.no_update, dash.no_update, dash.no_update
6 changes: 0 additions & 6 deletions app/components/navbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details.


from datetime import date

import dash_bootstrap_components as dbc
from dash import dcc, html
from dateutil.relativedelta import relativedelta # type: ignore

pyro_logo = "https://pyronear.org/img/logo_letters_orange.png"

Expand Down Expand Up @@ -74,9 +71,6 @@ def Navbar(lang="fr"):
dbc.ModalBody(
dcc.DatePickerSingle(
id="my-date-picker-single",
min_date_allowed=date.today() - relativedelta(months=3),
max_date_allowed=date.today(),
initial_visible_month=date.today(),
)
),
dbc.ModalFooter(
Expand Down
Loading