Skip to content
This repository was archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
- router-deprecated + final router 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
ThorstenHans committed Sep 15, 2016
1 parent 1752b3f commit 9aaa672
Show file tree
Hide file tree
Showing 36 changed files with 301 additions and 192 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@
"systemjs-builder": "0.15.13",
"tether": "^1.1.1",
"typescript": "^2.0.2",
"typings":"^1.3.2"
"typings": "^1.3.2"
},
"dependencies": {
"@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-deprecated": "2.0.0-rc.2",
"@angular/forms": "2.0.0",
"@angular/router": "^3.0.0",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",
Expand Down
15 changes: 1 addition & 14 deletions src/BoardZ/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {Component, AfterViewInit} from '@angular/core';
import {RouteConfig} from '@angular/router-deprecated';

import {LoginComponent} from './components/login/login';
import {DashboardComponent} from './components/dashboard/dashboard';
import {GamesComponent} from './components/games/games';
import {NotificationsComponent} from './components/notifications/notifications';
import {RadiusSearchComponent} from './components/radiusSearch/radiusSearch';
import {LogService} from './services/logService';
import {LogLevel} from './models/logLevel';
import {SignalRService} from './services/signalrService';
Expand All @@ -22,13 +15,7 @@ declare var window: IBoardZAppWindow;
selector: 'boardz-app',
templateUrl: 'app.html'
})
@RouteConfig([
{ path: '/', name: 'Dashboard', useAsDefault: true, component: DashboardComponent },
{ path: '/login', name: 'Login', component: LoginComponent },
{ path: '/notifications', name: 'Notifications', component: NotificationsComponent },
{ path: '/games/...', name: 'Games', component: GamesComponent, data: { displayName: 'Games' } },
{ path: '/radiussearch', name: 'RadiusSearch', component: RadiusSearchComponent }
])

