Skip to content

Commit

Permalink
Chapter 9 upgraded to RC.1. References to angular-upgrade remvoed
Browse files Browse the repository at this point in the history
  • Loading branch information
deeleman committed May 7, 2016
1 parent 48c4e6a commit a405a67
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 51 deletions.
10 changes: 5 additions & 5 deletions chapter_09/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Component } from 'angular2/core';
import { Component } from '@angular/core';
import { SHARED_PROVIDERS, SHARED_DIRECTIVES, AuthenticationService } from './shared/shared';
import { HTTP_PROVIDERS } from 'angular2/http';
import { ROUTER_PROVIDERS, RouteConfig, ROUTER_DIRECTIVES, Router } from 'angular2/router';
import { HTTP_PROVIDERS } from '@angular/http';
import { ROUTER_PROVIDERS, ROUTER_DIRECTIVES, Router, RouteConfig } from '@angular/router-deprecated';
import { TimerComponent } from './timer/timer';
import { TasksComponent, TaskEditorComponent } from './tasks/tasks';
import { FORM_PROVIDERS } from 'angular2/common';
import { FORM_PROVIDERS } from '@angular/common';
import { LoginComponent } from './login/login';
import { AnimationBuilder } from 'angular2/src/animate/animation_builder';
import { AnimationBuilder } from '@angular/platform-browser/src/animate/animation_builder';

