diff --git a/mpwo_api/migrations/versions/b7cfe0c17708_.py b/mpwo_api/migrations/versions/b7cfe0c17708_.py index 8ea38239..15b36b5e 100644 --- a/mpwo_api/migrations/versions/b7cfe0c17708_.py +++ b/mpwo_api/migrations/versions/b7cfe0c17708_.py @@ -21,6 +21,8 @@ def upgrade(): op.create_table('sports', sa.Column('id', sa.Integer(), nullable=False), sa.Column('label', sa.String(length=50), nullable=False), + sa.Column('img', sa.String(length=255), nullable=True), + sa.Column('is_default', sa.Boolean(), default=False, nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('label') ) diff --git a/mpwo_api/mpwo_api/activities/models.py b/mpwo_api/mpwo_api/activities/models.py index 09eb27ee..94370745 100644 --- a/mpwo_api/mpwo_api/activities/models.py +++ b/mpwo_api/mpwo_api/activities/models.py @@ -76,6 +76,8 @@ class Sport(db.Model): __tablename__ = "sports" id = db.Column(db.Integer, primary_key=True, autoincrement=True) label = db.Column(db.String(50), unique=True, nullable=False) + img = db.Column(db.String(255), unique=True, nullable=True) + is_default = db.Column(db.Boolean, default=False, nullable=False) activities = db.relationship('Activity', lazy=True, backref=db.backref('sports', lazy='joined')) @@ -93,7 +95,9 @@ class Sport(db.Model): return { 'id': self.id, 'label': self.label, - '_can_be_deleted': len(self.activities) == 0 + 'img': self.img, + '_can_be_deleted': + len(self.activities) == 0 and not self.is_default } diff --git a/mpwo_api/mpwo_api/activities/utils.py b/mpwo_api/mpwo_api/activities/utils.py index ac911d72..3b3a4833 100644 --- a/mpwo_api/mpwo_api/activities/utils.py +++ b/mpwo_api/mpwo_api/activities/utils.py @@ -43,7 +43,7 @@ def create_activity( duration=duration ) - if title is not None: + if title is not None and title != '': new_activity.title = title else: sport = Sport.query.filter_by(id=new_activity.sport_id).first() diff --git a/mpwo_api/mpwo_api/tests/test_sports_api.py b/mpwo_api/mpwo_api/tests/test_sports_api.py index 5514c97c..af08d8d6 100644 --- a/mpwo_api/mpwo_api/tests/test_sports_api.py +++ b/mpwo_api/mpwo_api/tests/test_sports_api.py @@ -3,12 +3,14 @@ import json expected_sport_1_cycling_result = { 'id': 1, 'label': 'Cycling', + 'img': None, '_can_be_deleted': True } expected_sport_2_running_result = { 'id': 2, 'label': 'Running', + 'img': None, '_can_be_deleted': True } diff --git a/mpwo_api/server.py b/mpwo_api/server.py index 396238d8..fd0925f1 100644 --- a/mpwo_api/server.py +++ b/mpwo_api/server.py @@ -27,12 +27,30 @@ def init_data(): password='mpwoadmin') admin.admin = True db.session.add(admin) - db.session.add(Sport(label='Cycling (Sport)')) - db.session.add(Sport(label='Cycling (Transport)')) - db.session.add(Sport(label='Hiking')) - db.session.add(Sport(label='Mountain Biking')) - db.session.add(Sport(label='Running')) - db.session.add(Sport(label='Walking')) + sport = Sport(label='Cycling (Sport)') + sport.img = '/img/sports/cycling-sport.png' + sport.is_default = True + db.session.add(sport) + sport = Sport(label='Cycling (Transport)') + sport.img = '/img/sports/cycling-transport.png' + sport.is_default = True + db.session.add(sport) + sport = Sport(label='Hiking') + sport.img = '/img/sports/hiking.png' + sport.is_default = True + db.session.add(sport) + sport = Sport(label='Mountain Biking') + sport.img = '/img/sports/mountain-biking.png' + sport.is_default = True + db.session.add(sport) + sport = Sport(label='Running') + sport.img = '/img/sports/running.png' + sport.is_default = True + db.session.add(sport) + sport = Sport(label='Walking') + sport.img = '/img/sports/walking.png' + sport.is_default = True + db.session.add(sport) db.session.commit() print('Initial data stored in database.') diff --git a/mpwo_client/public/img/photo.png b/mpwo_client/public/img/photo.png new file mode 100644 index 00000000..a802c0d7 Binary files /dev/null and b/mpwo_client/public/img/photo.png differ diff --git a/mpwo_client/public/img/sports/cycling-sport.png b/mpwo_client/public/img/sports/cycling-sport.png new file mode 100644 index 00000000..25f5e0df Binary files /dev/null and b/mpwo_client/public/img/sports/cycling-sport.png differ diff --git a/mpwo_client/public/img/sports/cycling-transport.png b/mpwo_client/public/img/sports/cycling-transport.png new file mode 100644 index 00000000..5df055c8 Binary files /dev/null and b/mpwo_client/public/img/sports/cycling-transport.png differ diff --git a/mpwo_client/public/img/sports/hiking.png b/mpwo_client/public/img/sports/hiking.png new file mode 100644 index 00000000..cc06eeb8 Binary files /dev/null and b/mpwo_client/public/img/sports/hiking.png differ diff --git a/mpwo_client/public/img/sports/mountain-biking.png b/mpwo_client/public/img/sports/mountain-biking.png new file mode 100644 index 00000000..9b26acfc Binary files /dev/null and b/mpwo_client/public/img/sports/mountain-biking.png differ diff --git a/mpwo_client/public/img/sports/running.png b/mpwo_client/public/img/sports/running.png new file mode 100644 index 00000000..fe4a2814 Binary files /dev/null and b/mpwo_client/public/img/sports/running.png differ diff --git a/mpwo_client/public/img/sports/walking.png b/mpwo_client/public/img/sports/walking.png new file mode 100644 index 00000000..1fc5c0d7 Binary files /dev/null and b/mpwo_client/public/img/sports/walking.png differ diff --git a/mpwo_client/public/index.html b/mpwo_client/public/index.html index 0bd4f0ec..909b499b 100644 --- a/mpwo_client/public/index.html +++ b/mpwo_client/public/index.html @@ -7,9 +7,10 @@ + href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" + integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" + crossorigin="anonymous"> s.id === activity.sport_id) + : [] + const activityDate = activity + ? formatActivityDate(activity.activity_date) + : null return ( -
+
- mpwo - Activity + mpwo - {title} -

- Activity -

{message ? ( {message} ) : ( @@ -46,79 +51,129 @@ class ActivityDisplay extends React.Component { }} close={() => this.setState({ displayModal: false })} />} - {activity && sports.length > 0 && ( + {activity && sport && (
-
+
- {sports.filter(sport => sport.id === activity.sport_id) - .map(sport => sport.label)} -{' '} - {activity.activity_date}{' '} - -