Book Image

Building Large-Scale Web Applications with Angular

By : Chandermani Arora, Kevin Hennessy, Christoffer Noring, Doguhan Uluca
Book Image

Building Large-Scale Web Applications with Angular

By: Chandermani Arora, Kevin Hennessy, Christoffer Noring, Doguhan Uluca

Overview of this book

<p>If you have been burnt by unreliable JavaScript frameworks before, you will be amazed by the maturity of the Angular platform. Angular enables you to build fast, efficient, and real-world web apps. In this Learning Path, you'll learn Angular and to deliver high-quality and production-grade Angular apps from design to deployment.</p> <p>You will begin by creating a simple fitness app, using the building blocks of Angular, and make your final app, Personal Trainer, by morphing the workout app into a full-fledged personal workout builder and runner with an advanced directive building - the most fundamental and powerful feature of Angular.</p> <p>You will learn the different ways of architecting Angular applications using RxJS, and some of the patterns that are involved in it. Later you’ll be introduced to the router-first architecture, a seven-step approach to designing and developing mid-to-large line-of-business apps, along with popular recipes. By the end of this book, you will be familiar with the scope of web development using Angular, Swagger, and Docker, learning patterns and practices to be successful as an individual developer on the web or as a team in the Enterprise.</p> <p>This Learning Path includes content from the following Packt products:</p> <p><span style="background-color: transparent;">•Angular 6 by Example by Chandermani Arora, Kevin Hennessy&nbsp;</span><br /><span style="background-color: transparent;">•Architecting Angular Applications with Redux, RxJS, and NgRx by Christoffer Noring</span><br /><span style="background-color: transparent;">•Angular 6 for Enterprise-Ready Web Applications by Doguhan Uluca</span></p>
Table of Contents (23 chapters)
Title Page
Copyright
Contributors
About Packt
Preface
Index

The 7 Minute Workout model


Designing the model for this app requires us to first detail the functional aspects of the 7 Minute Workout app, and then derive a model that satisfies those requirements. Based on the problem statement defined earlier, some of the obvious requirements are as follows:

  • Being able to start the workout.
  • Providing a visual clue about the current exercise and its progress. This includes the following:
    • Providing a visual depiction of the current exercise
    • Providing step-by-step instructions on how to do a specific exercise
    • The time left for the current exercise
  • Notifying the user when the workout ends.

Some other valuable features that we will add to this app are as follows:

  • The ability to pause the current workout.
  • Providing information about the next exercise to follow.
  • Providing audio clues so that the user can perform the workout without constantly looking at the screen. This includes:
    • A timer click sound
    • Details about the next exercise
    • Signaling that the exercise is about to start
  • Showing related videos for the exercise in progress and the ability to play them.

As we can see, the central themes for this app are workout and exercise. Here, a workout is a set of exercises performed in a specific order for a particular duration. So, let's go ahead and define the model for our workout and exercise.

Based on the requirements just mentioned, we will need the following details about an exercise:

  • The name. This should be unique.
  • The title. This is shown to the user.
  • The description of the exercise.
  • Instructions on how to perform the exercise.
  • Images for the exercise.
  • The name of the audio clip for the exercise.
  • Related videos.

With TypeScript, we can define the classes for our model.

The Exercise class looks as follows:

export class Exercise { 
  constructor( 
    public name: string,
    public title: string,
    public description: string, 
    public image: string,
    public nameSound?: string,
    public procedure?: string,
    public videos?: Array<string>) { }
} 

Note

TypeScript tips Declaring constructor parameters with public or private is a shorthand for creating and initializing class members at one go. The ? suffix after nameSound, procedure, and videos implies that these are optional parameters.

For the workout, we need to track the following properties:

  • The name. This should be unique.
  • The title. This is shown to the user.
  • The exercises that are part of the workout.
  • The duration for each exercise.
  • The rest duration between two exercises.

The model class to track workout progress (WorkoutPlan) looks as follows:

export class WorkoutPlan { 
  constructor( 
    public name: string, 
    public title: string, 
    public restBetweenExercise: number, 
    public exercises: ExercisePlan[], 
    public description?: string) { } 
 
  totalWorkoutDuration(): number { ... } 
} 

The totalWorkoutDuration function returns the total duration of the workout in seconds.

WorkoutPlan has a reference to another class in the preceding definition, ExercisePlan. It tracks the exercise and the duration of the exercise in a workout, which is quite apparent once we look at the definition of ExercisePlan:

export class ExercisePlan { 
  constructor( 
    public exercise: Exercise, 
    public duration: number) { } 
} 

Let me save you some typing and tell you where to get the model classes, but before that, we need to decide where to add them. We are ready for our first feature.