Skip to content

Commit d896e13

Browse files
author
JLRR2019
committed
Paginación en news, falta en home
1 parent 0ffa4b1 commit d896e13

File tree

4 files changed

+62
-14
lines changed

4 files changed

+62
-14
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,25 @@ <h1 class="fw-bolder fs-5 mb-4">Noticias destacadas</h1>
2626
<section class="py-5">
2727
<div class="container px-5">
2828
<h2 class="fw-bolder fs-5 mb-4">Noticias que te pueden interesar.</h2>
29-
<div id="moreImages" class="row gx-5">
29+
<div id="moreImages" class="row gx-5" *ngIf="ready">
3030
<newsTemplate class="col-lg-4 mb-5" *ngFor="let ng of news" [news]="ng"></newsTemplate>
3131
</div>
3232
<div class="text-end mb-5 mb-xl-0">
33-
<a class="text-decoration-none" href="#!">
34-
<!--will show next-->
35-
<!-- puts the variable created in execution ?page and associates it with next page which is getNumber + 1 (that is, we add 1)-->
36-
<!--in request of we put (page, 3) and page will be equal to 1 for what I just explained above, this is how it is done-->
37-
<a id="moreImagesButton" class="btn btn-secondary button">
38-
<i class="fa fa-eye"></i> Más contenido
39-
</a>
40-
<div id="loader"></div>
33+
<a class="text-decoration-none">
34+
<button class="btn btn-secondary button" (click)="nextpage()" >
35+
<i class="fa fa-eye"></i> Pagina siguiente
36+
</button>
37+
<div id="loader"></div>
4138
</a>
42-
</div>
39+
</div>
40+
<div *ngIf="page > 0" class="text-end mb-5 mb-xl-0">
41+
<a class="text-decoration-none">
42+
<button class="btn btn-secondary button" (click)="prevpage()" >
43+
<i class="fa fa-eye"></i> Pagina anterior
44+
</button>
45+
<div id="loader"></div>
46+
</a>
47+
</div>
4348

4449

4550
</div>

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,47 @@ export class NewsComponent{
1313

1414
//25: int;
1515
//25: int;
16+
page:number = 0;
1617
ready: boolean = false;
1718
news!: News[];
1819
imagesCarousel = ['assets/images/ diabloIV.jgp', 'assets/images/ overwatch2.jpg', 'assets/images/ marioKart9.jgp']
1920

2021
constructor(private router: Router, public newsService: NewsService, activatedRoute: ActivatedRoute){
2122

22-
const id = activatedRoute.snapshot.params['id'];
23-
this.newsService.getNews().subscribe(
24-
(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+
24+
this.newsService.findNewsPage(this.page).subscribe(
25+
(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
2526
(error: any) => console.error(error)
27+
);
2628

29+
}
2730

28-
);
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+
}
42+
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+
);
49+
}
2950

51+
changepage(num:number){
52+
if (num == -1){
53+
this.page -= 1;
54+
}else{
55+
this.page += 1;
56+
}
3057
}
3158

3259
getNewsImage(news: News){

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class ShowNewsComponent{
1414

1515
news!: News;
1616

17+
1718
constructor(public newsService: NewsService, public loginService: LoginService, activatedRoute: ActivatedRoute){
1819

1920
const id = activatedRoute.snapshot.params['id'];
@@ -25,6 +26,7 @@ export class ShowNewsComponent{
2526

2627
}
2728

29+
2830
isAdmin(){
2931
return this.loginService.isAdmin();
3032
}

frontend/src/app/models/news.model.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
export interface NewsPage {
2+
3+
content: News[];
4+
empty: boolean;
5+
first: boolean;
6+
last: boolean;
7+
number: number;
8+
numberOfElements: number;
9+
size: number;
10+
pageable: any[];
11+
sort: boolean [];
12+
}
13+
14+
115
export interface News {
216
id?: number;
317

0 commit comments

Comments
 (0)