) {
- this.form = fb.group({
- email: ['test@angular-university.io', [Validators.required]],
- password: ['test', [Validators.required]]
- });
+ this.form = fb.group({
+ email: ['test@angular-university.io', [Validators.required]],
+ password: ['test', [Validators.required]]
+ });
}
@@ -35,6 +37,20 @@ export class LoginComponent implements OnInit {
login() {
+ const val = this.form.value;
+
+ this.auth.login(val.email, val.password)
+ .pipe(
+ tap(user => {
+ this.store.dispatch(new Login({user}));
+
+ this.router.navigateByUrl('/courses');
+ })
+ )
+ .subscribe(
+ noop,
+ () => alert('Login Failed')
+ );
}
diff --git a/src/app/courses/course/course.component.html b/src/app/courses/course/course.component.html
index 549ab1a..51662d4 100644
--- a/src/app/courses/course/course.component.html
+++ b/src/app/courses/course/course.component.html
@@ -12,12 +12,11 @@ {{course?.description}}
-
+
- #
+ #
{{lesson.seqNo}}
@@ -50,8 +49,7 @@ {{course?.description}}
-
+
diff --git a/src/app/courses/course/course.component.ts b/src/app/courses/course/course.component.ts
index 5d13329..ede611e 100644
--- a/src/app/courses/course/course.component.ts
+++ b/src/app/courses/course/course.component.ts
@@ -1,11 +1,10 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute} from "@angular/router";
-import {MatPaginator, MatSort, MatTableDataSource} from "@angular/material";
+import {MatPaginator, MatTableDataSource} from "@angular/material";
import {Course} from "../model/course";
import {CoursesService} from "../services/courses.service";
import {debounceTime, distinctUntilChanged, startWith, tap, delay} from 'rxjs/operators';
-import {merge} from "rxjs/observable/merge";
-import {fromEvent} from 'rxjs/observable/fromEvent';
+import {merge, fromEvent} from "rxjs";
import {LessonsDataSource} from "../services/lessons.datasource";
@@ -24,8 +23,6 @@ export class CourseComponent implements OnInit, AfterViewInit {
@ViewChild(MatPaginator) paginator: MatPaginator;
- @ViewChild(MatSort) sort: MatSort;
-
constructor(private route: ActivatedRoute,
private coursesService: CoursesService) {
@@ -38,15 +35,13 @@ export class CourseComponent implements OnInit, AfterViewInit {
this.dataSource = new LessonsDataSource(this.coursesService);
- this.dataSource.loadLessons(this.course.id, '', 'asc', 0, 3);
+ this.dataSource.loadLessons(this.course.id, 0, 3);
}
ngAfterViewInit() {
- this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);
-
- merge(this.sort.sortChange, this.paginator.page)
+ this.paginator.page
.pipe(
tap(() => this.loadLessonsPage())
)
@@ -57,8 +52,6 @@ export class CourseComponent implements OnInit, AfterViewInit {
loadLessonsPage() {
this.dataSource.loadLessons(
this.course.id,
- '',
- this.sort.direction,
this.paginator.pageIndex,
this.paginator.pageSize);
}
diff --git a/src/app/courses/home/home.component.ts b/src/app/courses/home/home.component.ts
index c1c63c7..4908cf0 100644
--- a/src/app/courses/home/home.component.ts
+++ b/src/app/courses/home/home.component.ts
@@ -1,8 +1,10 @@
import {Component, OnInit} from '@angular/core';
import {Course} from "../model/course";
-import {Observable} from "rxjs/Observable";
+import {Observable} from "rxjs";
import {map} from "rxjs/operators";
import {CoursesService} from "../services/courses.service";
+import { Store } from '@ngrx/store';
+import { AppState } from '../../reducers';
@Component({
selector: 'home',
@@ -17,7 +19,7 @@ export class HomeComponent implements OnInit {
advancedCourses$: Observable;
- constructor(private coursesService: CoursesService) {
+ constructor(private coursesService: CoursesService, private store: Store) {
}
diff --git a/src/app/courses/services/course.resolver.ts b/src/app/courses/services/course.resolver.ts
index 94460fb..655dcc1 100644
--- a/src/app/courses/services/course.resolver.ts
+++ b/src/app/courses/services/course.resolver.ts
@@ -4,7 +4,7 @@
import {Injectable} from "@angular/core";
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from "@angular/router";
import {Course} from "../model/course";
-import {Observable} from "rxjs/Observable";
+import {Observable} from "rxjs";
import {CoursesService} from "./courses.service";
diff --git a/src/app/courses/services/courses.service.ts b/src/app/courses/services/courses.service.ts
index df3e076..1ad8a76 100644
--- a/src/app/courses/services/courses.service.ts
+++ b/src/app/courses/services/courses.service.ts
@@ -2,7 +2,7 @@
import {Injectable} from "@angular/core";
import {HttpClient, HttpParams} from "@angular/common/http";
-import {Observable} from "rxjs/Observable";
+import {Observable} from "rxjs";
import {Course} from "../model/course";
import {map} from "rxjs/operators";
import {Lesson} from "../model/lesson";
@@ -38,14 +38,14 @@ export class CoursesService {
}
findLessons(
- courseId:number, filter = '', sortOrder = 'asc',
+ courseId:number,
pageNumber = 0, pageSize = 3): Observable {
return this.http.get('/api/lessons', {
params: new HttpParams()
.set('courseId', courseId.toString())
- .set('filter', filter)
- .set('sortOrder', sortOrder)
+ .set('filter', '')
+ .set('sortOrder', 'asc')
.set('pageNumber', pageNumber.toString())
.set('pageSize', pageSize.toString())
}).pipe(
diff --git a/src/app/courses/services/lessons.datasource.ts b/src/app/courses/services/lessons.datasource.ts
index b17790a..74f75ff 100644
--- a/src/app/courses/services/lessons.datasource.ts
+++ b/src/app/courses/services/lessons.datasource.ts
@@ -2,12 +2,10 @@
import {CollectionViewer, DataSource} from "@angular/cdk/collections";
-import {Observable} from "rxjs/Observable";
+import {Observable, BehaviorSubject, of} from "rxjs";
import {Lesson} from "../model/lesson";
import {CoursesService} from "./courses.service";
-import {BehaviorSubject} from "rxjs/BehaviorSubject";
import {catchError, finalize} from "rxjs/operators";
-import {of} from "rxjs/observable/of";
@@ -24,15 +22,12 @@ export class LessonsDataSource implements DataSource {
}
loadLessons(courseId:number,
- filter:string,
- sortDirection:string,
pageIndex:number,
pageSize:number) {
this.loadingSubject.next(true);
- this.coursesService.findLessons(courseId, filter, sortDirection,
- pageIndex, pageSize).pipe(
+ this.coursesService.findLessons(courseId, pageIndex, pageSize).pipe(
catchError(() => of([])),
finalize(() => this.loadingSubject.next(false))
)
diff --git a/src/app/model/user.model.ts b/src/app/model/user.model.ts
index c79ce54..c646cd7 100644
--- a/src/app/model/user.model.ts
+++ b/src/app/model/user.model.ts
@@ -1,4 +1,4 @@
export interface User {
- id: string;
- email: string;
-}
\ No newline at end of file
+ id: string;
+ email: string;
+}
diff --git a/src/app/reducers/index.ts b/src/app/reducers/index.ts
new file mode 100644
index 0000000..8379ff1
--- /dev/null
+++ b/src/app/reducers/index.ts
@@ -0,0 +1,37 @@
+import { ActionReducerMap, MetaReducer } from '@ngrx/store';
+import { environment } from '../../environments/environment';
+import { User } from '../model/user.model';
+import { AuthActionTypes } from '../auth/auth.actions';
+
+interface AuthState {
+ loggedIn: boolean;
+ user: User;
+}
+
+export interface AppState {
+ // auth: AuthState;
+}
+
+// const initialAuthState: AuthState = {
+// loggedIn: false,
+// user: undefined
+// }
+
+// function authReducer(state: AuthState = initialAuthState, action): AuthState {
+// switch (action.type) {
+// case AuthActionTypes.LoginAction:
+// return {
+// loggedIn: true,
+// user: action.payload.user
+// };
+// default:
+// return state;
+// }
+// }
+
+export const reducers: ActionReducerMap = {
+ // auth: authReducer
+};
+
+
+export const metaReducers: MetaReducer[] = !environment.production ? [] : [];
diff --git a/src/tsconfig.spec.json b/src/tsconfig.spec.json
index 63d89ff..18bad40 100644
--- a/src/tsconfig.spec.json
+++ b/src/tsconfig.spec.json
@@ -11,7 +11,8 @@
]
},
"files": [
- "test.ts"
+ "test.ts",
+ "polyfills.ts"
],
"include": [
"**/*.spec.ts",
diff --git a/tslint.json b/tslint.json
index c24dc29..c6773f5 100644
--- a/tslint.json
+++ b/tslint.json
@@ -15,7 +15,6 @@
"forin": true,
"import-blacklist": [
true,
- "rxjs",
"rxjs/Rx"
],
"import-spacing": true,