Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:cvazquezlos/BREMS-Library-App into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jherel committed Apr 14, 2017
2 parents 69084bf + aec3177 commit 7d067fd
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ public ResponseEntity<Resource> postResource(@RequestBody Resource resource, Htt
public ResponseEntity<Page<Resource>> 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<Resource> resources = resourceService.findByGenreAndTypeAllIgnoreCase(genre, type, page);
Page<Resource> resources = resourceService.findByGenreAndNameAndTypeAllIgnoreCase(genre, type, name, page);
if (resources.getNumberOfElements() >0) {
return new ResponseEntity<>(resources, HttpStatus.OK);
} else {
Expand Down
5 changes: 4 additions & 1 deletion backend/src/main/java/appSpring/service/ResourceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public List<Resource> findByGenreAndTypeAllIgnoreCase(String genre, String type)
}
}

public Page<Resource> findByGenreAndTypeAllIgnoreCase(String genre, String type, int page) {
public Page<Resource> 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) {
Expand Down
Binary file modified backend/target/classes/appSpring/service/ResourceService.class
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ <h1>Book Reserve System Management</h1>
<div class="col-sm-12 col-md-5 col-lg-3 col-md-offset-2 col-lg-offset-4">
<div id="search-input">
<div class="input-group col-md-12">
<input type="text" class="form-control input-lg" name="mySearch" placeholder="Buscar" />
<span class="input-group-btn"><button (click)="gotoSearch()" class="glyphicon glyphicon-search" type="submit"></button></span>
<input type="text" #mySearch class="form-control input-lg" name="mySearch" placeholder="Buscar" />
<span class="input-group-btn"><button (click)="gotoSearch(mySearch.value)" class="glyphicon glyphicon-search" type="submit"></button></span>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/component/public/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h5 class="authorName">por {{resource.author}}</h5>
</div>
</div>
</ng-template>
<button id="moreSearch" type="button" class="btn btn-lg btn-block btn-view-more">Ver más</button>
<button id="moreSearch" (click)="addSearch()" type="button" class="btn btn-lg btn-block btn-view-more">{{showMore}} {{search2}}</button>
</div>
</ng-template>
</div>
Expand Down
62 changes: 57 additions & 5 deletions frontend/src/app/component/public/home/search/search.component.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
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';

@Component({
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() {
Expand All @@ -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 '
)}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</div>
<div class="modal-footer">
<div>
<button type="submit" class="btn btn-primary btn-lg btn-block" (click)="logIn(username.value, password.value)">Iniciar sesi&oacute;n</button>
<button type="submit" class="btn btn-primary btn-lg btn-block submitButton" (click)="logIn(username.value, password.value)">Iniciar sesi&oacute;n</button>
</div>
<div>
<a [routerLink]="['']"><button id="login_lost_btn" type="button" class="btn btn-link">Olvid&eacute; mi contrase&ntilde;a</button></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div class="modal-footer">
<div>
<button (click)="register(firstName.value, lastName1.value, lastName2.value, userName.value, password.value, dni.value, email.value, phone.value)"
type="submit" class="btn btn-primary btn-lg btn-block">Registrarme</button>
type="submit" class="btn btn-primary btn-lg btn-block submitButton">Registrarme</button>
</div>
<div>
<a href="/"><button id="login_lost_btn" type="button" class="btn btn-link">Olvidé mi contraseña</button></a>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/app/component/public/public-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PublicComponent } from './public.component';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './home/about.component';
import { ContactComponent } from './home/contact.component';
import { SearchComponent } from './home/search/search.component';
import { ProfileComponent } from './user/profile.component';
import { LoginComponent } from './login/login.component';
import { RegisterComponent } from './login/register.component';
Expand All @@ -22,7 +23,8 @@ const publicRoutes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'about', component: AboutComponent },
{ path: 'contact', component: ContactComponent }
{ path: 'contact', component: ContactComponent },
{ path: 'search', component: SearchComponent }
]
}
]
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/app/service/resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ export class ResourceService {
.map(response => response.json().content)
.catch(error => Observable.throw('Server error'));
}

searchResources(name: string, page: number){
return this.http.get(RESOURCES_URL + '?name=' + name + '&page=' + page)
.map(response => response.json().content)
.catch(error => Observable.throw('Server error'));
}
}
5 changes: 4 additions & 1 deletion frontend/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ header .logo h1 {
.btn-view-more {
background-color: rgba(10, 78, 77, 0.9);
color: #ffffff;
display: none;
}

.btn-view-more:hover {
Expand Down Expand Up @@ -615,3 +614,7 @@ input#username {
#register-form input[name="firstName"], #register-form input[name="lastName1"] {
margin-bottom: 0.5vw;
}

.submitButton{
margin-left: 0px !important;
}

0 comments on commit 7d067fd

Please sign in to comment.