diff options
Diffstat (limited to 'client/angular/videos')
21 files changed, 0 insertions, 754 deletions
diff --git a/client/angular/videos/components/add/videos-add.component.html b/client/angular/videos/components/add/videos-add.component.html deleted file mode 100644 index 80d229cb8..000000000 --- a/client/angular/videos/components/add/videos-add.component.html +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | <h3>Upload a video</h3> | ||
2 | |||
3 | <form (ngSubmit)="uploadFile()" #videoForm="ngForm"> | ||
4 | <div class="form-group"> | ||
5 | <label for="name">Video name</label> | ||
6 | <input | ||
7 | type="text" class="form-control" name="name" id="name" required | ||
8 | ngControl="name" #name="ngForm" | ||
9 | > | ||
10 | <div [hidden]="name.valid || name.pristine" class="alert alert-danger"> | ||
11 | Name is required | ||
12 | </div> | ||
13 | </div> | ||
14 | |||
15 | <div class="form-group"> | ||
16 | <div class="btn btn-default btn-file"> | ||
17 | <span>Select the video...</span> | ||
18 | <input type="file" name="videofile" id="videofile"> | ||
19 | </div> | ||
20 | |||
21 | <span *ngIf="fileToUpload">{{ fileToUpload.name }}</span> | ||
22 | </div> | ||
23 | |||
24 | <div class="form-group"> | ||
25 | <label for="description">Description</label> | ||
26 | <textarea | ||
27 | name="description" id="description" class="form-control" placeholder="Description..." required | ||
28 | ngControl="description" #description="ngForm" | ||
29 | > | ||
30 | </textarea> | ||
31 | <div [hidden]="description.valid || description.pristine" class="alert alert-danger"> | ||
32 | A description is required | ||
33 | </div> | ||
34 | </div> | ||
35 | |||
36 | <div id="progress" *ngIf="progressBar.max !== 0"> | ||
37 | <progressbar [value]="progressBar.value" [max]="progressBar.max">{{ progressBar.value | bytes }} / {{ progressBar.max | bytes }}</progressbar> | ||
38 | </div> | ||
39 | |||
40 | <input type="submit" value="Upload" class="btn btn-default" [disabled]="!videoForm.form.valid || !fileToUpload"> | ||
41 | </form> | ||
diff --git a/client/angular/videos/components/add/videos-add.component.scss b/client/angular/videos/components/add/videos-add.component.scss deleted file mode 100644 index 01195f017..000000000 --- a/client/angular/videos/components/add/videos-add.component.scss +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | .btn-file { | ||
2 | position: relative; | ||
3 | overflow: hidden; | ||
4 | } | ||
5 | |||
6 | .btn-file input[type=file] { | ||
7 | position: absolute; | ||
8 | top: 0; | ||
9 | right: 0; | ||
10 | min-width: 100%; | ||
11 | min-height: 100%; | ||
12 | font-size: 100px; | ||
13 | text-align: right; | ||
14 | filter: alpha(opacity=0); | ||
15 | opacity: 0; | ||
16 | outline: none; | ||
17 | background: white; | ||
18 | cursor: inherit; | ||
19 | display: block; | ||
20 | } | ||
21 | |||
22 | .name_file { | ||
23 | display: inline-block; | ||
24 | margin-left: 10px; | ||
25 | } | ||
26 | |||
27 | .form-group { | ||
28 | margin-bottom: 10px; | ||
29 | } | ||
30 | |||
31 | #progress { | ||
32 | margin-bottom: 10px; | ||
33 | } | ||
diff --git a/client/angular/videos/components/add/videos-add.component.ts b/client/angular/videos/components/add/videos-add.component.ts deleted file mode 100644 index f1652be19..000000000 --- a/client/angular/videos/components/add/videos-add.component.ts +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | import { Component, ElementRef, OnInit } from '@angular/core'; | ||
2 | import { Router } from '@angular/router-deprecated'; | ||
3 | |||
4 | import { PROGRESSBAR_DIRECTIVES } from 'ng2-bootstrap/components/progressbar'; | ||
5 | import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; | ||
6 | |||
7 | import { AuthService } from '../../../users/services/auth.service'; | ||
8 | import { User } from '../../../users/models/user'; | ||
9 | |||
10 | // TODO: import it with systemjs | ||
11 | declare var jQuery:any; | ||
12 | |||
13 | @Component({ | ||
14 | selector: 'my-videos-add', | ||
15 | styleUrls: [ 'app/angular/videos/components/add/videos-add.component.css' ], | ||
16 | templateUrl: 'app/angular/videos/components/add/videos-add.component.html', | ||
17 | directives: [ PROGRESSBAR_DIRECTIVES ], | ||
18 | pipes: [ BytesPipe ] | ||
19 | }) | ||
20 | |||
21 | export class VideosAddComponent implements OnInit { | ||
22 | user: User; | ||
23 | fileToUpload: any; | ||
24 | progressBar: { value: number; max: number; } = { value: 0, max: 0 }; | ||
25 | |||
26 | private _form: any; | ||
27 | |||
28 | constructor( | ||
29 | private _router: Router, private _elementRef: ElementRef, | ||
30 | private _authService: AuthService | ||
31 | ) {} | ||
32 | |||
33 | ngOnInit() { | ||
34 | this.user = User.load(); | ||
35 | jQuery(this._elementRef.nativeElement).find('#videofile').fileupload({ | ||
36 | url: '/api/v1/videos', | ||
37 | dataType: 'json', | ||
38 | singleFileUploads: true, | ||
39 | multipart: true, | ||
40 | autoupload: false, | ||
41 | |||
42 | add: (e, data) => { | ||
43 | this._form = data; | ||
44 | this.fileToUpload = data['files'][0]; | ||
45 | }, | ||
46 | |||
47 | progressall: (e, data) => { | ||
48 | this.progressBar.value = data.loaded; | ||
49 | // The server is a little bit slow to answer (has to seed the video) | ||
50 | // So we add more time to the progress bar (+10%) | ||
51 | this.progressBar.max = data.total + (0.1 * data.total); | ||
52 | }, | ||
53 | |||
54 | done: (e, data) => { | ||
55 | this.progressBar.value = this.progressBar.max; | ||
56 | console.log('Video uploaded.'); | ||
57 | |||
58 | // Print all the videos once it's finished | ||
59 | this._router.navigate(['VideosList']); | ||
60 | } | ||
61 | }); | ||
62 | } | ||
63 | |||
64 | uploadFile() { | ||
65 | this._form.headers = this._authService.getRequestHeader().toJSON(); | ||
66 | this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray(); | ||
67 | this._form.submit(); | ||
68 | } | ||
69 | } | ||
diff --git a/client/angular/videos/components/list/sort.ts b/client/angular/videos/components/list/sort.ts deleted file mode 100644 index 6e8cc7936..000000000 --- a/client/angular/videos/components/list/sort.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export type SortField = "name" | "-name" | ||
2 | | "duration" | "-duration" | ||
3 | | "createdDate" | "-createdDate"; | ||
diff --git a/client/angular/videos/components/list/video-miniature.component.html b/client/angular/videos/components/list/video-miniature.component.html deleted file mode 100644 index 244254b5a..000000000 --- a/client/angular/videos/components/list/video-miniature.component.html +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | <div class="video-miniature col-md-4" (mouseenter)="onHover()" (mouseleave)="onBlur()"> | ||
2 | <a | ||
3 | [routerLink]="['VideosWatch', { id: video.id }]" [attr.title]="video.description" | ||
4 | class="video-miniature-thumbnail" | ||
5 | > | ||
6 | <img [attr.src]="video.thumbnailPath" alt="video thumbnail" /> | ||
7 | <span class="video-miniature-duration">{{ video.duration }}</span> | ||
8 | </a> | ||
9 | <span | ||
10 | *ngIf="displayRemoveIcon()" (click)="removeVideo(video.id)" | ||
11 | class="video-miniature-remove glyphicon glyphicon-remove" | ||
12 | ></span> | ||
13 | |||
14 | <div class="video-miniature-informations"> | ||
15 | <a [routerLink]="['VideosWatch', { id: video.id }]" class="video-miniature-name"> | ||
16 | <span>{{ video.name }}</span> | ||
17 | </a> | ||
18 | |||
19 | <span class="video-miniature-author">by {{ video.by }}</span> | ||
20 | <span class="video-miniature-created-date">on {{ video.createdDate | date:'short' }}</span> | ||
21 | </div> | ||
22 | </div> | ||
diff --git a/client/angular/videos/components/list/video-miniature.component.scss b/client/angular/videos/components/list/video-miniature.component.scss deleted file mode 100644 index 4488abe22..000000000 --- a/client/angular/videos/components/list/video-miniature.component.scss +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | .video-miniature { | ||
2 | height: 200px; | ||
3 | display: inline-block; | ||
4 | position: relative; | ||
5 | |||
6 | .video-miniature-thumbnail { | ||
7 | display: block; | ||
8 | position: relative; | ||
9 | |||
10 | .video-miniature-duration { | ||
11 | position: absolute; | ||
12 | right: 60px; | ||
13 | bottom: 2px; | ||
14 | display: inline-block; | ||
15 | background-color: rgba(0, 0, 0, 0.8); | ||
16 | color: rgba(255, 255, 255, 0.8); | ||
17 | padding: 2px; | ||
18 | font-size: 11px; | ||
19 | } | ||
20 | } | ||
21 | |||
22 | .video-miniature-remove { | ||
23 | display: inline-block; | ||
24 | position: absolute; | ||
25 | left: 16px; | ||
26 | background-color: rgba(0, 0, 0, 0.8); | ||
27 | color: rgba(255, 255, 255, 0.8); | ||
28 | padding: 2px; | ||
29 | cursor: pointer; | ||
30 | |||
31 | &:hover { | ||
32 | color: rgba(255, 255, 255, 0.9); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | .video-miniature-informations { | ||
37 | margin-left: 3px; | ||
38 | |||
39 | .video-miniature-name { | ||
40 | display: block; | ||
41 | font-weight: bold; | ||
42 | |||
43 | &:hover { | ||
44 | text-decoration: none; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | .video-miniature-author, .video-miniature-created-date { | ||
49 | display: block; | ||
50 | margin-left: 1px; | ||
51 | font-size: 11px; | ||
52 | color: rgba(0, 0, 0, 0.5); | ||
53 | } | ||
54 | } | ||
55 | } | ||
diff --git a/client/angular/videos/components/list/video-miniature.component.ts b/client/angular/videos/components/list/video-miniature.component.ts deleted file mode 100644 index 383c2c609..000000000 --- a/client/angular/videos/components/list/video-miniature.component.ts +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
1 | import { Component, Input, Output, EventEmitter } from '@angular/core'; | ||
2 | import { DatePipe } from '@angular/common'; | ||
3 | import { ROUTER_DIRECTIVES } from '@angular/router-deprecated'; | ||
4 | |||
5 | import { Video } from '../../video'; | ||
6 | import { VideosService } from '../../videos.service'; | ||
7 | import { User } from '../../../users/models/user'; | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-video-miniature', | ||
11 | styleUrls: [ 'app/angular/videos/components/list/video-miniature.component.css' ], | ||
12 | templateUrl: 'app/angular/videos/components/list/video-miniature.component.html', | ||
13 | directives: [ ROUTER_DIRECTIVES ], | ||
14 | pipes: [ DatePipe ] | ||
15 | }) | ||
16 | |||
17 | export class VideoMiniatureComponent { | ||
18 | @Output() removed = new EventEmitter<any>(); | ||
19 | |||
20 | @Input() video: Video; | ||
21 | @Input() user: User; | ||
22 | |||
23 | hovering: boolean = false; | ||
24 | |||
25 | constructor(private _videosService: VideosService) {} | ||
26 | |||
27 | onHover() { | ||
28 | this.hovering = true; | ||
29 | } | ||
30 | |||
31 | onBlur() { | ||
32 | this.hovering = false; | ||
33 | } | ||
34 | |||
35 | displayRemoveIcon(): boolean { | ||
36 | return this.hovering && this.video.isRemovableBy(this.user); | ||
37 | } | ||
38 | |||
39 | removeVideo(id: string) { | ||
40 | if (confirm('Do you really want to remove this video?')) { | ||
41 | this._videosService.removeVideo(id).subscribe( | ||
42 | status => this.removed.emit(true), | ||
43 | error => alert(error) | ||
44 | ); | ||
45 | } | ||
46 | } | ||
47 | } | ||
diff --git a/client/angular/videos/components/list/video-sort.component.html b/client/angular/videos/components/list/video-sort.component.html deleted file mode 100644 index 3bece0b22..000000000 --- a/client/angular/videos/components/list/video-sort.component.html +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | <select class="form-control input-sm" [(ngModel)]="currentSort" (ngModelChange)="onSortChange()"> | ||
2 | <option *ngFor="let choice of choiceKeys" [value]="choice"> | ||
3 | {{ getStringChoice(choice) }} | ||
4 | </option> | ||
5 | </select> | ||
diff --git a/client/angular/videos/components/list/video-sort.component.ts b/client/angular/videos/components/list/video-sort.component.ts deleted file mode 100644 index 0373cea38..000000000 --- a/client/angular/videos/components/list/video-sort.component.ts +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | import { Component, Input, Output, EventEmitter } from '@angular/core'; | ||
2 | |||
3 | import { SortField } from './sort'; | ||
4 | |||
5 | @Component({ | ||
6 | selector: 'my-video-sort', | ||
7 | // styleUrls: [ 'app/angular/videos/components/list/video-sort.component.css' ], | ||
8 | templateUrl: 'app/angular/videos/components/list/video-sort.component.html' | ||
9 | }) | ||
10 | |||
11 | export class VideoSortComponent { | ||
12 | @Output() sort = new EventEmitter<any>(); | ||
13 | |||
14 | @Input() currentSort: SortField; | ||
15 | |||
16 | sortChoices = { | ||
17 | 'name': 'Name - Asc', | ||
18 | '-name': 'Name - Desc', | ||
19 | 'duration': 'Duration - Asc', | ||
20 | '-duration': 'Duration - Desc', | ||
21 | 'createdDate': 'Created Date - Asc', | ||
22 | '-createdDate': 'Created Date - Desc' | ||
23 | }; | ||
24 | |||
25 | get choiceKeys() { | ||
26 | return Object.keys(this.sortChoices); | ||
27 | } | ||
28 | |||
29 | getStringChoice(choiceKey: SortField): string { | ||
30 | return this.sortChoices[choiceKey]; | ||
31 | } | ||
32 | |||
33 | onSortChange() { | ||
34 | this.sort.emit(this.currentSort); | ||
35 | } | ||
36 | } | ||
diff --git a/client/angular/videos/components/list/videos-list.component.html b/client/angular/videos/components/list/videos-list.component.html deleted file mode 100644 index edbbaf3ae..000000000 --- a/client/angular/videos/components/list/videos-list.component.html +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | <div class="row videos-info"> | ||
2 | <div class="col-md-9 videos-total-results"> {{ pagination.total }} videos</div> | ||
3 | <my-video-sort class="col-md-3" [currentSort]="sort" (sort)="onSort($event)"></my-video-sort> | ||
4 | </div> | ||
5 | |||
6 | <div class="videos-miniatures"> | ||
7 | <my-loader [loading]="loading"></my-loader> | ||
8 | |||
9 | <div class="col-md-12 no-video" *ngIf="!loading && videos.length === 0">There is no video.</div> | ||
10 | |||
11 | <my-video-miniature *ngFor="let video of videos" [video]="video" [user]="user" (removed)="onRemoved(video)"> | ||
12 | </my-video-miniature> | ||
13 | </div> | ||
14 | |||
15 | <pagination | ||
16 | [totalItems]="pagination.total" [itemsPerPage]="pagination.itemsPerPage" [(ngModel)]="pagination.currentPage" | ||
17 | (ngModelChange)="getVideos()" | ||
18 | ></pagination> | ||
diff --git a/client/angular/videos/components/list/videos-list.component.scss b/client/angular/videos/components/list/videos-list.component.scss deleted file mode 100644 index 9441d80c3..000000000 --- a/client/angular/videos/components/list/videos-list.component.scss +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | .videos-info { | ||
2 | |||
3 | padding-bottom: 20px; | ||
4 | margin-bottom: 20px; | ||
5 | border-bottom: 1px solid #f1f1f1; | ||
6 | height: 40px; | ||
7 | line-height: 40px; | ||
8 | width: 765px; | ||
9 | margin-left: 15px; | ||
10 | |||
11 | my-video-sort { | ||
12 | padding-right: 0; | ||
13 | } | ||
14 | |||
15 | .videos-total-results { | ||
16 | font-size: 13px; | ||
17 | padding-left: 0; | ||
18 | } | ||
19 | } | ||
20 | |||
21 | .videos-miniatures { | ||
22 | min-height: 600px; | ||
23 | |||
24 | my-videos-miniature { | ||
25 | display: inline-block; | ||
26 | } | ||
27 | |||
28 | .no-video { | ||
29 | margin-top: 50px; | ||
30 | text-align: center; | ||
31 | } | ||
32 | } | ||
33 | |||
34 | pagination { | ||
35 | display: block; | ||
36 | text-align: center; | ||
37 | } | ||
diff --git a/client/angular/videos/components/list/videos-list.component.ts b/client/angular/videos/components/list/videos-list.component.ts deleted file mode 100644 index 56230e331..000000000 --- a/client/angular/videos/components/list/videos-list.component.ts +++ /dev/null | |||
@@ -1,100 +0,0 @@ | |||
1 | import { Component, OnInit } from '@angular/core'; | ||
2 | import { ROUTER_DIRECTIVES, RouteParams, Router } from '@angular/router-deprecated'; | ||
3 | |||
4 | import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination'; | ||
5 | |||
6 | import { AuthService } from '../../../users/services/auth.service'; | ||
7 | import { Pagination } from '../../pagination'; | ||
8 | import { User } from '../../../users/models/user'; | ||
9 | import { VideosService } from '../../videos.service'; | ||
10 | import { Video } from '../../video'; | ||
11 | import { VideoMiniatureComponent } from './video-miniature.component'; | ||
12 | import { Search, SearchField } from '../../../app/search'; | ||
13 | import { VideoSortComponent } from './video-sort.component'; | ||
14 | import { SortField } from './sort'; | ||
15 | import { LoaderComponent } from '../../loader.component'; | ||
16 | |||
17 | @Component({ | ||
18 | selector: 'my-videos-list', | ||
19 | styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ], | ||
20 | templateUrl: 'app/angular/videos/components/list/videos-list.component.html', | ||
21 | directives: [ ROUTER_DIRECTIVES, PAGINATION_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent, LoaderComponent ] | ||
22 | }) | ||
23 | |||
24 | export class VideosListComponent implements OnInit { | ||
25 | user: User = null; | ||
26 | videos: Video[] = []; | ||
27 | pagination: Pagination = { | ||
28 | currentPage: 1, | ||
29 | itemsPerPage: 9, | ||
30 | total: 0 | ||
31 | }; | ||
32 | sort: SortField; | ||
33 | loading: boolean = false; | ||
34 | |||
35 | private search: Search; | ||
36 | |||
37 | constructor( | ||
38 | private _authService: AuthService, | ||
39 | private _videosService: VideosService, | ||
40 | private _routeParams: RouteParams, | ||
41 | private _router: Router | ||
42 | ) { | ||
43 | this.search = { | ||
44 | value: this._routeParams.get('search'), | ||
45 | field: <SearchField>this._routeParams.get('field') | ||
46 | }; | ||
47 | |||
48 | this.sort = <SortField>this._routeParams.get('sort') || '-createdDate'; | ||
49 | } | ||
50 | |||
51 | ngOnInit() { | ||
52 | if (this._authService.isLoggedIn()) { | ||
53 | this.user = User.load(); | ||
54 | } | ||
55 | |||
56 | this.getVideos(); | ||
57 | } | ||
58 | |||
59 | getVideos() { | ||
60 | this.loading = true; | ||
61 | this.videos = []; | ||
62 | |||
63 | let observable = null; | ||
64 | |||
65 | if (this.search.value !== null) { | ||
66 | observable = this._videosService.searchVideos(this.search, this.pagination, this.sort); | ||
67 | } else { | ||
68 | observable = this._videosService.getVideos(this.pagination, this.sort); | ||
69 | } | ||
70 | |||
71 | observable.subscribe( | ||
72 | ({ videos, totalVideos }) => { | ||
73 | this.videos = videos; | ||
74 | this.pagination.total = totalVideos; | ||
75 | this.loading = false; | ||
76 | }, | ||
77 | error => alert(error) | ||
78 | ); | ||
79 | } | ||
80 | |||
81 | onRemoved(video: Video): void { | ||
82 | this.videos.splice(this.videos.indexOf(video), 1); | ||
83 | } | ||
84 | |||
85 | onSort(sort: SortField) { | ||
86 | this.sort = sort; | ||
87 | |||
88 | const params: any = { | ||
89 | sort: this.sort | ||
90 | }; | ||
91 | |||
92 | if (this.search.value) { | ||
93 | params.search = this.search.value; | ||
94 | params.field = this.search.field; | ||
95 | } | ||
96 | |||
97 | this._router.navigate(['VideosList', params]); | ||
98 | this.getVideos(); | ||
99 | } | ||
100 | } | ||
diff --git a/client/angular/videos/components/watch/videos-watch.component.html b/client/angular/videos/components/watch/videos-watch.component.html deleted file mode 100644 index 6c36b27e2..000000000 --- a/client/angular/videos/components/watch/videos-watch.component.html +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | <my-loader [loading]="loading"></my-loader> | ||
2 | |||
3 | <div class="embed-responsive embed-responsive-19by9"> | ||
4 | </div> | ||
5 | |||
6 | <div id="torrent-info"> | ||
7 | <div id="torrent-info-download">Download: {{ downloadSpeed | bytes }}/s</div> | ||
8 | <div id="torrent-info-upload">Upload: {{ uploadSpeed | bytes }}/s</div> | ||
9 | <div id="torrent-info-peers">Number of peers: {{ numPeers }}</div> | ||
10 | <div> | ||
diff --git a/client/angular/videos/components/watch/videos-watch.component.scss b/client/angular/videos/components/watch/videos-watch.component.scss deleted file mode 100644 index 1228d42f4..000000000 --- a/client/angular/videos/components/watch/videos-watch.component.scss +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | .embed-responsive { | ||
2 | height: 500px; | ||
3 | } | ||
4 | |||
5 | #torrent-info { | ||
6 | font-size: 10px; | ||
7 | |||
8 | div { | ||
9 | display: inline-block; | ||
10 | width: 33%; | ||
11 | text-align: center; | ||
12 | } | ||
13 | } | ||
diff --git a/client/angular/videos/components/watch/videos-watch.component.ts b/client/angular/videos/components/watch/videos-watch.component.ts deleted file mode 100644 index e551e1f9a..000000000 --- a/client/angular/videos/components/watch/videos-watch.component.ts +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | import { Component, OnInit, ElementRef } from '@angular/core'; | ||
2 | import { RouteParams, CanDeactivate, ComponentInstruction } from '@angular/router-deprecated'; | ||
3 | |||
4 | import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; | ||
5 | |||
6 | import { LoaderComponent } from '../../loader.component'; | ||
7 | |||
8 | // TODO import it with systemjs | ||
9 | declare var WebTorrent: any; | ||
10 | |||
11 | import { Video } from '../../video'; | ||
12 | import { VideosService } from '../../videos.service'; | ||
13 | |||
14 | @Component({ | ||
15 | selector: 'my-video-watch', | ||
16 | templateUrl: 'app/angular/videos/components/watch/videos-watch.component.html', | ||
17 | styleUrls: [ 'app/angular/videos/components/watch/videos-watch.component.css' ], | ||
18 | directives: [ LoaderComponent ], | ||
19 | pipes: [ BytesPipe ] | ||
20 | }) | ||
21 | |||
22 | export class VideosWatchComponent implements OnInit, CanDeactivate { | ||
23 | video: Video; | ||
24 | downloadSpeed: number; | ||
25 | uploadSpeed: number; | ||
26 | numPeers: number; | ||
27 | loading: boolean = false; | ||
28 | |||
29 | private _interval: NodeJS.Timer; | ||
30 | private client: any; | ||
31 | |||
32 | constructor( | ||
33 | private _videosService: VideosService, | ||
34 | private _routeParams: RouteParams, | ||
35 | private _elementRef: ElementRef | ||
36 | ) { | ||
37 | // TODO: use a service | ||
38 | this.client = new WebTorrent({ dht: false }); | ||
39 | } | ||
40 | |||
41 | ngOnInit() { | ||
42 | let id = this._routeParams.get('id'); | ||
43 | this._videosService.getVideo(id).subscribe( | ||
44 | video => this.loadVideo(video), | ||
45 | error => alert(error) | ||
46 | ); | ||
47 | } | ||
48 | |||
49 | loadVideo(video: Video) { | ||
50 | this.loading = true; | ||
51 | this.video = video; | ||
52 | console.log('Adding ' + this.video.magnetUri + '.'); | ||
53 | this.client.add(this.video.magnetUri, (torrent) => { | ||
54 | this.loading = false; | ||
55 | console.log('Added ' + this.video.magnetUri + '.'); | ||
56 | torrent.files[0].appendTo(this._elementRef.nativeElement.querySelector('.embed-responsive'), (err) => { | ||
57 | if (err) { | ||
58 | alert('Cannot append the file.'); | ||
59 | console.error(err); | ||
60 | } | ||
61 | }); | ||
62 | |||
63 | // Refresh each second | ||
64 | this._interval = setInterval(() => { | ||
65 | this.downloadSpeed = torrent.downloadSpeed; | ||
66 | this.uploadSpeed = torrent.uploadSpeed; | ||
67 | this.numPeers = torrent.numPeers; | ||
68 | }, 1000); | ||
69 | }); | ||
70 | } | ||
71 | |||
72 | routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) : any { | ||
73 | console.log('Removing video from webtorrent.'); | ||
74 | clearInterval(this._interval); | ||
75 | this.client.remove(this.video.magnetUri); | ||
76 | return true; | ||
77 | } | ||
78 | } | ||
diff --git a/client/angular/videos/loader.component.html b/client/angular/videos/loader.component.html deleted file mode 100644 index d02296a2d..000000000 --- a/client/angular/videos/loader.component.html +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | <div id="video-loading" class="col-md-12 text-center" *ngIf="loading"> | ||
2 | <div class="glyphicon glyphicon-refresh glyphicon-refresh-animate"></div> | ||
3 | </div> | ||
diff --git a/client/angular/videos/loader.component.scss b/client/angular/videos/loader.component.scss deleted file mode 100644 index 454195811..000000000 --- a/client/angular/videos/loader.component.scss +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | div { | ||
2 | margin-top: 150px; | ||
3 | } | ||
4 | |||
5 | // Thanks https://gist.github.com/alexandrevicenzi/680147013e902a4eaa5d | ||
6 | .glyphicon-refresh-animate { | ||
7 | -animation: spin .7s infinite linear; | ||
8 | -ms-animation: spin .7s infinite linear; | ||
9 | -webkit-animation: spinw .7s infinite linear; | ||
10 | -moz-animation: spinm .7s infinite linear; | ||
11 | } | ||
12 | |||
13 | @keyframes spin { | ||
14 | from { transform: scale(1) rotate(0deg);} | ||
15 | to { transform: scale(1) rotate(360deg);} | ||
16 | } | ||
17 | |||
18 | @-webkit-keyframes spinw { | ||
19 | from { -webkit-transform: rotate(0deg);} | ||
20 | to { -webkit-transform: rotate(360deg);} | ||
21 | } | ||
22 | |||
23 | @-moz-keyframes spinm { | ||
24 | from { -moz-transform: rotate(0deg);} | ||
25 | to { -moz-transform: rotate(360deg);} | ||
26 | } | ||
diff --git a/client/angular/videos/loader.component.ts b/client/angular/videos/loader.component.ts deleted file mode 100644 index 24329432e..000000000 --- a/client/angular/videos/loader.component.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | import { Component, Input } from '@angular/core'; | ||
2 | |||
3 | @Component({ | ||
4 | selector: 'my-loader', | ||
5 | styleUrls: [ 'app/angular/videos/loader.component.css' ], | ||
6 | templateUrl: 'app/angular/videos/loader.component.html' | ||
7 | }) | ||
8 | |||
9 | export class LoaderComponent { | ||
10 | @Input() loading: boolean; | ||
11 | } | ||
diff --git a/client/angular/videos/pagination.ts b/client/angular/videos/pagination.ts deleted file mode 100644 index 06f7a7875..000000000 --- a/client/angular/videos/pagination.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface Pagination { | ||
2 | currentPage: number; | ||
3 | itemsPerPage: number; | ||
4 | total: number; | ||
5 | } | ||
diff --git a/client/angular/videos/video.ts b/client/angular/videos/video.ts deleted file mode 100644 index eec537c9e..000000000 --- a/client/angular/videos/video.ts +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | export class Video { | ||
2 | id: string; | ||
3 | name: string; | ||
4 | description: string; | ||
5 | magnetUri: string; | ||
6 | podUrl: string; | ||
7 | isLocal: boolean; | ||
8 | thumbnailPath: string; | ||
9 | author: string; | ||
10 | createdDate: Date; | ||
11 | by: string; | ||
12 | duration: string; | ||
13 | |||
14 | private static createDurationString(duration: number): string { | ||
15 | const minutes = Math.floor(duration / 60); | ||
16 | const seconds = duration % 60; | ||
17 | const minutes_padding = minutes >= 10 ? '' : '0'; | ||
18 | const seconds_padding = seconds >= 10 ? '' : '0'; | ||
19 | |||
20 | return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString(); | ||
21 | } | ||
22 | |||
23 | private static createByString(author: string, podUrl: string): string { | ||
24 | let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':'); | ||
25 | |||
26 | if (port === '80' || port === '443') { | ||
27 | port = ''; | ||
28 | } else { | ||
29 | port = ':' + port; | ||
30 | } | ||
31 | |||
32 | return author + '@' + host + port; | ||
33 | } | ||
34 | |||
35 | constructor(hash: { | ||
36 | id: string, | ||
37 | name: string, | ||
38 | description: string, | ||
39 | magnetUri: string, | ||
40 | podUrl: string, | ||
41 | isLocal: boolean, | ||
42 | thumbnailPath: string, | ||
43 | author: string, | ||
44 | createdDate: string, | ||
45 | duration: number; | ||
46 | }) { | ||
47 | this.id = hash.id; | ||
48 | this.name = hash.name; | ||
49 | this.description = hash.description; | ||
50 | this.magnetUri = hash.magnetUri; | ||
51 | this.podUrl = hash.podUrl; | ||
52 | this.isLocal = hash.isLocal; | ||
53 | this.thumbnailPath = hash.thumbnailPath; | ||
54 | this.author = hash.author; | ||
55 | this.createdDate = new Date(hash.createdDate); | ||
56 | this.duration = Video.createDurationString(hash.duration); | ||
57 | this.by = Video.createByString(hash.author, hash.podUrl); | ||
58 | } | ||
59 | |||
60 | isRemovableBy(user): boolean { | ||
61 | return this.isLocal === true && user && this.author === user.username; | ||
62 | } | ||
63 | } | ||
diff --git a/client/angular/videos/videos.service.ts b/client/angular/videos/videos.service.ts deleted file mode 100644 index d5438fd82..000000000 --- a/client/angular/videos/videos.service.ts +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | import { Http, Response, URLSearchParams } from '@angular/http'; | ||
3 | import { Observable } from 'rxjs/Rx'; | ||
4 | |||
5 | import { Pagination } from './pagination'; | ||
6 | import { Video } from './video'; | ||
7 | import { AuthService } from '../users/services/auth.service'; | ||
8 | import { Search } from '../app/search'; | ||
9 | import { SortField } from './components/list/sort'; | ||
10 | |||
11 | @Injectable() | ||
12 | export class VideosService { | ||
13 | private _baseVideoUrl = '/api/v1/videos/'; | ||
14 | |||
15 | constructor (private http: Http, private _authService: AuthService) {} | ||
16 | |||
17 | getVideos(pagination: Pagination, sort: SortField) { | ||
18 | const params = this.createPaginationParams(pagination); | ||
19 | |||
20 | if (sort) params.set('sort', sort); | ||
21 | |||
22 | return this.http.get(this._baseVideoUrl, { search: params }) | ||
23 | .map(res => res.json()) | ||
24 | .map(this.extractVideos) | ||
25 | .catch(this.handleError); | ||
26 | } | ||
27 | |||
28 | getVideo(id: string) { | ||
29 | return this.http.get(this._baseVideoUrl + id) | ||
30 | .map(res => <Video> res.json()) | ||
31 | .catch(this.handleError); | ||
32 | } | ||
33 | |||
34 | removeVideo(id: string) { | ||
35 | const options = this._authService.getAuthRequestOptions(); | ||
36 | return this.http.delete(this._baseVideoUrl + id, options) | ||
37 | .map(res => <number> res.status) | ||
38 | .catch(this.handleError); | ||
39 | } | ||
40 | |||
41 | searchVideos(search: Search, pagination: Pagination, sort: SortField) { | ||
42 | const params = this.createPaginationParams(pagination); | ||
43 | |||
44 | if (search.field) params.set('field', search.field); | ||
45 | if (sort) params.set('sort', sort); | ||
46 | |||
47 | return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search.value), { search: params }) | ||
48 | .map(res => res.json()) | ||
49 | .map(this.extractVideos) | ||
50 | .catch(this.handleError); | ||
51 | } | ||
52 | |||
53 | private extractVideos (body: any) { | ||
54 | const videos_json = body.data; | ||
55 | const totalVideos = body.total; | ||
56 | const videos = []; | ||
57 | for (const video_json of videos_json) { | ||
58 | videos.push(new Video(video_json)); | ||
59 | } | ||
60 | |||
61 | return { videos, totalVideos }; | ||
62 | } | ||
63 | |||
64 | private handleError (error: Response) { | ||
65 | console.error(error); | ||
66 | return Observable.throw(error.json().error || 'Server error'); | ||
67 | } | ||
68 | |||
69 | private createPaginationParams(pagination: Pagination) { | ||
70 | const params = new URLSearchParams(); | ||
71 | const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage; | ||
72 | const count: number = pagination.itemsPerPage; | ||
73 | |||
74 | params.set('start', start.toString()); | ||
75 | params.set('count', count.toString()); | ||
76 | |||
77 | return params; | ||
78 | } | ||
79 | } | ||