From 82dc2a6b0e8b45e4f94ad045851c34056c5bc8be Mon Sep 17 00:00:00 2001 From: Irena Date: Mon, 13 Nov 2017 16:33:05 +0200 Subject: [PATCH 1/2] Commit --- src/app/app.component.css | 5 ++ src/app/app.component.html | 5 ++ src/app/app.component.spec.ts | 27 ++++++++++ src/app/app.component.ts | 9 ++++ src/app/app.module.ts | 51 +++++++++++++++++++ src/app/authguard.guard.spec.ts | 15 ++++++ src/app/authguard.guard.ts | 15 ++++++ src/app/dashboard/dashboard.component.css | 15 ++++++ src/app/dashboard/dashboard.component.html | 15 ++++++ src/app/dashboard/dashboard.component.spec.ts | 25 +++++++++ src/app/dashboard/dashboard.component.ts | 17 +++++++ src/app/footer/footer.component.css | 0 src/app/footer/footer.component.html | 1 + src/app/footer/footer.component.spec.ts | 25 +++++++++ src/app/footer/footer.component.ts | 16 ++++++ src/app/header/header.component.css | 6 +++ src/app/header/header.component.html | 1 + src/app/header/header.component.spec.ts | 25 +++++++++ src/app/header/header.component.ts | 16 ++++++ src/app/login-form/login-form.component.css | 0 src/app/login-form/login-form.component.html | 30 +++++++++++ .../login-form/login-form.component.spec.ts | 25 +++++++++ src/app/login-form/login-form.component.ts | 35 +++++++++++++ src/app/signup-form/signup-form.component.css | 0 .../signup-form/signup-form.component.html | 51 +++++++++++++++++++ .../signup-form/signup-form.component.spec.ts | 25 +++++++++ src/app/signup-form/signup-form.component.ts | 49 ++++++++++++++++++ src/app/user.service.spec.ts | 15 ++++++ src/app/user.service.ts | 21 ++++++++ src/app/user.ts | 5 ++ src/app/users.ts | 6 +++ src/styles.css | 1 + tsconfig.json | 19 +++++++ 33 files changed, 571 insertions(+) create mode 100644 src/app/app.component.css create mode 100644 src/app/app.component.html create mode 100644 src/app/app.component.spec.ts create mode 100644 src/app/app.component.ts create mode 100644 src/app/app.module.ts create mode 100644 src/app/authguard.guard.spec.ts create mode 100644 src/app/authguard.guard.ts create mode 100644 src/app/dashboard/dashboard.component.css create mode 100644 src/app/dashboard/dashboard.component.html create mode 100644 src/app/dashboard/dashboard.component.spec.ts create mode 100644 src/app/dashboard/dashboard.component.ts create mode 100644 src/app/footer/footer.component.css create mode 100644 src/app/footer/footer.component.html create mode 100644 src/app/footer/footer.component.spec.ts create mode 100644 src/app/footer/footer.component.ts create mode 100644 src/app/header/header.component.css create mode 100644 src/app/header/header.component.html create mode 100644 src/app/header/header.component.spec.ts create mode 100644 src/app/header/header.component.ts create mode 100644 src/app/login-form/login-form.component.css create mode 100644 src/app/login-form/login-form.component.html create mode 100644 src/app/login-form/login-form.component.spec.ts create mode 100644 src/app/login-form/login-form.component.ts create mode 100644 src/app/signup-form/signup-form.component.css create mode 100644 src/app/signup-form/signup-form.component.html create mode 100644 src/app/signup-form/signup-form.component.spec.ts create mode 100644 src/app/signup-form/signup-form.component.ts create mode 100644 src/app/user.service.spec.ts create mode 100644 src/app/user.service.ts create mode 100644 src/app/user.ts create mode 100644 src/app/users.ts create mode 100644 src/styles.css create mode 100644 tsconfig.json diff --git a/src/app/app.component.css b/src/app/app.component.css new file mode 100644 index 0000000..74b16a8 --- /dev/null +++ b/src/app/app.component.css @@ -0,0 +1,5 @@ +#wrapper { + display: flex; + flex-direction: column; + min-height: 100vh; +} diff --git a/src/app/app.component.html b/src/app/app.component.html new file mode 100644 index 0000000..8548910 --- /dev/null +++ b/src/app/app.component.html @@ -0,0 +1,5 @@ +
+ + + +
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts new file mode 100644 index 0000000..bcbdf36 --- /dev/null +++ b/src/app/app.component.spec.ts @@ -0,0 +1,27 @@ +import { TestBed, async } from '@angular/core/testing'; +import { AppComponent } from './app.component'; +describe('AppComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ + AppComponent + ], + }).compileComponents(); + })); + it('should create the app', async(() => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.debugElement.componentInstance; + expect(app).toBeTruthy(); + })); + it(`should have as title 'app'`, async(() => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.debugElement.componentInstance; + expect(app.title).toEqual('app'); + })); + it('should render title in a h1 tag', async(() => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.debugElement.nativeElement; + expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!'); + })); +}); diff --git a/src/app/app.component.ts b/src/app/app.component.ts new file mode 100644 index 0000000..bb05f90 --- /dev/null +++ b/src/app/app.component.ts @@ -0,0 +1,9 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'] +}) + +export class AppComponent {} diff --git a/src/app/app.module.ts b/src/app/app.module.ts new file mode 100644 index 0000000..fc30124 --- /dev/null +++ b/src/app/app.module.ts @@ -0,0 +1,51 @@ +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { FormsModule } from '@angular/forms'; +import { HttpClientModule } from '@angular/common/http'; +import { AppComponent } from './app.component'; +import { HeaderComponent } from './header/header.component'; +import { LoginFormComponent } from './login-form/login-form.component'; +import { FooterComponent } from './footer/footer.component'; +import { DashboardComponent } from './dashboard/dashboard.component'; +import { RouterModule, Routes } from '@angular/router'; +import { UserService } from './user.service'; +import { AuthguardGuard } from './authguard.guard'; +import { AlertModule } from 'ngx-bootstrap'; +import { SignupFormComponent } from './signup-form/signup-form.component'; + +const appRoutes:Routes = [ + { + path: '', + component: LoginFormComponent + }, + { + path: 'dashboard', + canActivate: [AuthguardGuard], + component: DashboardComponent + + }, + { + path: 'signup', + component: SignupFormComponent + + } +]; + +@NgModule({ + imports: [ + RouterModule.forRoot(appRoutes), + BrowserModule, + AlertModule.forRoot() + ], + declarations: [ + AppComponent, + HeaderComponent, + LoginFormComponent, + FooterComponent, + DashboardComponent, + SignupFormComponent + ], + providers: [UserService, AuthguardGuard], + bootstrap: [ AppComponent ] +}) +export class AppModule { } diff --git a/src/app/authguard.guard.spec.ts b/src/app/authguard.guard.spec.ts new file mode 100644 index 0000000..1c15a0f --- /dev/null +++ b/src/app/authguard.guard.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, async, inject } from '@angular/core/testing'; + +import { AuthguardGuard } from './authguard.guard'; + +describe('AuthguardGuard', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [AuthguardGuard] + }); + }); + + it('should ...', inject([AuthguardGuard], (guard: AuthguardGuard) => { + expect(guard).toBeTruthy(); + })); +}); diff --git a/src/app/authguard.guard.ts b/src/app/authguard.guard.ts new file mode 100644 index 0000000..9cb4f64 --- /dev/null +++ b/src/app/authguard.guard.ts @@ -0,0 +1,15 @@ +import { Injectable } from '@angular/core'; +import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; +import {UserService} from './user.service'; +import {Router} from '@angular/router'; + +@Injectable() +export class AuthguardGuard implements CanActivate { + + constructor(private user: UserService) {} + + canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable | Promise { + return this.user.getUserLoggedIn(); + } +} diff --git a/src/app/dashboard/dashboard.component.css b/src/app/dashboard/dashboard.component.css new file mode 100644 index 0000000..2a02c4d --- /dev/null +++ b/src/app/dashboard/dashboard.component.css @@ -0,0 +1,15 @@ +#standardRoom { + background-color: black; + height: 200px; + color: white; + font-size: 24px; + line-height: 200px; +} + +#goldRoom { + background-color: pink; + height: 200px; + color: white; + font-size: 24px; + line-height: 200px; +} diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html new file mode 100644 index 0000000..ec8b969 --- /dev/null +++ b/src/app/dashboard/dashboard.component.html @@ -0,0 +1,15 @@ +

