aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/app/videos
diff options
context:
space:
mode:
Diffstat (limited to 'client/app/videos')
-rw-r--r--client/app/videos/shared/video.model.ts6
-rw-r--r--client/app/videos/shared/video.service.ts18
-rw-r--r--client/app/videos/video-add/video-add.component.ts2
-rw-r--r--client/app/videos/video-list/video-list.component.ts26
-rw-r--r--client/app/videos/video-list/video-miniature.component.ts8
-rw-r--r--client/app/videos/video-list/video-sort.component.ts2
-rw-r--r--client/app/videos/video-watch/video-watch.component.ts20
7 files changed, 41 insertions, 41 deletions
diff --git a/client/app/videos/shared/video.model.ts b/client/app/videos/shared/video.model.ts
index eec537c9e..2b018ad86 100644
--- a/client/app/videos/shared/video.model.ts
+++ b/client/app/videos/shared/video.model.ts
@@ -11,7 +11,7 @@ export class Video {
11 by: string; 11 by: string;
12 duration: string; 12 duration: string;
13 13
14 private static createDurationString(duration: number): string { 14 private static createDurationString(duration: number) {
15 const minutes = Math.floor(duration / 60); 15 const minutes = Math.floor(duration / 60);
16 const seconds = duration % 60; 16 const seconds = duration % 60;
17 const minutes_padding = minutes >= 10 ? '' : '0'; 17 const minutes_padding = minutes >= 10 ? '' : '0';
@@ -20,7 +20,7 @@ export class Video {
20 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString(); 20 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
21 } 21 }
22 22
23 private static createByString(author: string, podUrl: string): string { 23 private static createByString(author: string, podUrl: string) {
24 let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':'); 24 let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
25 25
26 if (port === '80' || port === '443') { 26 if (port === '80' || port === '443') {
@@ -57,7 +57,7 @@ export class Video {
57 this.by = Video.createByString(hash.author, hash.podUrl); 57 this.by = Video.createByString(hash.author, hash.podUrl);
58 } 58 }
59 59
60 isRemovableBy(user): boolean { 60 isRemovableBy(user) {
61 return this.isLocal === true && user && this.author === user.username; 61 return this.isLocal === true && user && this.author === user.username;
62 } 62 }
63} 63}
diff --git a/client/app/videos/shared/video.service.ts b/client/app/videos/shared/video.service.ts
index 78789c3cc..b6e0800a0 100644
--- a/client/app/videos/shared/video.service.ts
+++ b/client/app/videos/shared/video.service.ts
@@ -10,30 +10,30 @@ import { Video } from './video.model';
10 10
11@Injectable() 11@Injectable()
12export class VideoService { 12export class VideoService {
13 private _baseVideoUrl = '/api/v1/videos/'; 13 private static BASE_VIDEO_URL = '/api/v1/videos/';
14 14
15 constructor (private http: Http, private _authService: AuthService) {} 15 constructor(private http: Http, private authService: AuthService) {}
16 16
17 getVideos(pagination: Pagination, sort: SortField) { 17 getVideos(pagination: Pagination, sort: SortField) {
18 const params = this.createPaginationParams(pagination); 18 const params = this.createPaginationParams(pagination);
19 19
20 if (sort) params.set('sort', sort); 20 if (sort) params.set('sort', sort);
21 21
22 return this.http.get(this._baseVideoUrl, { search: params }) 22 return this.http.get(VideoService.BASE_VIDEO_URL, { search: params })
23 .map(res => res.json()) 23 .map(res => res.json())
24 .map(this.extractVideos) 24 .map(this.extractVideos)
25 .catch(this.handleError); 25 .catch(this.handleError);
26 } 26 }
27 27
28 getVideo(id: string) { 28 getVideo(id: string) {
29 return this.http.get(this._baseVideoUrl + id) 29 return this.http.get(VideoService.BASE_VIDEO_URL + id)
30 .map(res => <Video> res.json()) 30 .map(res => <Video> res.json())
31 .catch(this.handleError); 31 .catch(this.handleError);
32 } 32 }
33 33
34 removeVideo(id: string) { 34 removeVideo(id: string) {
35 const options = this._authService.getAuthRequestOptions(); 35 const options = this.authService.getAuthRequestOptions();
36 return this.http.delete(this._baseVideoUrl + id, options) 36 return this.http.delete(VideoService.BASE_VIDEO_URL + id, options)
37 .map(res => <number> res.status) 37 .map(res => <number> res.status)
38 .catch(this.handleError); 38 .catch(this.handleError);
39 } 39 }
@@ -44,13 +44,13 @@ export class VideoService {
44 if (search.field) params.set('field', search.field); 44 if (search.field) params.set('field', search.field);
45 if (sort) params.set('sort', sort); 45 if (sort) params.set('sort', sort);
46 46
47 return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search.value), { search: params }) 47 return this.http.get(VideoService.BASE_VIDEO_URL + 'search/' + encodeURIComponent(search.value), { search: params })
48 .map(res => res.json()) 48 .map(res => res.json())
49 .map(this.extractVideos) 49 .map(this.extractVideos)
50 .catch(this.handleError); 50 .catch(this.handleError);
51 } 51 }
52 52
53 private extractVideos (body: any) { 53 private extractVideos(body: any) {
54 const videos_json = body.data; 54 const videos_json = body.data;
55 const totalVideos = body.total; 55 const totalVideos = body.total;
56 const videos = []; 56 const videos = [];
@@ -61,7 +61,7 @@ export class VideoService {
61 return { videos, totalVideos }; 61 return { videos, totalVideos };
62 } 62 }
63 63
64 private handleError (error: Response) { 64 private handleError(error: Response) {
65 console.error(error); 65 console.error(error);
66 return Observable.throw(error.json().error || 'Server error'); 66 return Observable.throw(error.json().error || 'Server error');
67 } 67 }
diff --git a/client/app/videos/video-add/video-add.component.ts b/client/app/videos/video-add/video-add.component.ts
index ca583a103..67a04a2b4 100644
--- a/client/app/videos/video-add/video-add.component.ts
+++ b/client/app/videos/video-add/video-add.component.ts
@@ -7,7 +7,7 @@ import { PROGRESSBAR_DIRECTIVES } from 'ng2-bootstrap/components/progressbar';
7import { AuthService, User } from '../../users/index'; 7import { AuthService, User } from '../../users/index';
8 8
9// TODO: import it with systemjs 9// TODO: import it with systemjs
10declare var jQuery:any; 10declare var jQuery: any;
11 11
12@Component({ 12@Component({
13 selector: 'my-videos-add', 13 selector: 'my-videos-add',
diff --git a/client/app/videos/video-list/video-list.component.ts b/client/app/videos/video-list/video-list.component.ts
index a88fb379a..3f54c98ce 100644
--- a/client/app/videos/video-list/video-list.component.ts
+++ b/client/app/videos/video-list/video-list.component.ts
@@ -31,26 +31,26 @@ export class VideoListComponent implements OnInit {
31 total: 0 31 total: 0
32 }; 32 };
33 sort: SortField; 33 sort: SortField;
34 loading: boolean = false; 34 loading = false;
35 35
36 private search: Search; 36 private search: Search;
37 37
38 constructor( 38 constructor(
39 private _authService: AuthService, 39 private authService: AuthService,
40 private _videoService: VideoService, 40 private videoService: VideoService,
41 private _routeParams: RouteParams, 41 private routeParams: RouteParams,
42 private _router: Router 42 private router: Router
43 ) { 43 ) {
44 this.search = { 44 this.search = {
45 value: this._routeParams.get('search'), 45 value: this.routeParams.get('search'),
46 field: <SearchField>this._routeParams.get('field') 46 field: <SearchField>this.routeParams.get('field')
47 }; 47 };
48 48
49 this.sort = <SortField>this._routeParams.get('sort') || '-createdDate'; 49 this.sort = <SortField>this.routeParams.get('sort') || '-createdDate';
50 } 50 }
51 51
52 ngOnInit() { 52 ngOnInit() {
53 if (this._authService.isLoggedIn()) { 53 if (this.authService.isLoggedIn()) {
54 this.user = User.load(); 54 this.user = User.load();
55 } 55 }
56 56
@@ -64,9 +64,9 @@ export class VideoListComponent implements OnInit {
64 let observable = null; 64 let observable = null;
65 65
66 if (this.search.value !== null) { 66 if (this.search.value !== null) {
67 observable = this._videoService.searchVideos(this.search, this.pagination, this.sort); 67 observable = this.videoService.searchVideos(this.search, this.pagination, this.sort);
68 } else { 68 } else {
69 observable = this._videoService.getVideos(this.pagination, this.sort); 69 observable = this.videoService.getVideos(this.pagination, this.sort);
70 } 70 }
71 71
72 observable.subscribe( 72 observable.subscribe(
@@ -79,7 +79,7 @@ export class VideoListComponent implements OnInit {
79 ); 79 );
80 } 80 }
81 81
82 onRemoved(video: Video): void { 82 onRemoved(video: Video) {
83 this.videos.splice(this.videos.indexOf(video), 1); 83 this.videos.splice(this.videos.indexOf(video), 1);
84 } 84 }
85 85
@@ -95,7 +95,7 @@ export class VideoListComponent implements OnInit {
95 params.field = this.search.field; 95 params.field = this.search.field;
96 } 96 }
97 97
98 this._router.navigate(['VideosList', params]); 98 this.router.navigate(['VideosList', params]);
99 this.getVideos(); 99 this.getVideos();
100 } 100 }
101} 101}
diff --git a/client/app/videos/video-list/video-miniature.component.ts b/client/app/videos/video-list/video-miniature.component.ts
index 817636768..73416607a 100644
--- a/client/app/videos/video-list/video-miniature.component.ts
+++ b/client/app/videos/video-list/video-miniature.component.ts
@@ -19,9 +19,9 @@ export class VideoMiniatureComponent {
19 @Input() video: Video; 19 @Input() video: Video;
20 @Input() user: User; 20 @Input() user: User;
21 21
22 hovering: boolean = false; 22 hovering = false;
23 23
24 constructor(private _videoService: VideoService) {} 24 constructor(private videoService: VideoService) {}
25 25
26 onHover() { 26 onHover() {
27 this.hovering = true; 27 this.hovering = true;
@@ -31,13 +31,13 @@ export class VideoMiniatureComponent {
31 this.hovering = false; 31 this.hovering = false;
32 } 32 }
33 33
34 displayRemoveIcon(): boolean { 34 displayRemoveIcon() {
35 return this.hovering && this.video.isRemovableBy(this.user); 35 return this.hovering && this.video.isRemovableBy(this.user);
36 } 36 }
37 37
38 removeVideo(id: string) { 38 removeVideo(id: string) {
39 if (confirm('Do you really want to remove this video?')) { 39 if (confirm('Do you really want to remove this video?')) {
40 this._videoService.removeVideo(id).subscribe( 40 this.videoService.removeVideo(id).subscribe(
41 status => this.removed.emit(true), 41 status => this.removed.emit(true),
42 error => alert(error) 42 error => alert(error)
43 ); 43 );
diff --git a/client/app/videos/video-list/video-sort.component.ts b/client/app/videos/video-list/video-sort.component.ts
index d00d7ed49..ed06c7510 100644
--- a/client/app/videos/video-list/video-sort.component.ts
+++ b/client/app/videos/video-list/video-sort.component.ts
@@ -26,7 +26,7 @@ export class VideoSortComponent {
26 return Object.keys(this.sortChoices); 26 return Object.keys(this.sortChoices);
27 } 27 }
28 28
29 getStringChoice(choiceKey: SortField): string { 29 getStringChoice(choiceKey: SortField) {
30 return this.sortChoices[choiceKey]; 30 return this.sortChoices[choiceKey];
31 } 31 }
32 32
diff --git a/client/app/videos/video-watch/video-watch.component.ts b/client/app/videos/video-watch/video-watch.component.ts
index 891e6563f..c159b4004 100644
--- a/client/app/videos/video-watch/video-watch.component.ts
+++ b/client/app/videos/video-watch/video-watch.component.ts
@@ -23,21 +23,21 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
23 numPeers: number; 23 numPeers: number;
24 loading: boolean = false; 24 loading: boolean = false;
25 25
26 private _interval: NodeJS.Timer; 26 private interval: NodeJS.Timer;
27 private client: any; 27 private client: any;
28 28
29 constructor( 29 constructor(
30 private _videoService: VideoService, 30 private videoService: VideoService,
31 private _routeParams: RouteParams, 31 private routeParams: RouteParams,
32 private _elementRef: ElementRef 32 private elementRef: ElementRef
33 ) { 33 ) {
34 // TODO: use a service 34 // TODO: use a service
35 this.client = new WebTorrent({ dht: false }); 35 this.client = new WebTorrent({ dht: false });
36 } 36 }
37 37
38 ngOnInit() { 38 ngOnInit() {
39 let id = this._routeParams.get('id'); 39 let id = this.routeParams.get('id');
40 this._videoService.getVideo(id).subscribe( 40 this.videoService.getVideo(id).subscribe(
41 video => this.loadVideo(video), 41 video => this.loadVideo(video),
42 error => alert(error) 42 error => alert(error)
43 ); 43 );
@@ -50,7 +50,7 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
50 this.client.add(this.video.magnetUri, (torrent) => { 50 this.client.add(this.video.magnetUri, (torrent) => {
51 this.loading = false; 51 this.loading = false;
52 console.log('Added ' + this.video.magnetUri + '.'); 52 console.log('Added ' + this.video.magnetUri + '.');
53 torrent.files[0].appendTo(this._elementRef.nativeElement.querySelector('.embed-responsive'), (err) => { 53 torrent.files[0].appendTo(this.elementRef.nativeElement.querySelector('.embed-responsive'), (err) => {
54 if (err) { 54 if (err) {
55 alert('Cannot append the file.'); 55 alert('Cannot append the file.');
56 console.error(err); 56 console.error(err);
@@ -58,7 +58,7 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
58 }); 58 });
59 59
60 // Refresh each second 60 // Refresh each second
61 this._interval = setInterval(() => { 61 this.interval = setInterval(() => {
62 this.downloadSpeed = torrent.downloadSpeed; 62 this.downloadSpeed = torrent.downloadSpeed;
63 this.uploadSpeed = torrent.uploadSpeed; 63 this.uploadSpeed = torrent.uploadSpeed;
64 this.numPeers = torrent.numPeers; 64 this.numPeers = torrent.numPeers;
@@ -66,9 +66,9 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
66 }); 66 });
67 } 67 }
68 68
69 routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) : any { 69 routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
70 console.log('Removing video from webtorrent.'); 70 console.log('Removing video from webtorrent.');
71 clearInterval(this._interval); 71 clearInterval(this.interval);
72 this.client.remove(this.video.magnetUri); 72 this.client.remove(this.video.magnetUri);
73 return true; 73 return true;
74 } 74 }