Skip to content

Commit

Permalink
settings db insert bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanopp committed Aug 12, 2020
1 parent 451d9d0 commit 0b0d98b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
10 changes: 10 additions & 0 deletions src/fitly/assets/fitly.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ a:hover {
fill-opacity: .25 !important;
}

.DateInput_input {
height: calc(1.5em + 0.5rem + 2px);
padding: 0.25rem 0.5rem;
font-size: 0.8203125rem;
line-height: 1.5;
border-radius: 0.2rem;
text-align: center;
font-weight: 400;
}

/* Dash Table */

.dash-cell column-0 cell--selected focused{
Expand Down
37 changes: 24 additions & 13 deletions src/fitly/pages/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def athlete_card():
dbc.CardHeader(html.H4(className='text-left', children='Athlete')),
dbc.CardBody([
generate_db_setting('name', 'Name', athlete_info.name),
generate_db_setting('birthday', 'Birthday (YYYY-MM-DD)', athlete_info.birthday),
generate_db_setting('birthday', 'Birthday', athlete_info.birthday, input_type='datepicker'),
generate_db_setting('sex', 'Sex (M/F)', athlete_info.sex),
generate_db_setting('weight', 'Weight (lbs)', athlete_info.weight_lbs),
generate_db_setting('rest-hr', 'Resting HR', athlete_info.resting_hr),
Expand Down Expand Up @@ -315,13 +315,23 @@ def generate_hr_zone_card():
])


def generate_db_setting(id, title, value, placeholder=None):
def generate_db_setting(id, title, value, placeholder=None, input_type='text'):
dbc_input = dbc.Input(id=id + '-input', className='text-center col-5', type='text', bs_size="sm", value=value,
placeholder=placeholder)
if input_type == 'datepicker':
dbc_input = dcc.DatePickerSingle(
id=id + '-input',
className='text-center col-5',
initial_visible_month=value,
date=value,
month_format='MMM Do, YYYY',
)

return (
# html.Div(id=id, className='row mb-2 mt-2', children=[
html.Div(id=id, className='row align-items-center mb-2 mt-2', children=[
html.H6(title, className='col-5 mb-0'),
dbc.Input(id=id + '-input', className='text-center col-5', type='text', bs_size="sm", value=value,
placeholder=placeholder),
dbc_input,
html.Button(id=id + '-input-submit', className='col-2 fa fa-upload',
style={'display': 'inline-block', 'border': '0px'}),

Expand Down Expand Up @@ -429,8 +439,6 @@ def generate_settings_dashboard():
html.Div(className='col-12', children=[
dcc.DatePickerSingle(
id='truncate-date',
with_portal=True,
day_size=75,
style={'textAlign': 'center'},
className='mb-2',
month_format='MMM Do, YYYY',
Expand Down Expand Up @@ -493,6 +501,9 @@ def generate_settings_dashboard():


def update_athlete_db_value(value, value_name):
date_fields = ['birthday']
if value_name in date_fields:
value = datetime.strptime(value, '%Y-%m-%d')
session, engine = db_connect()
# TODO: Update athlete_filter if expanding to more users
athlete_info = session.query(athlete).filter(athlete.athlete_id == 1)
Expand Down Expand Up @@ -611,7 +622,7 @@ def update_athlete_db_value(value, value_name):
],
[
State('name-input', 'value'),
State('birthday-input', 'value'),
State('birthday-input', 'date'), # Since this is datepicker need to grab the data attribute
State('sex-input', 'value'),
State('weight-input', 'value'),
State('rest-hr-input', 'value'),
Expand Down Expand Up @@ -667,8 +678,8 @@ def save_athlete_settings(
latest_dict = {'name-input-submit': 'name',
'birthday-input-submit': 'birthday',
'sex-input-submit': 'sex',
'weight-input-submit': 'weight',
'rest-hr-input-submit': 'rest_hr',
'weight-input-submit': 'weight_lbs',
'rest-hr-input-submit': 'resting_hr',
'ride-ftp-input-submit': 'ride_ftp',
'run-ftp-input-submit': 'run_ftp',
'weekly-activity-score-goal-input-submit': 'weekly_activity_score_goal',
Expand Down Expand Up @@ -701,8 +712,8 @@ def save_athlete_settings(
'name',
'birthday',
'sex',
'weight',
'rest_hr',
'weight_lbs',
'resting_hr',
'ride_ftp',
'run_ftp',
'weekly_activity_score_goal',
Expand Down Expand Up @@ -735,8 +746,8 @@ def save_athlete_settings(
'name': name_value,
'birthday': birthday_value,
'sex': sex_value,
'weight': weight_value,
'rest_hr': rest_hr_value,
'weight_lbs': weight_value,
'resting_hr': rest_hr_value,
'ride_ftp': ride_ftp_value,
'run_ftp': run_ftp_value,
'weekly_activity_score_goal': wk_act_value,
Expand Down

0 comments on commit 0b0d98b

Please sign in to comment.