Skip to content

Commit e21b5fb

Browse files
committed
feat: enhance workout details and request DTO with subtype handling and UI updates for current page title
1 parent e23e0e9 commit e21b5fb

6 files changed

Lines changed: 54 additions & 20 deletions

File tree

boot/src/main/kotlin/org/freekode/tp2intervals/domain/workout/WorkoutDetails.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.freekode.tp2intervals.domain.TrainingType
88

99
data class WorkoutDetails(
1010
val type: TrainingType,
11+
val subType: TrainingType,
1112
val name: String,
1213
val description: String?,
1314
val duration: Duration?,

boot/src/main/kotlin/org/freekode/tp2intervals/infrastructure/platform/trainingpeaks/workout/CreateTPWorkoutRequestDTO.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class CreateTPWorkoutRequestDTO(
3333
return CreateTPWorkoutRequestDTO(
3434
athleteId = athleteId,
3535
workoutDay = workout.date ?: LocalDate.now(),
36-
workoutTypeValueId = TPTrainingTypeMapper.getByType(workout.details.type),
37-
workoutSubTypeId = 49,
36+
workoutTypeValueId = TPTrainingTypeMapper.getWorkoutTypeValueId(workout.details.type),
37+
workoutSubTypeId = TPTrainingTypeMapper.getWorkoutSubTypeValueId(workout.details.type),
3838
title = workout.details.name,
3939
description = buildDescription(workout),
4040
totalTime = null,

boot/src/main/kotlin/org/freekode/tp2intervals/infrastructure/platform/trainingpeaks/workout/TPTrainingTypeMapper.kt

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,46 @@ import org.freekode.tp2intervals.domain.TrainingType
44

55
class TPTrainingTypeMapper {
66
companion object {
7-
private val typeMap = mapOf(
7+
8+
private val workoutTypeMap = mapOf(
89
TrainingType.SWIM to 1,
910
TrainingType.BIKE to 2,
1011
TrainingType.VIRTUAL_BIKE to 2,
12+
TrainingType.MTB to 2,
13+
TrainingType.RUN to 3,
14+
TrainingType.WALK to 3,
15+
TrainingType.WEIGHT to 9,
16+
TrainingType.NOTE to 7,
17+
TrainingType.UNKNOWN to 100
18+
)
19+
20+
private val workoutSubTypeMap = mapOf(
21+
TrainingType.SWIM to 1,
22+
TrainingType.BIKE to 2,
23+
TrainingType.VIRTUAL_BIKE to 49,
1124
TrainingType.RUN to 3,
1225
TrainingType.MTB to 8,
1326
TrainingType.WEIGHT to 9,
14-
TrainingType.NOTE to 7, // day off
15-
TrainingType.UNKNOWN to 4, // brick
16-
TrainingType.UNKNOWN to 5, // crosstrain
17-
TrainingType.UNKNOWN to 9, // custom
18-
TrainingType.UNKNOWN to 11, // xc-ski
19-
TrainingType.UNKNOWN to 12, // rowing
20-
TrainingType.UNKNOWN to 13, // walk
21-
TrainingType.UNKNOWN to 100 // other
27+
TrainingType.NOTE to 7,
28+
TrainingType.WALK to 13,
29+
TrainingType.UNKNOWN to 100
2230
)
2331

24-
fun getByValue(value: Int): TrainingType =
25-
typeMap.filterValues { it == value }.keys.firstOrNull() ?: TrainingType.UNKNOWN
32+
fun getWorkoutTypeValueId(trainingType: TrainingType): Int =
33+
workoutTypeMap[trainingType] ?: workoutTypeMap[TrainingType.UNKNOWN]!!
2634

27-
fun getByType(trainingType: TrainingType): Int = typeMap[trainingType]!!
35+
fun getWorkoutSubTypeValueId(trainingType: TrainingType): Int =
36+
workoutSubTypeMap[trainingType] ?: workoutSubTypeMap[TrainingType.UNKNOWN]!!
37+
38+
fun getByValue(value: Int): TrainingType =
39+
workoutSubTypeMap.filterValues { it == value }.keys.firstOrNull()
40+
?: TrainingType.UNKNOWN
2841

42+
/**
43+
* Keep this for backwards compatibility with existing code.
44+
* Prefer getWorkoutTypeValueId() or getWorkoutSubTypeValueId().
45+
*/
46+
fun getByType(trainingType: TrainingType): Int =
47+
getWorkoutTypeValueId(trainingType)
2948
}
30-
}
49+
}

ui/src/app/top-bar/top-bar.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<mat-icon>menu</mat-icon>
1010
</button>
1111

12+
<span class="mobile-page-title">
13+
{{ currentPageTitle }}
14+
</span>
15+
1216
} @else {
1317

1418
<div class="desktop-menu">

ui/src/app/top-bar/top-bar.component.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
gap: 8px;
1010
}
1111

12-
.mobile-title {
13-
display: flex;
14-
align-items: center;
15-
gap: 8px;
12+
.mobile-page-title {
1613
margin-left: 12px;
17-
font-weight: 500;
14+
font-weight: 600;
15+
font-size: 1rem;
1816
white-space: nowrap;
17+
overflow: hidden;
18+
text-overflow: ellipsis;
1919
}
2020

2121
.spacer {

ui/src/app/top-bar/top-bar.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ export class TopBarComponent {
3333
shareReplay()
3434
);
3535

36+
get currentPageTitle(): string {
37+
const currentUrl = this.router.url.split('?')[0].split('#')[0];
38+
39+
const currentButton = this.menuButtons.find(button =>
40+
currentUrl === button.url || currentUrl.startsWith(`${button.url}/`)
41+
);
42+
43+
return currentButton?.name ?? '';
44+
}
45+
3646
constructor(
3747
protected router: Router,
3848
private breakpointObserver: BreakpointObserver

0 commit comments

Comments
 (0)