From 10ef8fa4a702e8cb8ad071aa4c516ee208904210 Mon Sep 17 00:00:00 2001
From: Pablo Deeleman
Date: Fri, 18 Mar 2016 00:26:48 +0100
Subject: [PATCH] better code formatting and indenting for chapter 8
---
chapter_08/app/app.component.ts | 47 +++++------
chapter_08/app/login/login.component.ts | 84 +++++++++----------
.../shared/services/authentication.service.ts | 58 ++++++-------
.../app/timer/timer-widget.component.ts | 4 +-
chapter_08/app/timer/timer.component.ts | 10 +--
5 files changed, 101 insertions(+), 102 deletions(-)
diff --git a/chapter_08/app/app.component.ts b/chapter_08/app/app.component.ts
index 7039123..b2b4de6 100644
--- a/chapter_08/app/app.component.ts
+++ b/chapter_08/app/app.component.ts
@@ -1,6 +1,6 @@
import { Component } from 'angular2/core';
import { TimerComponent } from './timer/timer';
-import { TASKS_DIRECTIVES, TasksComponent, TaskEditorComponent } from './tasks/tasks';
+import { TasksComponent, TaskEditorComponent } from './tasks/tasks';
import { SHARED_PROVIDERS, SHARED_DIRECTIVES, AuthenticationService } from './shared/shared';
import { HTTP_PROVIDERS } from 'angular2/http';
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from 'angular2/router';
@@ -34,34 +34,33 @@ import { LoginComponent } from './login/login';
- `
+ `
})
@RouteConfig([
- { path: '', name: 'Home', redirectTo: ['TasksComponent'] },
- { path: 'tasks', name: 'TasksComponent', component: TasksComponent, useAsDefault: true },
- { path: 'tasks/editor', name: 'TaskEditorComponent', component: TaskEditorComponent },
- { path: 'timer/...', name: 'TimerComponent', component: TimerComponent },
- { path: 'login', name: 'LoginComponent', component: LoginComponent }
+ { path: '', name: 'Home', redirectTo: ['TasksComponent'] },
+ { path: 'tasks', name: 'TasksComponent', component: TasksComponent, useAsDefault: true },
+ { path: 'tasks/editor', name: 'TaskEditorComponent', component: TaskEditorComponent },
+ { path: 'timer/...', name: 'TimerComponent', component: TimerComponent },
+ { path: 'login', name: 'LoginComponent', component: LoginComponent }
])
export default class AppComponent {
- userIsLogged: boolean;
+ userIsLogged: boolean;
- constructor(
- private authenticationService: AuthenticationService,
- private router: Router)
- {
- authenticationService.userLoggedInStatus.subscribe(userIsloggedIn => {
- this.userIsLogged = userIsloggedIn;
- });
- }
+ constructor(
+ private authenticationService: AuthenticationService,
+ private router: Router) {
+ authenticationService.userLoggedInStatus.subscribe(userIsloggedIn => {
+ this.userIsLogged = userIsloggedIn;
+ });
+ }
- logout($event): void {
- $event.preventDefault();
+ logout($event): void {
+ $event.preventDefault();
- this.authenticationService.logout().then(success => {
- if(success) {
- this.router.navigateByUrl('/');
- }
- });
- }
+ this.authenticationService.logout().then(success => {
+ if (success) {
+ this.router.navigateByUrl('/');
+ }
+ });
+ }
}
diff --git a/chapter_08/app/login/login.component.ts b/chapter_08/app/login/login.component.ts
index a805924..ea1d3ef 100644
--- a/chapter_08/app/login/login.component.ts
+++ b/chapter_08/app/login/login.component.ts
@@ -4,50 +4,50 @@ import { Router } from 'angular2/router';
import { AuthenticationService } from '../shared/shared';
@Component({
- selector: 'pomodoro-login',
- templateUrl: 'app/login/login.component.html'
+ selector: 'pomodoro-login',
+ templateUrl: 'app/login/login.component.html'
})
export default class LoginComponent {
- loginForm: ControlGroup;
- showAlert: boolean = false;
- showUsernameHint: boolean = false;
-
- constructor(
- formBuilder: FormBuilder,
- private router: Router,
- private authenticationService: AuthenticationService) {
- this.loginForm = formBuilder.group({
- username: ['', Validators.compose([Validators.required, this.usernameValidator])],
- password: ['', Validators.required]
- });
-
- const username = this.loginForm.controls['username'];
- username.valueChanges.subscribe(value => {
- this.showUsernameHint = (username.dirty && value.indexOf('@') < 0);
- });
-
- }
-
- private usernameValidator(control: Control): {[key: string]: boolean} {
- if(!/(.+)@(.+){2,}\.(.+){2,}/.test(control.value)) {
- return {
- 'emailNotValid': true
- };
- }
-
- return null;
+ loginForm: ControlGroup;
+ showAlert: boolean = false;
+ showUsernameHint: boolean = false;
+
+ constructor(
+ formBuilder: FormBuilder,
+ private router: Router,
+ private authenticationService: AuthenticationService) {
+ this.loginForm = formBuilder.group({
+ username: ['', Validators.compose([Validators.required, this.usernameValidator])],
+ password: ['', Validators.required]
+ });
+
+ const username = this.loginForm.controls['username'];
+ username.valueChanges.subscribe(value => {
+ this.showUsernameHint = (username.dirty && value.indexOf('@') < 0);
+ });
+
+ }
+
+ private usernameValidator(control: Control): { [key: string]: boolean } {
+ if (!/(.+)@(.+){2,}\.(.+){2,}/.test(control.value)) {
+ return {
+ 'emailNotValid': true
+ };
}
- authenticate() {
- this.showAlert = !this.loginForm.valid && this.loginForm.dirty;
- let credentials: any = this.loginForm.value;
-
- this.authenticationService.login(credentials).then(success => {
- if(success) {
- this.router.navigateByUrl('/');
- } else {
- this.showAlert = true;
- }
- });
- }
+ return null;
+ }
+
+ authenticate() {
+ this.showAlert = !this.loginForm.valid && this.loginForm.dirty;
+ let credentials: any = this.loginForm.value;
+
+ this.authenticationService.login(credentials).then(success => {
+ if (success) {
+ this.router.navigateByUrl('/');
+ } else {
+ this.showAlert = true;
+ }
+ });
+ }
}
diff --git a/chapter_08/app/shared/services/authentication.service.ts b/chapter_08/app/shared/services/authentication.service.ts
index 6aee2a3..489d53f 100644
--- a/chapter_08/app/shared/services/authentication.service.ts
+++ b/chapter_08/app/shared/services/authentication.service.ts
@@ -2,39 +2,39 @@ import { Injectable, EventEmitter } from 'angular2/core';
@Injectable()
export default class AuthenticationService {
- userLoggedInStatus: EventEmitter;
+ userLoggedInStatus: EventEmitter;
- constructor() {
- this.userLoggedInStatus = new EventEmitter();
- }
+ constructor() {
+ this.userLoggedInStatus = new EventEmitter();
+ }
- login({ username, password }): Promise {
- return new Promise(resolve => {
- let validCredentials: boolean = false;
+ login({ username, password }): Promise {
+ return new Promise(resolve => {
+ let validCredentials: boolean = false;
- // @NOTE: In a normal case scenario this check should
- // be performed against a web service, which would return
- // the session token upon validating the user successfully
- if (username === 'john.doe@mail.com' &&
- password === 'letmein') {
- validCredentials = true;
- window.sessionStorage.setItem('token', 'eyJhbGciOi');
- }
+ // @NOTE: In a normal case scenario this check should
+ // be performed against a web service, which would return
+ // the session token upon validating the user successfully
+ if (username === 'john.doe@mail.com' &&
+ password === 'letmein') {
+ validCredentials = true;
+ window.sessionStorage.setItem('token', 'eyJhbGciOi');
+ }
- this.userLoggedInStatus.emit(validCredentials);
- resolve(validCredentials);
- });
- }
+ this.userLoggedInStatus.emit(validCredentials);
+ resolve(validCredentials);
+ });
+ }
- logout(): Promise {
- return new Promise(resolve => {
- window.sessionStorage.removeItem('token');
- this.userLoggedInStatus.emit(false);
- resolve(true);
- });
- }
+ logout(): Promise {
+ return new Promise(resolve => {
+ window.sessionStorage.removeItem('token');
+ this.userLoggedInStatus.emit(false);
+ resolve(true);
+ });
+ }
- static grantAccess(): boolean {
- return !!window.sessionStorage.getItem('token');
- }
+ static grantAccess(): boolean {
+ return !!window.sessionStorage.getItem('token');
+ }
}
diff --git a/chapter_08/app/timer/timer-widget.component.ts b/chapter_08/app/timer/timer-widget.component.ts
index e97c05f..2ef3857 100644
--- a/chapter_08/app/timer/timer-widget.component.ts
+++ b/chapter_08/app/timer/timer-widget.component.ts
@@ -1,4 +1,4 @@
-import { Component, Input, OnInit } from 'angular2/core';
+import { Component, OnInit } from 'angular2/core';
import { RouteParams, CanReuse, OnReuse } from 'angular2/router';
import { SettingsService, TaskService } from '../shared/shared';
@@ -16,7 +16,7 @@ import { SettingsService, TaskService } from '../shared/shared';
`
})
-export default class TimerWidgetComponent {
+export default class TimerWidgetComponent implements OnInit, CanReuse, OnReuse {
minutes: number;
seconds: number;
isPaused: boolean;
diff --git a/chapter_08/app/timer/timer.component.ts b/chapter_08/app/timer/timer.component.ts
index 1ee0626..c68360d 100644
--- a/chapter_08/app/timer/timer.component.ts
+++ b/chapter_08/app/timer/timer.component.ts
@@ -3,12 +3,12 @@ import { RouteConfig, ROUTER_DIRECTIVES } from 'angular2/router';
import TimerWidgetComponent from './timer-widget.component';
@Component({
- selector: 'pomodoro-timer',
- directives: [ROUTER_DIRECTIVES],
- template: ''
+ selector: 'pomodoro-timer',
+ directives: [ROUTER_DIRECTIVES],
+ template: ''
})
@RouteConfig([
- { path: '/task/:id', name: 'TaskTimer', component: TimerWidgetComponent },
- { path: '/', name: 'GenericTimer', component: TimerWidgetComponent, useAsDefault: true }
+ { path: '/task/:id', name: 'TaskTimer', component: TimerWidgetComponent },
+ { path: '/', name: 'GenericTimer', component: TimerWidgetComponent, useAsDefault: true }
])
export default class TimerComponent {}