Skip to content

Commit 00cae42

Browse files
author
JLRR2019
committed
Paginación aplicada al home
1 parent 41beac7 commit 00cae42

File tree

7 files changed

+73
-34
lines changed

7 files changed

+73
-34
lines changed

backend/gamelink/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spring.mustache.suffix=.html
1010

1111
spring.datasource.url=jdbc:postgresql://localhost:5432/gamelink
1212
spring.datasource.username=postgres
13-
spring.datasource.password=password
13+
spring.datasource.password=Juanluis-123
1414
spring.jpa.hibernate.ddl-auto=create-drop
1515

1616
logging.level.org.springframework.security=DEBUG

backend/gamelink/target/classes/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spring.mustache.suffix=.html
1010

1111
spring.datasource.url=jdbc:postgresql://localhost:5432/gamelink
1212
spring.datasource.username=postgres
13-
spring.datasource.password=password
13+
spring.datasource.password=Juanluis-123
1414
spring.jpa.hibernate.ddl-auto=create-drop
1515

1616
logging.level.org.springframework.security=DEBUG

frontend/package-lock.json

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/app/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { CarouselComponent } from './components/carousel/carousel.component';
2626

2727

2828
@NgModule({
29-
declarations: [AppComponent, LoginComponent, HeadComponent, NewsComponent, NavBarComponent, FooterComponent, NewsTemplateComponent,VideogameCatalogComponent, ShowNewsComponent, HomeComponent, UserProfile,VideogameCardComponent, CarouselComponent],
29+
declarations: [AppComponent, LoginComponent, HeadComponent, NewsComponent, NavBarComponent, FooterComponent, NewsTemplateComponent,VideogameCatalogComponent, ShowNewsComponent, HomeComponent, UserProfile,VideogameCardComponent, VideogameCatalogComponent, CarouselComponent],
3030
imports: [BrowserModule, FormsModule, HttpClientModule, routing, FormsModule,RouterModule, NgbModule],
3131
bootstrap: [AppComponent]
3232
})

frontend/src/app/components/home/home.component.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ <h1 class="display-5 fw-bolder text-white mb-2">Tienda y noticiero de videojuego
5151
<div id="moreImages" class="row gx-5 justify-content-center">
5252
<newsTemplate class="col-lg-4 mb-5" *ngFor="let ng of news" [news]="ng"></newsTemplate>
5353
</div>
54+
<div class="text-end mb-5 mb-xl-0">
55+
<a class="text-decoration-none">
56+
<button class="btn btn-secondary button" (click)="nextpage()" >
57+
<i class="fa fa-eye"></i> Pagina siguiente
58+
</button>
59+
<div id="loader"></div>
60+
</a>
61+
</div>
62+
<div *ngIf="page > 0" class="text-end mb-5 mb-xl-0">
63+
<a class="text-decoration-none">
64+
<button class="btn btn-secondary button" (click)="prevpage()" >
65+
<i class="fa fa-eye"></i> Pagina anterior
66+
</button>
67+
<div id="loader"></div>
68+
</a>
69+
</div>
5470

5571
</div>
5672
</section>

frontend/src/app/components/home/home.component.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,50 @@ import { NewsService } from 'src/app/services/news.service';
1212

1313

1414
export class HomeComponent{
15+
16+
page:number = 0;
17+
ready: boolean = false;
1518
news!: News[];
1619

1720

1821
constructor( public newsService: NewsService, activatedRoute: ActivatedRoute){
1922

20-
const id = activatedRoute.snapshot.params['id'];
21-
this.newsService.getNews().subscribe(
22-
(news) => this.news = news as News[], //casting in ts, es mejor hacerlo en el servicio (as Observable<News>), pero al dar error, hacemos el cast en el component
23-
(error: any) => console.error(error)
23+
//const id = activatedRoute.snapshot.params['id'];
2424

25+
this.newsService.findNewsPage(this.page).subscribe(
26+
(news) => {var x = news['content'] ;this.news = x as News[];}, //casting in ts, es mejor hacerlo en el servicio (as Observable<News>), pero al dar error, hacemos el cast en el component
27+
(error: any) => console.error(error)
28+
);
29+
}
2530

26-
);
31+
ngOnInit(){
32+
this.ready = true;
33+
}
34+
35+
nextpage(){
36+
this.changepage(1)
37+
this.newsService.findNewsPage(this.page).subscribe(
38+
(news) => {var x = news['content'] ;this.news = x as News[];},
39+
(error: any) => console.error(error)
40+
);
41+
}
2742

43+
prevpage(){
44+
this.changepage(-1)
45+
this.newsService.findNewsPage(this.page).subscribe(
46+
(news) => {var x = news['content'] ;this.news = x as News[];},
47+
(error: any) => console.error(error)
48+
);
2849
}
2950

51+
changepage(num:number){
52+
if (num == -1){
53+
this.page -= 1;
54+
}else{
55+
this.page += 1;
56+
}
57+
}
58+
59+
60+
3061
}

frontend/src/app/components/news/news.component.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,5 @@ export class NewsComponent{
6464
}
6565
}
6666

67-
//esto es una prueba
68-
nextPage(){
69-
if(this.news){
70-
return this.router.navigate(['/news/1'])
71-
} else {
72-
return undefined;
73-
}
74-
}
7567

7668
}

0 commit comments

Comments
 (0)