From b248cef15fc81f9fca2142db982ef1b3fde8e676 Mon Sep 17 00:00:00 2001 From: Blay93 Date: Fri, 14 Apr 2017 14:55:28 +0200 Subject: [PATCH] Completed search bar 2 and fixed some errors --- .../ResourceRestController.java | 3 +- .../appSpring/service/ResourceService.java | 5 +- .../appSpring/service/ResourceService.class | Bin 7157 -> 7381 bytes .../public/header/header.component.html | 4 +- .../public/header/header.component.ts | 4 +- .../public/home/search/search.component.html | 2 +- .../public/home/search/search.component.ts | 62 ++++++++++++++++-- .../public/login/login.component.html | 2 +- .../public/login/register.component.html | 2 +- .../component/public/public-routing.module.ts | 4 +- frontend/src/app/service/resource.service.ts | 6 ++ frontend/src/styles.css | 5 +- 12 files changed, 83 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/appSpring/restController/ResourceRestController.java b/backend/src/main/java/appSpring/restController/ResourceRestController.java index cc4e527..a4626a0 100644 --- a/backend/src/main/java/appSpring/restController/ResourceRestController.java +++ b/backend/src/main/java/appSpring/restController/ResourceRestController.java @@ -69,11 +69,12 @@ public ResponseEntity postResource(@RequestBody Resource resource, Htt public ResponseEntity> getAllResource(HttpSession session, @RequestParam(value = "genre", required = false) String genre, @RequestParam(value = "type", required = false) String type, + @RequestParam(value = "name", required = false) String name, @RequestParam (required=false) Integer page) { session.setMaxInactiveInterval(-1); if(page==null) page=0; - Page resources = resourceService.findByGenreAndTypeAllIgnoreCase(genre, type, page); + Page resources = resourceService.findByGenreAndNameAndTypeAllIgnoreCase(genre, type, name, page); if (resources.getNumberOfElements() >0) { return new ResponseEntity<>(resources, HttpStatus.OK); } else { diff --git a/backend/src/main/java/appSpring/service/ResourceService.java b/backend/src/main/java/appSpring/service/ResourceService.java index abe6ed4..0415d9c 100644 --- a/backend/src/main/java/appSpring/service/ResourceService.java +++ b/backend/src/main/java/appSpring/service/ResourceService.java @@ -86,7 +86,10 @@ public List findByGenreAndTypeAllIgnoreCase(String genre, String type) } } - public Page findByGenreAndTypeAllIgnoreCase(String genre, String type, int page) { + public Page findByGenreAndNameAndTypeAllIgnoreCase(String genre, String type, String name, int page) { + if (name != null){ + return repository.findByTitleLikeIgnoreCaseOrGenreNameLikeIgnoreCaseOrAuthorLikeIgnoreCaseOrEditorialLikeIgnoreCase("%" + name + "%", "%" + name + "%", "%" + name + "%", "%" + name + "%", new PageRequest(page,3)); + } if (genre != null && type == null) { return repository.findByGenreNameLikeIgnoreCase(genre, new PageRequest(page,3)); } else if (genre != null && type != null) { diff --git a/backend/target/classes/appSpring/service/ResourceService.class b/backend/target/classes/appSpring/service/ResourceService.class index d02f238fe3a7d369e4cd7f125ecd52cd87c751b3..f4e3f68a0a3c2658ad0c339553e3322c795492bb 100644 GIT binary patch delta 1606 zcmbtVYfw~W7=F%P&e_XB*j-`Sz;VNY#HmZqx;1!ixRM6W*4E%3M;zbFVjpvo#|II+WQ?~Qu^7wOVL zz*cr4)xi#%?b>_9S|D^?rTN2J=?MvNw)l4VJOQ8D?71x(_N&e19sWS05;h?$K*+Tq zh^P!JIs~MX|59rmSM8M1i5NSZy4Dm#myCO`i<#1L^b+E%L@r&n8{OQgM}To66L3x@R9&SNlU2Nieq?H!Ycwitb2)Pi;UOsx&X-^sb~vDV*>Om^EXKt z5g;$*uJi{K3lfO(WmLu++(A@2{gG&dtHxzaXsWi>Mt@jSos=<27k4IYsWpK&`GuVp zaNRshj%(}8ID>a2ynS^Ku}D;DlkqOzV|g~Wb4q}`9_lM51sC*+tXHVI5Of+@ z6vsJN_`hNDbx16BC-3+bnbuGy>RXRAT1$vCU=s}3i~t%C#T__+t#|-;VhBErVjE6j zJ7#Fmze5vjguWFLtrua3gLW>JV-*BVY9UFdNe4*MYf>Tl3Mj!4oLGySV5C49^HM7T zOfdY7Kz2bEg*b?Qrn;Q2`*qkjLN=XNq(uwaN~H$aQJ2$tn98GXo4z2%Y}Yt5AJSnl zI0y?uY$U^JT@Lp=xL*Sw`7by^;3x;j7a|Yhamx7wRbU|JA#GqP3tgrp&glU!uthD%-_=>_(pZFTzXgA-7 zZ;4C;1?|Ohl8h8uB^FnarWEV(J$|5(sHS8;l4PQwcKn2&NyqukhyD`QNf_3i#AW&? f5G4o_ju{q|!~8hwpk%-BN_6;D8!?gU_zn06EAxv} delta 1418 zcmZWpX;52L6#nkZ^0GV#Btn`LN~A!EL18-8N^qEQDKni>%Fq#{i<;U@2qYmT4^Gv_w|>*oY5ctt)BaUnW8gq?mPFK?|kRn^WFC@ z)c(EJa^~X6QvlZBw+TzgD&11aCro90jk3y6#}HoJHLxyTlT))Ih8+s5=w>ifu3ztM zvBCva!A z#=Qy#v5$Lg9^-yt-p4oC4zmaOpSEQyM(~J?hZ*uZ0=FPu;l!gXB1q~?ltZVz{Bu8e{y9AU79g6j3#5?zrV zHP{qT+XXx;PI8iAl{g8XG+kcmZ8765oRabO(g`IKYA~wc9lXm2^F0mkGgt*#PecuR z{2mKF#H@^u7#xe8Hql5`8f-8?X>(#+a$L9~F>&;d6`a8*{P+Boj!#Mabnq%v&{!a*A!P%3`Yozh1++^p_xe^@N;*n^+1(^pcQQLYiEuCD}`oYpD#ip+g?6 z6)@Af2_|et5w@TVTTz4C(SSS9h&vI$HfsMaLwNwa)N z5_ee*3Q>papr`bL1*?+)2Iz{sZpzw;e%|PIx^_uuouGiE^<&Xk+DYCpA8{DO8TL%$A-`b;qirt3G#;D6llG@GIF!Njexomoml(znoWXdTOFxA-{IW~V;LS0Z z#rs&R79i_{i{zd5n~q^dP}$!jo|J%`nCHsi1E0&3#c2sHW7;okptA%Lm~&JtZ9ki) z=E~8H1kNuAca3NjDoN5q!u3+LkAzF&S{iIUc9D3y(T)Mck)o_Ugc`(t?9+tY0)BN- zUg}GHMYMEIT)@}b+=uZE>8K~ty(l5eK-4jOOO}zyZ^U=_o-T1C75jlK6Or2SBYq;E tkk$*`Mbyg}(Vp>t=x=J2!DJlOFFHrW_Pm3N{VY0>@C)UF*cpBW{soNoL(BjG diff --git a/frontend/src/app/component/public/header/header.component.html b/frontend/src/app/component/public/header/header.component.html index d845ee2..872a62d 100644 --- a/frontend/src/app/component/public/header/header.component.html +++ b/frontend/src/app/component/public/header/header.component.html @@ -9,8 +9,8 @@

Book Reserve System Management

- - + +
diff --git a/frontend/src/app/component/public/header/header.component.ts b/frontend/src/app/component/public/header/header.component.ts index 6a7021f..5d89ebc 100644 --- a/frontend/src/app/component/public/header/header.component.ts +++ b/frontend/src/app/component/public/header/header.component.ts @@ -21,8 +21,8 @@ export class HeaderComponent { this.isAdmin = false; } - gotoSearch() { - this.router.navigate(['/search']); + gotoSearch(search) { + this.router.navigate(['/search'], { queryParams: { name: search } }); this.update('index'); } diff --git a/frontend/src/app/component/public/home/search/search.component.html b/frontend/src/app/component/public/home/search/search.component.html index 85b8b83..f0e7d74 100644 --- a/frontend/src/app/component/public/home/search/search.component.html +++ b/frontend/src/app/component/public/home/search/search.component.html @@ -62,7 +62,7 @@
por {{resource.author}}
- + diff --git a/frontend/src/app/component/public/home/search/search.component.ts b/frontend/src/app/component/public/home/search/search.component.ts index c09dd49..9f8bed9 100644 --- a/frontend/src/app/component/public/home/search/search.component.ts +++ b/frontend/src/app/component/public/home/search/search.component.ts @@ -1,11 +1,13 @@ -import { Component, OnInit } from '@angular/core'; -import { Router } from '@angular/router'; +import { Component, OnInit, DoCheck } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; import { BOOKS_IMG_URL } from '../../../../util'; import { Genre } from '../../../../model/genre.model'; import { Resource } from '../../../../model/resource.model'; +import { ResourceService } from '../../../../service/resource.service'; + import { GenreService } from '../../../../service/genre.service'; import { SessionService } from '../../../../service/session.service'; @@ -13,22 +15,30 @@ import { SessionService } from '../../../../service/session.service'; templateUrl: 'search.component.html' }) -export class SearchComponent implements OnInit { +export class SearchComponent implements OnInit, DoCheck { genres: Genre[]; genresPage: number; + resourcesPage: number; + search: string; + search2: string; + showMore: string; img_url: string; isLogged: boolean; resources: Resource[]; visible: boolean; + activeSearch: boolean; - constructor(private router: Router, private genreService: GenreService, private sessionService: SessionService) { + constructor(private router: Router, private route: ActivatedRoute, private genreService: GenreService, private resourceService: ResourceService, private sessionService: SessionService) { this.genres = []; this.genresPage = 0; + this.resourcesPage = 0; this.img_url = BOOKS_IMG_URL; this.isLogged = false; this.resources = []; - this.visible = false; + this.visible = true; + this.showMore = 'No hay resultados para '; + this.activeSearch = true; } ngOnInit() { @@ -37,13 +47,55 @@ export class SearchComponent implements OnInit { error => console.log(error) ); this.isLogged = this.sessionService.checkCredentials(); + this.route.queryParams.subscribe( + params => { + this.searchResourcesByName(params['name']); + this.search = (params['name']); + if (params['name']!=null) this.showMore = 'Ver más resultados para '; + }, + error => console.log(error) + ) + this.search2 = this.search; + } + + ngDoCheck(){ + if(this.search != this.search2){ + this.search2 = this.search; + this.searchResourcesByName(this.search); + } } searchResourcesByGenre(id: number) { + this.activeSearch = false; + this.showMore = 'Ver más resultados'; + this.search = ''; + this.search2 = ''; this.visible = true; this.genreService.getGenre(id).subscribe( genre => this.resources = genre, error => console.log(error) ); } + + searchResourcesByName(name: string){ + this.activeSearch = true; + this.visible = true; + this.resourcesPage = 0; + this.resourceService.searchResources(name,this.resourcesPage).subscribe( + search => this.resources = search, + error => { + console.log(error); + this.resources = []; + this.showMore = 'No hay resultados para '; + }) + } + + addSearch(){ + if (this.resources == null || this.activeSearch == false) return; + this.resourcesPage ++; + this.resourceService.searchResources(this.search, this.resourcesPage).subscribe( + search => this.resources = this.resources.concat(search), + error => this.showMore = 'No hay más resultados para ' + )} + } diff --git a/frontend/src/app/component/public/login/login.component.html b/frontend/src/app/component/public/login/login.component.html index 262ff21..2af92ee 100644 --- a/frontend/src/app/component/public/login/login.component.html +++ b/frontend/src/app/component/public/login/login.component.html @@ -27,7 +27,7 @@