Skip to content

Commit e316ac3

Browse files
committed
Version 1.0.0 RC-1
1 parent b25e429 commit e316ac3

31 files changed

+91
-186
lines changed

src/app/_guard/auth.guard.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ export class AuthGuard implements CanActivate {
88

99
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
1010
if (localStorage.getItem('currentUser')) {
11-
console.log( 'AuthGuard '+ this.router.url );
11+
1212
// logged in so return true
13+
// let returnUrl = route.queryParams['returnUrl'];
14+
console.log( 'AuthGuard '+ this.router.url + ' state Url ' + state.url);
15+
16+
1317
return true;
1418
}
15-
console.log( this.router );
19+
// console.log( this.router );
1620
// not logged in so redirect to login page with the return url
1721
this.router.navigate(['login'], { queryParams: { returnUrl: state.url }});
1822
return false;

src/app/_guard/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export * from './auth.guard';
1+
export * from './auth.guard';
2+
// export * from './home.guard';

src/app/_services/backend.service.ts

-3
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,8 @@ export class BackendService {
4646

4747
// private helper methods
4848
private form() {
49-
// let currentUser = JSON.parse(localStorage.getItem('currentUser'));
50-
// if (currentUser && currentUser.token) {
5149
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
5250
return new RequestOptions({ headers: headers });
53-
// }
5451
}
5552

5653
private jwt() {

src/app/app.component.css

-1
This file was deleted.

src/app/app.component.ts

+5-30
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,24 @@ import { RootComponent } from './root'
1717
import { AuthenticationService } from "./_services";
1818
/**
1919
* App Component
20-
* Top Level Component
2120
*/
2221
@Component({
2322
selector: 'app',
24-
// encapsulation: ViewEncapsulation.None,
25-
// styleUrls: [
26-
// './app.component.css'
27-
// ],
2823
template: `
2924
<ng-progress></ng-progress>
30-
<root></root>
25+
<root ></root>
3126
`
3227
})
33-
export class AppComponent implements DoCheck {
34-
// public name = 'Reetek Angular CRM';
35-
// currentUser: User;
28+
export class AppComponent implements OnInit {
29+
30+
isAuth:boolean;
3631

3732
constructor(
3833
public appState: AppState,
3934
private router: Router,
4035
private authService: AuthenticationService
41-
) {
42-
// console.log('Initial App constructor auth ' + this.authService.isAuthenticated(), this.router);
43-
44-
}
36+
) {}
4537

4638
public ngOnInit() {
47-
// console.log('Initial App ngOnInit');
48-
49-
// this.currentUser = JSON.parse(localStorage.getItem('currentUser'));
50-
// if (!this.currentUser) this.currentUser = <User>{};
51-
52-
// console.log('Initial App ngDoCheck ' + this.router.url + ' auth ' + this.authService.isAuthenticated());
53-
}
54-
55-
public ngDoCheck() {
56-
57-
58-
59-
// this.currentUser = JSON.parse(localStorage.getItem('currentUser'));
60-
// if (!this.currentUser) this.currentUser = <User>{};
61-
// console.log('Initial App ngDoCheck ' + this.router.url + ' auth ' + this.authService.isAuthenticated());
62-
6339
}
64-
6540
}

src/app/app.module.ts

+15-21
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
} from '@angularclass/hmr';
1919
import {
2020
RouterModule,
21-
PreloadAllModules
21+
PreloadAllModules,
22+
2223
} from '@angular/router';
2324

2425
/*
@@ -34,7 +35,7 @@ import { AppState, InternalStateType } from './app.service';
3435
import { AboutComponent } from './about';
3536
import { ErrorPageComponent } from './errorpage';
3637
import { LoginComponent } from './login';
37-
import { LogoutComponent } from './logout';
38+
// import { LogoutComponent } from './logout';
3839
import { RootComponent } from './root';
3940
import { DashboardComponent } from './dashboard'
4041
import { ConfirmDialog} from './shared'
@@ -45,9 +46,10 @@ import { ConfirmDialog} from './shared'
4546
import { ChartsModule } from 'ng2-charts';
4647
import { RootModule } from './root';
4748
import { CustomerModule } from './customer';
48-
// import { ProductModule } from './products';
49-
// import { SharedModule } from './shared';
50-
import { AuthGuard } from './_guard';
49+
50+
import {AppPreloader } from './app.preloader';
51+
52+
import { AuthGuard } from './_guard';
5153
import { BackendService, AuthenticationService, PagerService } from './_services';
5254
// import { } from '../_services';
5355
// import { BackendService, AlertService, AuthenticationService, UserService } from './_services';
@@ -82,13 +84,11 @@ type StoreType = {
8284
ErrorPageComponent,
8385
// XLargeDirective,
8486
LoginComponent,
85-
LogoutComponent,
87+
// LogoutComponent,
8688
RootComponent,
8789
DashboardComponent,
8890
ConfirmDialog,
89-
90-
// StarComponent
91-
// AlertComponent
91+
9292
],
9393
/**
9494
* Import Angular's modules.
@@ -100,11 +100,9 @@ type StoreType = {
100100
FormsModule,
101101
HttpModule,
102102
ChartsModule,
103-
NgProgressModule,
104-
RouterModule.forRoot(ROUTES, {preloadingStrategy: PreloadAllModules }),
105-
// NgProgressBrowserXhr,
106-
// RouterModule.forRoot(ROUTES, { useHash: true, preloadingStrategy: PreloadAllModules }),
107-
// ProductModule,
103+
NgProgressModule,
104+
// RouterModule.forRoot(ROUTES, {preloadingStrategy: PreloadAllModules }),
105+
RouterModule.forRoot(ROUTES, {preloadingStrategy: AppPreloader, initialNavigation:false}),
108106
CustomerModule,
109107
RootModule,
110108

@@ -115,6 +113,8 @@ type StoreType = {
115113
*/
116114
providers: [
117115
AuthGuard,
116+
117+
AppPreloader,
118118
BackendService,
119119
AuthenticationService,
120120
PagerService,
@@ -129,13 +129,7 @@ export class AppModule {
129129
public appRef: ApplicationRef,
130130
public appState: AppState,
131131
private progress: NgProgressService
132-
) {
133-
134-
// console.log('AppModule ...')
135-
// let http = <Http>{}
136-
// console.log(this.http)
137-
// this.http.get("http://localhost:5354/token");
138-
}
132+
) { }
139133

140134
public hmrOnInit(store: StoreType) {
141135
if (!store || !store.state) {

src/app/app.preloader.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { PreloadingStrategy, Route } from '@angular/router';
2+
3+
import { Observable } from 'rxjs/Observable';
4+
import 'rxjs/add/observable/of';
5+
6+
export class AppPreloader implements PreloadingStrategy {
7+
preload(route: Route, load: Function): Observable<any> {
8+
return route.data && route.data.preload ? load() : Observable.of(null);
9+
}
10+
}

src/app/app.routes.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { Routes } from '@angular/router';
22
import { AppComponent } from './app.component';
3-
// import { HomeComponent } from './home';
43
import { AboutComponent } from './about';
54
import { ErrorPageComponent } from './errorpage';
65

76
import { CustomerListComponent } from './customer';
8-
import { LogoutComponent } from './logout';
97
import { RootComponent } from './root';
108
import { LoginComponent } from './login';
11-
// import { DataResolver } from './app.resolver';
129
import { AuthGuard } from './_guard';
1310

1411
export const ROUTES: Routes = [
15-
{ path: '', component: RootComponent},
16-
{ path: 'login', redirectTo:''},
12+
{ path: '', component: RootComponent, canActivate: [AuthGuard]},
13+
{ path: 'root', component: RootComponent},
14+
{ path: 'login', component:RootComponent},
1715
{ path: '**', component: ErrorPageComponent, canActivate: [AuthGuard]},
1816
];

src/app/customer/customer-detail.component.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { Router, ActivatedRoute } from '@angular/router';
3-
43
import { Subscription } from 'rxjs/Subscription';
54

65
import { ICustomer } from './customer';

src/app/customer/customer.module.ts

-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import { RouterModule} from '@angular/router';
33
import { ReactiveFormsModule } from '@angular/forms';
44
import {NgProgressModule, NgProgressBrowserXhr, NgProgressService } from 'ngx-progressbar';
55

6-
// Imports for loading & configuring the in-memory web api
7-
// import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
8-
// import { CustomerData } from './customer-data';
9-
106
import { CustomerListComponent } from './customer-list.component';
117
import { CustomerDetailComponent } from './customer-detail.component';
128
import { CustomerDetailGuard, CustomerEditGuard } from './customer-guard.service';

src/app/customer/customer.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ export interface ICustomer {
77
age: number;
88
email: string;
99
isActive: boolean;
10-
1110
}

src/app/dashboard/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export * from './dashboard.component';
2+
// export {DashboardModule} from './dashboard.module';
3+
// export * from './dashboard.routes';

src/app/login/login.component.ts

+8-20
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { Component, ViewEncapsulation, OnInit, DoCheck } from '@angular/core';
2-
import { Router, ActivatedRoute } from '@angular/router';
1+
import {Component, EventEmitter, ViewEncapsulation, OnInit, DoCheck, Output} from '@angular/core';
2+
import {Router, ActivatedRoute} from '@angular/router';
33

44
import { AuthenticationService } from '../_services';
55
import { Observable } from 'rxjs/Observable';
66
import {MaterialModule} from '@angular/material';
77

8+
89
@Component({
910
selector: 'login',
1011
moduleId: module.id.toString(),
11-
// encapsulation: ViewEncapsulation.None,
1212
templateUrl: './login.component.html',
1313
styles: [`
1414
.login-card {
@@ -20,26 +20,23 @@ import {MaterialModule} from '@angular/material';
2020
})
2121

2222
export class LoginComponent implements OnInit {
23+
2324
model: any = {};
2425
loading = false;
2526
returnUrl: string;
2627

2728
constructor(
2829
private route: ActivatedRoute,
2930
private router: Router,
30-
private authenticationService: AuthenticationService) { }
31+
private authenticationService: AuthenticationService) {}
3132

3233
ngOnInit() {
33-
// reset login status
3434
this.authenticationService.logout();
3535

3636
this.model.username = 'hho@test.com';
3737
this.model.password = 'password';
3838

39-
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
40-
// this.returnUrl = this.returnUrl === "/"?"dashboard":this.returnUrl;
41-
42-
console.log(this.returnUrl)
39+
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] ||"/dashboard" ;
4340
}
4441

4542
login() {
@@ -48,22 +45,13 @@ export class LoginComponent implements OnInit {
4845
this.authenticationService.login(this.model)
4946
.subscribe(
5047
data => {
51-
console.log(this.route)
52-
// this.router.navigate(['/']);
53-
this.router.navigate([this.returnUrl]);
48+
console.log('login '+this.returnUrl );
49+
this.router.navigate([this.returnUrl]);
5450
},
5551
error => {
5652
console.log(error);
5753
this.loading = false;
5854
});
5955
}
6056

61-
public ngOnChecks(){
62-
console.log(this.router.navigated )
63-
}
64-
65-
// private handleError(error: Response) {
66-
// console.error(error);
67-
// return Observable.throw(error.json().error || 'Server error');
68-
// }
6957
}

src/app/logout/index.ts

-1
This file was deleted.

src/app/logout/logout.component.ts

-31
This file was deleted.

src/app/root/root.component.css

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@ a.active {
1010
}
1111

1212
.main {
13-
/*padding: 10px;*/
14-
margin: 20px;
13+
margin: 20px;
1514
}
1615

1716
div.avatar {
1817
background-image: url('/assets/img/avatar0.png');
1918
background-size: cover;
2019
}
2120

22-
.profile-card{
23-
/*min-width: 220px;*/
24-
}
25-
2621
.footer {
2722
position: absolute;
2823
right: 0;

src/app/root/root.component.html

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

33
<div *ngIf="!authService.isAuthenticated()">
4-
<login></login>
4+
<login ></login>
55
</div>
66

7-
<div *ngIf="authService.isAuthenticated()">
7+
<div [hidden]="!authService.isAuthenticated()">
88
<md-sidenav-container class="app-container" fullscreen>
99
<md-sidenav dark #sidenav mode="side" opened="true">
1010
<md-card class="profile-card">
@@ -55,9 +55,6 @@
5555

5656
</md-toolbar>
5757
<div class="main">
58-
<div *ngIf="showDashboard">
59-
<dashboard></dashboard>
60-
</div>
6158
<router-outlet></router-outlet>
6259
</div>
6360
<footer class="footer">

0 commit comments

Comments
 (0)