+ Logged successfully. + Go back +

+ + diff --git a/src/app/dashboard/dashboard.component.spec.ts b/src/app/dashboard/dashboard.component.spec.ts new file mode 100644 index 0000000..9c996c3 --- /dev/null +++ b/src/app/dashboard/dashboard.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { DashboardComponent } from './dashboard.component'; + +describe('DashboardComponent', () => { + let component: DashboardComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ DashboardComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(DashboardComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts new file mode 100644 index 0000000..78a0df0 --- /dev/null +++ b/src/app/dashboard/dashboard.component.ts @@ -0,0 +1,17 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { UserService } from '../user.service'; + +@Component({ + selector: 'app-dashboard', + templateUrl: './dashboard.component.html', + styleUrls: ['./dashboard.component.css'], + encapsulation: ViewEncapsulation.None +}) +export class DashboardComponent implements OnInit { + + constructor(private user: UserService) { } + + ngOnInit() { + } + +} diff --git a/src/app/footer/footer.component.css b/src/app/footer/footer.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/footer/footer.component.html b/src/app/footer/footer.component.html new file mode 100644 index 0000000..1825eb3 --- /dev/null +++ b/src/app/footer/footer.component.html @@ -0,0 +1 @@ +

Footer will be here

diff --git a/src/app/footer/footer.component.spec.ts b/src/app/footer/footer.component.spec.ts new file mode 100644 index 0000000..2ca6c45 --- /dev/null +++ b/src/app/footer/footer.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { FooterComponent } from './footer.component'; + +describe('FooterComponent', () => { + let component: FooterComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ FooterComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(FooterComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/footer/footer.component.ts b/src/app/footer/footer.component.ts new file mode 100644 index 0000000..3d8f7e9 --- /dev/null +++ b/src/app/footer/footer.component.ts @@ -0,0 +1,16 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; + +@Component({ + selector: 'app-footer', + templateUrl: './footer.component.html', + styleUrls: ['./footer.component.css'], + encapsulation: ViewEncapsulation.None +}) +export class FooterComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/header/header.component.css b/src/app/header/header.component.css new file mode 100644 index 0000000..dd31c07 --- /dev/null +++ b/src/app/header/header.component.css @@ -0,0 +1,6 @@ +header { + text-align: center; + padding: 20px 0; + font-size: 30px; + border-bottom: 2px solid #eee; +} diff --git a/src/app/header/header.component.html b/src/app/header/header.component.html new file mode 100644 index 0000000..2100222 --- /dev/null +++ b/src/app/header/header.component.html @@ -0,0 +1 @@ +
Team Chat
diff --git a/src/app/header/header.component.spec.ts b/src/app/header/header.component.spec.ts new file mode 100644 index 0000000..2d0479d --- /dev/null +++ b/src/app/header/header.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HeaderComponent } from './header.component'; + +describe('HeaderComponent', () => { + let component: HeaderComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ HeaderComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(HeaderComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts new file mode 100644 index 0000000..5d1e556 --- /dev/null +++ b/src/app/header/header.component.ts @@ -0,0 +1,16 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; + +@Component({ + selector: 'app-header', + templateUrl: './header.component.html', + styleUrls: ['./header.component.css'], + encapsulation: ViewEncapsulation.None +}) +export class HeaderComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/login-form/login-form.component.css b/src/app/login-form/login-form.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/login-form/login-form.component.html b/src/app/login-form/login-form.component.html new file mode 100644 index 0000000..6577df0 --- /dev/null +++ b/src/app/login-form/login-form.component.html @@ -0,0 +1,30 @@ +
+
+
+
+

Login

+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+
+
diff --git a/src/app/login-form/login-form.component.spec.ts b/src/app/login-form/login-form.component.spec.ts new file mode 100644 index 0000000..c5f08d4 --- /dev/null +++ b/src/app/login-form/login-form.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoginFormComponent } from './login-form.component'; + +describe('LoginFormComponent', () => { + let component: LoginFormComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ LoginFormComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LoginFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/login-form/login-form.component.ts b/src/app/login-form/login-form.component.ts new file mode 100644 index 0000000..1d2243b --- /dev/null +++ b/src/app/login-form/login-form.component.ts @@ -0,0 +1,35 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { Router } from '@angular/router'; +import { UserService } from '../user.service'; +import { USERS } from '../users'; + +@Component({ + selector: 'app-login-form', + templateUrl: './login-form.component.html', + styleUrls: ['./login-form.component.css'], + encapsulation: ViewEncapsulation.None +}) + +export class LoginFormComponent implements OnInit { + + constructor(private router: Router, private user: UserService) { + } + + ngOnInit() { + } + + loginUser(e) { + e.preventDefault(); + console.log(e); + var usernameForm = e.target.elements[0].value; + var passwordForm = e.target.elements[1].value; + + var authenticatedUsername = USERS.find(u => u.username === usernameForm); + var authenticatedPassword = USERS.find(u => u.password === passwordForm); + + if (authenticatedUsername != null && authenticatedPassword != null) { + this.user.setUserLoggedIn(); + this.router.navigate(['dashboard']); + } + } +} diff --git a/src/app/signup-form/signup-form.component.css b/src/app/signup-form/signup-form.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/signup-form/signup-form.component.html b/src/app/signup-form/signup-form.component.html new file mode 100644 index 0000000..1a3e489 --- /dev/null +++ b/src/app/signup-form/signup-form.component.html @@ -0,0 +1,51 @@ +
+
+
+
+

Sign up

+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+
+ +
+ +
+
+
+
+
diff --git a/src/app/signup-form/signup-form.component.spec.ts b/src/app/signup-form/signup-form.component.spec.ts new file mode 100644 index 0000000..53e36f9 --- /dev/null +++ b/src/app/signup-form/signup-form.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SignupFormComponent } from './signup-form.component'; + +describe('SignupFormComponent', () => { + let component: SignupFormComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ SignupFormComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SignupFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/signup-form/signup-form.component.ts b/src/app/signup-form/signup-form.component.ts new file mode 100644 index 0000000..1c79e35 --- /dev/null +++ b/src/app/signup-form/signup-form.component.ts @@ -0,0 +1,49 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { Router } from '@angular/router'; +import { UserService } from '../user.service'; +import { User } from '../user'; +import { USERS } from '../users'; +import { NgIf } from '@angular/common'; + + +@Component({ + selector: 'app-signup-form', + templateUrl: './signup-form.component.html', + styleUrls: ['./signup-form.component.css'], + encapsulation: ViewEncapsulation.None +}) + +export class SignupFormComponent implements OnInit { + + constructor(private router: Router, private user: UserService) { + } + ngOnInit() { + } + formResults = ""; + isValid = null; + registerUser(e) { + e.preventDefault(); + console.log(e); + var usernameForm = e.target.elements[0].value; + var passwordForm = e.target.elements[1].value; + var repasswordForm = e.target.elements[2].value; + + var authenticatedUsername = USERS.find(u => u.username === usernameForm); + var authenticatedPassword = false; + if (passwordForm === repasswordForm) { + authenticatedPassword = true; + } + + if (authenticatedUsername == null && authenticatedPassword) { + var newUser = {username: usernameForm, password: passwordForm, permission: 'standard'} + USERS.push(newUser); + this.formResults = "User is created. Go to login page."; + this.isValid = true; + this.router.navigate(['dashboard']); + } + else { + this.formResults = "Username already exists or passwords not match"; + this.isValid = false; + } + } +} diff --git a/src/app/user.service.spec.ts b/src/app/user.service.spec.ts new file mode 100644 index 0000000..b26195c --- /dev/null +++ b/src/app/user.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { UserService } from './user.service'; + +describe('UserService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [UserService] + }); + }); + + it('should be created', inject([UserService], (service: UserService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/user.service.ts b/src/app/user.service.ts new file mode 100644 index 0000000..65a3c5b --- /dev/null +++ b/src/app/user.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; + +@Injectable() +export class UserService { + private isUserLoggedIn; + private username; + + constructor() { + this.isUserLoggedIn = false; + } + + setUserLoggedIn() { + this.isUserLoggedIn = true; + this.username = 'admin'; + } + + getUserLoggedIn() { + return this.isUserLoggedIn; + } + +} diff --git a/src/app/user.ts b/src/app/user.ts new file mode 100644 index 0000000..0de1f58 --- /dev/null +++ b/src/app/user.ts @@ -0,0 +1,5 @@ +export class User { + username: string; + password: string; + permission: string; +} diff --git a/src/app/users.ts b/src/app/users.ts new file mode 100644 index 0000000..9f160f8 --- /dev/null +++ b/src/app/users.ts @@ -0,0 +1,6 @@ +import {User} from './user'; + +export const USERS: User[] = [ + {username: 'roei', password: 'roei', permission: 'standard'}, + {username: 'admin', password: 'admin', permission: 'gold'} +]; diff --git a/src/styles.css b/src/styles.css new file mode 100644 index 0000000..90d4ee0 --- /dev/null +++ b/src/styles.css @@ -0,0 +1 @@ +/* You can add global styles to this file, and also import other style files */ diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a6c016b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "outDir": "./dist/out-tsc", + "sourceMap": true, + "declaration": false, + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es5", + "typeRoots": [ + "node_modules/@types" + ], + "lib": [ + "es2017", + "dom" + ] + } +} From 52618cb63eccf3f0d73a4d9ed83b3d784ac14915 Mon Sep 17 00:00:00 2001 From: Irena Date: Tue, 14 Nov 2017 16:23:16 +0200 Subject: [PATCH 2/2] Commit with kinda server side --- package.json | 55 +++++++++++++ server/data/users.json | 10 +++ server/routes/api.js | 9 +++ server/server.js | 67 +++++++++++++++ src/app/app.module.ts | 13 ++- src/app/dashboard/dashboard.component.ts | 4 +- src/app/login-form/login-form.component.html | 8 +- src/app/login-form/login-form.component.ts | 38 ++++++--- src/app/login-service.service.spec.ts | 15 ++++ src/app/login-service.service.ts | 47 +++++++++++ src/app/signup-form/signup-form.component.ts | 2 +- src/app/sing-service.service.spec.ts | 15 ++++ src/app/sing-service.service.ts | 39 +++++++++ .../standart-room/standart-room.component.css | 0 .../standart-room.component.html | 3 + .../standart-room.component.spec.ts | 25 ++++++ .../standart-room/standart-room.component.ts | 16 ++++ src/app/user.service.ts | 8 +- src/app/user.ts | 2 +- src/app/users.ts | 4 +- src/assets/.gitkeep | 0 src/environments/environment.prod.ts | 3 + src/environments/environment.ts | 8 ++ src/favicon.ico | Bin 0 -> 5430 bytes src/index.html | 14 ++++ src/main.ts | 12 +++ src/polyfills.ts | 76 ++++++++++++++++++ src/test.ts | 32 ++++++++ src/tsconfig.app.json | 13 +++ src/tsconfig.spec.json | 20 +++++ src/typings.d.ts | 5 ++ 31 files changed, 534 insertions(+), 29 deletions(-) create mode 100644 package.json create mode 100644 server/data/users.json create mode 100644 server/routes/api.js create mode 100644 server/server.js create mode 100644 src/app/login-service.service.spec.ts create mode 100644 src/app/login-service.service.ts create mode 100644 src/app/sing-service.service.spec.ts create mode 100644 src/app/sing-service.service.ts create mode 100644 src/app/standart-room/standart-room.component.css create mode 100644 src/app/standart-room/standart-room.component.html create mode 100644 src/app/standart-room/standart-room.component.spec.ts create mode 100644 src/app/standart-room/standart-room.component.ts create mode 100644 src/assets/.gitkeep create mode 100644 src/environments/environment.prod.ts create mode 100644 src/environments/environment.ts create mode 100644 src/favicon.ico create mode 100644 src/index.html create mode 100644 src/main.ts create mode 100644 src/polyfills.ts create mode 100644 src/test.ts create mode 100644 src/tsconfig.app.json create mode 100644 src/tsconfig.spec.json create mode 100644 src/typings.d.ts diff --git a/package.json b/package.json new file mode 100644 index 0000000..c92c4c2 --- /dev/null +++ b/package.json @@ -0,0 +1,55 @@ +{ + "name": "teamchat", + "version": "0.0.0", + "license": "MIT", + "scripts": { + "ng": "ng", + "start": "ng serve", + "build": "ng build", + "test": "ng test", + "lint": "ng lint", + "e2e": "ng e2e" + }, + "private": true, + "dependencies": { + "@angular/animations": "^5.0.0", + "@angular/common": "^5.0.0", + "@angular/compiler": "^5.0.0", + "@angular/core": "^5.0.0", + "@angular/forms": "^5.0.0", + "@angular/http": "^5.0.0", + "@angular/platform-browser": "^5.0.0", + "@angular/platform-browser-dynamic": "^5.0.0", + "@angular/router": "^5.0.0", + "body-parser": "^1.18.2", + "bootstrap": "^3.3.7", + "core-js": "^2.4.1", + "cors": "^2.8.4", + "express": "^4.16.2", + "file-system": "^2.2.2", + "ngx-bootstrap": "^2.0.0-beta.8", + "rxjs": "^5.5.2", + "zone.js": "^0.8.14" + }, + "devDependencies": { + "@angular/cli": "1.5.0", + "@angular/compiler-cli": "^5.0.0", + "@angular/language-service": "^5.0.0", + "@types/jasmine": "~2.5.53", + "@types/jasminewd2": "~2.0.2", + "@types/node": "~6.0.60", + "codelyzer": "~3.2.0", + "jasmine-core": "~2.6.2", + "jasmine-spec-reporter": "~4.1.0", + "karma": "~1.7.0", + "karma-chrome-launcher": "~2.1.1", + "karma-cli": "~1.0.1", + "karma-coverage-istanbul-reporter": "^1.2.1", + "karma-jasmine": "~1.1.0", + "karma-jasmine-html-reporter": "^0.2.2", + "protractor": "~5.1.2", + "ts-node": "~3.2.0", + "tslint": "~5.7.0", + "typescript": "~2.4.2" + } +} diff --git a/server/data/users.json b/server/data/users.json new file mode 100644 index 0000000..d4c7c15 --- /dev/null +++ b/server/data/users.json @@ -0,0 +1,10 @@ +[ + { + "username": "admin", + "password": "admin" + }, + { + "username": "roei", + "password": "roei" + } +] diff --git a/server/routes/api.js b/server/routes/api.js new file mode 100644 index 0000000..6bd0243 --- /dev/null +++ b/server/routes/api.js @@ -0,0 +1,9 @@ +const express = require('express'); +const router = express.Router(); + +/* GET api listing. */ +router.get('/', (req, res) => { + res.send('api works'); +}); + +module.exports = router; diff --git a/server/server.js b/server/server.js new file mode 100644 index 0000000..f97254a --- /dev/null +++ b/server/server.js @@ -0,0 +1,67 @@ +const express = require('express'); +const path = require('path'); +const http = require('http'); +const bodyParser = require('body-parser'); +var file = require('file-system'); +var fs = require('fs'); +var cors = require('cors'); + +// Get our API routes +const api = require('./routes/api'); + +const app = express(); + +app.use(cors()); +// Parsers for POST data +app.use(bodyParser.json()); + +app.use(bodyParser.urlencoded({extended: false})); + +// Point static path to dist +app.use(express.static(path.join(__dirname, 'dist'))); +// Set our api routes +app.use('/api', api); + +// Catch all other routes and return the index file +app.get('/validate/:username', (req, res) => { + if (doesUserExist(req.params.username)) +res.send("user connected"); +else +res.send("user doesnt exist!"); +}); + +app.post('/', (req, res) => { + + if (doesUserExist(req.body.username)) { + let tempUser = jsonUsers.find(user => user.username === req.body.username); + if (tempUser.password === req.body.password) + // res.send(tempUser); + res.redirect('/dashboard'); + else + send('username or password incorrect, please try again'); + } + else + res.send('user doesnt exist!'); +}); +/** + * Get port from environment and store in Express. + */ +const port = process.env.PORT || '3000'; +app.set('port', port); + +/** + * Create HTTP server. + */ +const server = http.createServer(app); + +/** + * Listen on provided port, on all network interfaces. + */ +server.listen(port, () => console.log(`API running on localhost:${port}`)); + +var jsonUsers = JSON.parse(fs.readFileSync('C:\\Users\\Jbt\\WebstormProjects\\teamChatTheRealOne\\teamchat\\server\\data\\users.json'), 'utf-8'); + +function doesUserExist(username) { + return jsonUsers.filter(user => user.username === username).length === 1; +} + diff --git a/src/app/app.module.ts b/src/app/app.module.ts index fc30124..e12c1cc 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,7 +1,7 @@ import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; -import { HttpClientModule } from '@angular/common/http'; +import { HttpClient, HttpClientModule, HttpHandler } from '@angular/common/http'; import { AppComponent } from './app.component'; import { HeaderComponent } from './header/header.component'; import { LoginFormComponent } from './login-form/login-form.component'; @@ -12,6 +12,8 @@ import { UserService } from './user.service'; import { AuthguardGuard } from './authguard.guard'; import { AlertModule } from 'ngx-bootstrap'; import { SignupFormComponent } from './signup-form/signup-form.component'; +import { StandartRoomComponent } from './standart-room/standart-room.component'; +import { SingServiceService } from './sing-service.service'; const appRoutes:Routes = [ { @@ -35,7 +37,9 @@ const appRoutes:Routes = [ imports: [ RouterModule.forRoot(appRoutes), BrowserModule, - AlertModule.forRoot() + AlertModule.forRoot(), + FormsModule, + HttpClientModule ], declarations: [ AppComponent, @@ -43,9 +47,10 @@ const appRoutes:Routes = [ LoginFormComponent, FooterComponent, DashboardComponent, - SignupFormComponent + SignupFormComponent, + StandartRoomComponent ], - providers: [UserService, AuthguardGuard], + providers: [UserService, AuthguardGuard,SingServiceService,HttpClient], bootstrap: [ AppComponent ] }) export class AppModule { } diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts index 78a0df0..d20cc95 100644 --- a/src/app/dashboard/dashboard.component.ts +++ b/src/app/dashboard/dashboard.component.ts @@ -1,5 +1,7 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { Router } from '@angular/router'; import { UserService } from '../user.service'; +import { USERS } from '../users'; @Component({ selector: 'app-dashboard', @@ -10,7 +12,7 @@ import { UserService } from '../user.service'; export class DashboardComponent implements OnInit { constructor(private user: UserService) { } - + hasPermission = null; ngOnInit() { } diff --git a/src/app/login-form/login-form.component.html b/src/app/login-form/login-form.component.html index 6577df0..9c44b72 100644 --- a/src/app/login-form/login-form.component.html +++ b/src/app/login-form/login-form.component.html @@ -5,22 +5,22 @@

Login

-
+
- +
- +
- +
diff --git a/src/app/login-form/login-form.component.ts b/src/app/login-form/login-form.component.ts index 1d2243b..803d4d0 100644 --- a/src/app/login-form/login-form.component.ts +++ b/src/app/login-form/login-form.component.ts @@ -2,6 +2,12 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { Router } from '@angular/router'; import { UserService } from '../user.service'; import { USERS } from '../users'; +import { Observable} from 'rxjs/Observable'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/catch'; +import { User } from '../user'; +import {SingServiceService} from '../sing-service.service'; +import { NgModel } from '@angular/forms'; @Component({ selector: 'app-login-form', @@ -12,24 +18,30 @@ import { USERS } from '../users'; export class LoginFormComponent implements OnInit { - constructor(private router: Router, private user: UserService) { + loginUser2: User = {username:"", password:""}; + constructor(private login:SingServiceService) { } ngOnInit() { } + submit() { + this.login.loginUser(this.loginUser2.username,this.loginUser2.password).subscribe((res) => console.log(res)); + } + // loginUser(e) { + // e.preventDefault(); + // console.log(e); + // var usernameForm = e.target.elements[0].value; + // var passwordForm = e.target.elements[1].value; + + // this.login.loginUser(this.loginUser2.username,this.loginUser2.password); - loginUser(e) { - e.preventDefault(); - console.log(e); - var usernameForm = e.target.elements[0].value; - var passwordForm = e.target.elements[1].value; + // var authenticatedUsername = USERS.find(u => u.username === usernameForm); + // var authenticatedPassword = USERS.find(u => u.password === passwordForm); - var authenticatedUsername = USERS.find(u => u.username === usernameForm); - var authenticatedPassword = USERS.find(u => u.password === passwordForm); + // if (authenticatedUsername != null && authenticatedPassword != null) { + // this.user.setUserLoggedIn(usernameForm); - if (authenticatedUsername != null && authenticatedPassword != null) { - this.user.setUserLoggedIn(); - this.router.navigate(['dashboard']); - } + // this.router.navigate(['dashboard']); + // } } -} + diff --git a/src/app/login-service.service.spec.ts b/src/app/login-service.service.spec.ts new file mode 100644 index 0000000..c451bee --- /dev/null +++ b/src/app/login-service.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { LoginService } from './login-service.service'; + +describe('LoginServiceService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [LoginService] + }); + }); + + it('should be created', inject([LoginService], (service: LoginService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/login-service.service.ts b/src/app/login-service.service.ts new file mode 100644 index 0000000..0c91e2c --- /dev/null +++ b/src/app/login-service.service.ts @@ -0,0 +1,47 @@ +import { Injectable } from '@angular/core'; +import { User } from './user'; +import { Observable } from 'rxjs/Observable'; +import { HttpClient } from '@angular/common/http'; +import { NgModel } from '@angular/forms'; +import { of } from 'rxjs/observable/of'; +import { catchError, map, tap } from 'rxjs/operators'; + +@Injectable() +export class LoginService { + + constructor(private http: HttpClient) { } + + // loginUser (userName: string): Observable { + // return this.http.get("http://localhost:3000/validate/" + userName) + // .pipe( + // tap(users => this.log(`fetched users`)), + // catchError(this.handleError('getUsers', [])) + // ); + // } + + loginUser (userName: string,password:string) { + let body = {username: userName,password : password}; + return this.http.post("http://localhost:3000/validate/",body) + .pipe( + tap(users => this.log(`fetched users`)), + catchError(this.handleError('getUsers', [])) + ); + } + + private handleError (operation = 'operation', result?: T) { + return (error: any): Observable => { + + // TODO: send the error to remote logging infrastructure + console.log(error.toString()); // log to console instead + // TODO: better job of transforming error for user consumption + this.log(`${operation} failed: ${error.message}`); + + // Let the app keep running by returning an empty result. + return of(result as T); + }; + } + + private log(message: string) { + } + +} diff --git a/src/app/signup-form/signup-form.component.ts b/src/app/signup-form/signup-form.component.ts index 1c79e35..d83d122 100644 --- a/src/app/signup-form/signup-form.component.ts +++ b/src/app/signup-form/signup-form.component.ts @@ -35,7 +35,7 @@ export class SignupFormComponent implements OnInit { } if (authenticatedUsername == null && authenticatedPassword) { - var newUser = {username: usernameForm, password: passwordForm, permission: 'standard'} + var newUser = {username: usernameForm, password: passwordForm} USERS.push(newUser); this.formResults = "User is created. Go to login page."; this.isValid = true; diff --git a/src/app/sing-service.service.spec.ts b/src/app/sing-service.service.spec.ts new file mode 100644 index 0000000..d6f8709 --- /dev/null +++ b/src/app/sing-service.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { SingServiceService } from './sing-service.service'; + +describe('SingServiceService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [SingServiceService] + }); + }); + + it('should be created', inject([SingServiceService], (service: SingServiceService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/sing-service.service.ts b/src/app/sing-service.service.ts new file mode 100644 index 0000000..edea29d --- /dev/null +++ b/src/app/sing-service.service.ts @@ -0,0 +1,39 @@ +import { Injectable } from '@angular/core'; +import { User } from './user'; +import { Observable } from 'rxjs/Observable'; +import { HttpClient } from '@angular/common/http'; +import { NgModel } from '@angular/forms'; +import { of } from 'rxjs/observable/of'; +import { catchError, map, tap } from 'rxjs/operators'; + +@Injectable() +export class SingServiceService { + + constructor(private http: HttpClient) { } + loginUser (userName: string,password:string) { + let body = {username: userName,password : password}; + return this.http.post("http://localhost:3000/validate/",body) + .pipe( + tap(users => this.log(`fetched users`)), + catchError(this.handleError('getUsers', [])) + ); + } + + private handleError (operation = 'operation', result?: T) { + return (error: any): Observable => { + + // TODO: send the error to remote logging infrastructure + console.log(error.toString()); // log to console instead + // TODO: better job of transforming error for user consumption + this.log(`${operation} failed: ${error.message}`); + + // Let the app keep running by returning an empty result. + return of(result as T); + }; + } + + private log(message: string) { + } + + +} diff --git a/src/app/standart-room/standart-room.component.css b/src/app/standart-room/standart-room.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/standart-room/standart-room.component.html b/src/app/standart-room/standart-room.component.html new file mode 100644 index 0000000..5fd7a3b --- /dev/null +++ b/src/app/standart-room/standart-room.component.html @@ -0,0 +1,3 @@ +

+ standart-room works! +

diff --git a/src/app/standart-room/standart-room.component.spec.ts b/src/app/standart-room/standart-room.component.spec.ts new file mode 100644 index 0000000..e1fd229 --- /dev/null +++ b/src/app/standart-room/standart-room.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { StandartRoomComponent } from './standart-room.component'; + +describe('StandartRoomComponent', () => { + let component: StandartRoomComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ StandartRoomComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(StandartRoomComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/standart-room/standart-room.component.ts b/src/app/standart-room/standart-room.component.ts new file mode 100644 index 0000000..2e45c36 --- /dev/null +++ b/src/app/standart-room/standart-room.component.ts @@ -0,0 +1,16 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; + +@Component({ + selector: 'app-standart-room', + templateUrl: './standart-room.component.html', + styleUrls: ['./standart-room.component.css'], + encapsulation: ViewEncapsulation.None +}) +export class StandartRoomComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/user.service.ts b/src/app/user.service.ts index 65a3c5b..9bd1b8c 100644 --- a/src/app/user.service.ts +++ b/src/app/user.service.ts @@ -1,19 +1,21 @@ import { Injectable } from '@angular/core'; +import { USERS } from './users'; @Injectable() export class UserService { private isUserLoggedIn; - private username; + public username; constructor() { this.isUserLoggedIn = false; } - setUserLoggedIn() { + setUserLoggedIn(userName) { this.isUserLoggedIn = true; - this.username = 'admin'; + this.username = userName; } + getUserLoggedIn() { return this.isUserLoggedIn; } diff --git a/src/app/user.ts b/src/app/user.ts index 0de1f58..b23d28e 100644 --- a/src/app/user.ts +++ b/src/app/user.ts @@ -1,5 +1,5 @@ export class User { username: string; password: string; - permission: string; + } diff --git a/src/app/users.ts b/src/app/users.ts index 9f160f8..1603afd 100644 --- a/src/app/users.ts +++ b/src/app/users.ts @@ -1,6 +1,6 @@ import {User} from './user'; export const USERS: User[] = [ - {username: 'roei', password: 'roei', permission: 'standard'}, - {username: 'admin', password: 'admin', permission: 'gold'} + {username: 'roei', password: 'roei'}, + {username: 'admin', password: 'admin'} ]; diff --git a/src/assets/.gitkeep b/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts new file mode 100644 index 0000000..3612073 --- /dev/null +++ b/src/environments/environment.prod.ts @@ -0,0 +1,3 @@ +export const environment = { + production: true +}; diff --git a/src/environments/environment.ts b/src/environments/environment.ts new file mode 100644 index 0000000..b7f639a --- /dev/null +++ b/src/environments/environment.ts @@ -0,0 +1,8 @@ +// The file contents for the current environment will overwrite these during build. +// The build system defaults to the dev environment which uses `environment.ts`, but if you do +// `ng build --env=prod` then `environment.prod.ts` will be used instead. +// The list of which env maps to which file can be found in `.angular-cli.json`. + +export const environment = { + production: false +}; diff --git a/src/favicon.ico b/src/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..8081c7ceaf2be08bf59010158c586170d9d2d517 GIT binary patch literal 5430 zcmc(je{54#6vvCoAI3i*G5%$U7!sA3wtMZ$fH6V9C`=eXGJb@R1%(I_{vnZtpD{6n z5Pl{DmxzBDbrB>}`90e12m8T*36WoeDLA&SD_hw{H^wM!cl_RWcVA!I+x87ee975; z@4kD^=bYPn&pmG@(+JZ`rqQEKxW<}RzhW}I!|ulN=fmjVi@x{p$cC`)5$a!)X&U+blKNvN5tg=uLvuLnuqRM;Yc*swiexsoh#XPNu{9F#c`G zQLe{yWA(Y6(;>y|-efAy11k<09(@Oo1B2@0`PtZSkqK&${ zgEY}`W@t{%?9u5rF?}Y7OL{338l*JY#P!%MVQY@oqnItpZ}?s z!r?*kwuR{A@jg2Chlf0^{q*>8n5Ir~YWf*wmsh7B5&EpHfd5@xVaj&gqsdui^spyL zB|kUoblGoO7G(MuKTfa9?pGH0@QP^b#!lM1yHWLh*2iq#`C1TdrnO-d#?Oh@XV2HK zKA{`eo{--^K&MW66Lgsktfvn#cCAc*(}qsfhrvOjMGLE?`dHVipu1J3Kgr%g?cNa8 z)pkmC8DGH~fG+dlrp(5^-QBeEvkOvv#q7MBVLtm2oD^$lJZx--_=K&Ttd=-krx(Bb zcEoKJda@S!%%@`P-##$>*u%T*mh+QjV@)Qa=Mk1?#zLk+M4tIt%}wagT{5J%!tXAE;r{@=bb%nNVxvI+C+$t?!VJ@0d@HIyMJTI{vEw0Ul ze(ha!e&qANbTL1ZneNl45t=#Ot??C0MHjjgY8%*mGisN|S6%g3;Hlx#fMNcL<87MW zZ>6moo1YD?P!fJ#Jb(4)_cc50X5n0KoDYfdPoL^iV`k&o{LPyaoqMqk92wVM#_O0l z09$(A-D+gVIlq4TA&{1T@BsUH`Bm=r#l$Z51J-U&F32+hfUP-iLo=jg7Xmy+WLq6_tWv&`wDlz#`&)Jp~iQf zZP)tu>}pIIJKuw+$&t}GQuqMd%Z>0?t%&BM&Wo^4P^Y z)c6h^f2R>X8*}q|bblAF?@;%?2>$y+cMQbN{X$)^R>vtNq_5AB|0N5U*d^T?X9{xQnJYeU{ zoZL#obI;~Pp95f1`%X3D$Mh*4^?O?IT~7HqlWguezmg?Ybq|7>qQ(@pPHbE9V?f|( z+0xo!#m@Np9PljsyxBY-UA*{U*la#8Wz2sO|48_-5t8%_!n?S$zlGe+NA%?vmxjS- zHE5O3ZarU=X}$7>;Okp(UWXJxI%G_J-@IH;%5#Rt$(WUX?6*Ux!IRd$dLP6+SmPn= z8zjm4jGjN772R{FGkXwcNv8GBcZI#@Y2m{RNF_w8(Z%^A*!bS*!}s6sh*NnURytky humW;*g7R+&|Ledvc- + + + + Teamchat + + + + + + + + + diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..91ec6da --- /dev/null +++ b/src/main.ts @@ -0,0 +1,12 @@ +import { enableProdMode } from '@angular/core'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + +import { AppModule } from './app/app.module'; +import { environment } from './environments/environment'; + +if (environment.production) { + enableProdMode(); +} + +platformBrowserDynamic().bootstrapModule(AppModule) + .catch(err => console.log(err)); diff --git a/src/polyfills.ts b/src/polyfills.ts new file mode 100644 index 0000000..20d4075 --- /dev/null +++ b/src/polyfills.ts @@ -0,0 +1,76 @@ +/** + * This file includes polyfills needed by Angular and is loaded before the app. + * You can add your own extra polyfills to this file. + * + * This file is divided into 2 sections: + * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. + * 2. Application imports. Files imported after ZoneJS that should be loaded before your main + * file. + * + * The current setup is for so-called "evergreen" browsers; the last versions of browsers that + * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), + * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. + * + * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html + */ + +/*************************************************************************************************** + * BROWSER POLYFILLS + */ + +/** IE9, IE10 and IE11 requires all of the following polyfills. **/ +// import 'core-js/es6/symbol'; +// import 'core-js/es6/object'; +// import 'core-js/es6/function'; +// import 'core-js/es6/parse-int'; +// import 'core-js/es6/parse-float'; +// import 'core-js/es6/number'; +// import 'core-js/es6/math'; +// import 'core-js/es6/string'; +// import 'core-js/es6/date'; +// import 'core-js/es6/array'; +// import 'core-js/es6/regexp'; +// import 'core-js/es6/map'; +// import 'core-js/es6/weak-map'; +// import 'core-js/es6/set'; + +/** IE10 and IE11 requires the following for NgClass support on SVG elements */ +// import 'classlist.js'; // Run `npm install --save classlist.js`. + +/** IE10 and IE11 requires the following for the Reflect API. */ +// import 'core-js/es6/reflect'; + + +/** Evergreen browsers require these. **/ +// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. +import 'core-js/es7/reflect'; + + +/** + * Required to support Web Animations `@angular/platform-browser/animations`. + * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation + **/ +// import 'web-animations-js'; // Run `npm install --save web-animations-js`. + + + +/*************************************************************************************************** + * Zone JS is required by Angular itself. + */ +import 'zone.js/dist/zone'; // Included with Angular CLI. + + + +/*************************************************************************************************** + * APPLICATION IMPORTS + */ + +/** + * Date, currency, decimal and percent pipes. + * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 + */ +// import 'intl'; // Run `npm install --save intl`. +/** + * Need to import at least one locale-data with intl. + */ +// import 'intl/locale-data/jsonp/en'; diff --git a/src/test.ts b/src/test.ts new file mode 100644 index 0000000..cd612ee --- /dev/null +++ b/src/test.ts @@ -0,0 +1,32 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js/dist/long-stack-trace-zone'; +import 'zone.js/dist/proxy.js'; +import 'zone.js/dist/sync-test'; +import 'zone.js/dist/jasmine-patch'; +import 'zone.js/dist/async-test'; +import 'zone.js/dist/fake-async-test'; +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. +declare const __karma__: any; +declare const require: any; + +// Prevent Karma from running prematurely. +__karma__.loaded = function () {}; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting() +); +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); +// Finally, start Karma to run the tests. +__karma__.start(); diff --git a/src/tsconfig.app.json b/src/tsconfig.app.json new file mode 100644 index 0000000..39ba8db --- /dev/null +++ b/src/tsconfig.app.json @@ -0,0 +1,13 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../out-tsc/app", + "baseUrl": "./", + "module": "es2015", + "types": [] + }, + "exclude": [ + "test.ts", + "**/*.spec.ts" + ] +} diff --git a/src/tsconfig.spec.json b/src/tsconfig.spec.json new file mode 100644 index 0000000..63d89ff --- /dev/null +++ b/src/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../out-tsc/spec", + "baseUrl": "./", + "module": "commonjs", + "target": "es5", + "types": [ + "jasmine", + "node" + ] + }, + "files": [ + "test.ts" + ], + "include": [ + "**/*.spec.ts", + "**/*.d.ts" + ] +} diff --git a/src/typings.d.ts b/src/typings.d.ts new file mode 100644 index 0000000..ef5c7bd --- /dev/null +++ b/src/typings.d.ts @@ -0,0 +1,5 @@ +/* SystemJS module definition */ +declare var module: NodeModule; +interface NodeModule { + id: string; +}