updating data models to have status for both week and day and updated calendar to complete based on status
This commit is contained in:
@@ -11,4 +11,9 @@ import { CalendarComponent } from "./calendar/calendar.component";
|
|||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
title = 'runningPlans';
|
title = 'runningPlans';
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<table class="noselect">
|
<table class="noselect">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Week</th>
|
<th>Week</th>
|
||||||
|
<th>Total Milage</th>
|
||||||
<th>Monday</th>
|
<th>Monday</th>
|
||||||
<th>Tuesday</th>
|
<th>Tuesday</th>
|
||||||
<th>Wednesday</th>
|
<th>Wednesday</th>
|
||||||
@@ -9,21 +10,22 @@
|
|||||||
<th>Friday</th>
|
<th>Friday</th>
|
||||||
<th>Saturday</th>
|
<th>Saturday</th>
|
||||||
<th>Sunday</th>
|
<th>Sunday</th>
|
||||||
<th>Total Milage</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
@for (planWeek of examplePlan.planDetials; track $index) {
|
@for (planWeek of examplePlan.planDetials; track planWeek.week; let i = $index) {
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td [ngClass]="{'completedWeek': planWeek.status === status.Complete}">
|
||||||
<div>Week {{planWeek.week}}</div>
|
<div>Week {{planWeek.week}}</div>
|
||||||
</td>
|
</td>
|
||||||
@for (workout of planWeek.workouts; track $index) {
|
<td [ngClass]="{'completedWeek': planWeek.status === status.Complete}">{{planWeek.totalMilage}}</td>
|
||||||
<td class="incompleteWorkout" (click)="onCellClick($event)">
|
@for (workout of planWeek.workouts; track workout.day; let j = $index) {
|
||||||
|
<td [ngClass]="{'incompleteWorkout': workout.status === status.Incomplete, 'completedWorkout': workout.status === status.Complete}"
|
||||||
|
(click)="onCellClick(i, j)">
|
||||||
<div>{{workout.type}}</div>
|
<div>{{workout.type}}</div>
|
||||||
<div>{{workout.totalDistance == 0 ? '' : workout.totalDistance + ' miles'}}</div>
|
<div>{{workout.totalDistance == 0 ? '' : workout.totalDistance + ' miles'}}</div>
|
||||||
<div>{{workout.description}}</div>
|
<div>{{workout.description}}</div>
|
||||||
</td>
|
</td>
|
||||||
}
|
}
|
||||||
<td>{{planWeek.totalMilage}}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -42,4 +42,8 @@ td {
|
|||||||
}
|
}
|
||||||
.completedWorkout:hover {
|
.completedWorkout:hover {
|
||||||
background-color: rgb(89, 161, 89);
|
background-color: rgb(89, 161, 89);
|
||||||
|
}
|
||||||
|
|
||||||
|
.completedWeek {
|
||||||
|
background-color: rgb(107, 194, 107);
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,45 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { examplePlan } from '../testData/examplePlan';
|
import { examplePlan } from '../testData/examplePlan';
|
||||||
import { Plan } from '../models/plan.model';
|
import { Plan } from '../models/plan.model';
|
||||||
|
import { CommonModule } from "@angular/common";
|
||||||
|
import { Status } from '../models/workout.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'calendar',
|
selector: 'calendar',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [],
|
imports: [CommonModule],
|
||||||
templateUrl: './calendar.component.html',
|
templateUrl: './calendar.component.html',
|
||||||
styleUrl: './calendar.component.scss'
|
styleUrl: './calendar.component.scss'
|
||||||
})
|
})
|
||||||
export class CalendarComponent {
|
export class CalendarComponent {
|
||||||
examplePlan: Plan = examplePlan;
|
examplePlan: Plan = examplePlan;
|
||||||
|
status = Status;
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onCellClick(event: Event) {
|
onCellClick(weekNum: number, dayNum: number) {
|
||||||
const target = event.currentTarget as HTMLElement;
|
let status = examplePlan.planDetials[weekNum].workouts[dayNum].status
|
||||||
if (target.classList.contains('incompleteWorkout')) {
|
if (status === Status.Incomplete) {
|
||||||
target.classList.replace('incompleteWorkout', 'completedWorkout')
|
examplePlan.planDetials[weekNum].workouts[dayNum].status = Status.Complete
|
||||||
} else if (target.classList.contains('completedWorkout')) {
|
} else if (status === Status.Complete) {
|
||||||
target.classList.replace('completedWorkout', 'incompleteWorkout')
|
examplePlan.planDetials[weekNum].workouts[dayNum].status = Status.Incomplete
|
||||||
|
}
|
||||||
|
this.checkCompletedWeek(weekNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkCompletedWeek(weekNum: number) {
|
||||||
|
let completeCount = 0;
|
||||||
|
examplePlan.planDetials[weekNum].workouts.forEach(workout => {
|
||||||
|
if (workout.status === Status.Complete) {
|
||||||
|
completeCount++
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (completeCount === 7) {
|
||||||
|
examplePlan.planDetials[weekNum].status = Status.Complete
|
||||||
|
} else {
|
||||||
|
examplePlan.planDetials[weekNum].status = Status.Incomplete
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,5 +12,12 @@ export interface Plan {
|
|||||||
export interface Week {
|
export interface Week {
|
||||||
week: number,
|
week: number,
|
||||||
totalMilage: number,
|
totalMilage: number,
|
||||||
|
status: Status,
|
||||||
workouts: Workout[]
|
workouts: Workout[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Status {
|
||||||
|
Complete = 'complete',
|
||||||
|
Incomplete = 'incomplete',
|
||||||
|
Skipped = 'skipped'
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,8 @@ export interface Workout {
|
|||||||
day: number,
|
day: number,
|
||||||
type: WorkoutType,
|
type: WorkoutType,
|
||||||
totalDistance: number,
|
totalDistance: number,
|
||||||
description: string
|
description: string,
|
||||||
|
status: Status
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum WorkoutType {
|
export enum WorkoutType {
|
||||||
@@ -16,4 +17,10 @@ export enum WorkoutType {
|
|||||||
GeneralAerobic = "General Aerobic",
|
GeneralAerobic = "General Aerobic",
|
||||||
Recovery = "Recovery",
|
Recovery = "Recovery",
|
||||||
Rest = "Rest or Crosstrain"
|
Rest = "Rest or Crosstrain"
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Status {
|
||||||
|
Complete = 'complete',
|
||||||
|
Incomplete = 'incomplete',
|
||||||
|
Skipped = 'skipped'
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user