From 3be787de7f1417d59a49e2b1edf5744282810f12 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 16 Dec 2023 21:18:09 +0100 Subject: [PATCH] API & Client - add a user preference for dark mode --- ...14f48e46f320_add_dark_theme_preferences.py | 34 ++++++++++++++++++ fittrackee/tests/users/test_auth_api.py | 2 ++ fittrackee/tests/users/test_users_model.py | 9 +++++ fittrackee/users/auth.py | 9 +++++ fittrackee/users/models.py | 2 ++ fittrackee_client/src/components/NavBar.vue | 29 ++++++++------- .../User/ProfileDisplay/UserPreferences.vue | 9 +++++ .../ProfileEdition/UserPreferencesEdition.vue | 35 ++++++++++++++++++- fittrackee_client/src/locales/en/user.json | 8 +++++ fittrackee_client/src/locales/fr/user.json | 8 +++++ .../src/store/modules/authUser/actions.ts | 8 +++++ .../src/store/modules/root/enums.ts | 2 ++ .../src/store/modules/root/getters.ts | 3 ++ .../src/store/modules/root/mutations.ts | 6 ++++ .../src/store/modules/root/state.ts | 1 + .../src/store/modules/root/types.ts | 7 ++++ fittrackee_client/src/types/user.ts | 2 ++ 17 files changed, 161 insertions(+), 13 deletions(-) create mode 100644 fittrackee/migrations/versions/35_14f48e46f320_add_dark_theme_preferences.py diff --git a/fittrackee/migrations/versions/35_14f48e46f320_add_dark_theme_preferences.py b/fittrackee/migrations/versions/35_14f48e46f320_add_dark_theme_preferences.py new file mode 100644 index 00000000..b2a95b3c --- /dev/null +++ b/fittrackee/migrations/versions/35_14f48e46f320_add_dark_theme_preferences.py @@ -0,0 +1,34 @@ +"""add dark theme preferences + +Revision ID: 14f48e46f320 +Revises: 24eb097614e4 +Create Date: 2023-12-16 18:35:31.377007 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '14f48e46f320' +down_revision = '24eb097614e4' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('users', schema=None) as batch_op: + batch_op.add_column( + sa.Column('use_dark_mode', sa.Boolean(), nullable=True) + ) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('users', schema=None) as batch_op: + batch_op.drop_column('use_dark_mode') + + # ### end Alembic commands ### diff --git a/fittrackee/tests/users/test_auth_api.py b/fittrackee/tests/users/test_auth_api.py index c26b1ea2..e86fd699 100644 --- a/fittrackee/tests/users/test_auth_api.py +++ b/fittrackee/tests/users/test_auth_api.py @@ -1459,6 +1459,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin): imperial_units=True, display_ascent=False, start_elevation_at_zero=False, + use_dark_mode=True, use_raw_gpx_speed=True, date_format='yyyy-MM-dd', ) @@ -1478,6 +1479,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin): assert data['data']['timezone'] == 'America/New_York' assert data['data']['date_format'] == 'yyyy-MM-dd' assert data['data']['weekm'] is True + assert data['data']['use_dark_mode'] is True @pytest.mark.parametrize( 'client_scope, can_access', diff --git a/fittrackee/tests/users/test_users_model.py b/fittrackee/tests/users/test_users_model.py index 7da4c89a..6d92a1dc 100644 --- a/fittrackee/tests/users/test_users_model.py +++ b/fittrackee/tests/users/test_users_model.py @@ -77,6 +77,12 @@ class TestUserSerializeAsAuthUser(UserModelAssertMixin): assert serialized_user['timezone'] == user_1.timezone assert serialized_user['weekm'] == user_1.weekm assert serialized_user['display_ascent'] == user_1.display_ascent + assert ( + serialized_user['start_elevation_at_zero'] + == user_1.start_elevation_at_zero + ) + assert serialized_user['use_raw_gpx_speed'] == user_1.use_raw_gpx_speed + assert serialized_user['use_dark_mode'] == user_1.use_dark_mode def test_it_returns_workouts_infos(self, app: Flask, user_1: User) -> None: serialized_user = user_1.serialize(user_1) @@ -155,6 +161,9 @@ class TestUserSerializeAsAdmin(UserModelAssertMixin): assert 'language' not in serialized_user assert 'timezone' not in serialized_user assert 'weekm' not in serialized_user + assert 'start_elevation_at_zero' not in serialized_user + assert 'use_raw_gpx_speed' not in serialized_user + assert 'use_dark_mode' not in serialized_user def test_it_returns_workouts_infos( self, app: Flask, user_1_admin: User, user_2: User diff --git a/fittrackee/users/auth.py b/fittrackee/users/auth.py index 2da61719..0d606ad2 100644 --- a/fittrackee/users/auth.py +++ b/fittrackee/users/auth.py @@ -361,6 +361,7 @@ def get_authenticated_user_profile( "total_ascent": 720.35, "total_distance": 67.895, "total_duration": "6:50:27", + "use_dark_mode": null, "use_raw_gpx_speed": false, "username": "sam", "weekm": false @@ -478,6 +479,7 @@ def edit_user(auth_user: User) -> Union[Dict, HttpResponse]: "total_ascent": 720.35, "total_distance": 67.895, "total_duration": "6:50:27", + "use_dark_mode": null, "use_raw_gpx_speed": false, "username": "sam" "weekm": true, @@ -650,6 +652,7 @@ def update_user_account(auth_user: User) -> Union[Dict, HttpResponse]: "total_ascent": 720.35, "total_distance": 67.895, "total_duration": "6:50:27", + "use_dark_mode": null, "use_raw_gpx_speed": false, "username": "sam" "weekm": true, @@ -878,6 +881,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]: "total_ascent": 720.35, "total_distance": 67.895, "total_duration": "6:50:27", + "use_dark_mode": null, "use_raw_gpx_speed": true, "username": "sam" "weekm": true, @@ -892,6 +896,8 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]: : Union[Dict, HttpResponse]: 'language', 'start_elevation_at_zero', 'timezone', + 'use_dark_mode', 'use_raw_gpx_speed', 'weekm', } @@ -928,6 +935,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]: language = get_language(post_data.get('language')) start_elevation_at_zero = post_data.get('start_elevation_at_zero') use_raw_gpx_speed = post_data.get('use_raw_gpx_speed') + use_dark_mode = post_data.get('use_dark_mode') timezone = post_data.get('timezone') weekm = post_data.get('weekm') @@ -938,6 +946,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]: auth_user.language = language auth_user.start_elevation_at_zero = start_elevation_at_zero auth_user.timezone = timezone + auth_user.use_dark_mode = use_dark_mode auth_user.use_raw_gpx_speed = use_raw_gpx_speed auth_user.weekm = weekm db.session.commit() diff --git a/fittrackee/users/models.py b/fittrackee/users/models.py index 5298c496..c26d41ac 100644 --- a/fittrackee/users/models.py +++ b/fittrackee/users/models.py @@ -63,6 +63,7 @@ class User(BaseModel): db.Boolean, default=True, nullable=False ) use_raw_gpx_speed = db.Column(db.Boolean, default=False, nullable=False) + use_dark_mode = db.Column(db.Boolean, default=False, nullable=True) def __repr__(self) -> str: return f'' @@ -217,6 +218,7 @@ class User(BaseModel): 'language': self.language, 'start_elevation_at_zero': self.start_elevation_at_zero, 'timezone': self.timezone, + 'use_dark_mode': self.use_dark_mode, 'use_raw_gpx_speed': self.use_raw_gpx_speed, 'weekm': self.weekm, }, diff --git a/fittrackee_client/src/components/NavBar.vue b/fittrackee_client/src/components/NavBar.vue index 4b351b74..16c0e5de 100644 --- a/fittrackee_client/src/components/NavBar.vue +++ b/fittrackee_client/src/components/NavBar.vue @@ -107,7 +107,7 @@