From 1db36f7916827c50be4d0e2b2d13d42dda9544d2 Mon Sep 17 00:00:00 2001 From: Thorsten Hans Date: Fri, 16 Sep 2016 03:17:29 +0200 Subject: [PATCH] =?UTF-8?q?some=20more=20polish=20=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gulpTasks/web.js | 9 ++ package.json | 2 + src/BoardZ/app/apiConfig.ts | 6 + src/BoardZ/app/appConfig.ts | 3 - .../app/components/dashboard/dashboard.html | 4 +- .../app/components/dashboard/dashboard.ts | 7 +- src/BoardZ/app/components/games/details.html | 4 +- src/BoardZ/app/components/games/details.ts | 35 +++--- src/BoardZ/app/components/games/games.ts | 13 -- .../games/{games.html => gamesRoot.html} | 0 src/BoardZ/app/components/games/gamesRoot.ts | 8 ++ .../app/components/games/gamesRoutes.ts | 35 ------ src/BoardZ/app/components/games/list.html | 2 +- src/BoardZ/app/components/games/list.ts | 6 +- src/BoardZ/app/components/header/header.ts | 10 +- .../app/components/locateIt/locateIt.ts | 6 +- src/BoardZ/app/components/login/login.html | 68 ++++++----- src/BoardZ/app/components/login/login.ts | 2 +- .../app/components/pictureIt/pictureIt.html | 6 +- .../components/radiusSearch/radiusSearch.html | 2 +- .../components/radiusSearch/radiusSearch.ts | 2 +- src/BoardZ/app/components/sidebar/sidebar.ts | 3 +- src/BoardZ/app/guards/authGuard.ts | 4 +- src/BoardZ/app/interfaces/boardzAppWindow.ts | 3 +- src/BoardZ/app/main.ts | 8 +- src/BoardZ/app/models/navigationEntry.ts | 2 +- src/BoardZ/app/models/notification.ts | 2 +- src/BoardZ/app/models/notificationType.ts | 2 +- src/BoardZ/app/models/player.ts | 2 +- src/BoardZ/app/models/tokenData.ts | 2 +- src/BoardZ/app/modules/appDeclarations.ts | 25 ---- src/BoardZ/app/modules/appModule.ts | 20 ++- src/BoardZ/app/modules/appProviders.ts | 50 -------- src/BoardZ/app/modules/appRoutes.ts | 24 ---- src/BoardZ/app/modules/config.ts | 115 ++++++++++++++++++ src/BoardZ/app/modules/coreModule.ts | 15 --- src/BoardZ/app/modules/gamesModule.ts | 24 ++-- src/BoardZ/app/modules/sharedModule.ts | 12 ++ .../gameDetailsResolver.ts | 8 +- src/BoardZ/app/routes/index.ts | 49 ++++++++ src/BoardZ/app/services/appInjector.ts | 11 -- src/BoardZ/app/services/authenticatedHttp.ts | 12 +- .../app/services/desktopCameraService.ts | 12 +- src/BoardZ/app/services/geolocationService.ts | 8 +- src/BoardZ/app/services/logService.ts | 6 +- src/BoardZ/app/services/loginService.ts | 13 +- src/BoardZ/app/services/playersService.ts | 2 +- src/BoardZ/app/services/signalrService.ts | 9 +- src/BoardZ/app/services/tokenService.ts | 5 +- .../app/services/uiNotificationService.ts | 2 +- src/BoardZ/css/app.css | 20 +-- src/BoardZ/index.html | 2 +- src/BoardZ/system.setup.js | 11 +- tslint.json | 57 +++++++++ 54 files changed, 416 insertions(+), 354 deletions(-) create mode 100644 src/BoardZ/app/apiConfig.ts delete mode 100644 src/BoardZ/app/appConfig.ts delete mode 100644 src/BoardZ/app/components/games/games.ts rename src/BoardZ/app/components/games/{games.html => gamesRoot.html} (100%) create mode 100644 src/BoardZ/app/components/games/gamesRoot.ts delete mode 100644 src/BoardZ/app/components/games/gamesRoutes.ts delete mode 100644 src/BoardZ/app/modules/appDeclarations.ts delete mode 100644 src/BoardZ/app/modules/appProviders.ts delete mode 100644 src/BoardZ/app/modules/appRoutes.ts create mode 100644 src/BoardZ/app/modules/config.ts delete mode 100644 src/BoardZ/app/modules/coreModule.ts create mode 100644 src/BoardZ/app/modules/sharedModule.ts rename src/BoardZ/app/{components/games => resolvers}/gameDetailsResolver.ts (76%) create mode 100644 src/BoardZ/app/routes/index.ts delete mode 100644 src/BoardZ/app/services/appInjector.ts create mode 100644 tslint.json diff --git a/gulpTasks/web.js b/gulpTasks/web.js index 423cc09..cd64c08 100644 --- a/gulpTasks/web.js +++ b/gulpTasks/web.js @@ -19,6 +19,7 @@ rename = require('gulp-rename'), inject = require('gulp-inject'), uglify = require('gulp-uglify'), + tslint = require('gulp-tslint'), watch = require('gulp-watch'), Builder = require('systemjs-builder'); @@ -30,6 +31,14 @@ .pipe(gulp.dest(path.join(config.targets.buildFolder))); }); + gulp.task("[private-web]:lint-app-code", () => + gulp.src(config.source.files.app.ts) + .pipe(tslint({ + formatter: 'verbose' + })) + .pipe(tslint.report()) + ); + gulp.task('[private-web]:bundle-vendor-scripts', function () { var builder = new Builder(); gulp.src(config.source.files.angular2rc1deps) diff --git a/package.json b/package.json index 90f8047..9b8891b 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "gulp-sourcemaps": "^1.6.0", "gulp-symdest": "^1.0.0", "gulp-tap": "^0.1.3", + "gulp-tslint": "^6.1.1", "gulp-typescript": "^2.10.0", "gulp-uglify": "^1.4.1", "gulp-watch": "^4.3.5", @@ -56,6 +57,7 @@ "stream-series": "^0.1.1", "systemjs-builder": "0.15.13", "tether": "^1.1.1", + "tslint": "^3.15.1", "typescript": "^2.0.2", "typings": "^1.3.2" }, diff --git a/src/BoardZ/app/apiConfig.ts b/src/BoardZ/app/apiConfig.ts new file mode 100644 index 0000000..b3bb33c --- /dev/null +++ b/src/BoardZ/app/apiConfig.ts @@ -0,0 +1,6 @@ +export class ApiConfig { + + public get rootUrl(): string { + return 'https://boardzapi.azurewebsites.net/'; + } +} diff --git a/src/BoardZ/app/appConfig.ts b/src/BoardZ/app/appConfig.ts deleted file mode 100644 index e6a02e9..0000000 --- a/src/BoardZ/app/appConfig.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class AppConfiguration { - public apiEndpoint: string = 'https://boardzapi.azurewebsites.net/'; -} diff --git a/src/BoardZ/app/components/dashboard/dashboard.html b/src/BoardZ/app/components/dashboard/dashboard.html index cc991d1..15501f5 100644 --- a/src/BoardZ/app/components/dashboard/dashboard.html +++ b/src/BoardZ/app/components/dashboard/dashboard.html @@ -4,9 +4,9 @@

Dashboard

- +
- +
diff --git a/src/BoardZ/app/components/dashboard/dashboard.ts b/src/BoardZ/app/components/dashboard/dashboard.ts index cbc15eb..0fe6c48 100644 --- a/src/BoardZ/app/components/dashboard/dashboard.ts +++ b/src/BoardZ/app/components/dashboard/dashboard.ts @@ -7,19 +7,18 @@ import {PlayersService} from '../../services/playersService'; selector: 'dashboard', templateUrl: 'dashboard.html' }) -//todo: @NeedsAuthentication() export class DashboardComponent implements OnInit { public playerCount: string = '-'; public gameCount: string = '-'; - constructor(private _gamesService: GamesService, + constructor(private _gamesService: GamesService, private _playersService: PlayersService) { } - ngOnInit(): any { + public ngOnInit(): any { this._playersService.getPlayerCount() .subscribe(result => this.playerCount = result.toString()); - + this._gamesService.getGameCount() .subscribe(result => this.gameCount = result.toString()); } diff --git a/src/BoardZ/app/components/games/details.html b/src/BoardZ/app/components/games/details.html index c048863..5eca94d 100644 --- a/src/BoardZ/app/components/games/details.html +++ b/src/BoardZ/app/components/games/details.html @@ -1,6 +1,6 @@
-
+

