From 0629423ce335137ce77d1ee8fe30fc0eee36d83b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Jul 2016 17:15:14 +0200 Subject: Client: Update to Angular RC4 --- client/src/app/videos/index.ts | 2 + client/src/app/videos/shared/pagination.model.ts | 2 +- .../videos/video-list/video-list.component.html | 10 ++-- .../videos/video-list/video-list.component.scss | 2 +- .../app/videos/video-list/video-list.component.ts | 64 +++++++++++++--------- .../video-list/video-miniature.component.html | 14 +++-- .../video-list/video-miniature.component.scss | 45 +++++++++------ .../videos/video-watch/video-watch.component.ts | 38 +++++++------ client/src/app/videos/videos.component.ts | 10 ++++ client/src/app/videos/videos.routes.ts | 27 +++++++++ 10 files changed, 139 insertions(+), 75 deletions(-) create mode 100644 client/src/app/videos/videos.component.ts create mode 100644 client/src/app/videos/videos.routes.ts (limited to 'client/src/app/videos') diff --git a/client/src/app/videos/index.ts b/client/src/app/videos/index.ts index 9a92fa57a..a9088a907 100644 --- a/client/src/app/videos/index.ts +++ b/client/src/app/videos/index.ts @@ -2,3 +2,5 @@ export * from './shared'; export * from './video-add'; export * from './video-list'; export * from './video-watch'; +export * from './videos.component'; +export * from './videos.routes'; diff --git a/client/src/app/videos/shared/pagination.model.ts b/client/src/app/videos/shared/pagination.model.ts index 06f7a7875..eda44ebfb 100644 --- a/client/src/app/videos/shared/pagination.model.ts +++ b/client/src/app/videos/shared/pagination.model.ts @@ -1,5 +1,5 @@ export interface Pagination { currentPage: number; itemsPerPage: number; - total: number; + totalItems: number; } diff --git a/client/src/app/videos/video-list/video-list.component.html b/client/src/app/videos/video-list/video-list.component.html index 52abc3dc2..0e17ef2c4 100644 --- a/client/src/app/videos/video-list/video-list.component.html +++ b/client/src/app/videos/video-list/video-list.component.html @@ -1,8 +1,8 @@
- {{ pagination.total }} videos + {{ pagination.totalItems }} videos - +
@@ -14,7 +14,7 @@ - diff --git a/client/src/app/videos/video-list/video-list.component.scss b/client/src/app/videos/video-list/video-list.component.scss index dc2c065d8..1f491a6c3 100644 --- a/client/src/app/videos/video-list/video-list.component.scss +++ b/client/src/app/videos/video-list/video-list.component.scss @@ -24,7 +24,7 @@ } .videos-miniatures { - min-height: 600px; + min-height: 650px; my-video-miniature { transition: all 0.5s ease; diff --git a/client/src/app/videos/video-list/video-list.component.ts b/client/src/app/videos/video-list/video-list.component.ts index 46263eb65..0ebf0ef5c 100644 --- a/client/src/app/videos/video-list/video-list.component.ts +++ b/client/src/app/videos/video-list/video-list.component.ts @@ -1,5 +1,7 @@ -import { Component, OnInit } from '@angular/core'; -import { Router, ROUTER_DIRECTIVES, RouteSegment } from '@angular/router'; +import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; +import { AsyncPipe } from '@angular/common'; +import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router'; +import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination'; @@ -18,52 +20,64 @@ import { SearchService } from '../../shared'; @Component({ selector: 'my-videos-list', styles: [ require('./video-list.component.scss') ], + pipes: [ AsyncPipe ], template: require('./video-list.component.html'), directives: [ LoaderComponent, PAGINATION_DIRECTIVES, ROUTER_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent ] }) -export class VideoListComponent implements OnInit { - loading = false; +export class VideoListComponent implements OnInit, OnDestroy { + loading: BehaviorSubject = new BehaviorSubject(false); pagination: Pagination = { currentPage: 1, itemsPerPage: 9, - total: 0 + totalItems: null }; sort: SortField; user: User = null; videos: Video[] = []; private search: Search; + private sub: any; constructor( private authService: AuthService, + private changeDetector: ChangeDetectorRef, private router: Router, - private routeSegment: RouteSegment, + private route: ActivatedRoute, private videoService: VideoService, - private searchService: SearchService // Temporary + private searchService: SearchService ) {} ngOnInit() { - if (this.authService.isLoggedIn()) { - this.user = User.load(); - } + this.sub = this.route.params.subscribe(routeParams => { + if (this.authService.isLoggedIn()) { + this.user = User.load(); + } - this.search = { - value: this.routeSegment.getParam('search'), - field: this.routeSegment.getParam('field') - }; + this.search = { + value: routeParams['search'], + field: routeParams['field'] + }; - // Temporary - this.searchChanged(this.search); + // Update the search service component + this.searchService.searchChanged.next(this.search); - this.sort = this.routeSegment.getParam('sort') || '-createdDate'; + this.sort = routeParams['sort'] || '-createdDate'; + + this.getVideos(); + }); + } - this.getVideos(); + ngOnDestroy() { + this.sub.unsubscribe(); } - getVideos() { - this.loading = true; + getVideos(detectChanges = true) { + this.loading.next(true); this.videos = []; + this.pagination.currentPage = 1; + + this.changeDetector.detectChanges(); let observable = null; @@ -76,9 +90,9 @@ export class VideoListComponent implements OnInit { observable.subscribe( ({ videos, totalVideos }) => { this.videos = videos; - this.pagination.total = totalVideos; + this.pagination.totalItems = totalVideos; - this.loading = false; + this.loading.next(false); }, error => alert(error) ); @@ -89,7 +103,7 @@ export class VideoListComponent implements OnInit { } onRemoved(video: Video) { - this.getVideos(); + this.getVideos(false); } onSort(sort: SortField) { @@ -106,8 +120,4 @@ export class VideoListComponent implements OnInit { this.router.navigate(['/videos/list', params]); } - - searchChanged(search: Search) { - this.searchService.searchChanged.next(search); - } } diff --git a/client/src/app/videos/video-list/video-miniature.component.html b/client/src/app/videos/video-list/video-miniature.component.html index 92e19bb8b..3cf28620e 100644 --- a/client/src/app/videos/video-list/video-miniature.component.html +++ b/client/src/app/videos/video-list/video-miniature.component.html @@ -13,14 +13,16 @@
- {{ video.name }} + {{ video.name }} - - {{ tag }} - +
+ + {{ tag }} + +
- by {{ video.by }} - on {{ video.createdDate | date:'short' }} + {{ video.by }} + {{ video.createdDate | date:'short' }}
diff --git a/client/src/app/videos/video-list/video-miniature.component.scss b/client/src/app/videos/video-list/video-miniature.component.scss index 40d37b83f..3a096dabd 100644 --- a/client/src/app/videos/video-list/video-miniature.component.scss +++ b/client/src/app/videos/video-list/video-miniature.component.scss @@ -1,3 +1,5 @@ +@import "../../../sass/pre-customizations.scss"; + .video-miniature { margin-top: 30px; display: inline-block; @@ -34,34 +36,40 @@ } .video-miniature-informations { - margin-left: 3px; width: 200px; .video-miniature-name-tags { display: block; .video-miniature-name { + height: 23px; + display: block; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; font-weight: bold; + transition: color 0.2s; + font-size: 15px; &:hover { text-decoration: none; } - - &::after { - content: '\002022'; - margin-left: 3px; - } } - .video-miniature-tag { - font-size: 12px; - cursor: pointer; - transition: opacity 0.5s; - position: relative; - top: -2px; + .video-miniature-tags { + // Fix for chrome when tags a long + width: 201px; - &:hover { - opacity: 0.9; + .video-miniature-tag { + font-size: 13px; + cursor: pointer; + position: relative; + top: -2px; + + .label { + line-height: $line-height-base; + transition: background-color 0.2s; + } } } } @@ -69,16 +77,17 @@ .video-miniature-author, .video-miniature-created-date { display: block; margin-left: 1px; - font-size: 11px; - color: rgb(54, 118, 173); + font-size: 12px; + color: #337ab7; + opacity: 0.9; } .video-miniature-author { - transition: opacity 0.5s; + transition: color 0.2s; &:hover { + color: #23527c; text-decoration: none; - opacity: 0.9; } } } diff --git a/client/src/app/videos/video-watch/video-watch.component.ts b/client/src/app/videos/video-watch/video-watch.component.ts index 99188bfb3..09255de5d 100644 --- a/client/src/app/videos/video-watch/video-watch.component.ts +++ b/client/src/app/videos/video-watch/video-watch.component.ts @@ -1,5 +1,5 @@ -import { Component, ElementRef, OnInit } from '@angular/core'; -import { CanDeactivate, RouteSegment } from '@angular/router'; +import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; @@ -15,7 +15,7 @@ import { WebTorrentService } from './webtorrent.service'; pipes: [ BytesPipe ] }) -export class VideoWatchComponent implements OnInit, CanDeactivate { +export class VideoWatchComponent implements OnInit, OnDestroy { private static LOADTIME_TOO_LONG: number = 30000; downloadSpeed: number; @@ -26,11 +26,12 @@ export class VideoWatchComponent implements OnInit, CanDeactivate { video: Video; private errorTimer: NodeJS.Timer; + private sub: any; private torrentInfosInterval: NodeJS.Timer; constructor( private elementRef: ElementRef, - private routeSegment: RouteSegment, + private route: ActivatedRoute, private videoService: VideoService, private webTorrentService: WebTorrentService ) {} @@ -73,22 +74,25 @@ export class VideoWatchComponent implements OnInit, CanDeactivate { }); } - ngOnInit() { - let id = this.routeSegment.getParam('id'); - this.videoService.getVideo(id).subscribe( - video => { - this.video = video; - this.loadVideo(); - }, - error => alert(error) - ); - } - - routerCanDeactivate() { + ngOnDestroy() { console.log('Removing video from webtorrent.'); clearInterval(this.torrentInfosInterval); this.webTorrentService.remove(this.video.magnetUri); - return Promise.resolve(true); + + this.sub.unsubscribe(); + } + + ngOnInit() { + this.sub = this.route.params.subscribe(routeParams => { + let id = routeParams['id']; + this.videoService.getVideo(id).subscribe( + video => { + this.video = video; + this.loadVideo(); + }, + error => alert(error) + ); + }); } private loadTooLong() { diff --git a/client/src/app/videos/videos.component.ts b/client/src/app/videos/videos.component.ts new file mode 100644 index 000000000..76252afbb --- /dev/null +++ b/client/src/app/videos/videos.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; +import { ROUTER_DIRECTIVES } from '@angular/router'; + +@Component({ + template: '', + directives: [ ROUTER_DIRECTIVES ] +}) + +export class VideosComponent { +} diff --git a/client/src/app/videos/videos.routes.ts b/client/src/app/videos/videos.routes.ts new file mode 100644 index 000000000..1f088b376 --- /dev/null +++ b/client/src/app/videos/videos.routes.ts @@ -0,0 +1,27 @@ +import { RouterConfig } from '@angular/router'; + +import { VideoAddComponent } from './video-add'; +import { VideoListComponent } from './video-list'; +import { VideosComponent } from './videos.component'; +import { VideoWatchComponent } from './video-watch'; + +export const VideosRoutes: RouterConfig = [ + { + path: 'videos', + component: VideosComponent, + children: [ + { + path: 'list', + component: VideoListComponent + }, + { + path: 'add', + component: VideoAddComponent + }, + { + path: 'watch/:id', + component: VideoWatchComponent + } + ] + } +]; -- cgit v1.2.3