aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/app/videos/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/app/videos/shared')
-rw-r--r--client/app/videos/shared/video.model.ts59
-rw-r--r--client/app/videos/shared/video.service.ts39
2 files changed, 51 insertions, 47 deletions
diff --git a/client/app/videos/shared/video.model.ts b/client/app/videos/shared/video.model.ts
index 2b018ad86..614403d79 100644
--- a/client/app/videos/shared/video.model.ts
+++ b/client/app/videos/shared/video.model.ts
@@ -1,24 +1,15 @@
1export class Video { 1export class Video {
2 id: string; 2 author: string;
3 name: string; 3 by: string;
4 createdDate: Date;
4 description: string; 5 description: string;
6 duration: string;
7 id: string;
8 isLocal: boolean;
5 magnetUri: string; 9 magnetUri: string;
10 name: string;
6 podUrl: string; 11 podUrl: string;
7 isLocal: boolean;
8 thumbnailPath: string; 12 thumbnailPath: string;
9 author: string;
10 createdDate: Date;
11 by: string;
12 duration: string;
13
14 private static createDurationString(duration: number) {
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 13
23 private static createByString(author: string, podUrl: string) { 14 private static createByString(author: string, podUrl: string) {
24 let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':'); 15 let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
@@ -32,28 +23,38 @@ export class Video {
32 return author + '@' + host + port; 23 return author + '@' + host + port;
33 } 24 }
34 25
26 private static createDurationString(duration: number) {
27 const minutes = Math.floor(duration / 60);
28 const seconds = duration % 60;
29 const minutes_padding = minutes >= 10 ? '' : '0';
30 const seconds_padding = seconds >= 10 ? '' : '0';
31
32 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
33 }
34
35 constructor(hash: { 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, 36 author: string,
44 createdDate: string, 37 createdDate: string,
38 description: string,
45 duration: number; 39 duration: number;
40 id: string,
41 isLocal: boolean,
42 magnetUri: string,
43 name: string,
44 podUrl: string,
45 thumbnailPath: string
46 }) { 46 }) {
47 this.id = hash.id; 47 this.author = hash.author;
48 this.name = hash.name; 48 this.createdDate = new Date(hash.createdDate);
49 this.description = hash.description; 49 this.description = hash.description;
50 this.duration = Video.createDurationString(hash.duration);
51 this.id = hash.id;
52 this.isLocal = hash.isLocal;
50 this.magnetUri = hash.magnetUri; 53 this.magnetUri = hash.magnetUri;
54 this.name = hash.name;
51 this.podUrl = hash.podUrl; 55 this.podUrl = hash.podUrl;
52 this.isLocal = hash.isLocal;
53 this.thumbnailPath = hash.thumbnailPath; 56 this.thumbnailPath = hash.thumbnailPath;
54 this.author = hash.author; 57
55 this.createdDate = new Date(hash.createdDate);
56 this.duration = Video.createDurationString(hash.duration);
57 this.by = Video.createByString(hash.author, hash.podUrl); 58 this.by = Video.createByString(hash.author, hash.podUrl);
58 } 59 }
59 60
diff --git a/client/app/videos/shared/video.service.ts b/client/app/videos/shared/video.service.ts
index b6e0800a0..7b6519f00 100644
--- a/client/app/videos/shared/video.service.ts
+++ b/client/app/videos/shared/video.service.ts
@@ -12,7 +12,16 @@ import { Video } from './video.model';
12export class VideoService { 12export class VideoService {
13 private static BASE_VIDEO_URL = '/api/v1/videos/'; 13 private static BASE_VIDEO_URL = '/api/v1/videos/';
14 14
15 constructor(private http: Http, private authService: AuthService) {} 15 constructor(
16 private authService: AuthService,
17 private http: Http
18 ) {}
19
20 getVideo(id: string) {
21 return this.http.get(VideoService.BASE_VIDEO_URL + id)
22 .map(res => <Video> res.json())
23 .catch(this.handleError);
24 }
16 25
17 getVideos(pagination: Pagination, sort: SortField) { 26 getVideos(pagination: Pagination, sort: SortField) {
18 const params = this.createPaginationParams(pagination); 27 const params = this.createPaginationParams(pagination);
@@ -25,12 +34,6 @@ export class VideoService {
25 .catch(this.handleError); 34 .catch(this.handleError);
26 } 35 }
27 36
28 getVideo(id: string) {
29 return this.http.get(VideoService.BASE_VIDEO_URL + id)
30 .map(res => <Video> res.json())
31 .catch(this.handleError);
32 }
33
34 removeVideo(id: string) { 37 removeVideo(id: string) {
35 const options = this.authService.getAuthRequestOptions(); 38 const options = this.authService.getAuthRequestOptions();
36 return this.http.delete(VideoService.BASE_VIDEO_URL + id, options) 39 return this.http.delete(VideoService.BASE_VIDEO_URL + id, options)
@@ -50,6 +53,17 @@ export class VideoService {
50 .catch(this.handleError); 53 .catch(this.handleError);
51 } 54 }
52 55
56 private createPaginationParams(pagination: Pagination) {
57 const params = new URLSearchParams();
58 const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage;
59 const count: number = pagination.itemsPerPage;
60
61 params.set('start', start.toString());
62 params.set('count', count.toString());
63
64 return params;
65 }
66
53 private extractVideos(body: any) { 67 private extractVideos(body: any) {
54 const videos_json = body.data; 68 const videos_json = body.data;
55 const totalVideos = body.total; 69 const totalVideos = body.total;
@@ -65,15 +79,4 @@ export class VideoService {
65 console.error(error); 79 console.error(error);
66 return Observable.throw(error.json().error || 'Server error'); 80 return Observable.throw(error.json().error || 'Server error');
67 } 81 }
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} 82}