def save_config_and_update_page(self): context = self.view.context io = IO(self.view.current_user) config = io.read_user_config() config.activity_config.charts_to_plot = context['switches'] io.save_user_config(config) return ActivityPresenter(io, context).make_layout(), config
def activity_delete_intervals_and_refresh_view(self): context = self.view.context activity_id = int(context['activity']) io = IO(self.view.current_user) config = io.read_user_config() activity = io.get_hardio_activity_by_id(activity_id) activity.delete_intervals() io.save_activity(activity) return ActivityPresenter(io, context).make_figure(activity, config)
def activity_find_intervals_and_refresh_view(self): context = self.view.context activity_id = int(context['activity']) io = IO(self.view.current_user) config = io.read_user_config() activity = io.get_hardio_activity_by_id(int(activity_id)) interval_finder_params = context['interval_finder_prams'] found_intervals = activity.find_intervals(**interval_finder_params) activity.add_intervals(found_intervals) io.save_activity(activity) return ActivityPresenter(io, context).make_figure(activity, config)
def activity_create_intervals_and_refresh_view(self): context = self.view.context intervals_range = self._relayout_data_to_range( context['intervals_range']) activity_id = int(context['activity']) io = IO(self.view.current_user) config = io.read_user_config() if intervals_range: activity = io.get_hardio_activity_by_id(activity_id) activity.add_interval(*intervals_range) io.save_activity(activity) return ActivityPresenter(io, context).make_figure(activity, config) else: return dash.no_update
def set_month_year(io: IO, user_selected_moth_year: str) -> tuple[int, int]: """ Produce Month/Year combination to filter calendar by :param io: instance of IO object :param user_selected_moth_year: string containing user-selected combination of Month/Year :return: tuple[int, int] Month, Year """ config = io.read_user_config() if user_selected_moth_year: month_year = _month_year_to_tuple(user_selected_moth_year) update_user_config_in_db(config, io, month_year) month, year = month_year elif config.user_calendar_date_preference: month, year = config.user_calendar_date_preference else: month: int = datetime.now().month year: int = datetime.now().year return month, year
def render_page_content(pathname, user_config) -> dash.Dash.layout: """ Callback defines general structure of an multi-page Dash app. :param pathname: string :param user_config: json containing user configuration :return: layout, username, user_config """ io = IO(current_user.id) config = io.read_user_config() if pathname == "/application/": return [dash_app.presenter.get_calendar()], [current_user.username] elif pathname == "/power/": return [html.H2(f"Not yet implemented")], [current_user.username] elif pathname == "/fitness/": return [html.H2(f"Not yet implemented")], [current_user.username] elif pathname == "/application/activity": dash_app.context = {'activity': None} return [dash_app.presenter.get_activity()], [current_user.username] elif "/application/activity/" in pathname: activity_id = pathname.split("/")[-1] dash_app.context = {'activity': activity_id} return [dash_app.presenter.get_activity()], [current_user.username] elif pathname == "/application/test_strava": return [ html.H1("Activity", style={"textAlign": "center"}), html.H2(f"Current user id: {current_user.id}"), test_strava_methods_page.make_layout() ], [current_user.username] # If the user tries to reach a different page, return a 404 message return dbc.Card([ html.H1("404: Not Found", className="text-danger"), html.Hr(), html.P(f"The pathname {pathname} was not recognized...") ]), [current_user.username]