Skip to content

Instantly share code, notes, and snippets.

@chandermani
Last active May 13, 2018 14:51
Show Gist options
  • Select an option

  • Save chandermani/4d9ab6b62a53cd69a23dc294da242c6d to your computer and use it in GitHub Desktop.

Select an option

Save chandermani/4d9ab6b62a53cd69a23dc294da242c6d to your computer and use it in GitHub Desktop.

Revisions

  1. chandermani revised this gist May 13, 2018. 1 changed file with 37 additions and 35 deletions.
    72 changes: 37 additions & 35 deletions workout-history-tracker-v1.service.ts
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,51 @@
    import { ExercisePlan } from '../workout-runner/model';
    import { CoreModule } from './core.module';
    import { Injectable } from '@angular/core';
    import { ExercisePlan } from '../workout-runner/model';

    @Injectable({
    providedIn: CoreModule
    })
    export class WorkoutHistoryTrackerService {
    private maxHistoryItems = 20; //Tracking last 20 exercises
    private currentWorkoutLog: WorkoutLogEntry = null;
    private workoutHistory: Array<WorkoutLogEntry> = [];
    private workoutTracked: boolean;
    private maxHistoryItems = 20; // Tracking last 20 exercises
    private currentWorkoutLog: WorkoutLogEntry = null;
    private workoutHistory: Array<WorkoutLogEntry> = [];
    private workoutTracked: boolean;

    constructor() { }
    constructor() { }

    get tracking(): boolean {
    return this.workoutTracked;
    }
    startTracking() {
    this.workoutTracked = true;
    this.currentWorkoutLog = new WorkoutLogEntry(new Date());
    if (this.workoutHistory.length >= this.maxHistoryItems) {
    this.workoutHistory.shift();
    }
    this.workoutHistory.push(this.currentWorkoutLog);
    get tracking(): boolean {
    return this.workoutTracked;
    }
    startTracking() {
    this.workoutTracked = true;
    this.currentWorkoutLog = new WorkoutLogEntry(new Date());
    if (this.workoutHistory.length >= this.maxHistoryItems) {
    this.workoutHistory.shift();
    }
    this.workoutHistory.push(this.currentWorkoutLog);
    }

    exerciseComplete(exercise: ExercisePlan) {
    this.currentWorkoutLog.lastExercise = exercise.exercise.title;
    ++this.currentWorkoutLog.exercisesDone;
    }
    exerciseComplete(exercise: ExercisePlan) {
    this.currentWorkoutLog.lastExercise = exercise.exercise.title;
    ++this.currentWorkoutLog.exercisesDone;
    }

    endTracking(completed: boolean) {
    this.currentWorkoutLog.completed = completed;
    this.currentWorkoutLog.endedOn = new Date();
    this.currentWorkoutLog = null;
    this.workoutTracked = false;
    };
    getHistory(): Array<WorkoutLogEntry> {
    return this.workoutHistory;
    }
    endTracking(completed: boolean) {
    this.currentWorkoutLog.completed = completed;
    this.currentWorkoutLog.endedOn = new Date();
    this.currentWorkoutLog = null;
    this.workoutTracked = false;
    }
    getHistory(): Array<WorkoutLogEntry> {
    return this.workoutHistory;
    }
    }

    export class WorkoutLogEntry {
    constructor(
    public startedOn: Date,
    public completed: boolean = false,
    public exercisesDone: number = 0,
    public lastExercise?: string,
    public endedOn?: Date) { }
    constructor(
    public startedOn: Date,
    public completed: boolean = false,
    public exercisesDone: number = 0,
    public lastExercise?: string,
    public endedOn?: Date) { }
    }
  2. chandermani revised this gist May 10, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions workout-history-tracker-v1.service.ts
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    import { ExercisePlan } from '../workout-runner/model';
    import { CoreModule } from './core.module';
    @Injectable({
    providedIn: CoreModule
    })
    export class WorkoutHistoryTrackerService {
    private maxHistoryItems = 20; //Tracking last 20 exercises
    private currentWorkoutLog: WorkoutLogEntry = null;
  3. chandermani revised this gist May 10, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions workout-history-tracker-v1.service.ts
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    import { ExercisePlan } from '../workout-runner/model';
    import { CoreModule } from './core.module';
    export class WorkoutHistoryTrackerService {
    private maxHistoryItems = 20; //Tracking last 20 exercises
    private currentWorkoutLog: WorkoutLogEntry = null;
  4. chandermani created this gist Feb 13, 2018.
    45 changes: 45 additions & 0 deletions workout-history-tracker-v1.service.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    import { ExercisePlan } from '../workout-runner/model';
    export class WorkoutHistoryTrackerService {
    private maxHistoryItems = 20; //Tracking last 20 exercises
    private currentWorkoutLog: WorkoutLogEntry = null;
    private workoutHistory: Array<WorkoutLogEntry> = [];
    private workoutTracked: boolean;

    constructor() { }

    get tracking(): boolean {
    return this.workoutTracked;
    }
    startTracking() {
    this.workoutTracked = true;
    this.currentWorkoutLog = new WorkoutLogEntry(new Date());
    if (this.workoutHistory.length >= this.maxHistoryItems) {
    this.workoutHistory.shift();
    }
    this.workoutHistory.push(this.currentWorkoutLog);
    }

    exerciseComplete(exercise: ExercisePlan) {
    this.currentWorkoutLog.lastExercise = exercise.exercise.title;
    ++this.currentWorkoutLog.exercisesDone;
    }

    endTracking(completed: boolean) {
    this.currentWorkoutLog.completed = completed;
    this.currentWorkoutLog.endedOn = new Date();
    this.currentWorkoutLog = null;
    this.workoutTracked = false;
    };
    getHistory(): Array<WorkoutLogEntry> {
    return this.workoutHistory;
    }
    }

    export class WorkoutLogEntry {
    constructor(
    public startedOn: Date,
    public completed: boolean = false,
    public exercisesDone: number = 0,
    public lastExercise?: string,
    public endedOn?: Date) { }
    }