From 322940742b4dca168de6dfed0d1ebf5926dab528 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 22 May 2016 10:43:06 +0200 Subject: Add pagination support to the client --- .../components/list/video-miniature.component.html | 2 +- .../components/list/video-miniature.component.scss | 6 ++---- .../components/list/videos-list.component.html | 14 ++++++++++--- .../components/list/videos-list.component.scss | 10 +++++++--- .../components/list/videos-list.component.ts | 23 ++++++++++++++++------ 5 files changed, 38 insertions(+), 17 deletions(-) (limited to 'client/angular/videos/components/list') diff --git a/client/angular/videos/components/list/video-miniature.component.html b/client/angular/videos/components/list/video-miniature.component.html index b88a19d5e..244254b5a 100644 --- a/client/angular/videos/components/list/video-miniature.component.html +++ b/client/angular/videos/components/list/video-miniature.component.html @@ -1,4 +1,4 @@ -
+ - - +
+
There is no video.
+ + + +
+ + diff --git a/client/angular/videos/components/list/videos-list.component.scss b/client/angular/videos/components/list/videos-list.component.scss index ac930978c..05c38b833 100644 --- a/client/angular/videos/components/list/videos-list.component.scss +++ b/client/angular/videos/components/list/videos-list.component.scss @@ -1,8 +1,12 @@ -.loading { - display: inline-block; - margin-top: 100px; +.videos-miniatures { + min-height: 600px; } my-videos-miniature { display: inline-block; } + +pagination { + display: block; + text-align: center; +} diff --git a/client/angular/videos/components/list/videos-list.component.ts b/client/angular/videos/components/list/videos-list.component.ts index 6fc0c1f04..341afdaa6 100644 --- a/client/angular/videos/components/list/videos-list.component.ts +++ b/client/angular/videos/components/list/videos-list.component.ts @@ -1,7 +1,10 @@ import { Component, OnInit } from '@angular/core'; import { ROUTER_DIRECTIVES, RouteParams } from '@angular/router-deprecated'; +import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination'; + import { AuthService } from '../../../users/services/auth.service'; +import { Pagination } from '../../pagination'; import { User } from '../../../users/models/user'; import { VideosService } from '../../videos.service'; import { Video } from '../../video'; @@ -11,21 +14,26 @@ import { VideoMiniatureComponent } from './video-miniature.component'; selector: 'my-videos-list', styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ], templateUrl: 'app/angular/videos/components/list/videos-list.component.html', - directives: [ ROUTER_DIRECTIVES, VideoMiniatureComponent ] + directives: [ ROUTER_DIRECTIVES, PAGINATION_DIRECTIVES, VideoMiniatureComponent ] }) export class VideosListComponent implements OnInit { user: User = null; videos: Video[] = []; + pagination: Pagination = { + currentPage: 1, + itemsPerPage: 9, + total: 0 + } private search: string; constructor( private _authService: AuthService, private _videosService: VideosService, - routeParams: RouteParams + private _routeParams: RouteParams ) { - this.search = routeParams.get('search'); + this.search = this._routeParams.get('search'); } ngOnInit() { @@ -40,13 +48,16 @@ export class VideosListComponent implements OnInit { let observable = null; if (this.search !== null) { - observable = this._videosService.searchVideos(this.search); + observable = this._videosService.searchVideos(this.search, this.pagination); } else { - observable = this._videosService.getVideos(); + observable = this._videosService.getVideos(this.pagination); } observable.subscribe( - videos => this.videos = videos, + ({ videos, totalVideos }) => { + this.videos = videos; + this.pagination.total = totalVideos; + }, error => alert(error) ); } -- cgit v1.2.3