From 47b742a16e101deff2f9f453b71764092b58224a Mon Sep 17 00:00:00 2001 From: Brett Epps Date: Sun, 18 Sep 2016 13:41:42 -0500 Subject: [PATCH] Update Angular 2 example to Angular 2.0.0 final release --- .../src/main/webapp/.gitignore | 4 + .../src/main/webapp/app/app.component.ts | 67 ++++++++++++++++ .../src/main/webapp/app/app.module.ts | 20 +++++ .../src/main/webapp/app/app.ts | 78 ------------------- .../src/main/webapp/app/keycloak.service.ts | 48 ++++++++++++ .../src/main/webapp/app/keycloak.ts | 49 ------------ .../src/main/webapp/app/main.ts | 23 +++--- .../src/main/webapp/index.html | 51 ++++-------- .../src/main/webapp/package.json | 36 ++++++--- .../src/main/webapp/systemjs.config.js | 43 ++++++++++ .../src/main/webapp/tsconfig.json | 11 +-- .../src/main/webapp/typings.json | 7 ++ 12 files changed, 240 insertions(+), 197 deletions(-) create mode 100644 examples/demo-template/angular2-product-app/src/main/webapp/.gitignore create mode 100644 examples/demo-template/angular2-product-app/src/main/webapp/app/app.component.ts create mode 100644 examples/demo-template/angular2-product-app/src/main/webapp/app/app.module.ts delete mode 100644 examples/demo-template/angular2-product-app/src/main/webapp/app/app.ts create mode 100644 examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.service.ts delete mode 100644 examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.ts create mode 100644 examples/demo-template/angular2-product-app/src/main/webapp/systemjs.config.js create mode 100644 examples/demo-template/angular2-product-app/src/main/webapp/typings.json diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/.gitignore b/examples/demo-template/angular2-product-app/src/main/webapp/.gitignore new file mode 100644 index 0000000000..1c790facbc --- /dev/null +++ b/examples/demo-template/angular2-product-app/src/main/webapp/.gitignore @@ -0,0 +1,4 @@ +app/*.js +app/*.js.map +node_modules +typings diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/app/app.component.ts b/examples/demo-template/angular2-product-app/src/main/webapp/app/app.component.ts new file mode 100644 index 0000000000..d43e25740d --- /dev/null +++ b/examples/demo-template/angular2-product-app/src/main/webapp/app/app.component.ts @@ -0,0 +1,67 @@ +import { Component } from '@angular/core'; +import { Http, Headers, RequestOptions, Response } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/map'; + +import { KeycloakService } from './keycloak.service'; + +@Component({ + selector: 'my-app', + template: ` +
+
+

Angular2 Product (Beta)

+

Products

+ + + + + + + + + + + + + +
Product Listing
{{p}}
+
+
+` +}) +export class AppComponent { + products: string[] = []; + + constructor(private http: Http, private kc: KeycloakService) {} + + logout() { + this.kc.logout(); + } + + reloadData() { + //angular dont have http interceptor yet + + this.kc.getToken() + .then(token => { + let headers = new Headers({ + 'Accept': 'application/json', + 'Authorization': 'Bearer ' + token + }); + + let options = new RequestOptions({ headers }); + + this.http.get('/database/products', options) + .map(res => res.json()) + .subscribe(prods => this.products = prods, + error => console.log(error)); + }) + .catch(error => console.log(error)); + } + + private handleError(error: Response) { + console.error(error); + return Observable.throw(error.json().error || 'Server error'); + } +} diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/app/app.module.ts b/examples/demo-template/angular2-product-app/src/main/webapp/app/app.module.ts new file mode 100644 index 0000000000..f345fa3ea6 --- /dev/null +++ b/examples/demo-template/angular2-product-app/src/main/webapp/app/app.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { HttpModule } from '@angular/http'; +import { KeycloakService } from './keycloak.service'; +import { AppComponent } from './app.component'; + +@NgModule({ + imports: [ + BrowserModule, + HttpModule + ], + declarations: [ + AppComponent + ], + providers: [ + KeycloakService, + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/app/app.ts b/examples/demo-template/angular2-product-app/src/main/webapp/app/app.ts deleted file mode 100644 index 8630f006ea..0000000000 --- a/examples/demo-template/angular2-product-app/src/main/webapp/app/app.ts +++ /dev/null @@ -1,78 +0,0 @@ -import {Http, Headers, - RequestOptions, Response} from 'angular2/http'; -import {Component} from 'angular2/core'; -import {Observable} from 'rxjs/Observable'; -import {KeycloakService} from './keycloak'; - - - - -@Component({ - selector: 'my-app', - template: -` -
-
-

Angular2 Product (Beta)

-

Products

- - - - - - - - - - - - - - -
Product Listing
{{p}}
-
-
-` -}) -export class AppComponent { - - constructor(private _kc:KeycloakService, private http:Http){ } - - products : string[] = []; - - logout(){ - this._kc.logout(); - } - - reloadData() { - //angular dont have http interceptor yet - - this._kc.getToken().then( - token=>{ - let headers = new Headers({ - 'Accept': 'application/json', - 'Authorization': 'Bearer ' + token - }); - - let options = new RequestOptions({ headers: headers }); - - this.http.get('/database/products', options) - .map(res => res.json()) - .subscribe( - prods => this.products = prods, - error => console.log(error)); - - }, - error=>{ - console.log(error); - } - ); - - } - - private handleError (error: Response) { - console.error(error); - return Observable.throw(error.json().error || 'Server error'); - } - -} diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.service.ts b/examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.service.ts new file mode 100644 index 0000000000..33fc28357e --- /dev/null +++ b/examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.service.ts @@ -0,0 +1,48 @@ +import { Injectable } from '@angular/core'; + +declare var Keycloak: any; + +@Injectable() +export class KeycloakService { + static auth: any = {}; + + static init(): Promise { + let keycloakAuth: any = new Keycloak('keycloak.json'); + KeycloakService.auth.loggedIn = false; + + return new Promise((resolve, reject) => { + keycloakAuth.init({ onLoad: 'login-required' }) + .success(() => { + KeycloakService.auth.loggedIn = true; + KeycloakService.auth.authz = keycloakAuth; + KeycloakService.auth.logoutUrl = keycloakAuth.authServerUrl + "/realms/demo/protocol/openid-connect/logout?redirect_uri=/angular2-product/index.html"; + resolve(); + }) + .error(() => { + reject(); + }); + }); + } + + logout() { + console.log('*** LOGOUT'); + KeycloakService.auth.loggedIn = false; + KeycloakService.auth.authz = null; + + window.location.href = KeycloakService.auth.logoutUrl; + } + + getToken(): Promise { + return new Promise((resolve, reject) => { + if (KeycloakService.auth.authz.token) { + KeycloakService.auth.authz.updateToken(5) + .success(() => { + resolve(KeycloakService.auth.authz.token); + }) + .error(() => { + reject('Failed to refresh token'); + }); + } + }); + } +} diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.ts b/examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.ts deleted file mode 100644 index 64242ae932..0000000000 --- a/examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.ts +++ /dev/null @@ -1,49 +0,0 @@ -import {Injectable} from 'angular2/core'; - - -declare var Keycloak: any; - -@Injectable() -export class KeycloakService { - - static auth : any = {}; - - static init() : Promise{ - let keycloakAuth : any = new Keycloak('keycloak.json'); - KeycloakService.auth.loggedIn = false; - - return new Promise((resolve,reject)=>{ - keycloakAuth.init({ onLoad: 'login-required' }) - .success( () => { - KeycloakService.auth.loggedIn = true; - KeycloakService.auth.authz = keycloakAuth; - KeycloakService.auth.logoutUrl = keycloakAuth.authServerUrl + "/realms/demo/tokens/logout?redirect_uri=/angular2-product/index.html"; - resolve(null); - }) - .error(()=> { - reject(null); - }); - }); - } - - logout(){ - console.log('*** LOGOUT'); - KeycloakService.auth.loggedIn = false; - KeycloakService.auth.authz = null; - - window.location.href = KeycloakService.auth.logoutUrl; - } - - getToken(): Promise{ - return new Promise((resolve,reject)=>{ - if (KeycloakService.auth.authz.token) { - KeycloakService.auth.authz.updateToken(5).success(function() { - resolve(KeycloakService.auth.authz.token); - }) - .error(function() { - reject('Failed to refresh token'); - }); - } - }); - } -} diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/app/main.ts b/examples/demo-template/angular2-product-app/src/main/webapp/app/main.ts index 73613b2b92..6bf99bfc91 100644 --- a/examples/demo-template/angular2-product-app/src/main/webapp/app/main.ts +++ b/examples/demo-template/angular2-product-app/src/main/webapp/app/main.ts @@ -1,14 +1,11 @@ -import 'rxjs/Rx'; -import {bootstrap} from 'angular2/platform/browser'; -import {HTTP_BINDINGS} from 'angular2/http'; -import {KeycloakService} from './keycloak'; -import {AppComponent} from './app'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +import { AppModule } from './app.module'; -KeycloakService.init().then( - o=>{ - bootstrap(AppComponent,[HTTP_BINDINGS, KeycloakService]); - }, - x=>{ - window.location.reload(); - } -); \ No newline at end of file +import {KeycloakService} from './keycloak.service'; + +KeycloakService.init() + .then(() => { + const platform = platformBrowserDynamic(); + platform.bootstrapModule(AppModule); + }) + .catch(() => window.location.reload()); diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/index.html b/examples/demo-template/angular2-product-app/src/main/webapp/index.html index 2da600c335..1edeb56477 100644 --- a/examples/demo-template/angular2-product-app/src/main/webapp/index.html +++ b/examples/demo-template/angular2-product-app/src/main/webapp/index.html @@ -2,48 +2,23 @@ Angular 2 QuickStart + - - - - - - + + + + + + + + + + - Loading... - - - - - - - - - - - - - - - - - - - - diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/package.json b/examples/demo-template/angular2-product-app/src/main/webapp/package.json index f66b44c110..5bd783b03e 100644 --- a/examples/demo-template/angular2-product-app/src/main/webapp/package.json +++ b/examples/demo-template/angular2-product-app/src/main/webapp/package.json @@ -2,24 +2,36 @@ "name": "angular2-product-app", "version": "1.0.0", "scripts": { + "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ", + "lite": "lite-server", + "postinstall": "typings install", "tsc": "tsc", "tsc:w": "tsc -w", - "lite": "lite-server", - "start": "concurrent \"npm run tsc:w\" \"npm run lite\" " + "typings": "typings" }, "license": "ISC", "dependencies": { - "angular2": "2.0.0-beta.3", - "systemjs": "0.19.6", - "es6-promise": "^3.0.2", - "es6-shim": "^0.33.3", - "reflect-metadata": "0.1.2", - "rxjs": "5.0.0-beta.0", - "zone.js": "0.5.11" + "@angular/common": "2.0.0", + "@angular/compiler": "2.0.0", + "@angular/core": "2.0.0", + "@angular/forms": "2.0.0", + "@angular/http": "2.0.0", + "@angular/platform-browser": "2.0.0", + "@angular/platform-browser-dynamic": "2.0.0", + "@angular/router": "3.0.0", + "@angular/upgrade": "2.0.0", + "angular2-in-memory-web-api": "0.0.20", + "bootstrap": "^3.3.6", + "core-js": "^2.4.1", + "reflect-metadata": "^0.1.3", + "rxjs": "5.0.0-beta.12", + "systemjs": "0.19.27", + "zone.js": "^0.6.21" }, "devDependencies": { - "concurrently": "^1.0.0", - "lite-server": "^2.0.1", - "typescript": "^1.7.5" + "concurrently": "^2.2.0", + "lite-server": "^2.2.2", + "typescript": "^2.0.2", + "typings": "^1.3.2" } } diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/systemjs.config.js b/examples/demo-template/angular2-product-app/src/main/webapp/systemjs.config.js new file mode 100644 index 0000000000..de199e68ce --- /dev/null +++ b/examples/demo-template/angular2-product-app/src/main/webapp/systemjs.config.js @@ -0,0 +1,43 @@ +/** + * System configuration for Angular 2 samples + * Adjust as necessary for your application needs. + */ +(function (global) { + System.config({ + paths: { + // paths serve as alias + 'npm:': 'node_modules/' + }, + // map tells the System loader where to look for things + map: { + // our app is within the app folder + app: 'app', + // angular bundles + '@angular/core': 'npm:@angular/core/bundles/core.umd.js', + '@angular/common': 'npm:@angular/common/bundles/common.umd.js', + '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', + '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', + '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', + '@angular/http': 'npm:@angular/http/bundles/http.umd.js', + '@angular/router': 'npm:@angular/router/bundles/router.umd.js', + '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', + // other libraries + 'rxjs': 'npm:rxjs', + 'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api', + }, + // packages tells the System loader how to load when no filename and/or no extension + packages: { + app: { + main: './main.js', + defaultExtension: 'js' + }, + rxjs: { + defaultExtension: 'js' + }, + 'angular2-in-memory-web-api': { + main: './index.js', + defaultExtension: 'js' + } + } + }); +})(this); diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/tsconfig.json b/examples/demo-template/angular2-product-app/src/main/webapp/tsconfig.json index 52c77a54a4..e6a6eac11d 100644 --- a/examples/demo-template/angular2-product-app/src/main/webapp/tsconfig.json +++ b/examples/demo-template/angular2-product-app/src/main/webapp/tsconfig.json @@ -1,15 +1,12 @@ { "compilerOptions": { "target": "es5", - "module": "system", + "module": "commonjs", "moduleResolution": "node", - "sourceMap": false, + "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false - }, - "exclude": [ - "node_modules" - ] -} \ No newline at end of file + } +} diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/typings.json b/examples/demo-template/angular2-product-app/src/main/webapp/typings.json new file mode 100644 index 0000000000..7da31ca0af --- /dev/null +++ b/examples/demo-template/angular2-product-app/src/main/webapp/typings.json @@ -0,0 +1,7 @@ +{ + "globalDependencies": { + "core-js": "registry:dt/core-js#0.0.0+20160725163759", + "jasmine": "registry:dt/jasmine#2.2.0+20160621224255", + "node": "registry:dt/node#6.0.0+20160909174046" + } +}