- Filter by Title:
+ Filter by Description:
diff --git a/store-front/src/app/components/book-list/book-list.component.ts b/store-front/src/app/components/book-list/book-list.component.ts
index 9a6e518..4857081 100644
--- a/store-front/src/app/components/book-list/book-list.component.ts
+++ b/store-front/src/app/components/book-list/book-list.component.ts
@@ -1,7 +1,7 @@
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import {Book} from "../../models/book";
import {BookService} from "../../services/book.service";
-import {Router} from "@angular/router";
+import {Params, ActivatedRoute,Router} from "@angular/router";
import {Http} from "@angular/http";
import {AppConst} from '../../constants/app-const';
@@ -19,16 +19,8 @@ export class BookListComponent implements OnInit {
private bookList: Book[];
private serverPath = AppConst.serverPath;
- constructor(private bookService:BookService, private router: Router, private http: Http) {
- this.bookService.getBookList().subscribe(
- res => {
- console.log(res.json());
- this.bookList=res.json();
- },
- err => {
- console.log(err);
- }
- );
+ constructor(private bookService:BookService, private router: Router, private http: Http, private route:ActivatedRoute) {
+
}
onSelect(book:Book) {
@@ -38,6 +30,24 @@ export class BookListComponent implements OnInit {
ngOnInit() {
+
+ this.route.queryParams.subscribe(params => {
+ if (params['bookList']){
+ console.log("filtered book list");
+ this.bookList = JSON.parse(params['bookList']);
+ } else {
+ this.bookService.getBookList().subscribe(
+ res => {
+ console.log(res.json());
+ this.bookList=res.json();
+ },
+ err => {
+ console.log(err);
+ }
+ );
+ }
+
+ });
}
}
diff --git a/store-front/src/app/components/book-list/data-filter.pipe.ts b/store-front/src/app/components/book-list/data-filter.pipe.ts
index 151bb45..2bf7c25 100644
--- a/store-front/src/app/components/book-list/data-filter.pipe.ts
+++ b/store-front/src/app/components/book-list/data-filter.pipe.ts
@@ -8,7 +8,7 @@ export class DataFilterPipe implements PipeTransform {
transform(array: any[], query: string): any {
if (query) {
- return _.filter(array, row=>row.title.indexOf(query) > -1);
+ return _.filter(array, row=>row.description.indexOf(query) > -1);
}
return array;
}
diff --git a/store-front/src/app/components/nav-bar/nav-bar.component.html b/store-front/src/app/components/nav-bar/nav-bar.component.html
index 381fb74..3962992 100644
--- a/store-front/src/app/components/nav-bar/nav-bar.component.html
+++ b/store-front/src/app/components/nav-bar/nav-bar.component.html
@@ -9,9 +9,9 @@
diff --git a/store-front/src/app/components/nav-bar/nav-bar.component.ts b/store-front/src/app/components/nav-bar/nav-bar.component.ts
index e797bec..ed9740a 100644
--- a/store-front/src/app/components/nav-bar/nav-bar.component.ts
+++ b/store-front/src/app/components/nav-bar/nav-bar.component.ts
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import {LoginService} from "../../services/login.service";
-import {Router} from "@angular/router";
+import {Router, NavigationExtras} from "@angular/router";
+import {BookService} from "../../services/book.service";
+import {Book} from "../../models/book";
@Component({
selector: 'app-nav-bar',
@@ -9,8 +11,14 @@ import {Router} from "@angular/router";
})
export class NavBarComponent implements OnInit {
private loggedIn = false;
+ private keyword:string;
+ private bookList:Book[] = [];
- constructor(private loginService: LoginService, private router: Router) { }
+ constructor(
+ private loginService: LoginService,
+ private router: Router,
+ private bookService:BookService
+ ) { }
ngOnInit() {
this.loginService.checkSession().subscribe(
@@ -23,6 +31,25 @@ export class NavBarComponent implements OnInit {
);
}
+ onSearchByTitle(){
+ this.bookService.searchBook(this.keyword).subscribe(
+ res => {
+ this.bookList=res.json();
+
+ let navigationExtras: NavigationExtras = {
+ queryParams: {
+ "bookList": JSON.stringify(this.bookList)
+ }
+ };
+
+ this.router.navigate(['/bookList'], navigationExtras);
+ },
+ error => {
+ console.log(error);
+ }
+ );
+ }
+
logout(){
this.loginService.logout().subscribe(
res => {
diff --git a/store-front/src/app/services/book.service.ts b/store-front/src/app/services/book.service.ts
index afb2f6c..b414970 100644
--- a/store-front/src/app/services/book.service.ts
+++ b/store-front/src/app/services/book.service.ts
@@ -24,4 +24,12 @@ export class BookService {
return this.http.get(url, {headers : tokenHeader});
}
+ searchBook(keyword:string) {
+ let url = AppConst.serverPath+"/book/searchBook";
+ let tokenHeader = new Headers ({
+ 'x-auth-token' : localStorage.getItem("xAuthToken")
+ });
+ return this.http.post(url, keyword, {headers : tokenHeader});
+ }
+
}