export class BoardzAppComponent implements AfterViewInit {
constructor(private _signalRService: SignalRService,
private _loginService: LoginService,
Expand Down
4 changes: 2 additions & 2 deletions src/BoardZ/app/components/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ <h3>Dashboard</h3>
</div>

<div class="col-md-6">
<widget [target]="'Games'" [caption]="'Games'" [color]="'aqua'" [count]="gameCount" [icon]="'gamepad'"></widget>
<widget [target]="'/games/all'" [caption]="'Games'" [color]="'red'" [count]="gameCount" [icon]="'gamepad'"></widget>
</div>
<div class="col-md-6">
<widget [target]="'RadiusSearch'" [caption]="'Players'" [color]="'green'" [count]="playerCount" [icon]="'users'"></widget>
<widget [target]="'/radiussearch'" [caption]="'Players'" [color]="'blue'" [count]="playerCount" [icon]="'users'"></widget>
</div>
</div>
4 changes: 1 addition & 3 deletions src/BoardZ/app/components/dashboard/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {Component, OnInit} from '@angular/core';

import {NeedsAuthentication} from '../../decorators/needsAuthentication';
import {GamesService} from '../../services/gamesService';
import {PlayersService} from '../../services/playersService';

Expand All @@ -9,7 +7,7 @@ import {PlayersService} from '../../services/playersService';
selector: 'dashboard',
templateUrl: 'dashboard.html'
})
@NeedsAuthentication()
//todo: @NeedsAuthentication()
export class DashboardComponent implements OnInit {
public playerCount: string = '-';
public gameCount: string = '-';
Expand Down
10 changes: 6 additions & 4 deletions src/BoardZ/app/components/games/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
<div class="col-md-12">
<div class="box box-info">
<div class="box-header with-border">
<h3 *ngIf="model.id === null" class="box-title">New game</h3>
<h3 *ngIf="model.id !== null" class="box-title">Game details</h3>
<h3 *ngIf="model.id" class="box-title">New game</h3>
<h3 *ngIf="!model.id" class="box-title">Game details</h3>
</div>
<form ngForm class="form-horizontal" #form="ngForm" (ngSubmit)="saveChanges()">
<div class="panel-body" *ngIf="true">
<div class="form-group" [class.has-error]="!name.pristine && !name.valid">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" id="name" name="name" class="form-control" placeholder="Game name" required
<input type="text" id="name" name="name" class="form-control" placeholder="Game name"
required
[(ngModel)]="model.name" ngControl="name" #name="ngModel"/>
<div class="alert alert-danger" [hidden]="name.pristine || name.valid">
Game name is required
Expand All @@ -20,7 +21,8 @@ <h3 *ngIf="model.id !== null" class="box-title">Game details</h3>
<div class="form-group" [class.has-error]="!description.pristine && !description.valid">
<label for="description" class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<textarea id="description" name="description" class="form-control" rows="3" placeholder="Game description" required
<textarea id="description" name="description" class="form-control" rows="3"
placeholder="Game description" required
[(ngModel)]="model.description" ngControl="description"
#description="ngModel"></textarea>
<div class="alert alert-danger" [hidden]="description.pristine || description.valid">
Expand Down
24 changes: 8 additions & 16 deletions src/BoardZ/app/components/games/details.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router-deprecated';

import {NeedsAuthentication} from '../../decorators/needsAuthentication';
import {Router, ActivatedRoute} from '@angular/router';
import {Game} from '../../models/game';
import {LogService} from '../../services/logService';
import {GamesService} from '../../services/gamesService';
Expand All @@ -27,7 +25,7 @@ export interface RouteTree {
selector: 'gameDetail',
templateUrl: 'details.html'
})
@NeedsAuthentication()
//todo: @NeedsAuthentication()
export class GameDetailsComponent implements OnInit {

private _needsReset: boolean;
Expand All @@ -42,24 +40,18 @@ export class GameDetailsComponent implements OnInit {
constructor(private _logService: LogService,
private _gameService: GamesService,
private _router: Router,
private route: ActivatedRoute,
private _notificationService: NotificationService,
private _playersService: PlayersService,
private _signalRService: SignalRService,
private _loginService: LoginService) {
}

public ngOnInit(): any {
return undefined;
}

public routerOnActivate(curr: RouteSegment, prev?: RouteSegment, currTree?: RouteTree, prevTree?: RouteTree): void {
let id = curr.params['id'];

if (!id) {
this.originalModel = this._gameService.deepClone(this.model = new Game());
return;
}
this.loadGame(id);
this.route.data.forEach((data: { game: Game }) => {
this.originalModel = this._gameService.deepClone(this.model = data.game || new Game());
if (this._needsReset) this.reset();
});
}

private loadGame(id: string): void {
Expand All @@ -77,7 +69,7 @@ export class GameDetailsComponent implements OnInit {
}

public abort(): void {
this._router.navigate(['GamesList']);
this._router.navigate(['/games/all']);
}

public reset(): void {
Expand Down
23 changes: 23 additions & 0 deletions src/BoardZ/app/components/games/gameDetailsResolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Injectable} from '@angular/core';
import {Resolve, ActivatedRouteSnapshot} from '@angular/router';
import {Game} from '../../models/game';
import {GamesService} from '../../services/gamesService';

@Injectable()
export class GameDetailsResolver implements Resolve<Game> {
constructor(private _gamesService: GamesService) {
}

resolve(route: ActivatedRouteSnapshot): Promise<Game> {
let id = route.params['id'];
return new Promise((resolve) => {
this._gamesService.getById(id).subscribe(game => {
if (game) {
resolve(game)
} else {
resolve(new Game())
}
});
});
}
}
13 changes: 3 additions & 10 deletions src/BoardZ/app/components/games/games.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import {Component} from '@angular/core';
import {RouteConfig} from '@angular/router-deprecated';

import {NeedsAuthentication} from '../../decorators/needsAuthentication';
import {GameDetailsComponent} from './details';
import {GameListComponent} from './list';

@Component({
moduleId: module.id,
selector: 'games',
templateUrl: 'games.html'
})
@RouteConfig([
{ path: '/', component: GameListComponent, name: 'GamesList', useAsDefault: true, data: { displayName: 'Game overview' } },
{ path: '/create', component: GameDetailsComponent, name: 'CreateGame', data: { displayName: 'Create a new game' } },
{ path: '/details/:id', component: GameDetailsComponent, name: 'GameDetails', data: { displayName: 'Game details' } }
])
@NeedsAuthentication()

//todo: ROUTER
//todo: @NeedsAuthentication()
export class GamesComponent {
}
35 changes: 35 additions & 0 deletions src/BoardZ/app/components/games/gamesRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {Routes, RouterModule} from '@angular/router';
import {GamesComponent} from './games';
import {AuthGuard} from '../../guards/authGuard';
import {GameDetailsComponent} from './details';
import {GameListComponent} from './list';
import {ModuleWithProviders} from '@angular/core';
import {GameDetailsResolver} from './gameDetailsResolver';

const gameRoutes: Routes = [

{
path: 'games',
component: GamesComponent,
canActivate: [AuthGuard],
children: [
{ path: 'all', component: GameListComponent, data: { displayName: 'Game overview' } },
{
path: 'new',
component: GameDetailsComponent,
name: 'CreateGame',
data: { displayName: 'Create a new game' }
},
{
path: 'details/:id',
component: GameDetailsComponent,
name: 'GameDetails',
resolve: { game: GameDetailsResolver },
data: { displayName: 'Game details' }
}
]
}

];

export const gamesRouting: ModuleWithProviders = RouterModule.forChild(gameRoutes);
19 changes: 8 additions & 11 deletions src/BoardZ/app/components/games/list.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router-deprecated';

import {Router, ActivatedRoute} from '@angular/router';
import {Game} from '../../models/game';
import {GamesService} from '../../services/gamesService';
import {NotificationService} from '../../services/notificationService';
import {NeedsAuthentication} from '../../decorators/needsAuthentication';

@NeedsAuthentication()
@Component({
moduleId: module.id,
selector: 'game-list',
Expand All @@ -16,20 +12,21 @@ import {NeedsAuthentication} from '../../decorators/needsAuthentication';
export class GameListComponent implements OnInit {
public games: Game[];

constructor(private _gamesService: GamesService,
private _router: Router,
constructor(private _gamesService: GamesService,
private _router: Router,
private _route: ActivatedRoute,
private _notificationService: NotificationService) {
}

public openGameDetails(game: Game): void {
this._router.navigate(['GameDetails', { id: game.id }]);
this._router.navigate(['../details', game.id], { relativeTo: this._route});
}

public openCreateGame():void{
this._router.navigate(['CreateGame']);
public openCreateGame(): void {
this._router.navigate(['../new'], {relativeTo: this._route });
}

ngOnInit() {
public ngOnInit(): void {
this._gamesService.getAll()
.subscribe(
(games)=> this.games = games,
Expand Down
7 changes: 3 additions & 4 deletions src/BoardZ/app/components/header/header.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Component, OnInit} from '@angular/core';

import {Notification} from '../../models/notification';
import {LoginService} from '../../services/loginService';
import {TokenService} from '../../services/tokenService';
Expand All @@ -16,16 +15,16 @@ export class HeaderComponent implements OnInit {
public loggedIn: boolean = false;
public currentLocation: string = 'BoardZ!';

constructor(public loginService: LoginService,
private _tokenService: TokenService,
constructor(public loginService: LoginService,
private _tokenService: TokenService,
private _notificationService: NotificationService) {
}

ngOnInit(): any {
this._notificationService.notifications.subscribe(
(notification) => this.onNotification(notification)
);
this._tokenService.check().subscribe(result => {
this._tokenService.isAuthenticated().subscribe(result => {
this.loggedIn = result
});
}
Expand Down
10 changes: 4 additions & 6 deletions src/BoardZ/app/components/login/login.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Component} from '@angular/core';
import {Router} from '@angular/router-deprecated';

import {Router} from '@angular/router';
import {LoginService} from '../../services/loginService';
import {LogService} from '../../services/logService';
import {NotificationService} from '../../services/notificationService';
Expand All @@ -14,9 +13,8 @@ import {SignalRService} from '../../services/signalrService';
export class LoginComponent {
private _userName: string;
private _password: string;

public _hasError: boolean = false;

constructor(private _router: Router,
private _loginService: LoginService,
private _logService: LogService,
Expand All @@ -26,13 +24,13 @@ export class LoginComponent {

public doLogin(): void {
this._logService.logDebug('LoginComponent.doLogin called');

this._loginService.login(this._userName, this._password)
.subscribe(
() => {
this._signalRService.start();
this.setError(false);
this._router.navigate(['Dashboard'])
this._router.navigate([''])
},
() => {
this.setError(true);
Expand Down
24 changes: 16 additions & 8 deletions src/BoardZ/app/components/notifications/notifications.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
<div class="row">
<div class="col-md-12">
<h1>Notification test sender</h1>
<h3>Test Notifications</h3>
</div>
</div>
<div class="row">
<div class="col-md-12">
<form class="form-inline">
<label for="message">Message: </label>
<input type="text" size="20" class="form-control" id="message" placeholder="Your message" #msg required />
<label> Send as: </label>
<button type="button" class="btn btn-info btn-default" (click)="notificationService.notifyInformation(msg.value)">Info</button>
<button type="button" class="btn btn-success btn-default" (click)="notificationService.notifySuccess(msg.value)">Success</button>
<button type="button" class="btn btn-warning btn-default" (click)="notificationService.notifyWarning(msg.value)">Warning</button>
<button type="button" class="btn btn-danger btn-default" (click)="notificationService.notifyError(msg.value)">Error</button>
<input type="text" size="20" class="form-control" id="message" placeholder="Your message" #msg required/>
<div> Send as: </div>
<button type="button" class="btn btn-info btn-default"
(click)="notificationService.notifyInformation(msg.value)">Info
</button>
<button type="button" class="btn btn-success btn-default"
(click)="notificationService.notifySuccess(msg.value)">Success
</button>
<button type="button" class="btn btn-warning btn-default"
(click)="notificationService.notifyWarning(msg.value)">Warning
</button>
<button type="button" class="btn btn-danger btn-default"
(click)="notificationService.notifyError(msg.value)">Error
</button>
</form>
</div>
</div>
</div>
Loading

0 comments on commit 9aaa672

Please sign in to comment.