From fba97dced0caa46b5efb366781d194eef9d9dd10 Mon Sep 17 00:00:00 2001 From: Naj Date: Wed, 5 Apr 2017 12:20:41 -0400 Subject: [PATCH 01/15] implementing the skeleton of authentication flow --- src/app/app.component.ts | 1 + src/app/app.module.ts | 2 +- src/app/home/home.component.html | 3 ++ .../authentication/authentication.module.ts | 39 +++++++++++++++++++ .../authentication/authentication.routing.ts | 15 +++++++ .../authentication/guards/auth.guard.ts | 15 +++++++ .../authentication/login/login.component.html | 21 ++++++++++ .../authentication/login/login.component.ts | 10 +++++ src/app/widgit/authentication/models/user.ts | 8 ++++ .../authentication/profile.component.html | 7 ++++ .../authentication/profile.component.ts | 24 ++++++++++++ .../register/register-info.component.html | 29 ++++++++++++++ .../register/register-info.component.ts | 23 +++++++++++ .../services/authentication.service.ts | 15 +++++++ .../authentication/services/user.service.ts | 24 ++++++++++++ src/app/widgit/widgit.module.ts | 8 +++- 16 files changed, 241 insertions(+), 3 deletions(-) create mode 100644 src/app/widgit/authentication/authentication.module.ts create mode 100644 src/app/widgit/authentication/authentication.routing.ts create mode 100644 src/app/widgit/authentication/guards/auth.guard.ts create mode 100644 src/app/widgit/authentication/login/login.component.html create mode 100644 src/app/widgit/authentication/login/login.component.ts create mode 100644 src/app/widgit/authentication/models/user.ts create mode 100644 src/app/widgit/authentication/profile.component.html create mode 100644 src/app/widgit/authentication/profile.component.ts create mode 100644 src/app/widgit/authentication/register/register-info.component.html create mode 100644 src/app/widgit/authentication/register/register-info.component.ts create mode 100644 src/app/widgit/authentication/services/authentication.service.ts create mode 100644 src/app/widgit/authentication/services/user.service.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 14b7f2c..e430bc5 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -19,6 +19,7 @@ export class AppComponent implements OnInit { ngOnInit() { this.treeElements = [ { title: 'Home', targetUrl: '/home', imageCssClass: 'glyphicon-globe' }, + { title: 'Account', targetUrl: '/login', imageCssClass: 'glyphicon-user' }, { title: 'Search', targetUrl: '/search', imageCssClass: 'glyphicon-search' }, { title: 'Car', targetUrl: '/car', imageCssClass: 'glyphicon-road' }, { title: 'Housing', targetUrl: '/housing', imageCssClass: 'glyphicon-home' } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 9d278b2..2600adf 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -33,7 +33,7 @@ const routes: Routes = [ ], imports: [ RouterModule.forRoot(routes), - BrowserModule, + BrowserModule, FormsModule, HttpModule, RouterModule, diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index deb8367..d787b0f 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -1,3 +1,6 @@

Welcome to the Angular 2 playground!

+
+ Start +
\ No newline at end of file diff --git a/src/app/widgit/authentication/authentication.module.ts b/src/app/widgit/authentication/authentication.module.ts new file mode 100644 index 0000000..b36a090 --- /dev/null +++ b/src/app/widgit/authentication/authentication.module.ts @@ -0,0 +1,39 @@ +import { RouterModule } from '@angular/router'; +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { FormsModule } from '@angular/forms'; +import { HttpModule } from '@angular/http'; + +import { authenticationRouting } from './authentication.routing'; + +import { AuthGuard } from './guards/auth.guard'; +import { AuthenticationService } from './services/authentication.service'; +import { UserService } from './services/user.service'; +import { ProfileComponent } from './profile.component'; +import { LoginComponent } from './login/login.component'; +import { RegisterInfoComponent } from './register/register-info.component'; + +@NgModule({ + imports: [ + BrowserModule, + FormsModule, + HttpModule, + authenticationRouting, + ], + declarations: [ + ProfileComponent, + LoginComponent, + RegisterInfoComponent + ], + providers: [ + AuthGuard, + AuthenticationService, + UserService, + ], + exports: [ + ProfileComponent, + LoginComponent, + RegisterInfoComponent + ] +}) +export class AuthenticationModule { } \ No newline at end of file diff --git a/src/app/widgit/authentication/authentication.routing.ts b/src/app/widgit/authentication/authentication.routing.ts new file mode 100644 index 0000000..fc1f36f --- /dev/null +++ b/src/app/widgit/authentication/authentication.routing.ts @@ -0,0 +1,15 @@ +import { Routes, RouterModule } from '@angular/router'; + +import { ProfileComponent } from './profile.component'; +import { LoginComponent } from './login/login.component'; +import { RegisterInfoComponent } from './register/register-info.component'; +import { AuthGuard } from './guards/auth.guard'; + +const appRoutes: Routes = [ + { path: 'profile', component: ProfileComponent, canActivate: [AuthGuard] }, + { path: 'login', component: LoginComponent }, + { path: 'register', component: RegisterInfoComponent }, + { path: '**', redirectTo: '' } // redirect to home. +]; + +export const authenticationRouting = RouterModule.forRoot(appRoutes); \ No newline at end of file diff --git a/src/app/widgit/authentication/guards/auth.guard.ts b/src/app/widgit/authentication/guards/auth.guard.ts new file mode 100644 index 0000000..d18bb98 --- /dev/null +++ b/src/app/widgit/authentication/guards/auth.guard.ts @@ -0,0 +1,15 @@ +import { Injectable } from '@angular/core'; +import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; + +@Injectable() +export class AuthGuard implements CanActivate { + constructor(private router: Router) { } + + canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { + // TODO + // check on state if the user is there return true [state.select('userprofile')] + // otherwise redirect to login and return false + // this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } }); + return true; + } +} \ No newline at end of file diff --git a/src/app/widgit/authentication/login/login.component.html b/src/app/widgit/authentication/login/login.component.html new file mode 100644 index 0000000..2f1aaa8 --- /dev/null +++ b/src/app/widgit/authentication/login/login.component.html @@ -0,0 +1,21 @@ +
+

Login

+
+
+
+ + +
+
+ + +
+
+ +
+
+
+
+ Register +
+
\ No newline at end of file diff --git a/src/app/widgit/authentication/login/login.component.ts b/src/app/widgit/authentication/login/login.component.ts new file mode 100644 index 0000000..d0e2fe9 --- /dev/null +++ b/src/app/widgit/authentication/login/login.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + moduleId: module.id, + templateUrl: 'login.component.html' +}) + +export class LoginComponent { + +} diff --git a/src/app/widgit/authentication/models/user.ts b/src/app/widgit/authentication/models/user.ts new file mode 100644 index 0000000..2b27f2a --- /dev/null +++ b/src/app/widgit/authentication/models/user.ts @@ -0,0 +1,8 @@ +export class User { + id: number; + username: string; + email: string; + password: string; + firstName: string; + lastName: string; +} \ No newline at end of file diff --git a/src/app/widgit/authentication/profile.component.html b/src/app/widgit/authentication/profile.component.html new file mode 100644 index 0000000..920e846 --- /dev/null +++ b/src/app/widgit/authentication/profile.component.html @@ -0,0 +1,7 @@ +
+

Hi {{currentUser.firstName}}!

+

your profile page

+ {{currentUser.firstName}} + {{currentUser.picture}} + +
\ No newline at end of file diff --git a/src/app/widgit/authentication/profile.component.ts b/src/app/widgit/authentication/profile.component.ts new file mode 100644 index 0000000..733f23e --- /dev/null +++ b/src/app/widgit/authentication/profile.component.ts @@ -0,0 +1,24 @@ +import { AuthenticationService } from './services/authentication.service'; +import { Component, OnInit } from '@angular/core'; + +import { User } from './models/user'; +import { UserService } from './services/user.service'; + +@Component({ + moduleId: module.id, + templateUrl: 'profile.component.html', + providers: [AuthenticationService] +}) +export class ProfileComponent implements OnInit { + currentUser: User; + users: User[] = []; + constructor(private authenticationService: AuthenticationService, private userService: UserService) { + // get the user from state. + // this.currentUser = state.select("userProfile-name"); + } + ngOnInit() { } + + logout(user) { + this.authenticationService.logout(user); + } +} \ No newline at end of file diff --git a/src/app/widgit/authentication/register/register-info.component.html b/src/app/widgit/authentication/register/register-info.component.html new file mode 100644 index 0000000..3e2a32d --- /dev/null +++ b/src/app/widgit/authentication/register/register-info.component.html @@ -0,0 +1,29 @@ +
+

Register

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + Cancel +
+
+
diff --git a/src/app/widgit/authentication/register/register-info.component.ts b/src/app/widgit/authentication/register/register-info.component.ts new file mode 100644 index 0000000..438d09f --- /dev/null +++ b/src/app/widgit/authentication/register/register-info.component.ts @@ -0,0 +1,23 @@ +import { User } from './../models/user'; +import { Component } from '@angular/core'; +import { Router } from '@angular/router'; + +import { UserService } from '../services/user.service'; +@Component({ + moduleId: module.id, + templateUrl: 'register-info.component.html' +}) +export class RegisterInfoComponent { + user: User = new User(); + constructor(private router: Router, private userService: UserService) { } + register() { + this.userService.register(this.user) + .subscribe( + data => { + this.router.navigate(['/profile']); + }, + error => { + console.log("[authentication] registration error") + }); + } +} diff --git a/src/app/widgit/authentication/services/authentication.service.ts b/src/app/widgit/authentication/services/authentication.service.ts new file mode 100644 index 0000000..7528a06 --- /dev/null +++ b/src/app/widgit/authentication/services/authentication.service.ts @@ -0,0 +1,15 @@ +import { Injectable } from '@angular/core'; +import { Http, Headers, Response } from '@angular/http'; + +@Injectable() +export class AuthenticationService { + constructor() { } + + login() { + //TODO + } + + logout(user) { + // TODO + } +} \ No newline at end of file diff --git a/src/app/widgit/authentication/services/user.service.ts b/src/app/widgit/authentication/services/user.service.ts new file mode 100644 index 0000000..6ea80fa --- /dev/null +++ b/src/app/widgit/authentication/services/user.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; +import { Http, Headers, RequestOptions, Response } from '@angular/http'; +import { User } from '../models/user'; +import { Observable } from 'rxjs/Observable'; +import { of } from 'rxjs/observable/of'; + +@Injectable() +export class UserService { + constructor() { } + getByUsername(username: string) { + // find by name. + } + + register(user: User): Observable { + // add a new user in state + return of(new User()); + } + + delete(id: number) { + // delete a user + } + + +} \ No newline at end of file diff --git a/src/app/widgit/widgit.module.ts b/src/app/widgit/widgit.module.ts index ba40f06..82c241d 100644 --- a/src/app/widgit/widgit.module.ts +++ b/src/app/widgit/widgit.module.ts @@ -6,18 +6,22 @@ import {UtilitiesModule} from '../utilities/utilities.module'; import {SearchFormComponent} from './search-form/search-form.component'; import { NavigationComponent } from './navigation/navigation.component'; import { NavigationItemComponent } from './navigation/navigation-item.component'; +import { AuthenticationModule } from './authentication/authentication.module'; + @NgModule({ imports: [ CommonModule, RouterModule, + AuthenticationModule, UtilitiesModule, - ReactiveFormsModule + ReactiveFormsModule, + ], exports: [ SearchFormComponent, NavigationComponent, - NavigationItemComponent + NavigationItemComponent, ], declarations: [ SearchFormComponent, From 81262393ebccce40c2031d7191739b470e4c470f Mon Sep 17 00:00:00 2001 From: Naj Date: Wed, 5 Apr 2017 12:42:22 -0400 Subject: [PATCH 02/15] adjusting routing --- .../widgit/authentication/authentication.routing.ts | 2 +- src/app/widgit/authentication/profile.component.ts | 3 +-- .../register/register-info.component.html | 10 +++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/app/widgit/authentication/authentication.routing.ts b/src/app/widgit/authentication/authentication.routing.ts index fc1f36f..1c9457a 100644 --- a/src/app/widgit/authentication/authentication.routing.ts +++ b/src/app/widgit/authentication/authentication.routing.ts @@ -9,7 +9,7 @@ const appRoutes: Routes = [ { path: 'profile', component: ProfileComponent, canActivate: [AuthGuard] }, { path: 'login', component: LoginComponent }, { path: 'register', component: RegisterInfoComponent }, - { path: '**', redirectTo: '' } // redirect to home. + { path: '**', redirectTo: '/home' } // redirect to home. ]; export const authenticationRouting = RouterModule.forRoot(appRoutes); \ No newline at end of file diff --git a/src/app/widgit/authentication/profile.component.ts b/src/app/widgit/authentication/profile.component.ts index 733f23e..42866cc 100644 --- a/src/app/widgit/authentication/profile.component.ts +++ b/src/app/widgit/authentication/profile.component.ts @@ -10,8 +10,7 @@ import { UserService } from './services/user.service'; providers: [AuthenticationService] }) export class ProfileComponent implements OnInit { - currentUser: User; - users: User[] = []; + currentUser: User = new User(); constructor(private authenticationService: AuthenticationService, private userService: UserService) { // get the user from state. // this.currentUser = state.select("userProfile-name"); diff --git a/src/app/widgit/authentication/register/register-info.component.html b/src/app/widgit/authentication/register/register-info.component.html index 3e2a32d..f76343e 100644 --- a/src/app/widgit/authentication/register/register-info.component.html +++ b/src/app/widgit/authentication/register/register-info.component.html @@ -3,23 +3,23 @@

Register

- +
- +
- +
- +
- +
From a3e5d689220f1f273e2998057f35dca1e218d05d Mon Sep 17 00:00:00 2001 From: Florian GOMBERT Date: Mon, 3 Apr 2017 17:11:01 -0400 Subject: [PATCH 03/15] form (creation) - Housing module + usage of NgRx "HousingAction.ADD_HOUSE" action. --- package.json | 1 + src/app/car/actions/cars.ts | 6 +- src/app/housing/actions/housing.ts | 6 +- .../components/edit/house-edit.component.html | 52 ++++++++++++++ .../components/edit/house-edit.component.scss | 0 .../edit/house-edit.component.spec.ts | 28 ++++++++ .../components/edit/house-edit.component.ts | 67 +++++++++++++++++++ .../components/list/house-list.component.html | 14 ++-- .../components/list/house-list.component.ts | 10 +-- .../containers/listing/listing.component.html | 2 + .../containers/listing/listing.component.ts | 19 ++++-- src/app/housing/effects/housing.ts | 61 ++++++++++++----- src/app/housing/housing.module.ts | 13 +++- src/app/housing/reducers/houses.reducer.ts | 5 +- src/app/housing/service/house.service.ts | 22 ++++-- 15 files changed, 253 insertions(+), 53 deletions(-) create mode 100644 src/app/housing/components/edit/house-edit.component.html create mode 100644 src/app/housing/components/edit/house-edit.component.scss create mode 100644 src/app/housing/components/edit/house-edit.component.spec.ts create mode 100644 src/app/housing/components/edit/house-edit.component.ts diff --git a/package.json b/package.json index 31c18db..7b84cf3 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@types/lodash": "4.14.50", "core-js": "^2.4.1", "lodash": "^4.17.4", + "ng2-validation": "^3.9.1", "rxjs": "^5.1.0", "zone.js": "^0.7.6" }, diff --git a/src/app/car/actions/cars.ts b/src/app/car/actions/cars.ts index adc81c4..5225848 100644 --- a/src/app/car/actions/cars.ts +++ b/src/app/car/actions/cars.ts @@ -3,9 +3,9 @@ import {Action} from '@ngrx/store'; import {Car} from '../domain/car'; export const CarAction = { - SEARCH: type(('Car - Search')), - ADD_CAR: type(('Car - Add car')), - LIST_CARS: type(('Car - list cars')), + SEARCH: type('Car - Search'), + ADD_CAR: type('Car - Add car'), + LIST_CARS: type('Car - list cars'), }; diff --git a/src/app/housing/actions/housing.ts b/src/app/housing/actions/housing.ts index c20d24e..51c8b69 100644 --- a/src/app/housing/actions/housing.ts +++ b/src/app/housing/actions/housing.ts @@ -3,9 +3,9 @@ import {Action} from '@ngrx/store'; import {House} from '../domain/housing'; export const HousingAction = { - SEARCH: type(('House - Search')), - ADD_HOUSE: type(('House - Add house')), - LIST_HOUSES: type(('House - list houses')), + SEARCH: type('House - Search'), + ADD_HOUSE: type('House - Add house'), + LIST_HOUSES: type('House - list houses'), }; diff --git a/src/app/housing/components/edit/house-edit.component.html b/src/app/housing/components/edit/house-edit.component.html new file mode 100644 index 0000000..b67b01d --- /dev/null +++ b/src/app/housing/components/edit/house-edit.component.html @@ -0,0 +1,52 @@ +
+ + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+ + +
diff --git a/src/app/housing/components/edit/house-edit.component.scss b/src/app/housing/components/edit/house-edit.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/housing/components/edit/house-edit.component.spec.ts b/src/app/housing/components/edit/house-edit.component.spec.ts new file mode 100644 index 0000000..288d074 --- /dev/null +++ b/src/app/housing/components/edit/house-edit.component.spec.ts @@ -0,0 +1,28 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HouseEditComponent } from './house-edit.component'; +import {expect} from 'chai'; + +describe('HouseListComponent', () => { + let component: HouseEditComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ HouseEditComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(HouseEditComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + + it('will be defined', sinon.test(() => { + expect(component).to.exist; + })); + +}); diff --git a/src/app/housing/components/edit/house-edit.component.ts b/src/app/housing/components/edit/house-edit.component.ts new file mode 100644 index 0000000..7894b37 --- /dev/null +++ b/src/app/housing/components/edit/house-edit.component.ts @@ -0,0 +1,67 @@ +import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { CustomValidators } from 'ng2-validation'; +import { House } from '../../domain/housing'; + +@Component({ + selector: 'app-house-edit', + templateUrl: 'house-edit.component.html', + styleUrls: ['house-edit.component.scss'] +}) +export class HouseEditComponent implements OnInit { + + @Input() + public house: House; + + @Output() + public houseCreated: EventEmitter; + + @Output() + public houseUpdated: EventEmitter; + + protected houseForm: FormGroup; + + protected inEditMode: boolean; + + protected currentYear: number; + + public constructor(private formBuilder: FormBuilder) { + this.house = this.defaultHouseEntity(); + this.houseCreated = new EventEmitter(); + this.houseUpdated = new EventEmitter(); + + this.currentYear = new Date().getFullYear(); + + this.houseForm = this.formBuilder.group({ + country: [this.house.country, [Validators.required, Validators.minLength(4), Validators.maxLength(200)]], + state: [this.house.state, Validators.required], + city: [this.house.city, Validators.required], + construction: [this.house.construction, [Validators.required, CustomValidators.range([1900, this.currentYear])]], + rooms: [this.house.rooms, [Validators.required, CustomValidators.range([1, 5])]] + }); + } + + ngOnInit() { + this.inEditMode = typeof this.house !== typeof undefined + && this.house.rooms !== -1; + } + + protected submitHouseEdit() { + if (!this.houseForm.valid) { + return; + } + + if (this.inEditMode) { + this.houseUpdated.emit(this.house); + } + else { + this.houseCreated.emit(this.house); + this.house = this.defaultHouseEntity(); + } + } + + private defaultHouseEntity(): House { + return { country: '', state: '', city: '', construction: '', rooms: -1 }; + } + +} diff --git a/src/app/housing/components/list/house-list.component.html b/src/app/housing/components/list/house-list.component.html index 243feba..dee54fe 100644 --- a/src/app/housing/components/list/house-list.component.html +++ b/src/app/housing/components/list/house-list.component.html @@ -1,11 +1,9 @@
-
-
-
{{house.country}}
-
{{house.state}}
-
{{house.city}}
-
{{house.construction}}
-
{{house.rooms}}
-
+
+
{{house.country}}
+
{{house.state}}
+
{{house.city}}
+
{{house.construction}}
+
{{house.rooms}}
diff --git a/src/app/housing/components/list/house-list.component.ts b/src/app/housing/components/list/house-list.component.ts index a0fc548..673f0b9 100644 --- a/src/app/housing/components/list/house-list.component.ts +++ b/src/app/housing/components/list/house-list.component.ts @@ -1,5 +1,5 @@ -import { Component, OnInit, Input } from '@angular/core'; -import {House} from '../../domain/housing'; +import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import { House } from '../../domain/housing'; @Component({ selector: 'app-house-list', @@ -8,9 +8,11 @@ import {House} from '../../domain/housing'; }) export class HouseListComponent implements OnInit { - @Input() public houseList: House[]; + @Input() + public houseList: House[]; - constructor() { } + constructor() { + } ngOnInit() { } diff --git a/src/app/housing/containers/listing/listing.component.html b/src/app/housing/containers/listing/listing.component.html index fd1a77f..06dd1a2 100644 --- a/src/app/housing/containers/listing/listing.component.html +++ b/src/app/housing/containers/listing/listing.component.html @@ -1,3 +1,5 @@ + + diff --git a/src/app/housing/containers/listing/listing.component.ts b/src/app/housing/containers/listing/listing.component.ts index 8cbea4f..6094bc9 100644 --- a/src/app/housing/containers/listing/listing.component.ts +++ b/src/app/housing/containers/listing/listing.component.ts @@ -1,7 +1,8 @@ -import {Component, OnInit} from '@angular/core'; -import {Store} from '@ngrx/store'; -import {House, HousesState} from '../../domain/housing'; -import {SearchOptions} from '../../../widgit/search-form/search-options'; +import { Component, OnInit } from '@angular/core'; +import { Store } from '@ngrx/store'; +import { ActionFactory } from '../../actions/housing'; +import { House, HousesState } from '../../domain/housing'; +import { SearchOptions } from '../../../widgit/search-form/search-options'; @Component({ selector: 'app-listing', @@ -9,13 +10,15 @@ import {SearchOptions} from '../../../widgit/search-form/search-options'; styleUrls: ['listing.component.scss'] }) export class ListingComponent implements OnInit { + houseList: House[]; + searchOptions: SearchOptions; - constructor(private housingStore: Store) {} + constructor(private housingStore: Store) { + } ngOnInit() { - this.searchOptions = { name: 'houses', target: './search' @@ -24,4 +27,8 @@ export class ListingComponent implements OnInit { this.housingStore.select(state => state.houses).subscribe(houses => this.houseList = houses); } + protected houseCreated(newHouse: House) { + this.housingStore.dispatch(ActionFactory.addHouse(newHouse)); + } + } diff --git a/src/app/housing/effects/housing.ts b/src/app/housing/effects/housing.ts index a1a3d90..e810f18 100644 --- a/src/app/housing/effects/housing.ts +++ b/src/app/housing/effects/housing.ts @@ -1,14 +1,14 @@ - import { Injectable } from '@angular/core'; import { Effect, Actions, toPayload } from '@ngrx/effects'; +import { Action } from '@ngrx/store'; import { Observable } from 'rxjs/Observable'; import { of } from 'rxjs/observable/of'; -import { Action } from '@ngrx/store'; -import { HouseService } from '../service/house.service'; -import {ActionFactory, HousingAction} from '../actions/housing'; import { empty } from 'rxjs/observable/empty'; import 'rxjs/add/operator/skip'; import 'rxjs/add/operator/takeUntil'; +import { House } from '../domain/housing'; +import { HouseService } from '../service/house.service'; +import { ActionFactory, HousingAction } from '../actions/housing'; @Injectable() export class HousingEffects { @@ -17,20 +17,47 @@ export class HousingEffects { search$: Observable = this.actions$ .ofType(HousingAction.SEARCH) .map(toPayload) - .switchMap(searchTerm => { - if (searchTerm === '') { - return of(ActionFactory.clearHouses()); - } + .switchMap(searchTerm => this.performSearch(searchTerm)); - const nextSearch$ = this.actions$.ofType(HousingAction.SEARCH).skip(1); + @Effect() + addHouse$: Observable = this.actions$ + .ofType(HousingAction.ADD_HOUSE) + .map(toPayload) + .switchMap(newHouse => this.performAddHouse(newHouse)); + + constructor(private actions$: Actions, private houseService: HouseService) { + } - return this.houseService.findHouses(searchTerm) - .takeUntil(nextSearch$) - .map(result => ActionFactory.searchComplete(result)) - .catch(error => { - return of(ActionFactory.clearHouses()); - }); - }); + private performSearch(searchTerm: string): Observable { + if (searchTerm === '') { + return of(ActionFactory.clearHouses()); + // TODO: implement the Toast-ing mechanism! + } + + const nextSearch$ = this.actions$ + .ofType(HousingAction.SEARCH) + .skip(1); + + return this.houseService.findHouses(searchTerm) + .takeUntil(nextSearch$) + .map(result => ActionFactory.searchComplete(result)) + .catch(error => { + return of(ActionFactory.clearHouses()); + // TODO: implement the Toast-ing mechanism! + }); + } - constructor(private actions$: Actions, private houseService: HouseService) { } + private performAddHouse(newHouse: House): Observable { + return this.houseService.addHouse(newHouse) + .map(result => { + // TODO: implement the Toast-ing mechanism! + return result; + }) + .switchMap(newHouse => this.houseService.getHouses()) + .map(houseList => ActionFactory.listHouses(houseList)) + .catch(err => { + // TODO: implement the Toast-ing mechanism! + return of({ type: 'Some random string', payload: 'Nothing to do!' } as Action); + }); + } } diff --git a/src/app/housing/housing.module.ts b/src/app/housing/housing.module.ts index 13d4d56..f908191 100644 --- a/src/app/housing/housing.module.ts +++ b/src/app/housing/housing.module.ts @@ -1,7 +1,9 @@ import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; +import { ReactiveFormsModule } from '@angular/forms'; import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; import {HouseListComponent} from './components/list/house-list.component'; +import {HouseEditComponent} from './components/edit/house-edit.component'; import {ListingComponent} from './containers/listing/listing.component'; import {SearchResultComponent} from './containers/search-result/search-result.component'; import {WidgitModule} from '../widgit/widgit.module'; @@ -19,14 +21,21 @@ import {HouseService} from './service/house.service'; CommonModule, WidgitModule, UtilitiesModule, - NgbModule + NgbModule, + ReactiveFormsModule ], exports: [ HouseListComponent, + HouseEditComponent, + ListingComponent, + SearchResultComponent + ], + declarations: [ + HouseListComponent, + HouseEditComponent, ListingComponent, SearchResultComponent ], - declarations: [HouseListComponent, ListingComponent, SearchResultComponent], providers: [HouseService, HousesListedGuard] }) export class HousingModule { } diff --git a/src/app/housing/reducers/houses.reducer.ts b/src/app/housing/reducers/houses.reducer.ts index b89b278..990611c 100644 --- a/src/app/housing/reducers/houses.reducer.ts +++ b/src/app/housing/reducers/houses.reducer.ts @@ -1,11 +1,8 @@ import {Action} from '@ngrx/store'; import {HousingAction} from '../actions/housing'; -export const houses = (state: any = [], action: Action ) => { - +export const houses = (state: any = [], action: Action) => { switch (action.type) { - case HousingAction.ADD_HOUSE: - return [...state, action.payload]; case HousingAction.LIST_HOUSES: return [...action.payload]; default: diff --git a/src/app/housing/service/house.service.ts b/src/app/housing/service/house.service.ts index 71db331..068027f 100644 --- a/src/app/housing/service/house.service.ts +++ b/src/app/housing/service/house.service.ts @@ -1,13 +1,17 @@ import { Injectable } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; -import {Response, Http} from '@angular/http'; -import {House} from '../domain/housing'; - +import { Response, Http } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; +import { of } from 'rxjs/observable/of'; +import 'rxjs/add/operator/map'; +import { House } from '../domain/housing'; @Injectable() -export class HouseService { +export class /*Fake*/HouseService { + + private dataSet: House[]; constructor(private http: Http) { + this.dataSet = []; } findHouses(term: string): Observable { @@ -15,7 +19,13 @@ export class HouseService { } getHouses(): Observable { - return this.getFromUrl('/assets/mock/list/houses.json'); + return this.getFromUrl('/assets/mock/list/houses.json') + .switchMap(houseList => of([...houseList, ...this.dataSet])); + } + + addHouse(newHouse: House): Observable { + this.dataSet = [...this.dataSet, newHouse]; + return of(newHouse); // TODO: implement actual service call! } private getFromUrl(url: string): Observable { From bbfa7be7bb1b79bca1a64b6b4e5ce0417d6deff2 Mon Sep 17 00:00:00 2001 From: Florian GOMBERT Date: Tue, 4 Apr 2017 13:55:28 -0400 Subject: [PATCH 04/15] Few fixes, to pass the lint step. --- .../housing/components/edit/house-edit.component.ts | 11 +++++------ .../housing/containers/listing/listing.component.ts | 2 +- src/app/housing/effects/housing.ts | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/app/housing/components/edit/house-edit.component.ts b/src/app/housing/components/edit/house-edit.component.ts index 7894b37..c5e4f0c 100644 --- a/src/app/housing/components/edit/house-edit.component.ts +++ b/src/app/housing/components/edit/house-edit.component.ts @@ -19,11 +19,11 @@ export class HouseEditComponent implements OnInit { @Output() public houseUpdated: EventEmitter; - protected houseForm: FormGroup; + public houseForm: FormGroup; - protected inEditMode: boolean; + public currentYear: number; - protected currentYear: number; + protected inEditMode: boolean; public constructor(private formBuilder: FormBuilder) { this.house = this.defaultHouseEntity(); @@ -46,15 +46,14 @@ export class HouseEditComponent implements OnInit { && this.house.rooms !== -1; } - protected submitHouseEdit() { + public submitHouseEdit() { if (!this.houseForm.valid) { return; } if (this.inEditMode) { this.houseUpdated.emit(this.house); - } - else { + } else { this.houseCreated.emit(this.house); this.house = this.defaultHouseEntity(); } diff --git a/src/app/housing/containers/listing/listing.component.ts b/src/app/housing/containers/listing/listing.component.ts index 6094bc9..048995a 100644 --- a/src/app/housing/containers/listing/listing.component.ts +++ b/src/app/housing/containers/listing/listing.component.ts @@ -27,7 +27,7 @@ export class ListingComponent implements OnInit { this.housingStore.select(state => state.houses).subscribe(houses => this.houseList = houses); } - protected houseCreated(newHouse: House) { + public houseCreated(newHouse: House) { this.housingStore.dispatch(ActionFactory.addHouse(newHouse)); } diff --git a/src/app/housing/effects/housing.ts b/src/app/housing/effects/housing.ts index e810f18..553b8f2 100644 --- a/src/app/housing/effects/housing.ts +++ b/src/app/housing/effects/housing.ts @@ -53,7 +53,7 @@ export class HousingEffects { // TODO: implement the Toast-ing mechanism! return result; }) - .switchMap(newHouse => this.houseService.getHouses()) + .switchMap(house => this.houseService.getHouses()) .map(houseList => ActionFactory.listHouses(houseList)) .catch(err => { // TODO: implement the Toast-ing mechanism! From 46af4905a63595c217010106d18ce1bebd7d7157 Mon Sep 17 00:00:00 2001 From: Florian GOMBERT Date: Tue, 4 Apr 2017 14:51:12 -0400 Subject: [PATCH 05/15] Fixing most of the issues raised when running "ng test" ... one test is still failing though. --- src/app/app.module.ts | 3 +- .../car/components/add/add.component.spec.ts | 9 +-- .../list/car-list.component.spec.ts | 3 +- .../listing/listing.component.spec.ts | 2 +- .../search-result.component.spec.ts | 55 +++++++++---------- src/app/car/effects/car.spec.ts | 8 +-- src/app/car/guards/car-listing.spec.ts | 5 +- src/app/car/reducers/car.reducer.spec.ts | 1 + src/app/car/reducers/term.reducer.spec.ts | 1 + src/app/car/service/car.service.spec.ts | 1 + src/app/home/home.component.spec.ts | 7 +-- .../edit/house-edit.component.spec.ts | 9 +-- .../list/house-list.component.spec.ts | 12 ++-- src/app/housing/effects/housing.spec.ts | 8 +-- src/app/housing/guards/house-listing.spec.ts | 5 +- src/app/housing/housing.module.ts | 8 ++- .../housing/reducers/houses.reducer.spec.ts | 20 ------- src/app/utilities/object.service.spec.ts | 5 +- src/app/utilities/type.spec.ts | 1 + ...c.ts => navigation-item.component.spec.ts} | 26 ++++----- .../navigation/navigation.component.spec.ts | 1 + .../search-form/search-form.component.spec.ts | 37 ++++++------- 22 files changed, 104 insertions(+), 123 deletions(-) rename src/app/widgit/navigation/{navigation-item.componenet.spec.ts => navigation-item.component.spec.ts} (93%) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2600adf..80c7c50 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,6 +1,6 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; -import { FormsModule } from '@angular/forms'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; @@ -35,6 +35,7 @@ const routes: Routes = [ RouterModule.forRoot(routes), BrowserModule, FormsModule, + ReactiveFormsModule, HttpModule, RouterModule, CarRouteModule, diff --git a/src/app/car/components/add/add.component.spec.ts b/src/app/car/components/add/add.component.spec.ts index a73a7c4..af6eac0 100644 --- a/src/app/car/components/add/add.component.spec.ts +++ b/src/app/car/components/add/add.component.spec.ts @@ -1,7 +1,8 @@ +import { expect } from 'chai'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { AddComponent } from './add.component'; -import {ReactiveFormsModule, FormsModule} from '@angular/forms'; +import { ReactiveFormsModule, FormsModule } from '@angular/forms'; describe('AddComponent', () => { let component: AddComponent; @@ -9,10 +10,10 @@ describe('AddComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ AddComponent ], + declarations: [AddComponent], imports: [FormsModule, ReactiveFormsModule] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { @@ -27,6 +28,6 @@ describe('AddComponent', () => { it('will add nothing when form is not filled in', sinon.test(() => { - expect(component).to.exist; + expect(component).to.exist; })); }); diff --git a/src/app/car/components/list/car-list.component.spec.ts b/src/app/car/components/list/car-list.component.spec.ts index 2eb459c..066e5f9 100644 --- a/src/app/car/components/list/car-list.component.spec.ts +++ b/src/app/car/components/list/car-list.component.spec.ts @@ -1,5 +1,5 @@ +import { expect } from 'chai'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - import { CarListComponent } from './car-list.component'; describe('CarListComponent', () => { @@ -19,7 +19,6 @@ describe('CarListComponent', () => { fixture.detectChanges(); }); - it('will be defined', sinon.test(() => { expect(component).to.exist; })); diff --git a/src/app/car/containers/listing/listing.component.spec.ts b/src/app/car/containers/listing/listing.component.spec.ts index c87fe48..55cbf0f 100644 --- a/src/app/car/containers/listing/listing.component.spec.ts +++ b/src/app/car/containers/listing/listing.component.spec.ts @@ -1,7 +1,7 @@ +import { expect } from 'chai'; import {async, ComponentFixture, TestBed, inject} from '@angular/core/testing'; import {ListingComponent} from './listing.component'; import {NO_ERRORS_SCHEMA} from '@angular/core'; -import {CarService} from '../service/car.service'; import {StoreModule, Store} from '@ngrx/store'; import {Car, CarState} from '../../domain/car'; import {cars} from '../../reducers/car.reducer'; diff --git a/src/app/car/containers/search-result/search-result.component.spec.ts b/src/app/car/containers/search-result/search-result.component.spec.ts index 4f6c4a0..532d696 100644 --- a/src/app/car/containers/search-result/search-result.component.spec.ts +++ b/src/app/car/containers/search-result/search-result.component.spec.ts @@ -1,16 +1,15 @@ -import {async, ComponentFixture, TestBed, inject} from '@angular/core/testing'; -import {SearchResultComponent} from './search-result.component'; -import {NO_ERRORS_SCHEMA} from '@angular/core'; -import {ActivatedRoute, Params} from '@angular/router'; -import {SearchFormService} from '../../widgit/search-form/search-form.service'; -import {CarService} from '../service/car.service'; -import {Observable} from 'rxjs/Observable'; -import {BehaviorSubject} from 'rxjs/BehaviorSubject'; -import {StoreModule, Store} from '@ngrx/store'; -import {Car, CarState} from '../../domain/car'; -import {SearchOptions} from '../../../widgit/search-form/search-options'; -import {cars} from '../../reducers/car.reducer'; -import {ActionFactory} from '../../actions/cars'; +import { expect } from 'chai'; +import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; +import { SearchResultComponent } from './search-result.component'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { ActivatedRoute, Params } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; +import { BehaviorSubject } from 'rxjs/BehaviorSubject'; +import { StoreModule, Store } from '@ngrx/store'; +import { Car, CarState } from '../../domain/car'; +import { SearchOptions } from '../../../widgit/search-form/search-options'; +import { cars } from '../../reducers/car.reducer'; +import { ActionFactory } from '../../actions/cars'; describe('SearchResultComponent', () => { const carResponse: Car[] = [{ @@ -31,8 +30,8 @@ describe('SearchResultComponent', () => { let carStore: Store; let params: Params; - function mockQueryStringBehaviour (term: string) { - params = { q: term}; + function mockQueryStringBehaviour(term: string) { + params = { q: term }; mockProviders = [ { @@ -57,8 +56,8 @@ describe('SearchResultComponent', () => { beforeEach(async(() => { setupMocksWithTerm(); TestBed.configureTestingModule({ - imports: [StoreModule.provideStore({cars})], - declarations: [ SearchResultComponent ], + imports: [StoreModule.provideStore({ cars })], + declarations: [SearchResultComponent], schemas: [NO_ERRORS_SCHEMA], providers: mockProviders }).compileComponents(); @@ -72,9 +71,9 @@ describe('SearchResultComponent', () => { beforeEach(inject([Store], - (_carStore: Store) => { - carStore = _carStore; - })); + (_carStore: Store) => { + carStore = _carStore; + })); beforeEach(() => { component.ngOnInit(); @@ -91,10 +90,8 @@ describe('SearchResultComponent', () => { })); it('will be configured with search options', sinon.test(() => { - expect(component.searchOptions).to.eql(expectedSearchOptions); + expect(component.searchOptions).to.eql(expectedSearchOptions); })); - - }); describe('when initialised and a search term is not provided', () => { @@ -102,8 +99,8 @@ describe('SearchResultComponent', () => { beforeEach(async(() => { setupMocksWithoutTerm(); TestBed.configureTestingModule({ - imports: [StoreModule.provideStore({cars})], - declarations: [ SearchResultComponent ], + imports: [StoreModule.provideStore({ cars })], + declarations: [SearchResultComponent], schemas: [NO_ERRORS_SCHEMA], providers: mockProviders }).compileComponents(); @@ -116,11 +113,9 @@ describe('SearchResultComponent', () => { }); - beforeEach(inject([Store], - (_carStore: Store) => { - carStore = _carStore; - } - )); + beforeEach( + inject([Store], (_carStore: Store) => { carStore = _carStore; }) + ); beforeEach(() => { component.ngOnInit(); diff --git a/src/app/car/effects/car.spec.ts b/src/app/car/effects/car.spec.ts index 936227f..da0cb86 100644 --- a/src/app/car/effects/car.spec.ts +++ b/src/app/car/effects/car.spec.ts @@ -53,7 +53,7 @@ describe('CarEffects', () => { }))); beforeEach(() => { - mockCarService.findCars.returns(new BehaviorSubject([])); + (mockCarService.findCars as sinon.SinonStub).returns(new BehaviorSubject([])); store.select(state => state.cars).subscribe(carsList => subscribedCars = carsList); store.dispatch(ActionFactory.clearCars()); }); @@ -80,7 +80,7 @@ describe('CarEffects', () => { })); it('will return same search action', sinon.test(fakeAsync(() => { - mockCarService.findCars.returns(new BehaviorSubject([])); + (mockCarService.findCars as sinon.SinonStub).returns(new BehaviorSubject([])); executor.queue({ type: CarAction.SEARCH }); effect.search$.subscribe(result => { expect(result.type).to.equal('Car - list cars'); @@ -88,7 +88,7 @@ describe('CarEffects', () => { }))); it('will return an empty search result by calling car service', sinon.test(fakeAsync(() => { - mockCarService.findCars.returns(new BehaviorSubject([])); + (mockCarService.findCars as sinon.SinonStub).returns(new BehaviorSubject([])); executor.queue(ActionFactory.search('Ford')); effect.search$.subscribe(result => { expect(result.payload.length).to.equal(0); @@ -96,7 +96,7 @@ describe('CarEffects', () => { }))); it('will return a filled result', sinon.test(fakeAsync(() => { - mockCarService.findCars.returns(new BehaviorSubject(mockResponse)); + (mockCarService.findCars as sinon.SinonStub).returns(new BehaviorSubject(mockResponse)); executor.queue(ActionFactory.search('Toyota')); effect.search$.subscribe(result => { expect(result.payload).to.eql(mockResponse); diff --git a/src/app/car/guards/car-listing.spec.ts b/src/app/car/guards/car-listing.spec.ts index c23299e..73570ab 100644 --- a/src/app/car/guards/car-listing.spec.ts +++ b/src/app/car/guards/car-listing.spec.ts @@ -1,3 +1,4 @@ +import { expect } from 'chai'; import {inject, TestBed} from '@angular/core/testing'; import {Car, CarState} from '../domain/car'; import {CarModule} from '../car.module'; @@ -61,7 +62,7 @@ describe('CarsListedGuard', () => { describe('when response comes from service', () => { beforeEach(() => { - mockCarService.getCars.returns(new BehaviorSubject(mockResponse)); + (mockCarService.getCars as sinon.SinonStub).returns(new BehaviorSubject(mockResponse)); }); it('will ensure cars are updated', sinon.test(() => { @@ -80,7 +81,7 @@ describe('CarsListedGuard', () => { describe('when no response comes from service', () => { beforeEach(() => { - mockCarService.getCars.returns(new BehaviorSubject([])); + (mockCarService.getCars as sinon.SinonStub).returns(new BehaviorSubject([])); }); it('will allow activation', sinon.test(() => { diff --git a/src/app/car/reducers/car.reducer.spec.ts b/src/app/car/reducers/car.reducer.spec.ts index 65de942..9b6e57a 100644 --- a/src/app/car/reducers/car.reducer.spec.ts +++ b/src/app/car/reducers/car.reducer.spec.ts @@ -1,3 +1,4 @@ +import { expect } from 'chai'; import {Car, CarState} from '../domain/car'; import {cars} from './car.reducer'; import {TestBed, inject} from '@angular/core/testing'; diff --git a/src/app/car/reducers/term.reducer.spec.ts b/src/app/car/reducers/term.reducer.spec.ts index 0a340c1..b8ecd62 100644 --- a/src/app/car/reducers/term.reducer.spec.ts +++ b/src/app/car/reducers/term.reducer.spec.ts @@ -1,3 +1,4 @@ +import { expect } from 'chai'; import {TestBed, inject} from '@angular/core/testing'; import {StoreModule, Store, Action} from '@ngrx/store'; import {CarState} from '../domain/car'; diff --git a/src/app/car/service/car.service.spec.ts b/src/app/car/service/car.service.spec.ts index 935f4e8..3aeec6e 100644 --- a/src/app/car/service/car.service.spec.ts +++ b/src/app/car/service/car.service.spec.ts @@ -1,3 +1,4 @@ +import { expect } from 'chai'; import {fakeAsync, inject, TestBed} from '@angular/core/testing'; import {HttpModule, XHRBackend, ResponseOptions, Response, RequestMethod, ConnectionBackend} from '@angular/http'; import {MockBackend, MockConnection} from '@angular/http/testing'; diff --git a/src/app/home/home.component.spec.ts b/src/app/home/home.component.spec.ts index fe74022..b2a7573 100644 --- a/src/app/home/home.component.spec.ts +++ b/src/app/home/home.component.spec.ts @@ -1,5 +1,5 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - +import { expect } from 'chai'; import { HomeComponent } from './home.component'; describe('HomeComponent', () => { @@ -8,9 +8,8 @@ describe('HomeComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ HomeComponent ] - }) - .compileComponents(); + declarations: [HomeComponent] + }).compileComponents(); })); beforeEach(() => { diff --git a/src/app/housing/components/edit/house-edit.component.spec.ts b/src/app/housing/components/edit/house-edit.component.spec.ts index 288d074..6bb7e4e 100644 --- a/src/app/housing/components/edit/house-edit.component.spec.ts +++ b/src/app/housing/components/edit/house-edit.component.spec.ts @@ -1,7 +1,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - +import { expect } from 'chai'; import { HouseEditComponent } from './house-edit.component'; -import {expect} from 'chai'; describe('HouseListComponent', () => { let component: HouseEditComponent; @@ -9,9 +8,8 @@ describe('HouseListComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ HouseEditComponent ] - }) - .compileComponents(); + declarations: [HouseEditComponent] + }).compileComponents(); })); beforeEach(() => { @@ -20,7 +18,6 @@ describe('HouseListComponent', () => { fixture.detectChanges(); }); - it('will be defined', sinon.test(() => { expect(component).to.exist; })); diff --git a/src/app/housing/components/list/house-list.component.spec.ts b/src/app/housing/components/list/house-list.component.spec.ts index 532783b..9e5ea3f 100644 --- a/src/app/housing/components/list/house-list.component.spec.ts +++ b/src/app/housing/components/list/house-list.component.spec.ts @@ -1,7 +1,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - +import { NO_ERRORS_SCHEMA, EventEmitter } from '@angular/core'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { HouseListComponent } from './house-list.component'; -import {expect} from 'chai'; +import { expect } from 'chai'; describe('HouseListComponent', () => { let component: HouseListComponent; @@ -9,9 +10,11 @@ describe('HouseListComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ HouseListComponent ] + imports: [FormsModule, ReactiveFormsModule], + declarations: [HouseListComponent], + schemas: [NO_ERRORS_SCHEMA], }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { @@ -20,7 +23,6 @@ describe('HouseListComponent', () => { fixture.detectChanges(); }); - it('will be defined', sinon.test(() => { expect(component).to.exist; })); diff --git a/src/app/housing/effects/housing.spec.ts b/src/app/housing/effects/housing.spec.ts index e4d880a..49c900a 100644 --- a/src/app/housing/effects/housing.spec.ts +++ b/src/app/housing/effects/housing.spec.ts @@ -52,7 +52,7 @@ describe('HousingEffects', () => { }))); beforeEach(() => { - mockHouseService.findHouses.returns(new BehaviorSubject([])); + (mockHouseService.findHouses as sinon.SinonStub).returns(new BehaviorSubject([])); store.select(state => state.houses).subscribe(housesList => subscribedHouses = housesList); store.dispatch(ActionFactory.clearHouses()); }); @@ -79,7 +79,7 @@ describe('HousingEffects', () => { })); it('will return same search action', sinon.test(fakeAsync(() => { - mockHouseService.findHouses.returns(new BehaviorSubject([])); + (mockHouseService.findHouses as sinon.SinonStub).returns(new BehaviorSubject([])); executor.queue({ type: HousingAction.SEARCH }); effect.search$.subscribe(result => { expect(result.type).to.equal('House - list houses'); @@ -87,7 +87,7 @@ describe('HousingEffects', () => { }))); it('will return an empty search result by calling house service', sinon.test(fakeAsync(() => { - mockHouseService.findHouses.returns(new BehaviorSubject([])); + (mockHouseService.findHouses as sinon.SinonStub).returns(new BehaviorSubject([])); executor.queue(ActionFactory.search('Melbourne')); effect.search$.subscribe(result => { expect(result.payload.length).to.equal(0); @@ -95,7 +95,7 @@ describe('HousingEffects', () => { }))); it('will return a filled result', sinon.test(fakeAsync(() => { - mockHouseService.findHouses.returns(new BehaviorSubject(mockResponse)); + (mockHouseService.findHouses as sinon.SinonStub).returns(new BehaviorSubject(mockResponse)); executor.queue(ActionFactory.search('Sydney')); effect.search$.subscribe(result => { expect(result.payload).to.eql(mockResponse); diff --git a/src/app/housing/guards/house-listing.spec.ts b/src/app/housing/guards/house-listing.spec.ts index a01b2c5..7a8150b 100644 --- a/src/app/housing/guards/house-listing.spec.ts +++ b/src/app/housing/guards/house-listing.spec.ts @@ -54,7 +54,6 @@ describe('HousesListedGuard', () => { store.dispatch(ActionFactory.clearHouses()); }); - it('will always start with an empty store', sinon.test(() => { expect(subscribedHouses).to.eql([]); })); @@ -62,7 +61,7 @@ describe('HousesListedGuard', () => { describe('when response comes from service', () => { beforeEach(() => { - mockHouseService.getHouses.returns(new BehaviorSubject(mockResponse)); + (mockHouseService.getHouses as sinon.SinonStub).returns(new BehaviorSubject(mockResponse)); }); it('will ensure houses are updated', sinon.test(() => { @@ -81,7 +80,7 @@ describe('HousesListedGuard', () => { describe('when no response comes from service', () => { beforeEach(() => { - mockHouseService.getHouses.returns(new BehaviorSubject([])); + (mockHouseService.getHouses as sinon.SinonStub).returns(new BehaviorSubject([])); }); it('will allow activation', sinon.test(() => { diff --git a/src/app/housing/housing.module.ts b/src/app/housing/housing.module.ts index f908191..81cf48b 100644 --- a/src/app/housing/housing.module.ts +++ b/src/app/housing/housing.module.ts @@ -1,6 +1,6 @@ import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; -import { ReactiveFormsModule } from '@angular/forms'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; import {HouseListComponent} from './components/list/house-list.component'; import {HouseEditComponent} from './components/edit/house-edit.component'; @@ -22,6 +22,7 @@ import {HouseService} from './service/house.service'; WidgitModule, UtilitiesModule, NgbModule, + FormsModule, ReactiveFormsModule ], exports: [ @@ -36,6 +37,9 @@ import {HouseService} from './service/house.service'; ListingComponent, SearchResultComponent ], - providers: [HouseService, HousesListedGuard] + providers: [ + HouseService, + HousesListedGuard + ] }) export class HousingModule { } diff --git a/src/app/housing/reducers/houses.reducer.spec.ts b/src/app/housing/reducers/houses.reducer.spec.ts index b8f6f03..1767ae2 100644 --- a/src/app/housing/reducers/houses.reducer.spec.ts +++ b/src/app/housing/reducers/houses.reducer.spec.ts @@ -90,24 +90,4 @@ describe('housing reducer', () => { }); - describe(HousingAction.ADD_HOUSE, () => { - - it('Will add house to the state', sinon.test(() => { - const houseToAdd: House = { - country: 'going', - state: 'to', - city: 'be', - construction: 'added', - rooms: 1 - }; - - - store.dispatch(ActionFactory.listHouses(housingPayload)); - - store.dispatch(ActionFactory.addHouse(houseToAdd)); - - expect(subscribedHouses).to.eql([...housingPayload, houseToAdd]); - })); - }); - }); diff --git a/src/app/utilities/object.service.spec.ts b/src/app/utilities/object.service.spec.ts index 9ae27ad..14dc0a9 100644 --- a/src/app/utilities/object.service.spec.ts +++ b/src/app/utilities/object.service.spec.ts @@ -1,5 +1,6 @@ import { TestBed, inject } from '@angular/core/testing'; import { ObjectService } from './object.service'; +import { expect } from 'chai'; describe('ObjectService', () => { @@ -22,12 +23,12 @@ describe('ObjectService', () => { }); beforeEach(inject([ObjectService], (objectService: ObjectService) => { - service = objectService; + service = objectService; })); it('will be defined', sinon.test(() => { - expect(service).to.exist; + expect(service).to.exist; })); diff --git a/src/app/utilities/type.spec.ts b/src/app/utilities/type.spec.ts index aab916a..9a4ee72 100644 --- a/src/app/utilities/type.spec.ts +++ b/src/app/utilities/type.spec.ts @@ -1,3 +1,4 @@ +import { expect } from 'chai'; import {type} from './type'; describe('type', () => { diff --git a/src/app/widgit/navigation/navigation-item.componenet.spec.ts b/src/app/widgit/navigation/navigation-item.component.spec.ts similarity index 93% rename from src/app/widgit/navigation/navigation-item.componenet.spec.ts rename to src/app/widgit/navigation/navigation-item.component.spec.ts index 3547c08..d90e868 100644 --- a/src/app/widgit/navigation/navigation-item.componenet.spec.ts +++ b/src/app/widgit/navigation/navigation-item.component.spec.ts @@ -1,3 +1,4 @@ +import { expect } from 'chai'; import {NavigationItemComponent} from './navigation-item.component'; import {NO_ERRORS_SCHEMA, DebugElement} from '@angular/core'; import {TestBed, async, ComponentFixture, inject} from '@angular/core/testing'; @@ -63,11 +64,12 @@ describe('NavigationItemComponent', () => { }; } - function findLinkByName(name: string) { + function findLinkByName(name: string): any { const links = _.filter(fixture.debugElement.children, (element: DebugElement) => { const elementId = element.children[0].nativeElement.attributes.id.value; return _.endsWith( elementId, 'nav-node-' + name ) || _.endsWith( elementId, 'nav-link-' + name ); }); + if (!_.isEmpty(links[0].nativeElement.querySelector('ul'))) { return representElementNode(links[0].nativeElement.querySelector('ul'), links[0].nativeElement.querySelector('a')); } else { @@ -75,13 +77,13 @@ describe('NavigationItemComponent', () => { } } - parameters([ - [navMenu[0], expected[0]], - [navMenu[1], expected[1]], - [navMenu[2], expected[2]] - ], + parameters( + [ + [navMenu[0], expected[0]], + [navMenu[1], expected[1]], + [navMenu[2], expected[2]] + ], (elmt: TreeElement, result) => { - it('will generate link for ' + elmt.title, sinon.test(async(() => { fixture.whenStable().then(() => { const _comparableElmt = createComparableElement(elmt); @@ -97,24 +99,23 @@ describe('NavigationItemComponent', () => { }); }))); - it('will verify if ' + elmt.title + ' is as node', sinon.test(async(() => { fixture.whenStable().then(() => { expect(component.asNode(elmt)).to.eql(result.asNode); }); }))); - it('will verify if ' + elmt.title + ' is active', sinon.test(async(() => { fixture.whenStable().then(() => { const isActive: boolean = result.isActive; if (isActive) { - cmpLocation.path.returns(elmt.targetUrl); + (cmpLocation.path as sinon.SinonStub).returns(elmt.targetUrl); } expect(component.isActiveNavItem(elmt)).to.equal(result.isActive); }); }))); - }); + } + ); }); @@ -125,7 +126,6 @@ function parameters(inputData, execFunction) { }); } - function getData(): Array { const homeNode: TreeElement = { title: 'Home', targetUrl: '/home', imageCssClass: 'glyphicon-home' }; const searchNode: TreeElement = { title: 'Search', targetUrl: '/search', imageCssClass: 'glyphicon-search' }; @@ -141,5 +141,3 @@ function getData(): Array { ]; return [menu, expectedTable]; } - - diff --git a/src/app/widgit/navigation/navigation.component.spec.ts b/src/app/widgit/navigation/navigation.component.spec.ts index 3fb915d..da5476e 100644 --- a/src/app/widgit/navigation/navigation.component.spec.ts +++ b/src/app/widgit/navigation/navigation.component.spec.ts @@ -1,3 +1,4 @@ +import { expect } from 'chai'; import {async, ComponentFixture, TestBed} from '@angular/core/testing'; import {NavigationComponent} from './navigation.component'; import {NO_ERRORS_SCHEMA} from '@angular/core'; diff --git a/src/app/widgit/search-form/search-form.component.spec.ts b/src/app/widgit/search-form/search-form.component.spec.ts index 1d17961..7b9d607 100644 --- a/src/app/widgit/search-form/search-form.component.spec.ts +++ b/src/app/widgit/search-form/search-form.component.spec.ts @@ -1,13 +1,13 @@ -import {async, ComponentFixture, TestBed, inject} from '@angular/core/testing'; -import {SearchFormComponent, UNDEFINED_NAME, DEFAULT_TARGET} from './search-form.component'; -import {NO_ERRORS_SCHEMA, EventEmitter} from '@angular/core'; -import {FormsModule, ReactiveFormsModule} from '@angular/forms'; -import {Router} from '@angular/router'; -import {UtilitiesModule} from '../../utilities/utilities.module'; -import {SearchOptions} from './search-options'; -import {StoreModule, Store} from '@ngrx/store'; -import {term} from '../../car/reducers/term.reducer'; - +import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; +import { NO_ERRORS_SCHEMA, EventEmitter } from '@angular/core'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { Router } from '@angular/router'; +import { StoreModule, Store } from '@ngrx/store'; +import { expect } from 'chai'; +import { SearchFormComponent, UNDEFINED_NAME, DEFAULT_TARGET } from './search-form.component'; +import { UtilitiesModule } from '../../utilities/utilities.module'; +import { SearchOptions } from './search-options'; +import { term } from '../../car/reducers/term.reducer'; describe('SearchFormComponent', () => { let component: SearchFormComponent; @@ -29,8 +29,8 @@ describe('SearchFormComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - imports: [FormsModule, ReactiveFormsModule, UtilitiesModule, StoreModule.provideStore({term})], - declarations: [ SearchFormComponent ], + imports: [FormsModule, ReactiveFormsModule, UtilitiesModule, StoreModule.provideStore({ term })], + declarations: [SearchFormComponent], schemas: [NO_ERRORS_SCHEMA], providers: [ { @@ -41,7 +41,7 @@ describe('SearchFormComponent', () => { } ] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { @@ -50,7 +50,7 @@ describe('SearchFormComponent', () => { fixture.detectChanges(); }); - beforeEach(inject([Router], ( router: Router) => { + beforeEach(inject([Router], (router: Router) => { mockRouter = router; })); @@ -61,7 +61,7 @@ describe('SearchFormComponent', () => { it('will have configured options with undefined defaults', sinon.test(() => { - expect(component.configuredOptions).to.eql(undefinedDefaultConfigurtion); + expect(component.configuredOptions).to.eql(undefinedDefaultConfigurtion); })); describe('initialisation', () => { @@ -90,7 +90,7 @@ describe('SearchFormComponent', () => { describe('search', () => { const searchTerm = 'find-me'; - const expectedQueryParameters = {queryParams: {q : searchTerm}}; + const expectedQueryParameters = { queryParams: { q: searchTerm } }; beforeEach(() => { component.options = expectedOptions; @@ -99,10 +99,9 @@ describe('SearchFormComponent', () => { describe('when no valid input is provided', () => { - it('will be able to be called and navigate away', sinon.test(() => { component.search(); - sinon.assert.notCalled(mockRouter.navigate); + sinon.assert.notCalled(mockRouter.navigate as sinon.SinonStub); })); it('will not change the subscribed term', sinon.test(() => { @@ -127,7 +126,7 @@ describe('SearchFormComponent', () => { it('will navigate to the configured target', sinon.test(() => { component.search(); - sinon.assert.calledWith(mockRouter.navigate, [expectedOptions.target], expectedQueryParameters); + sinon.assert.calledWith(mockRouter.navigate as sinon.SinonStub, [expectedOptions.target], expectedQueryParameters); })); it('will update a subscribed term', sinon.test(() => { From aa251bb83ae94a010e851a4faaf29ad36655b846 Mon Sep 17 00:00:00 2001 From: Arran Bartish Date: Tue, 4 Apr 2017 15:12:58 -0400 Subject: [PATCH 06/15] fix test with no_schema --- .../housing/components/edit/house-edit.component.spec.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/housing/components/edit/house-edit.component.spec.ts b/src/app/housing/components/edit/house-edit.component.spec.ts index 6bb7e4e..fbc5470 100644 --- a/src/app/housing/components/edit/house-edit.component.spec.ts +++ b/src/app/housing/components/edit/house-edit.component.spec.ts @@ -1,6 +1,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { expect } from 'chai'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { HouseEditComponent } from './house-edit.component'; +import {NO_ERRORS_SCHEMA} from '@angular/core'; +import { expect } from 'chai'; describe('HouseListComponent', () => { let component: HouseEditComponent; @@ -8,7 +10,9 @@ describe('HouseListComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [HouseEditComponent] + imports: [FormsModule, ReactiveFormsModule], + declarations: [HouseEditComponent], + schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); })); From db38225fb45504f59923fb6915f6b44513a10b59 Mon Sep 17 00:00:00 2001 From: Arran Bartish Date: Tue, 4 Apr 2017 15:29:14 -0400 Subject: [PATCH 07/15] output the chrome version --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e7bf8b6..5d60edd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ before_install: - export CHROME_BIN=chromium-browser - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start + - google-chrome --version install: - npm install - npm install codecov From 2a887266166a9366f9a8a46db9caa6cea1b0099f Mon Sep 17 00:00:00 2001 From: Arran Bartish Date: Tue, 4 Apr 2017 15:42:28 -0400 Subject: [PATCH 08/15] this is so not going to work :poop: --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5d60edd..18187df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ apt: - google-chrome-stable - google-chrome-beta before_install: + - apt-get update - export CHROME_BIN=chromium-browser - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start From de87b53139e88d09b38998b9eeaf0927fd131f65 Mon Sep 17 00:00:00 2001 From: Arran Bartish Date: Tue, 4 Apr 2017 15:46:32 -0400 Subject: [PATCH 09/15] Revert "this is so not going to work :poop:" This reverts commit dd4ce2645ec91a84556d67343e41bd607b56c7ba. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 18187df..5d60edd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,6 @@ apt: - google-chrome-stable - google-chrome-beta before_install: - - apt-get update - export CHROME_BIN=chromium-browser - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start From 2141688ccb276d9df9ecf35cbf1ed3b08caf3e06 Mon Sep 17 00:00:00 2001 From: Arran Bartish Date: Tue, 4 Apr 2017 18:11:59 -0400 Subject: [PATCH 10/15] Lock the chrome driver version. Travis CI only has chrome 55 and the latest chrome driver only supports chrome >= 56. When travis has a chrome browser >= 56 we can revert this commit --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7b84cf3..12cba8f 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "ng build", "test": "ng test", "lint": "ng lint", - "e2e": "ng e2e" + "pree2e": "webdriver-manager update --versions.chrome=2.28", + "e2e": "ng e2e --webdriver-update false" }, "private": true, "dependencies": { @@ -64,6 +65,7 @@ "ts-node": "~2.0.0", "tslint": "~4.5.0", "typescript": "~2.0.0", - "wallaby-webpack": "0.0.33" + "wallaby-webpack": "0.0.33", + "webdriver-manager": "^12.0.4" } } From 5f52c96a06e3292ec30eb2dc81ffea1534884f31 Mon Sep 17 00:00:00 2001 From: Arran Bartish Date: Wed, 5 Apr 2017 07:43:19 -0400 Subject: [PATCH 11/15] update travis to use npm scripts --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5d60edd..63642d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,8 +19,8 @@ install: - npm install - npm install codecov script: - - npm run ng test -- --single-run=true --browsers Chrome --code-coverage + - npm run test -- --single-run=true --browsers Chrome --code-coverage - ./node_modules/codecov/bin/codecov - - npm run ng e2e - - npm run ng lint - - npm run ng build + - npm run e2e + - npm run lint + - npm run build -- --prod From 7b40c0f71175bcfc1d98d29f3b26a72da393554a Mon Sep 17 00:00:00 2001 From: Arran Bartish Date: Wed, 5 Apr 2017 07:49:36 -0400 Subject: [PATCH 12/15] revert prod build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 63642d2..7b05933 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,4 +23,4 @@ script: - ./node_modules/codecov/bin/codecov - npm run e2e - npm run lint - - npm run build -- --prod + - npm run build From 61a4de75d90cd1492863d20e5e4fd8966e50b66a Mon Sep 17 00:00:00 2001 From: Arran Bartish Date: Thu, 6 Apr 2017 09:10:42 -0400 Subject: [PATCH 13/15] reduce coverage :cry: --- karma.conf.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 23d6526..73c7e93 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -41,16 +41,16 @@ module.exports = function (config) { reporters: ['text'], thresholds: { global: { - statements: 98, + statements: 95.62, branches: 77.27, - lines: 91.89, + lines: 89.93, functions: 91.89 }, each: { - statements: 90, - branches: 50, - lines: 88.89, - functions: 66.67 + statements: 76.47, + branches: 33.33, + lines: 77.42, + functions: 41.67 } } }, From 541b935d079b149254dc359b55d127e4362d656c Mon Sep 17 00:00:00 2001 From: Arran Bartish Date: Thu, 6 Apr 2017 09:22:52 -0400 Subject: [PATCH 14/15] reduce coverage some more :cry: --- karma.conf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 73c7e93..3861aee 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -43,8 +43,8 @@ module.exports = function (config) { global: { statements: 95.62, branches: 77.27, - lines: 89.93, - functions: 91.89 + lines: 91.89, + functions: 89.93 }, each: { statements: 76.47, From 736c874c8cb2a62ef3d814f6fc237c98c2386caf Mon Sep 17 00:00:00 2001 From: Naj Date: Mon, 10 Apr 2017 08:58:56 -0400 Subject: [PATCH 15/15] adding effect - navigation --- package.json | 1 + src/app/app.component.ts | 2 +- src/app/app.module.ts | 33 +++++++----- src/app/home/home.component.html | 5 +- src/app/registration/actions/registring.ts | 54 +++++++++++++++++++ .../avatar/registration-avatar.component.html | 18 +++++++ .../avatar/registration-avatar.component.ts | 41 ++++++++++++++ .../contact/registration-info.component.html | 48 +++++++++++++++++ .../contact/registration-info.component.ts | 53 ++++++++++++++++++ src/app/registration/components/index.ts | 4 ++ .../components/profile/profile.component.html | 13 +++++ .../components/profile/profile.component.ts | 24 +++++++++ .../registration/registration.component.html | 4 ++ .../registration/registration.component.ts | 33 ++++++++++++ src/app/registration/domain/registration.ts | 20 +++++++ src/app/registration/effects/registration.ts | 54 +++++++++++++++++++ .../registration/guards/registration.guard.ts | 35 ++++++++++++ .../reducers/registration.reducer.ts | 16 ++++++ src/app/registration/registration.module.ts | 43 +++++++++++++++ src/app/registration/registration.route.ts | 48 +++++++++++++++++ .../service/registration.service.ts | 39 ++++++++++++++ .../authentication/authentication.module.ts | 39 -------------- .../authentication/authentication.routing.ts | 15 ------ .../authentication/guards/auth.guard.ts | 15 ------ .../authentication/login/login.component.html | 21 -------- .../authentication/login/login.component.ts | 10 ---- src/app/widgit/authentication/models/user.ts | 8 --- .../authentication/profile.component.html | 7 --- .../authentication/profile.component.ts | 23 -------- .../register/register-info.component.html | 29 ---------- .../register/register-info.component.ts | 23 -------- .../services/authentication.service.ts | 15 ------ .../authentication/services/user.service.ts | 24 --------- src/app/widgit/widgit.module.ts | 8 ++- 34 files changed, 574 insertions(+), 251 deletions(-) create mode 100644 src/app/registration/actions/registring.ts create mode 100644 src/app/registration/components/avatar/registration-avatar.component.html create mode 100644 src/app/registration/components/avatar/registration-avatar.component.ts create mode 100644 src/app/registration/components/contact/registration-info.component.html create mode 100644 src/app/registration/components/contact/registration-info.component.ts create mode 100644 src/app/registration/components/index.ts create mode 100644 src/app/registration/components/profile/profile.component.html create mode 100644 src/app/registration/components/profile/profile.component.ts create mode 100644 src/app/registration/containers/registration/registration.component.html create mode 100644 src/app/registration/containers/registration/registration.component.ts create mode 100644 src/app/registration/domain/registration.ts create mode 100644 src/app/registration/effects/registration.ts create mode 100644 src/app/registration/guards/registration.guard.ts create mode 100644 src/app/registration/reducers/registration.reducer.ts create mode 100644 src/app/registration/registration.module.ts create mode 100644 src/app/registration/registration.route.ts create mode 100644 src/app/registration/service/registration.service.ts delete mode 100644 src/app/widgit/authentication/authentication.module.ts delete mode 100644 src/app/widgit/authentication/authentication.routing.ts delete mode 100644 src/app/widgit/authentication/guards/auth.guard.ts delete mode 100644 src/app/widgit/authentication/login/login.component.html delete mode 100644 src/app/widgit/authentication/login/login.component.ts delete mode 100644 src/app/widgit/authentication/models/user.ts delete mode 100644 src/app/widgit/authentication/profile.component.html delete mode 100644 src/app/widgit/authentication/profile.component.ts delete mode 100644 src/app/widgit/authentication/register/register-info.component.html delete mode 100644 src/app/widgit/authentication/register/register-info.component.ts delete mode 100644 src/app/widgit/authentication/services/authentication.service.ts delete mode 100644 src/app/widgit/authentication/services/user.service.ts diff --git a/package.json b/package.json index 12cba8f..857e607 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@ngrx/effects": "^2.0.0", "@ngrx/store": "^2.2.1", "@types/lodash": "4.14.50", + "angular2-image-upload": "^0.5.1", "core-js": "^2.4.1", "lodash": "^4.17.4", "ng2-validation": "^3.9.1", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index e430bc5..d4a3c8a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -19,7 +19,7 @@ export class AppComponent implements OnInit { ngOnInit() { this.treeElements = [ { title: 'Home', targetUrl: '/home', imageCssClass: 'glyphicon-globe' }, - { title: 'Account', targetUrl: '/login', imageCssClass: 'glyphicon-user' }, + { title: 'Register', targetUrl: '/register', imageCssClass: 'glyphicon-user' }, { title: 'Search', targetUrl: '/search', imageCssClass: 'glyphicon-search' }, { title: 'Car', targetUrl: '/car', imageCssClass: 'glyphicon-road' }, { title: 'Housing', targetUrl: '/housing', imageCssClass: 'glyphicon-home' } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 80c7c50..d122a42 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,5 +1,6 @@ +import { registration } from './registration/reducers/registration.reducer'; import { BrowserModule } from '@angular/platform-browser'; -import { NgModule } from '@angular/core'; +import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; @@ -9,23 +10,28 @@ import { WidgitModule } from './widgit/widgit.module'; import { CarRouteModule } from './car/car.route'; import { HomeComponent } from './home/home.component'; import { PageNotFoundComponent } from './404/pageNotFound.component'; -import {StoreModule, ActionReducer, combineReducers} from '@ngrx/store'; -import {cars} from './car/reducers/car.reducer'; -import {EffectsModule} from '@ngrx/effects'; -import {CarEffects} from './car/effects/cars.'; -import {HousingRouteModule} from './housing/housing.route'; -import {houses} from './housing/reducers/houses.reducer'; -import {HousingEffects} from 'app/housing/effects/housing'; - +import { StoreModule, ActionReducer, combineReducers } from '@ngrx/store'; +import { cars } from './car/reducers/car.reducer'; +import { EffectsModule } from '@ngrx/effects'; +import { CarEffects } from './car/effects/cars.'; +import { HousingRouteModule } from './housing/housing.route'; +import { houses } from './housing/reducers/houses.reducer'; +import { HousingEffects } from 'app/housing/effects/housing'; +import { RegistrationModule } from './registration/registration.module'; +import { RegistrationEffects } from './registration/effects/registration'; +import { RegistrationRouteModule } from './registration/registration.route'; +import { ImageUploadModule } from 'angular2-image-upload'; const routes: Routes = [ { path: '', pathMatch: 'full', redirectTo: 'home' }, { path: 'home', component: HomeComponent }, + { path: 'register', loadChildren: './registration/registration.route#RegistrationRouteModule' }, { path: 'car', loadChildren: './car/car.route#CarRouteModule' }, { path: 'housing', loadChildren: './housing/housing.route#HousingRouteModule' }, { path: '**', component: PageNotFoundComponent } ]; @NgModule({ + schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: [ AppComponent, HomeComponent, @@ -33,18 +39,21 @@ const routes: Routes = [ ], imports: [ RouterModule.forRoot(routes), - BrowserModule, + BrowserModule, FormsModule, + RegistrationModule, ReactiveFormsModule, HttpModule, RouterModule, CarRouteModule, HousingRouteModule, + RegistrationRouteModule, WidgitModule, NgbModule.forRoot(), - StoreModule.provideStore({cars, houses}), + StoreModule.provideStore({ cars, houses, registration }), EffectsModule.run(CarEffects), - EffectsModule.run(HousingEffects) + EffectsModule.run(HousingEffects), + EffectsModule.run(RegistrationEffects) ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index d787b0f..eae1217 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -1,6 +1,3 @@

Welcome to the Angular 2 playground! -

-
- Start -
\ No newline at end of file +

\ No newline at end of file diff --git a/src/app/registration/actions/registring.ts b/src/app/registration/actions/registring.ts new file mode 100644 index 0000000..4881575 --- /dev/null +++ b/src/app/registration/actions/registring.ts @@ -0,0 +1,54 @@ +import { Registration } from './../domain/registration'; +import { type } from '../../utilities/type'; +import { Action } from '@ngrx/store'; +import { of } from 'rxjs/observable/of'; + +export const RegistrationAction = { + START_REGISTRATION: type('Registration - start registration'), + CREATE_REGISTRATION: type('Registration - Add registration'), + ABORT_REGISTRATIONS: type('Registration - abort registrations'), +}; + + +export class ActionFactory { + + + static startRegistration(registration: Registration): Action { + return new StartRegistrationAction(registration); + } + + static createRegistration(registration: Registration): Action { + return new CreateRegistrationAction(registration); + } + + static abortRegistration(registration: Registration): Action { + return new AbortRegistrationsAction(registration); + } + + static getRegistration(registration) { + return registration; + } + + static empty() { + return new Registration(); + } +} + +export class StartRegistrationAction implements Action { + type = RegistrationAction.START_REGISTRATION; + + constructor(public payload: Registration) { } +} + + +export class CreateRegistrationAction implements Action { + type = RegistrationAction.CREATE_REGISTRATION; + + constructor(public payload: Registration) { } +} + +export class AbortRegistrationsAction implements Action { + type = RegistrationAction.ABORT_REGISTRATIONS; + + constructor(public payload: Registration) { } +} diff --git a/src/app/registration/components/avatar/registration-avatar.component.html b/src/app/registration/components/avatar/registration-avatar.component.html new file mode 100644 index 0000000..6a5420c --- /dev/null +++ b/src/app/registration/components/avatar/registration-avatar.component.html @@ -0,0 +1,18 @@ +
+ +
+
+ +
+
+ +
+
+ + + +
+
+
+ diff --git a/src/app/registration/components/avatar/registration-avatar.component.ts b/src/app/registration/components/avatar/registration-avatar.component.ts new file mode 100644 index 0000000..0e2e09b --- /dev/null +++ b/src/app/registration/components/avatar/registration-avatar.component.ts @@ -0,0 +1,41 @@ +import { ActionFactory } from './../../actions/registring'; +import { RegistrationsState, User } from './../../domain/registration'; +import { Router } from '@angular/router'; +import { Component, OnInit, Input, Output, EventEmitter, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { CustomValidators } from 'ng2-validation'; +import { Registration } from '../../domain/registration'; +import { Store } from '@ngrx/store'; + +@Component({ + selector: 'app-registration-avatar', + templateUrl: 'registration-avatar.component.html', + +}) +export class RegistrationAvatarComponent implements OnInit { + + + public registration: Registration; + + public constructor(private router: Router, private registringStore: Store) { + } + + ngOnInit() { + this.registringStore.select(state => state.registration).subscribe(registration => this.registration = registration); + } + + upload(data: any) { + this.registration.user.avatar = data.src; + } + + public register() { + this.registringStore.dispatch(ActionFactory.createRegistration(this.registration)); + this.router.navigate(['/profile']); + } + + public abort() { + this.registringStore.dispatch(ActionFactory.abortRegistration(this.registration)); + this.router.navigate(['/home']); + } + +} \ No newline at end of file diff --git a/src/app/registration/components/contact/registration-info.component.html b/src/app/registration/components/contact/registration-info.component.html new file mode 100644 index 0000000..e5d5d44 --- /dev/null +++ b/src/app/registration/components/contact/registration-info.component.html @@ -0,0 +1,48 @@ +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+ + +
+
+ +
+
\ No newline at end of file diff --git a/src/app/registration/components/contact/registration-info.component.ts b/src/app/registration/components/contact/registration-info.component.ts new file mode 100644 index 0000000..f6a6f55 --- /dev/null +++ b/src/app/registration/components/contact/registration-info.component.ts @@ -0,0 +1,53 @@ +import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { CustomValidators } from 'ng2-validation'; +import { Registration, User, RegistrationsState } from '../../domain/registration'; +import { Router } from '@angular/router'; +import { Store } from '@ngrx/store'; + +@Component({ + selector: 'app-registration-info', + templateUrl: 'registration-info.component.html', +}) +export class RegistrationInfoComponent implements OnInit { + + @Input() + public registration: Registration; + + public user: User = new User(); + + @Output() + public registrationStarted: EventEmitter; + + @Output() + public registrationAborted: EventEmitter; + + public registrationForm: FormGroup; + public constructor(private formBuilder: FormBuilder) { + this.registrationStarted = new EventEmitter(); + this.registrationAborted = new EventEmitter(); + + this.registrationForm = this.formBuilder.group({ + firstName: [this.user.firstName, Validators.required], + lastName: [this.user.lastName, Validators.required], + username: [this.user.username, Validators.required], + email: [this.user.email, Validators.required], + password: [this.user.password, Validators.required] + }); + } + + ngOnInit() { + } + + public startRegistration() { + /* if (!this.registrationForm.valid) { + return; + }*/ + this.registration.user = this.user; + this.registrationStarted.emit(this.registration); + } + public abort() { + this.registration = new Registration(); + this.registrationAborted.emit(this.registration); + } +} \ No newline at end of file diff --git a/src/app/registration/components/index.ts b/src/app/registration/components/index.ts new file mode 100644 index 0000000..ed1ca2f --- /dev/null +++ b/src/app/registration/components/index.ts @@ -0,0 +1,4 @@ +export * from './avatar/registration-avatar.component' +export * from './contact/registration-info.component' +export * from './profile/profile.component' + diff --git a/src/app/registration/components/profile/profile.component.html b/src/app/registration/components/profile/profile.component.html new file mode 100644 index 0000000..8fb90c8 --- /dev/null +++ b/src/app/registration/components/profile/profile.component.html @@ -0,0 +1,13 @@ +
+

Hi {{registration.user.firstName}}!

+

your profile page

+ {{registration.user.email}} +
+
+
+ +
+
+
+ Logout +
\ No newline at end of file diff --git a/src/app/registration/components/profile/profile.component.ts b/src/app/registration/components/profile/profile.component.ts new file mode 100644 index 0000000..b098397 --- /dev/null +++ b/src/app/registration/components/profile/profile.component.ts @@ -0,0 +1,24 @@ +import { RegistrationsState } from './../../domain/registration'; +import { Store } from '@ngrx/store'; +import { Component, OnInit } from '@angular/core'; +import { User, Registration } from '../../domain/registration'; +import { Router } from '@angular/router'; + +@Component({ + moduleId: module.id, + templateUrl: 'profile.component.html' + +}) +export class ProfileComponent implements OnInit { + public registration: Registration; + + public constructor(private router: Router, private registringStore: Store) { + } + + ngOnInit() { + this.registringStore.select(state => state.registration).subscribe(registration => this.registration = registration); + } + + + +} \ No newline at end of file diff --git a/src/app/registration/containers/registration/registration.component.html b/src/app/registration/containers/registration/registration.component.html new file mode 100644 index 0000000..6b09534 --- /dev/null +++ b/src/app/registration/containers/registration/registration.component.html @@ -0,0 +1,4 @@ +
+

Register

+ +
\ No newline at end of file diff --git a/src/app/registration/containers/registration/registration.component.ts b/src/app/registration/containers/registration/registration.component.ts new file mode 100644 index 0000000..62f6568 --- /dev/null +++ b/src/app/registration/containers/registration/registration.component.ts @@ -0,0 +1,33 @@ +import { Router } from '@angular/router'; +import { Component, OnInit } from '@angular/core'; +import { Store } from '@ngrx/store'; +import { ActionFactory } from '../../actions/registring'; +import { SearchOptions } from '../../../widgit/search-form/search-options'; +import { RegistrationsState, Registration } from '../../domain/registration'; + +@Component({ + selector: 'app-registration', + templateUrl: 'registration.component.html', +}) +export class RegistrationComponent implements OnInit { + + registration: Registration; + constructor(private router: Router, private registringStore: Store) { + } + + ngOnInit() { + this.registringStore.select(state => state.registration).subscribe(registration => this.registration = registration); + } + + public registrationStarted() { + this.registringStore.dispatch(ActionFactory.startRegistration(this.registration)); + this.router.navigate(['/avatar']); + } + + public registrationAborted() { + this.registringStore.dispatch(ActionFactory.abortRegistration(this.registration)); + this.router.navigate(['/home']); + } + + +} diff --git a/src/app/registration/domain/registration.ts b/src/app/registration/domain/registration.ts new file mode 100644 index 0000000..3cf05e8 --- /dev/null +++ b/src/app/registration/domain/registration.ts @@ -0,0 +1,20 @@ + +export class User { + id: number; + username: string; + email: string; + password: string; + firstName: string; + lastName: string; + avatar: string; + +} + +export class Registration { + status: string; + user: User; +} + +export interface RegistrationsState { + registration: Registration; +} diff --git a/src/app/registration/effects/registration.ts b/src/app/registration/effects/registration.ts new file mode 100644 index 0000000..37e6c8b --- /dev/null +++ b/src/app/registration/effects/registration.ts @@ -0,0 +1,54 @@ +import { RegistrationAction, ActionFactory } from '../actions/registring'; +import { Injectable } from '@angular/core'; +import { Effect, Actions, toPayload } from '@ngrx/effects'; +import { Action } from '@ngrx/store'; +import { Observable } from 'rxjs/Observable'; +import { of } from 'rxjs/observable/of'; +import { empty } from 'rxjs/observable/empty'; +import 'rxjs/add/operator/skip'; +import 'rxjs/add/operator/takeUntil'; +import { StartRegistrationAction } from '../actions/registring'; +import { RegistrationService } from '../service/registration.service'; + +@Injectable() +export class RegistrationEffects { + + @Effect() + startRegistration$: Observable = this.actions$ + .ofType(RegistrationAction.START_REGISTRATION) + .map(toPayload) + .switchMap(newRegistration => { + return this.registrationService.startRegistration(newRegistration) + .catch(error => { + return of(null); + }); + }); + + @Effect() + createRegistration$: Observable = this.actions$ + .ofType(RegistrationAction.CREATE_REGISTRATION) + .map(toPayload) + .switchMap(registration => { + return this.registrationService.createRegistration(registration) + .catch(error => { + return of(null); + }); + }); + + @Effect() + abortRegistration$: Observable = this.actions$ + .ofType(RegistrationAction.ABORT_REGISTRATIONS) + .map(toPayload) + .switchMap(registration => { + return this.registrationService.abortRegistration(registration) + .catch(error => { + return of(null); + }); + }); + + + constructor(private actions$: Actions, private registrationService: RegistrationService) { + } + + +} diff --git a/src/app/registration/guards/registration.guard.ts b/src/app/registration/guards/registration.guard.ts new file mode 100644 index 0000000..77092a5 --- /dev/null +++ b/src/app/registration/guards/registration.guard.ts @@ -0,0 +1,35 @@ +import { Injectable } from '@angular/core'; +import { CanActivate, Router, ActivatedRouteSnapshot } from '@angular/router'; +import { Store } from '@ngrx/store'; +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/take'; +import 'rxjs/add/operator/filter'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/switchMap'; +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/let'; +import { RegistrationService } from '../service/registration.service'; +import { ActionFactory } from '../actions/registring'; +import { RegistrationsState } from '../domain/registration'; + +@Injectable() +export class RegistrationGuard implements CanActivate { + + constructor(private store: Store, + private registrationService: RegistrationService) { + } + + getRegistration(): Observable { + return this.registrationService.getLatestRegistration() + .do(registration => { + this.store.dispatch(ActionFactory.getRegistration(registration)) + }) + .map(registration => + ['started','created'].indexOf(registration.status) !== -1) + } + + canActivate(route: ActivatedRouteSnapshot): Observable { + return this.getRegistration(); + } +} diff --git a/src/app/registration/reducers/registration.reducer.ts b/src/app/registration/reducers/registration.reducer.ts new file mode 100644 index 0000000..14f226e --- /dev/null +++ b/src/app/registration/reducers/registration.reducer.ts @@ -0,0 +1,16 @@ +import { Action } from '@ngrx/store'; +import { Registration } from '../domain/registration'; +import { RegistrationAction } from '../actions/registring'; + +export const registration = (state: any = new Registration(), action: Action) => { + switch (action.type) { + case RegistrationAction.START_REGISTRATION: + return action.payload; + case RegistrationAction.CREATE_REGISTRATION: + return action.payload; + case RegistrationAction.ABORT_REGISTRATIONS: + return action.payload; + default: + return state; + } +}; diff --git a/src/app/registration/registration.module.ts b/src/app/registration/registration.module.ts new file mode 100644 index 0000000..fc34876 --- /dev/null +++ b/src/app/registration/registration.module.ts @@ -0,0 +1,43 @@ +import { RouterModule } from '@angular/router'; +import { ImageUploadModule } from 'angular2-image-upload'; +import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; +import { WidgitModule } from '../widgit/widgit.module'; +import { UtilitiesModule } from '../utilities/utilities.module'; +import { RegistrationComponent } from './containers/registration/registration.component'; +import { ProfileComponent, RegistrationInfoComponent, RegistrationAvatarComponent } from './components/index'; +import { RegistrationService } from './service/registration.service'; +import { RegistrationGuard } from './guards/registration.guard'; + +@NgModule({ + schemas: [CUSTOM_ELEMENTS_SCHEMA], + imports: [ + CommonModule, + WidgitModule, + UtilitiesModule, + NgbModule, + FormsModule, + RouterModule, + ImageUploadModule.forRoot(), + ReactiveFormsModule + ], + exports: [ + ProfileComponent, + RegistrationAvatarComponent, + RegistrationInfoComponent, + RegistrationComponent, + ], + declarations: [ + ProfileComponent, + RegistrationAvatarComponent, + RegistrationInfoComponent, + RegistrationComponent, + ], + providers: [ + RegistrationService, + RegistrationGuard + ] +}) +export class RegistrationModule { } diff --git a/src/app/registration/registration.route.ts b/src/app/registration/registration.route.ts new file mode 100644 index 0000000..87a39c3 --- /dev/null +++ b/src/app/registration/registration.route.ts @@ -0,0 +1,48 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { Routes, RouterModule } from '@angular/router'; +import { RegistrationInfoComponent } from './components/contact/registration-info.component'; +import { RegistrationAvatarComponent } from './components/avatar/registration-avatar.component'; +import { ProfileComponent } from './components/profile/profile.component'; +import { RegistrationGuard } from './guards/registration.guard'; +import { RegistrationModule } from './registration.module'; +import { RegistrationComponent } from './containers/registration/registration.component'; + + +const routes: Routes = [ + { + path: 'register', + redirectTo: '/register/init', + pathMatch: 'full' + }, + { + path: 'init', + component: RegistrationComponent + }, + { + path: 'contact', + component: RegistrationInfoComponent + }, + { + path: 'avatar', + canActivate: [RegistrationGuard], + component: RegistrationAvatarComponent + }, + { + path: 'profile', + canActivate: [RegistrationGuard], + component: ProfileComponent + } + +]; + +@NgModule({ + exports: [ + ], + imports: [ + RouterModule.forChild(routes), + RegistrationModule, + CommonModule + ], declarations: [] +}) +export class RegistrationRouteModule { } diff --git a/src/app/registration/service/registration.service.ts b/src/app/registration/service/registration.service.ts new file mode 100644 index 0000000..dca11eb --- /dev/null +++ b/src/app/registration/service/registration.service.ts @@ -0,0 +1,39 @@ +import { Injectable } from '@angular/core'; +import { Response, Http } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; +import { of } from 'rxjs/observable/of'; +import 'rxjs/add/operator/map'; +import { Registration } from '../domain/registration'; + +@Injectable() +export class RegistrationService { + + private record: Registration; + + constructor(private http: Http) { + this.record = new Registration(); + } + + startRegistration(newRegistration: Registration): Observable { + this.record.status = 'started'; + this.record.user = newRegistration.user; + return of(this.record); + } + + createRegistration(registration: Registration): Observable { + this.record.status = 'created'; + this.record.user = registration.user; + return of(this.record); + } + + abortRegistration(registration: Registration): Observable { + this.record.status = 'aborted'; + this.record.user = registration.user; + return of(registration); + } + + getLatestRegistration() { + return of(this.record); + } + +} diff --git a/src/app/widgit/authentication/authentication.module.ts b/src/app/widgit/authentication/authentication.module.ts deleted file mode 100644 index b36a090..0000000 --- a/src/app/widgit/authentication/authentication.module.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { RouterModule } from '@angular/router'; -import { NgModule } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { FormsModule } from '@angular/forms'; -import { HttpModule } from '@angular/http'; - -import { authenticationRouting } from './authentication.routing'; - -import { AuthGuard } from './guards/auth.guard'; -import { AuthenticationService } from './services/authentication.service'; -import { UserService } from './services/user.service'; -import { ProfileComponent } from './profile.component'; -import { LoginComponent } from './login/login.component'; -import { RegisterInfoComponent } from './register/register-info.component'; - -@NgModule({ - imports: [ - BrowserModule, - FormsModule, - HttpModule, - authenticationRouting, - ], - declarations: [ - ProfileComponent, - LoginComponent, - RegisterInfoComponent - ], - providers: [ - AuthGuard, - AuthenticationService, - UserService, - ], - exports: [ - ProfileComponent, - LoginComponent, - RegisterInfoComponent - ] -}) -export class AuthenticationModule { } \ No newline at end of file diff --git a/src/app/widgit/authentication/authentication.routing.ts b/src/app/widgit/authentication/authentication.routing.ts deleted file mode 100644 index 1c9457a..0000000 --- a/src/app/widgit/authentication/authentication.routing.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Routes, RouterModule } from '@angular/router'; - -import { ProfileComponent } from './profile.component'; -import { LoginComponent } from './login/login.component'; -import { RegisterInfoComponent } from './register/register-info.component'; -import { AuthGuard } from './guards/auth.guard'; - -const appRoutes: Routes = [ - { path: 'profile', component: ProfileComponent, canActivate: [AuthGuard] }, - { path: 'login', component: LoginComponent }, - { path: 'register', component: RegisterInfoComponent }, - { path: '**', redirectTo: '/home' } // redirect to home. -]; - -export const authenticationRouting = RouterModule.forRoot(appRoutes); \ No newline at end of file diff --git a/src/app/widgit/authentication/guards/auth.guard.ts b/src/app/widgit/authentication/guards/auth.guard.ts deleted file mode 100644 index d18bb98..0000000 --- a/src/app/widgit/authentication/guards/auth.guard.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; - -@Injectable() -export class AuthGuard implements CanActivate { - constructor(private router: Router) { } - - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { - // TODO - // check on state if the user is there return true [state.select('userprofile')] - // otherwise redirect to login and return false - // this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } }); - return true; - } -} \ No newline at end of file diff --git a/src/app/widgit/authentication/login/login.component.html b/src/app/widgit/authentication/login/login.component.html deleted file mode 100644 index 2f1aaa8..0000000 --- a/src/app/widgit/authentication/login/login.component.html +++ /dev/null @@ -1,21 +0,0 @@ -
-

Login

-
-
-
- - -
-
- - -
-
- -
-
-
-
- Register -
-
\ No newline at end of file diff --git a/src/app/widgit/authentication/login/login.component.ts b/src/app/widgit/authentication/login/login.component.ts deleted file mode 100644 index d0e2fe9..0000000 --- a/src/app/widgit/authentication/login/login.component.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Component } from '@angular/core'; - -@Component({ - moduleId: module.id, - templateUrl: 'login.component.html' -}) - -export class LoginComponent { - -} diff --git a/src/app/widgit/authentication/models/user.ts b/src/app/widgit/authentication/models/user.ts deleted file mode 100644 index 2b27f2a..0000000 --- a/src/app/widgit/authentication/models/user.ts +++ /dev/null @@ -1,8 +0,0 @@ -export class User { - id: number; - username: string; - email: string; - password: string; - firstName: string; - lastName: string; -} \ No newline at end of file diff --git a/src/app/widgit/authentication/profile.component.html b/src/app/widgit/authentication/profile.component.html deleted file mode 100644 index 920e846..0000000 --- a/src/app/widgit/authentication/profile.component.html +++ /dev/null @@ -1,7 +0,0 @@ -
-

Hi {{currentUser.firstName}}!

-

your profile page

- {{currentUser.firstName}} - {{currentUser.picture}} - -
\ No newline at end of file diff --git a/src/app/widgit/authentication/profile.component.ts b/src/app/widgit/authentication/profile.component.ts deleted file mode 100644 index 42866cc..0000000 --- a/src/app/widgit/authentication/profile.component.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { AuthenticationService } from './services/authentication.service'; -import { Component, OnInit } from '@angular/core'; - -import { User } from './models/user'; -import { UserService } from './services/user.service'; - -@Component({ - moduleId: module.id, - templateUrl: 'profile.component.html', - providers: [AuthenticationService] -}) -export class ProfileComponent implements OnInit { - currentUser: User = new User(); - constructor(private authenticationService: AuthenticationService, private userService: UserService) { - // get the user from state. - // this.currentUser = state.select("userProfile-name"); - } - ngOnInit() { } - - logout(user) { - this.authenticationService.logout(user); - } -} \ No newline at end of file diff --git a/src/app/widgit/authentication/register/register-info.component.html b/src/app/widgit/authentication/register/register-info.component.html deleted file mode 100644 index f76343e..0000000 --- a/src/app/widgit/authentication/register/register-info.component.html +++ /dev/null @@ -1,29 +0,0 @@ -
-

Register

-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - Cancel -
-
-
diff --git a/src/app/widgit/authentication/register/register-info.component.ts b/src/app/widgit/authentication/register/register-info.component.ts deleted file mode 100644 index 438d09f..0000000 --- a/src/app/widgit/authentication/register/register-info.component.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { User } from './../models/user'; -import { Component } from '@angular/core'; -import { Router } from '@angular/router'; - -import { UserService } from '../services/user.service'; -@Component({ - moduleId: module.id, - templateUrl: 'register-info.component.html' -}) -export class RegisterInfoComponent { - user: User = new User(); - constructor(private router: Router, private userService: UserService) { } - register() { - this.userService.register(this.user) - .subscribe( - data => { - this.router.navigate(['/profile']); - }, - error => { - console.log("[authentication] registration error") - }); - } -} diff --git a/src/app/widgit/authentication/services/authentication.service.ts b/src/app/widgit/authentication/services/authentication.service.ts deleted file mode 100644 index 7528a06..0000000 --- a/src/app/widgit/authentication/services/authentication.service.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Http, Headers, Response } from '@angular/http'; - -@Injectable() -export class AuthenticationService { - constructor() { } - - login() { - //TODO - } - - logout(user) { - // TODO - } -} \ No newline at end of file diff --git a/src/app/widgit/authentication/services/user.service.ts b/src/app/widgit/authentication/services/user.service.ts deleted file mode 100644 index 6ea80fa..0000000 --- a/src/app/widgit/authentication/services/user.service.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Http, Headers, RequestOptions, Response } from '@angular/http'; -import { User } from '../models/user'; -import { Observable } from 'rxjs/Observable'; -import { of } from 'rxjs/observable/of'; - -@Injectable() -export class UserService { - constructor() { } - getByUsername(username: string) { - // find by name. - } - - register(user: User): Observable { - // add a new user in state - return of(new User()); - } - - delete(id: number) { - // delete a user - } - - -} \ No newline at end of file diff --git a/src/app/widgit/widgit.module.ts b/src/app/widgit/widgit.module.ts index 82c241d..b1565f5 100644 --- a/src/app/widgit/widgit.module.ts +++ b/src/app/widgit/widgit.module.ts @@ -2,21 +2,19 @@ import { NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; import { CommonModule } from '@angular/common'; import { ReactiveFormsModule } from '@angular/forms'; -import {UtilitiesModule} from '../utilities/utilities.module'; -import {SearchFormComponent} from './search-form/search-form.component'; +import { UtilitiesModule } from '../utilities/utilities.module'; +import { SearchFormComponent } from './search-form/search-form.component'; import { NavigationComponent } from './navigation/navigation.component'; import { NavigationItemComponent } from './navigation/navigation-item.component'; -import { AuthenticationModule } from './authentication/authentication.module'; @NgModule({ imports: [ CommonModule, RouterModule, - AuthenticationModule, UtilitiesModule, ReactiveFormsModule, - + ], exports: [ SearchFormComponent,