New game

Game details

@@ -35,7 +35,7 @@

Game details

- -
+ +
+ - -
\ No newline at end of file +
+ +
diff --git a/src/BoardZ/app/components/login/login.ts b/src/BoardZ/app/components/login/login.ts index 39e10d9..e54fa26 100644 --- a/src/BoardZ/app/components/login/login.ts +++ b/src/BoardZ/app/components/login/login.ts @@ -30,7 +30,7 @@ export class LoginComponent { () => { this._signalRService.start(); this.setError(false); - this._router.navigate(['']) + this._router.navigate(['']); }, () => { this.setError(true); diff --git a/src/BoardZ/app/components/pictureIt/pictureIt.html b/src/BoardZ/app/components/pictureIt/pictureIt.html index a34d5f3..e8fef2d 100644 --- a/src/BoardZ/app/components/pictureIt/pictureIt.html +++ b/src/BoardZ/app/components/pictureIt/pictureIt.html @@ -4,11 +4,11 @@

Take a picture of your game

- +

Sorry, but we can't access your camera to take a picture. :-(

- +
diff --git a/src/BoardZ/app/components/radiusSearch/radiusSearch.html b/src/BoardZ/app/components/radiusSearch/radiusSearch.html index cc5e8b4..d47367e 100644 --- a/src/BoardZ/app/components/radiusSearch/radiusSearch.html +++ b/src/BoardZ/app/components/radiusSearch/radiusSearch.html @@ -17,7 +17,7 @@

Find players around you

- +
diff --git a/src/BoardZ/app/components/radiusSearch/radiusSearch.ts b/src/BoardZ/app/components/radiusSearch/radiusSearch.ts index 6a0ee49..04cca07 100644 --- a/src/BoardZ/app/components/radiusSearch/radiusSearch.ts +++ b/src/BoardZ/app/components/radiusSearch/radiusSearch.ts @@ -20,7 +20,7 @@ export class RadiusSearchComponent implements OnInit { public ngOnInit() { this._geoLocationService.locate() - .then((coordinates: GeoLocation)=> this._location = coordinates); + .then((coordinates: GeoLocation) => this._location = coordinates); } public search() { diff --git a/src/BoardZ/app/components/sidebar/sidebar.ts b/src/BoardZ/app/components/sidebar/sidebar.ts index ee32d42..ebbb574 100644 --- a/src/BoardZ/app/components/sidebar/sidebar.ts +++ b/src/BoardZ/app/components/sidebar/sidebar.ts @@ -15,7 +15,8 @@ export class SidebarComponent { this.navigationEntries.push(new NavigationEntry([''], 'dashboard', 'Dashboard')); this.navigationEntries.push(new NavigationEntry(['/games/all'], 'list', 'Games')); this.navigationEntries.push(new NavigationEntry(['/radiussearch'], 'location-arrow', 'Players search')); - this.navigationEntries.push(new NavigationEntry(['/notifications'], 'bell', 'Test Notifcations')); + + //this.navigationEntries.push(new NavigationEntry(['/notifications'], 'bell', 'Test Notifcations')); } } diff --git a/src/BoardZ/app/guards/authGuard.ts b/src/BoardZ/app/guards/authGuard.ts index ffcb13a..30a308d 100644 --- a/src/BoardZ/app/guards/authGuard.ts +++ b/src/BoardZ/app/guards/authGuard.ts @@ -18,9 +18,9 @@ export class AuthGuard implements CanActivate { isAuthenticated ? observer.next(isAuthenticated) : this.navigateToLogin() && observer.next(false); }, (error) => { - this.navigateToLogin() + this.navigateToLogin(); observer.next(false); - }, ()=> { + }, () => { observer.complete(); }); }); diff --git a/src/BoardZ/app/interfaces/boardzAppWindow.ts b/src/BoardZ/app/interfaces/boardzAppWindow.ts index 48536b6..4e2e8bb 100644 --- a/src/BoardZ/app/interfaces/boardzAppWindow.ts +++ b/src/BoardZ/app/interfaces/boardzAppWindow.ts @@ -1,5 +1,4 @@ - export interface IBoardZAppWindow extends Window { initAdminLTE(): void; - require(name:string): any; + require(name: string): any; } diff --git a/src/BoardZ/app/main.ts b/src/BoardZ/app/main.ts index 25013a8..b55a5ad 100644 --- a/src/BoardZ/app/main.ts +++ b/src/BoardZ/app/main.ts @@ -8,16 +8,12 @@ import 'pNotify/pnotify-adapter'; import 'signalr/signalr'; import 'leaflet/leaflet'; import 'fastclick/fastclick'; -import {enableProdMode, NgModuleRef} from '@angular/core'; +import {enableProdMode} from '@angular/core'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import 'rxjs/add/observable/of'; import 'rxjs/add/operator/map'; -import {appInjector} from './services/appInjector'; import {AppModule} from './modules/appModule'; enableProdMode(); -platformBrowserDynamic().bootstrapModule(AppModule) - .then((moduleReference: NgModuleRef) => { - appInjector(moduleReference.injector); - }); +platformBrowserDynamic().bootstrapModule(AppModule); diff --git a/src/BoardZ/app/models/navigationEntry.ts b/src/BoardZ/app/models/navigationEntry.ts index a2bdcde..d5eadd9 100644 --- a/src/BoardZ/app/models/navigationEntry.ts +++ b/src/BoardZ/app/models/navigationEntry.ts @@ -1,4 +1,4 @@ export class NavigationEntry { constructor(public links: Array, public icon: string, public displayName: string) { } -} \ No newline at end of file +} diff --git a/src/BoardZ/app/models/notification.ts b/src/BoardZ/app/models/notification.ts index a94ba1c..9c89399 100644 --- a/src/BoardZ/app/models/notification.ts +++ b/src/BoardZ/app/models/notification.ts @@ -19,4 +19,4 @@ export class Notification { return 'fa-info'; } } -} \ No newline at end of file +} diff --git a/src/BoardZ/app/models/notificationType.ts b/src/BoardZ/app/models/notificationType.ts index b4dd6ce..10b1059 100644 --- a/src/BoardZ/app/models/notificationType.ts +++ b/src/BoardZ/app/models/notificationType.ts @@ -3,4 +3,4 @@ export enum NotificationType { Success, Warning, Error, -} \ No newline at end of file +} diff --git a/src/BoardZ/app/models/player.ts b/src/BoardZ/app/models/player.ts index a022d1d..744b14b 100644 --- a/src/BoardZ/app/models/player.ts +++ b/src/BoardZ/app/models/player.ts @@ -7,4 +7,4 @@ export class Player{ public boardGameName: string; public coordinate: GeoLocation; public imageUrl: string; -} \ No newline at end of file +} diff --git a/src/BoardZ/app/models/tokenData.ts b/src/BoardZ/app/models/tokenData.ts index 64e8adc..a7d3cfd 100644 --- a/src/BoardZ/app/models/tokenData.ts +++ b/src/BoardZ/app/models/tokenData.ts @@ -2,4 +2,4 @@ export interface TokenData { access_token: string; token_type: string; expires_in: number; -} \ No newline at end of file +} diff --git a/src/BoardZ/app/modules/appDeclarations.ts b/src/BoardZ/app/modules/appDeclarations.ts deleted file mode 100644 index 547924b..0000000 --- a/src/BoardZ/app/modules/appDeclarations.ts +++ /dev/null @@ -1,25 +0,0 @@ -import {CloseSidebarOnClickDirective} from '../directives/closeSidebarOnClickDirective'; -import {BackButtonDirective} from '../directives/backButtonDirective'; -import {PictureItComponent} from '../components/pictureIt/pictureIt'; -import {LocateItComponent} from '../components/locateIt/locateIt'; -import {WidgetComponent} from '../components/widget/widget'; -import {SidebarComponent} from '../components/sidebar/sidebar'; -import {HeaderComponent} from '../components/header/header'; -import {BoardzAppComponent} from '../app'; -import {DashboardComponent} from '../components/dashboard/dashboard'; -import {LoginComponent} from '../components/login/login'; -import {RadiusSearchComponent} from '../components/radiusSearch/radiusSearch'; -import {NotificationsComponent} from '../components/notifications/notifications'; - -export const APP_DECLARATIONS = [ - BoardzAppComponent, - DashboardComponent, - LoginComponent, - RadiusSearchComponent, - NotificationsComponent, - HeaderComponent, - SidebarComponent, - WidgetComponent, - BackButtonDirective, - CloseSidebarOnClickDirective -]; diff --git a/src/BoardZ/app/modules/appModule.ts b/src/BoardZ/app/modules/appModule.ts index 783189c..01fd418 100644 --- a/src/BoardZ/app/modules/appModule.ts +++ b/src/BoardZ/app/modules/appModule.ts @@ -1,19 +1,15 @@ import {NgModule} from '@angular/core'; -import {BrowserModule} from '@angular/platform-browser'; -import {HttpModule} from '@angular/http'; -import {FormsModule} from '@angular/forms'; -import {BoardzAppComponent} from '../app'; -import {APP_PROVIDERS} from './appProviders'; -import {APP_DECLARATIONS} from './appDeclarations'; -import {APP_ROUTING} from './appRoutes'; -import {CoreModule} from './coreModule'; +import {ModuleConfiguration} from './config'; +import {SharedModule} from './sharedModule'; import {GamesModule} from './gamesModule'; @NgModule({ - imports: [BrowserModule, HttpModule, FormsModule, CoreModule, GamesModule, APP_ROUTING], - declarations: [APP_DECLARATIONS], - providers: APP_PROVIDERS, - bootstrap: [BoardzAppComponent], + imports: [ ModuleConfiguration.App.imports, SharedModule, GamesModule], + exports: ModuleConfiguration.App.exports, + declarations: ModuleConfiguration.App.declarations, + providers: ModuleConfiguration.App.providers, + bootstrap: ModuleConfiguration.App.bootstraps }) export class AppModule { + } diff --git a/src/BoardZ/app/modules/appProviders.ts b/src/BoardZ/app/modules/appProviders.ts deleted file mode 100644 index 01afc83..0000000 --- a/src/BoardZ/app/modules/appProviders.ts +++ /dev/null @@ -1,50 +0,0 @@ -import {HashLocationStrategy, LocationStrategy} from '@angular/common'; -import {XHRBackend, ConnectionBackend} from '@angular/http'; -import {AppConfiguration} from '../appConfig'; -import {NativeIntegrationService} from '../services/nativeIntegrationService'; -import {AuthenticatedHttp} from '../services/authenticatedHttp'; -import {TokenService} from '../services/tokenService'; -import {LoginService} from '../services/loginService'; -import {LogService} from '../services/logService'; -import {GamesService} from '../services/gamesService'; -import {GeolocationService} from '../services/geolocationService'; -import {PlayersService} from '../services/playersService'; -import {NotificationService} from '../services/notificationService'; -import {PlatformInformationService} from '../services/platformInformationService'; -import {CameraService} from '../services/cameraService'; -import {UiNotificationService} from '../services/uiNotificationService'; -import {SignalRService} from '../services/signalrService'; -import {MobileCameraService} from '../services/mobileCameraService'; -import {DesktopCameraService} from '../services/desktopCameraService'; -import {appRoutingProviders} from './appRoutes'; - -export const CORE_PROVIDERS = [ - { - provide: CameraService, useFactory: (()=> { - return (platformInformationService: PlatformInformationService): CameraService => { - return platformInformationService.isMobile ? new MobileCameraService() : new DesktopCameraService(); - }; - })(), deps: [PlatformInformationService] - }, - GeolocationService -]; - -export const APP_PROVIDERS = [ - { provide: LocationStrategy, useClass: HashLocationStrategy }, - { provide: ConnectionBackend, useClass: XHRBackend }, - AppConfiguration, - NativeIntegrationService, - AuthenticatedHttp, - TokenService, - LoginService, - LogService, - GamesService, - , - PlayersService, - NotificationService, - PlatformInformationService, - - UiNotificationService, - SignalRService, - appRoutingProviders -]; diff --git a/src/BoardZ/app/modules/appRoutes.ts b/src/BoardZ/app/modules/appRoutes.ts deleted file mode 100644 index c22e381..0000000 --- a/src/BoardZ/app/modules/appRoutes.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {ModuleWithProviders} from '@angular/core'; -import {RouterModule, Routes} from '@angular/router'; -import {DashboardComponent} from '../components/dashboard/dashboard'; -import {LoginComponent} from '../components/login/login'; -import {NotificationsComponent} from '../components/notifications/notifications'; -import {RadiusSearchComponent} from '../components/radiusSearch/radiusSearch'; -import {AuthGuard} from '../guards/authGuard'; - -const appRoutes: Routes = [ - - { path: '', name: 'Dashboard', canActivate: [AuthGuard], component: DashboardComponent }, - { path: 'login', name: 'Login', component: LoginComponent }, - { path: 'notifications', name: 'Notifications', canActivate: [AuthGuard], component: NotificationsComponent }, - //{ path: '/games/...', name: 'Games', component: GamesComponent, data: { displayName: 'Games' } }, - { path: 'radiussearch', name: 'RadiusSearch', canActivate: [AuthGuard], component: RadiusSearchComponent } -]; - -export const appRoutingProviders: any[] = [ - - AuthGuard -]; - -export const APP_ROUTING: ModuleWithProviders = RouterModule.forRoot(appRoutes); - diff --git a/src/BoardZ/app/modules/config.ts b/src/BoardZ/app/modules/config.ts new file mode 100644 index 0000000..2ad2ff5 --- /dev/null +++ b/src/BoardZ/app/modules/config.ts @@ -0,0 +1,115 @@ +import {FormsModule} from '@angular/forms'; +import {BoardzAppComponent} from '../app'; +import {DashboardComponent} from '../components/dashboard/dashboard'; +import {LoginComponent} from '../components/login/login'; +import {RadiusSearchComponent} from '../components/radiusSearch/radiusSearch'; +import {NotificationsComponent} from '../components/notifications/notifications'; +import {HeaderComponent} from '../components/header/header'; +import {SidebarComponent} from '../components/sidebar/sidebar'; +import {WidgetComponent} from '../components/widget/widget'; +import {BackButtonDirective} from '../directives/backButtonDirective'; +import {CloseSidebarOnClickDirective} from '../directives/closeSidebarOnClickDirective'; +import {BrowserModule} from '@angular/platform-browser'; +import {HttpModule, XHRBackend, ConnectionBackend} from '@angular/http'; +import {APP_ROUTING, appRoutingProviders, GAMES_ROUTING} from '../routes/index'; +import {ApiConfig} from '../apiConfig'; +import {HashLocationStrategy, LocationStrategy, CommonModule} from '@angular/common'; +import {NativeIntegrationService} from '../services/nativeIntegrationService'; +import {AuthenticatedHttp} from '../services/authenticatedHttp'; +import {TokenService} from '../services/tokenService'; +import {LoginService} from '../services/loginService'; +import {LogService} from '../services/logService'; +import {GamesService} from '../services/gamesService'; +import {PlayersService} from '../services/playersService'; +import {NotificationService} from '../services/notificationService'; +import {PlatformInformationService} from '../services/platformInformationService'; +import {UiNotificationService} from '../services/uiNotificationService'; +import {SignalRService} from '../services/signalrService'; +import {GameListComponent} from '../components/games/list'; +import {GameDetailsComponent} from '../components/games/details'; +import {GamesRootComponent} from '../components/games/gamesRoot'; +import {GameDetailsResolver} from '../resolvers/gameDetailsResolver'; +import {CameraService} from '../services/cameraService'; +import {MobileCameraService} from '../services/mobileCameraService'; +import {DesktopCameraService} from '../services/desktopCameraService'; +import {PictureItComponent} from '../components/pictureIt/pictureIt'; +import {LocateItComponent} from '../components/locateIt/locateIt'; +import {GeolocationService} from '../services/geolocationService'; + +export namespace ModuleConfiguration { + + export class App { + + public static declarations = [ + BoardzAppComponent, + DashboardComponent, + LoginComponent, + RadiusSearchComponent, + NotificationsComponent, + HeaderComponent, + SidebarComponent, + WidgetComponent, + BackButtonDirective, + CloseSidebarOnClickDirective + ]; + + public static imports = [ + BrowserModule, + HttpModule, + FormsModule, + APP_ROUTING + ]; + + public static exports = []; + + public static providers = [{ provide: LocationStrategy, useClass: HashLocationStrategy }, + { provide: ConnectionBackend, useClass: XHRBackend }, + ApiConfig, + NativeIntegrationService, + AuthenticatedHttp, + TokenService, + LoginService, + LogService, + GamesService, + PlayersService, + NotificationService, + PlatformInformationService, + UiNotificationService, + SignalRService, + appRoutingProviders]; + + public static bootstraps = [BoardzAppComponent] + } + + export class Games { + + public static declarations = [GamesRootComponent, GameDetailsComponent, GameListComponent]; + + public static imports = [CommonModule, FormsModule, GAMES_ROUTING]; + + public static exports = []; + + public static providers = [GameDetailsResolver]; + } + + export class Shared { + + public static declarations = [PictureItComponent, LocateItComponent]; + + public static imports = [CommonModule, FormsModule]; + + public static exports = [PictureItComponent, LocateItComponent]; + + public static providers = [ + { + provide: CameraService, useFactory: (() => { + return (platformInformationService: PlatformInformationService): CameraService => { + return platformInformationService.isMobile ? new MobileCameraService() : new DesktopCameraService(); + }; + })(), deps: [PlatformInformationService] + }, + GeolocationService + ]; + } +} + diff --git a/src/BoardZ/app/modules/coreModule.ts b/src/BoardZ/app/modules/coreModule.ts deleted file mode 100644 index 8829c86..0000000 --- a/src/BoardZ/app/modules/coreModule.ts +++ /dev/null @@ -1,15 +0,0 @@ -import {NgModule} from '@angular/core'; -import {PictureItComponent} from '../components/pictureIt/pictureIt'; -import {LocateItComponent} from '../components/locateIt/locateIt'; -import {CommonModule} from '@angular/common'; -import {FormsModule} from '@angular/forms'; -import {CORE_PROVIDERS} from './appProviders'; -@NgModule({ - imports: [CommonModule, FormsModule], - declarations: [PictureItComponent, LocateItComponent], - exports: [PictureItComponent, LocateItComponent], - providers: [CORE_PROVIDERS] -}) -export class CoreModule { - -} diff --git a/src/BoardZ/app/modules/gamesModule.ts b/src/BoardZ/app/modules/gamesModule.ts index 5b6c781..061327c 100644 --- a/src/BoardZ/app/modules/gamesModule.ts +++ b/src/BoardZ/app/modules/gamesModule.ts @@ -1,23 +1,13 @@ import {NgModule} from '@angular/core'; -import {FormsModule} from '@angular/forms'; -import {CommonModule} from '@angular/common'; -import {CoreModule} from './coreModule'; -import {gamesRouting} from '../components/games/gamesRoutes'; -import {GamesComponent} from '../components/games/games'; -import {GameDetailsComponent} from '../components/games/details'; -import {GameListComponent} from '../components/games/list'; -import {GameDetailsResolver} from '../components/games/gameDetailsResolver'; +import {ModuleConfiguration} from './config'; +import {SharedModule} from './sharedModule'; @NgModule({ - imports: [CommonModule, FormsModule, CoreModule, gamesRouting], - declarations: [ - GamesComponent, - GameDetailsComponent, - GameListComponent - ], - providers: [GameDetailsResolver] - } -) + imports: [ModuleConfiguration.Games.imports, SharedModule], + exports: ModuleConfiguration.Games.exports, + declarations: ModuleConfiguration.Games.declarations, + providers: ModuleConfiguration.Games.providers +}) export class GamesModule { } diff --git a/src/BoardZ/app/modules/sharedModule.ts b/src/BoardZ/app/modules/sharedModule.ts new file mode 100644 index 0000000..0232abd --- /dev/null +++ b/src/BoardZ/app/modules/sharedModule.ts @@ -0,0 +1,12 @@ +import {NgModule} from '@angular/core'; +import {ModuleConfiguration} from './config'; + +@NgModule({ + declarations: ModuleConfiguration.Shared.declarations, + imports: ModuleConfiguration.Shared.imports, + exports: ModuleConfiguration.Shared.exports, + providers: ModuleConfiguration.Shared.providers +}) +export class SharedModule { + +} diff --git a/src/BoardZ/app/components/games/gameDetailsResolver.ts b/src/BoardZ/app/resolvers/gameDetailsResolver.ts similarity index 76% rename from src/BoardZ/app/components/games/gameDetailsResolver.ts rename to src/BoardZ/app/resolvers/gameDetailsResolver.ts index 68ffbb8..472bbfa 100644 --- a/src/BoardZ/app/components/games/gameDetailsResolver.ts +++ b/src/BoardZ/app/resolvers/gameDetailsResolver.ts @@ -1,7 +1,7 @@ import {Injectable} from '@angular/core'; import {Resolve, ActivatedRouteSnapshot} from '@angular/router'; -import {Game} from '../../models/game'; -import {GamesService} from '../../services/gamesService'; +import {Game} from '../models/game'; +import {GamesService} from '../services/gamesService'; @Injectable() export class GameDetailsResolver implements Resolve { @@ -13,9 +13,9 @@ export class GameDetailsResolver implements Resolve { return new Promise((resolve) => { this._gamesService.getById(id).subscribe(game => { if (game) { - resolve(game) + resolve(game); } else { - resolve(new Game()) + resolve(new Game()); } }); }); diff --git a/src/BoardZ/app/routes/index.ts b/src/BoardZ/app/routes/index.ts new file mode 100644 index 0000000..5f530aa --- /dev/null +++ b/src/BoardZ/app/routes/index.ts @@ -0,0 +1,49 @@ +import {ModuleWithProviders} from '@angular/core'; +import {RouterModule, Routes} from '@angular/router'; +import {DashboardComponent} from '../components/dashboard/dashboard'; +import {LoginComponent} from '../components/login/login'; +import {NotificationsComponent} from '../components/notifications/notifications'; +import {RadiusSearchComponent} from '../components/radiusSearch/radiusSearch'; +import {AuthGuard} from '../guards/authGuard'; +import {GameDetailsResolver} from '../resolvers/gameDetailsResolver'; +import {GameDetailsComponent} from '../components/games/details'; +import {GameListComponent} from '../components/games/list'; +import {GamesRootComponent} from '../components/games/gamesRoot'; + +const appRootRoutes: Routes = [ + + { path: '', name: 'Dashboard', canActivate: [AuthGuard], component: DashboardComponent }, + { path: 'login', name: 'Login', component: LoginComponent }, + { path: 'notifications', name: 'Notifications', canActivate: [AuthGuard], component: NotificationsComponent }, + { path: 'radiussearch', name: 'RadiusSearch', canActivate: [AuthGuard], component: RadiusSearchComponent } +]; + +const gameRoutes: Routes = [ + + { + path: 'games', + component: GamesRootComponent, + 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 appRoutingProviders: any[] = [AuthGuard]; + +export const APP_ROUTING: ModuleWithProviders = RouterModule.forRoot(appRootRoutes); +export const GAMES_ROUTING: ModuleWithProviders = RouterModule.forChild(gameRoutes); diff --git a/src/BoardZ/app/services/appInjector.ts b/src/BoardZ/app/services/appInjector.ts deleted file mode 100644 index 3d038ed..0000000 --- a/src/BoardZ/app/services/appInjector.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {Injector} from '@angular/core'; - -let appInjectorRef: Injector; - -export const appInjector = (injector?: Injector): Injector => { - if (injector) { - appInjectorRef = injector; - } - - return appInjectorRef; -}; diff --git a/src/BoardZ/app/services/authenticatedHttp.ts b/src/BoardZ/app/services/authenticatedHttp.ts index 17cb0fc..b476cd5 100644 --- a/src/BoardZ/app/services/authenticatedHttp.ts +++ b/src/BoardZ/app/services/authenticatedHttp.ts @@ -1,18 +1,18 @@ import {Injectable} from '@angular/core'; import {Http, RequestOptionsArgs, Response, Headers} from '@angular/http'; import {Observable} from 'rxjs/Observable'; -import {AppConfiguration} from '../appConfig'; +import {ApiConfig} from '../apiConfig'; import {TokenService} from './tokenService'; @Injectable() export class AuthenticatedHttp { constructor(private _http: Http, - private _config: AppConfiguration, + private _config: ApiConfig, private _tokenService: TokenService) { } private buildUrl(appendix: string): string { - return `${this._config.apiEndpoint}${appendix}`; + return `${this._config.rootUrl}${appendix}`; } request(url: string, options?: RequestOptionsArgs): Observable { @@ -58,14 +58,14 @@ export class AuthenticatedHttp { } protected prepareOptions(options: RequestOptionsArgs): RequestOptionsArgs { - var token = this._tokenService.token; + let token = this._tokenService.token; if (token) { options = options || {}; - if (!options.headers) + if (!options.headers) { options.headers = new Headers(); - + } options.headers.append('Authorization', 'Bearer ' + token); } diff --git a/src/BoardZ/app/services/desktopCameraService.ts b/src/BoardZ/app/services/desktopCameraService.ts index 9c5ec0b..b7e0002 100644 --- a/src/BoardZ/app/services/desktopCameraService.ts +++ b/src/BoardZ/app/services/desktopCameraService.ts @@ -25,23 +25,23 @@ export class DesktopCameraService implements ICameraService { .then((stream: any) => { return new Promise((resolve, reject) => { try { - var vendorURL = window.URL || window.webkitURL; - var doc = document; - var videoElement = doc.createElement('video'); + let vendorURL = window.URL || window.webkitURL; + const doc = document; + let videoElement = doc.createElement('video'); videoElement.src = vendorURL.createObjectURL(stream); videoElement.play(); videoElement.addEventListener('canplay', () => { - var canvasElement = doc.createElement('canvas'); + let canvasElement = doc.createElement('canvas'); canvasElement.setAttribute('width', videoElement.videoWidth.toString()); canvasElement.setAttribute('height', videoElement.videoHeight.toString()); // Wait a bit before taking a screenshot so the camera has time to adjust lights setTimeout(() => { - var context = canvasElement.getContext('2d'); + let context = canvasElement.getContext('2d'); context.drawImage(videoElement, 0, 0, videoElement.videoWidth, videoElement.videoHeight); - var url = canvasElement.toDataURL('image/png'); + const url = canvasElement.toDataURL('image/png'); videoElement.pause(); diff --git a/src/BoardZ/app/services/geolocationService.ts b/src/BoardZ/app/services/geolocationService.ts index 9e6db67..d6b8189 100644 --- a/src/BoardZ/app/services/geolocationService.ts +++ b/src/BoardZ/app/services/geolocationService.ts @@ -4,11 +4,11 @@ import {GeoLocation} from '../models/geoLocation'; @Injectable() export class GeolocationService { public locate() { - return new Promise((resolve, reject)=> { + return new Promise((resolve, reject) => { if (window.navigator && window.navigator.geolocation) { - window.navigator.geolocation.getCurrentPosition((pos)=> { + window.navigator.geolocation.getCurrentPosition((pos) => { resolve(new GeoLocation(pos.coords.latitude, pos.coords.longitude, 16)); - }, (err)=> { + }, (err) => { reject(err); }, { enableHighAccuracy: false, @@ -20,4 +20,4 @@ export class GeolocationService { } }); } -} +} diff --git a/src/BoardZ/app/services/logService.ts b/src/BoardZ/app/services/logService.ts index 91594d1..25a557e 100644 --- a/src/BoardZ/app/services/logService.ts +++ b/src/BoardZ/app/services/logService.ts @@ -7,11 +7,13 @@ export class LogService { public maximumLogLevel: LogLevel = LogLevel.Warning; public log(message: string, logLevel?: LogLevel): void { - if (!logLevel) + if (!logLevel) { logLevel = this.defaultLogLevel; + } - if (logLevel > this.maximumLogLevel) + if (logLevel > this.maximumLogLevel) { return; + } this.doLog(this.formatMessage(logLevel, message)); } diff --git a/src/BoardZ/app/services/loginService.ts b/src/BoardZ/app/services/loginService.ts index 2d5f54b..533b8b2 100644 --- a/src/BoardZ/app/services/loginService.ts +++ b/src/BoardZ/app/services/loginService.ts @@ -3,7 +3,7 @@ import {Http, Headers, RequestOptions} from '@angular/http'; import {Router} from '@angular/router'; import {Observable} from 'rxjs/Observable'; import {TokenService} from './tokenService'; -import {AppConfiguration} from '../appConfig'; +import {ApiConfig} from '../apiConfig'; import {LogService} from './logService'; import {TokenData} from '../models/tokenData'; import {SignalRService} from './signalrService'; @@ -20,7 +20,7 @@ export class LoginService { return this._tokenService.username; } - constructor(private _config: AppConfiguration, + constructor(private _config: ApiConfig, private _logService: LogService, private _http: Http, private _router: Router, @@ -28,7 +28,9 @@ export class LoginService { private _signalRService: SignalRService) { this._tokenService.isAuthenticated() .subscribe((value) => { - if (!value) this.logout(); + if (!value) { + this.logout(); + } }); } @@ -59,8 +61,8 @@ export class LoginService { let body = 'grant_type=password&username=' + username + '&password=' + password, options = new RequestOptions({ headers: new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' }) }); - return Observable.create((observer)=> { - this._http.post(this._config.apiEndpoint + 'token', body, options) + return Observable.create((observer) => { + this._http.post(this._config.rootUrl + 'token', body, options) .map(response => response.json()) .subscribe( (tokenData) => { @@ -89,4 +91,3 @@ export class LoginService { this._tokenService.token = token; } } - diff --git a/src/BoardZ/app/services/playersService.ts b/src/BoardZ/app/services/playersService.ts index 596f6eb..c353d3d 100644 --- a/src/BoardZ/app/services/playersService.ts +++ b/src/BoardZ/app/services/playersService.ts @@ -30,7 +30,7 @@ export class PlayersService { } public getPlayerCount(): Observable { - return this._http.get('api/players/playercount').map(r => r.json()) + return this._http.get('api/players/playercount').map(r => r.json()); } public findNearby(radius: number, coordinates: GeoLocation): Observable { diff --git a/src/BoardZ/app/services/signalrService.ts b/src/BoardZ/app/services/signalrService.ts index e91d22c..77c3fbe 100644 --- a/src/BoardZ/app/services/signalrService.ts +++ b/src/BoardZ/app/services/signalrService.ts @@ -1,9 +1,8 @@ import {Injectable, EventEmitter} from '@angular/core'; -import {AppConfiguration} from '../appConfig'; +import {ApiConfig} from '../apiConfig'; import {LogService} from './logService'; import {TokenService} from './tokenService'; -// jQuery Ahoi declare var $; @Injectable() @@ -14,7 +13,7 @@ export class SignalRService { public someoneJoinedAGame: EventEmitter = new EventEmitter(); - constructor(private _configuration: AppConfiguration, + constructor(private _configuration: ApiConfig, private _tokenService: TokenService, private _logService: LogService) { this._hubConnection = $.hubConnection; @@ -33,12 +32,12 @@ export class SignalRService { return; } - this._connection = this._hubConnection(`${this._configuration.apiEndpoint}signalr`); + this._connection = this._hubConnection(`${this._configuration.rootUrl}signalr`); this._connection.qs = { 'authorization': this._tokenService.token }; this._playerProxy = this._connection.createHubProxy('playerHub'); this._playerProxy.on('someoneStartedPlaying', (username, game) => { - var msg = `${username} started playing ${game}.`; + let msg = `${username} started playing ${game}.`; this._logService.logDebug(`Received SignalR message: ${msg}`); this.someoneJoinedAGame.emit(msg); }); diff --git a/src/BoardZ/app/services/tokenService.ts b/src/BoardZ/app/services/tokenService.ts index c60a3cf..3d761c2 100644 --- a/src/BoardZ/app/services/tokenService.ts +++ b/src/BoardZ/app/services/tokenService.ts @@ -11,10 +11,11 @@ export class TokenService { private _authenticated: boolean; constructor(private _logService: LogService) { - var token = this.token; + let token = this.token; - if ((typeof token !== 'undefined') && (token !== null)) + if ((typeof token !== 'undefined') && (token !== null)) { this._authenticated = true; + } } public get token(): string { diff --git a/src/BoardZ/app/services/uiNotificationService.ts b/src/BoardZ/app/services/uiNotificationService.ts index fe2aa9c..ad7ad60 100644 --- a/src/BoardZ/app/services/uiNotificationService.ts +++ b/src/BoardZ/app/services/uiNotificationService.ts @@ -33,7 +33,7 @@ export class UiNotificationService { addclass: 'stack-bar-top', cornerclass: '', width: '100%', - delay:1500 + delay: 1500 }; new PNotify(settings); diff --git a/src/BoardZ/css/app.css b/src/BoardZ/css/app.css index 9552950..1f9159c 100644 --- a/src/BoardZ/css/app.css +++ b/src/BoardZ/css/app.css @@ -6,12 +6,14 @@ body { cursor: default; } -.ng-valid[required] { - border-left: 5px solid #42A948; +.ng-valid[required]{ + border-right: 3px solid #42A948; } -.ng-invalid { - border-left: 5px solid #a94442; +input.ng-invalid, +select.ng-invalid, +textarea.ng-invalid { + border-right: 3px solid indianred; } .respond-click { @@ -24,9 +26,12 @@ button, a{ } .danger { - color: #dd4b39; + color: indianred; +} +.alert.alert-danger{ + padding-top: 15px !important; + margin-top:3px !important; } - .stack-bar-top { top: 0; right: 0; @@ -42,10 +47,11 @@ button, a{ } /* Navigation */ -body .navbar-custom-menu [hidden="true"] { +body .navbar-custom-menu [hidden="true"], .hidden { display: none; } + body, .wrapper { overflow-x: hidden; diff --git a/src/BoardZ/index.html b/src/BoardZ/index.html index 43469cb..5414da7 100644 --- a/src/BoardZ/index.html +++ b/src/BoardZ/index.html @@ -8,7 +8,7 @@ - +
diff --git a/src/BoardZ/system.setup.js b/src/BoardZ/system.setup.js index 8efd1a0..c424807 100644 --- a/src/BoardZ/system.setup.js +++ b/src/BoardZ/system.setup.js @@ -30,13 +30,12 @@ // packages tells the System loader how to load when no filename and/or no extension var packages = { 'app': { main: 'main.js', defaultExtension: 'js' }, - 'rxjs': { defaultExtension: 'js' }, - + 'rxjs': { defaultExtension: 'js' } }; var config = { paths: { - 'ng:' : '@angular/' + 'ng:': '@angular/' }, map: map, packages: packages @@ -46,7 +45,7 @@ function backupModule() { return new Promise(function (resolve, reject) { - if(typeof module !== 'undefined' && module.hasOwnProperty('exports')) { + if (typeof module !== 'undefined' && module.hasOwnProperty('exports')) { window.module = module; module = undefined; } @@ -57,7 +56,7 @@ function backupModule() { function restoreModule() { return new Promise(function (resolve, reject) { - if(window.hasOwnProperty('module')) { + if (window.hasOwnProperty('module')) { module = window.module; } console.log('mod restored'); @@ -67,7 +66,7 @@ function restoreModule() { backupModule() .then(function () { - // return System.import('jquery'); + // return System.import('jquery'); }) .then(function () { return restoreModule(); diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..330ae06 --- /dev/null +++ b/tslint.json @@ -0,0 +1,57 @@ +{ + "rules": { + "no-require-imports": true, + "no-var-keyword": true, + "triple-equals": [ + true, + "allow-undefined-check" + ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + }, + { + "call-signature": "onespace", + "index-signature": "onespace", + "parameter": "onespace", + "property-declaration": "onespace", + "variable-declaration": "onespace" + } + ], + "curly": true, + "eofline": true, + "indent": [ + true, + "spaces" + ], + "no-trailing-whitespace": true, + "class-name": true, + "no-consecutive-blank-lines": true, + "one-line": [ + true, + "check-else", + "check-open-brace" + ], + "quotemark": [ + true, + "single" + ], + "semicolon": [ + true, + "always" + ], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-separator", + "check-operator", + "check-type" + ] + } +}