@Component({
selector: 'pomodoro-app',
Expand Down
6 changes: 3 additions & 3 deletions chapter_09/app/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from 'angular2/core';
import { FormBuilder, ControlGroup, Validators, Control } from 'angular2/common';
import { Router } from 'angular2/router';
import { Component } from '@angular/core';
import { FormBuilder, ControlGroup, Validators, Control } from '@angular/common';
import { Router } from '@angular/router-deprecated';
import { AuthenticationService } from '../shared/shared';

@Component({
Expand Down
3 changes: 2 additions & 1 deletion chapter_09/app/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'rxjs/add/operator/map';
import { bootstrap } from 'angular2/platform/browser';

import { bootstrap } from '@angular/platform-browser-dynamic';
import AppComponent from './app.component';

bootstrap(AppComponent, [])
6 changes: 3 additions & 3 deletions chapter_09/app/shared/directives/highlight.directive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Directive, ElementRef } from 'angular2/core';
import { AnimationBuilder } from 'angular2/src/animate/animation_builder';
import { CssAnimationBuilder } from 'angular2/src/animate/css_animation_builder';
import { Directive, ElementRef } from '@angular/core';
import { AnimationBuilder } from '@angular/platform-browser/src/animate/animation_builder';
import { CssAnimationBuilder } from '@angular/platform-browser/src/animate/css_animation_builder';

@Directive({
selector: '.pomodoro-highlight',
Expand Down
4 changes: 2 additions & 2 deletions chapter_09/app/shared/directives/router-outlet.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {
ViewContainerRef,
DynamicComponentLoader,
Attribute,
Input } from 'angular2/core';
Input } from '@angular/core';
import {
Router,
RouterOutlet,
ComponentInstruction } from 'angular2/router';
ComponentInstruction } from '@angular/router-deprecated';
import { AuthenticationService } from '../shared';

@Directive({
Expand Down
2 changes: 1 addition & 1 deletion chapter_09/app/shared/pipes/formatted-time.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Pipe, PipeTransform } from 'angular2/core';
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'pomodoroFormattedTime'
Expand Down
4 changes: 2 additions & 2 deletions chapter_09/app/shared/pipes/queued-only.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Pipe, PipeTransform } from 'angular2/core';
import { Pipe, PipeTransform } from '@angular/core';
import { Queueable } from '../shared';

@Pipe({
Expand All @@ -8,7 +8,7 @@ import { Queueable } from '../shared';
export default class QueuedOnlyPipe implements PipeTransform {
transform(queueableItems: Queueable[], ...args: any[]): Queueable[] {
return queueableItems.filter((queueableItem: Queueable) => {
return queueableItem.queued === args[0]
return queueableItem.queued === args[0];
});
}
}
33 changes: 31 additions & 2 deletions chapter_09/app/shared/services/authentication.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Injectable, EventEmitter } from 'angular2/core';
import { Injectable, EventEmitter } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export default class AuthenticationService {
userIsloggedIn: EventEmitter<boolean>;

constructor() {
constructor(public http: Http) {
this.userIsloggedIn = new EventEmitter();
}

Expand All @@ -15,6 +17,7 @@ export default class AuthenticationService {
// @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
// Please refer to {@link httpLogin()}.
if (username === '[email protected]' &&
password === 'letmein') {
validCredentials = true;
Expand All @@ -26,6 +29,32 @@ export default class AuthenticationService {
});
}

httpLogin(credentials): Promise<boolean> {
return new Promise(resolve => {

const url = '/api/authentication'; // Or your own API Auth url
const body = JSON.stringify(credentials);
const headers = new Headers({ 'Content-Type': 'application/json' });
const options = new RequestOptions({ headers: headers });

this.http.post(url, body, options)
.map(response => response.json())
.subscribe(authResponse => {
let validCredentials: boolean = false;

if(authResponse && authResponse.token) {
validCredentials = true;
window.sessionStorage.setItem('token', authResponse.token);
}

this.userIsloggedIn.emit(validCredentials);
resolve(validCredentials);
},
error => console.log(error)
);
});
}

logout(): Promise<boolean> {
return new Promise(resolve => {
window.sessionStorage.removeItem('token');
Expand Down
2 changes: 1 addition & 1 deletion chapter_09/app/shared/services/settings.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from 'angular2/core';
import { Injectable } from '@angular/core';

@Injectable()
export default class SettingsService {
Expand Down
5 changes: 3 additions & 2 deletions chapter_09/app/shared/services/task.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Injectable } from 'angular2/core';
import { Http, Response } from 'angular2/http';
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Task } from '../shared';
import 'rxjs/add/operator/map';

@Injectable()
export default class TaskService {
Expand Down
6 changes: 3 additions & 3 deletions chapter_09/app/tasks/task-editor.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component } from 'angular2/core';
import { Title } from 'angular2/platform/browser';
import { Component } from '@angular/core';
import { Title } from '@angular/platform-browser';
import {
Router,
ROUTER_DIRECTIVES,
ComponentInstruction,
CanActivate,
OnActivate,
CanDeactivate,
OnDeactivate } from 'angular2/router';
OnDeactivate } from '@angular/router-deprecated';
import { Task, TaskService, AuthenticationService } from '../shared/shared';

@Component({
Expand Down
2 changes: 1 addition & 1 deletion chapter_09/app/tasks/task-icons.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, OnInit } from 'angular2/core';
import { Component, Input, OnInit } from '@angular/core';
import { Task } from '../shared/shared';

@Component({
Expand Down
2 changes: 1 addition & 1 deletion chapter_09/app/tasks/task-tooltip.directive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Task } from '../shared/shared';
import { Input, Directive, HostListener } from 'angular2/core';
import { Input, Directive, HostListener } from '@angular/core';

@Directive({
selector: '[task]'
Expand Down
4 changes: 2 additions & 2 deletions chapter_09/app/tasks/tasks.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from 'angular2/core';
import { Component, OnInit } from '@angular/core';
import TaskIconsComponent from './task-icons.component';
import TaskTooltipDirective from './task-tooltip.directive';
import {
Expand All @@ -8,7 +8,7 @@ import {
SHARED_PIPES,
SHARED_DIRECTIVES
} from '../shared/shared';
import { Router } from 'angular2/router';
import { Router } from '@angular/router-deprecated';

@Component({
selector: 'pomodoro-tasks',
Expand Down
9 changes: 5 additions & 4 deletions chapter_09/app/timer/timer-widget.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Component, OnInit, ElementRef } from 'angular2/core';
import { RouteParams, CanReuse, OnReuse } from 'angular2/router';
import { Component, OnInit, ElementRef } from '@angular/core';
import { RouteParams, CanReuse, OnReuse } from '@angular/router-deprecated';
import { SettingsService, TaskService } from '../shared/shared';
import { AnimationBuilder } from 'angular2/src/animate/animation_builder';
import { CssAnimationBuilder } from 'angular2/src/animate/css_animation_builder';
import { AnimationBuilder } from '@angular/platform-browser/src/animate/animation_builder';
import { CssAnimationBuilder } from '@angular/platform-browser/src/animate/css_animation_builder';

@Component({
selector: 'pomodoro-timer-widget',
styleUrls: ['app/timer/timer-widget.component.css'],
providers: [],
template: `
<div class="text-center">
<img src="/app/shared/assets/img/pomodoro.png"
Expand Down
4 changes: 2 additions & 2 deletions chapter_09/app/timer/timer.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from 'angular2/core';
import { RouteConfig, ROUTER_DIRECTIVES } from 'angular2/router';
import { Component } from '@angular/core';
import { RouteConfig, ROUTER_DIRECTIVES } from '@angular/router-deprecated';
import TimerWidgetComponent from './timer-widget.component';

@Component({
Expand Down
18 changes: 6 additions & 12 deletions chapter_09/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@
<meta charset="utf-8">
<title>My Angular 2 Pomodoro Application</title>

<script src="node_modules/es6-shim/es6-shim.min.js"></script>

<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/angular2/bundles/angular2.js"></script>
<script src="node_modules/angular2/bundles/http.js"></script>
<script src="node_modules/angular2/bundles/router.js"></script>

<script src="systemjs.config.js"></script>
<script>
System.config({
packages: {
built: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import ('built/app/main')
.then(null, console.error.bind(console));
</script>
Expand Down
13 changes: 11 additions & 2 deletions chapter_09/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@
"typings": "typings"
},
"dependencies": {
"angular2": "2.0.0-beta.17",
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/http": "2.0.0-rc.1",
"@angular/platform-browser": "2.0.0-rc.1",
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"@angular/router": "2.0.0-rc.1",
"@angular/router-deprecated": "2.0.0-rc.1",

"bootstrap": "^3.3.6",

"systemjs": "0.19.26",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.6",
Expand All @@ -31,7 +41,6 @@
"devDependencies": {
"concurrently": "^2.0.0",
"lite-server": "^2.1.0",
"systemjs": "0.19.26",
"typescript": "1.8.10",
"typings": "0.8.1"
}
Expand Down
2 changes: 1 addition & 1 deletion chapter_09/typings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c"
"es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654"
}
}
1 change: 0 additions & 1 deletion chapter_10/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"@angular/router": "2.0.0-rc.1",
"@angular/router-deprecated": "2.0.0-rc.1",
"@angular/upgrade": "2.0.0-rc.1",

"bootstrap": "^3.3.6",

Expand Down

0 comments on commit a405a67

Please sign in to comment.