From 4a6995be18b15de1834a39c8921a0e4109671bb6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 3 Jun 2016 22:08:03 +0200 Subject: First draft to use webpack instead of systemjs --- client/src/app/videos/index.ts | 4 + client/src/app/videos/shared/index.ts | 5 + client/src/app/videos/shared/loader/index.ts | 1 + .../app/videos/shared/loader/loader.component.html | 3 + .../app/videos/shared/loader/loader.component.scss | 26 +++++ .../app/videos/shared/loader/loader.component.ts | 11 +++ client/src/app/videos/shared/pagination.model.ts | 5 + client/src/app/videos/shared/sort-field.type.ts | 3 + client/src/app/videos/shared/video.model.ts | 64 +++++++++++++ client/src/app/videos/shared/video.service.ts | 82 ++++++++++++++++ client/src/app/videos/video-add/index.ts | 1 + .../app/videos/video-add/video-add.component.html | 41 ++++++++ .../app/videos/video-add/video-add.component.scss | 33 +++++++ .../app/videos/video-add/video-add.component.ts | 69 ++++++++++++++ client/src/app/videos/video-list/index.ts | 3 + .../videos/video-list/video-list.component.html | 18 ++++ .../videos/video-list/video-list.component.scss | 37 ++++++++ .../app/videos/video-list/video-list.component.ts | 105 +++++++++++++++++++++ .../video-list/video-miniature.component.html | 22 +++++ .../video-list/video-miniature.component.scss | 55 +++++++++++ .../videos/video-list/video-miniature.component.ts | 46 +++++++++ .../videos/video-list/video-sort.component.html | 5 + .../app/videos/video-list/video-sort.component.ts | 35 +++++++ client/src/app/videos/video-watch/index.ts | 2 + .../videos/video-watch/video-watch.component.html | 10 ++ .../videos/video-watch/video-watch.component.scss | 13 +++ .../videos/video-watch/video-watch.component.ts | 72 ++++++++++++++ .../app/videos/video-watch/webtorrent.service.ts | 26 +++++ 28 files changed, 797 insertions(+) create mode 100644 client/src/app/videos/index.ts create mode 100644 client/src/app/videos/shared/index.ts create mode 100644 client/src/app/videos/shared/loader/index.ts create mode 100644 client/src/app/videos/shared/loader/loader.component.html create mode 100644 client/src/app/videos/shared/loader/loader.component.scss create mode 100644 client/src/app/videos/shared/loader/loader.component.ts create mode 100644 client/src/app/videos/shared/pagination.model.ts create mode 100644 client/src/app/videos/shared/sort-field.type.ts create mode 100644 client/src/app/videos/shared/video.model.ts create mode 100644 client/src/app/videos/shared/video.service.ts create mode 100644 client/src/app/videos/video-add/index.ts create mode 100644 client/src/app/videos/video-add/video-add.component.html create mode 100644 client/src/app/videos/video-add/video-add.component.scss create mode 100644 client/src/app/videos/video-add/video-add.component.ts create mode 100644 client/src/app/videos/video-list/index.ts create mode 100644 client/src/app/videos/video-list/video-list.component.html create mode 100644 client/src/app/videos/video-list/video-list.component.scss create mode 100644 client/src/app/videos/video-list/video-list.component.ts create mode 100644 client/src/app/videos/video-list/video-miniature.component.html create mode 100644 client/src/app/videos/video-list/video-miniature.component.scss create mode 100644 client/src/app/videos/video-list/video-miniature.component.ts create mode 100644 client/src/app/videos/video-list/video-sort.component.html create mode 100644 client/src/app/videos/video-list/video-sort.component.ts create mode 100644 client/src/app/videos/video-watch/index.ts create mode 100644 client/src/app/videos/video-watch/video-watch.component.html create mode 100644 client/src/app/videos/video-watch/video-watch.component.scss create mode 100644 client/src/app/videos/video-watch/video-watch.component.ts create mode 100644 client/src/app/videos/video-watch/webtorrent.service.ts (limited to 'client/src/app/videos') diff --git a/client/src/app/videos/index.ts b/client/src/app/videos/index.ts new file mode 100644 index 000000000..9a92fa57a --- /dev/null +++ b/client/src/app/videos/index.ts @@ -0,0 +1,4 @@ +export * from './shared'; +export * from './video-add'; +export * from './video-list'; +export * from './video-watch'; diff --git a/client/src/app/videos/shared/index.ts b/client/src/app/videos/shared/index.ts new file mode 100644 index 000000000..a54120f5d --- /dev/null +++ b/client/src/app/videos/shared/index.ts @@ -0,0 +1,5 @@ +export * from './loader'; +export * from './pagination.model'; +export * from './sort-field.type'; +export * from './video.model'; +export * from './video.service'; diff --git a/client/src/app/videos/shared/loader/index.ts b/client/src/app/videos/shared/loader/index.ts new file mode 100644 index 000000000..ab22584e4 --- /dev/null +++ b/client/src/app/videos/shared/loader/index.ts @@ -0,0 +1 @@ +export * from './loader.component'; diff --git a/client/src/app/videos/shared/loader/loader.component.html b/client/src/app/videos/shared/loader/loader.component.html new file mode 100644 index 000000000..d02296a2d --- /dev/null +++ b/client/src/app/videos/shared/loader/loader.component.html @@ -0,0 +1,3 @@ +
+
+
diff --git a/client/src/app/videos/shared/loader/loader.component.scss b/client/src/app/videos/shared/loader/loader.component.scss new file mode 100644 index 000000000..454195811 --- /dev/null +++ b/client/src/app/videos/shared/loader/loader.component.scss @@ -0,0 +1,26 @@ +div { + margin-top: 150px; +} + +// Thanks https://gist.github.com/alexandrevicenzi/680147013e902a4eaa5d +.glyphicon-refresh-animate { + -animation: spin .7s infinite linear; + -ms-animation: spin .7s infinite linear; + -webkit-animation: spinw .7s infinite linear; + -moz-animation: spinm .7s infinite linear; +} + +@keyframes spin { + from { transform: scale(1) rotate(0deg);} + to { transform: scale(1) rotate(360deg);} +} + +@-webkit-keyframes spinw { + from { -webkit-transform: rotate(0deg);} + to { -webkit-transform: rotate(360deg);} +} + +@-moz-keyframes spinm { + from { -moz-transform: rotate(0deg);} + to { -moz-transform: rotate(360deg);} +} diff --git a/client/src/app/videos/shared/loader/loader.component.ts b/client/src/app/videos/shared/loader/loader.component.ts new file mode 100644 index 000000000..cdd07d1b4 --- /dev/null +++ b/client/src/app/videos/shared/loader/loader.component.ts @@ -0,0 +1,11 @@ +import { Component, Input } from '@angular/core'; + +@Component({ + selector: 'my-loader', + styles: [ require('./loader.component.scss') ], + template: require('./loader.component.html') +}) + +export class LoaderComponent { + @Input() loading: boolean; +} diff --git a/client/src/app/videos/shared/pagination.model.ts b/client/src/app/videos/shared/pagination.model.ts new file mode 100644 index 000000000..06f7a7875 --- /dev/null +++ b/client/src/app/videos/shared/pagination.model.ts @@ -0,0 +1,5 @@ +export interface Pagination { + currentPage: number; + itemsPerPage: number; + total: number; +} diff --git a/client/src/app/videos/shared/sort-field.type.ts b/client/src/app/videos/shared/sort-field.type.ts new file mode 100644 index 000000000..6e8cc7936 --- /dev/null +++ b/client/src/app/videos/shared/sort-field.type.ts @@ -0,0 +1,3 @@ +export type SortField = "name" | "-name" + | "duration" | "-duration" + | "createdDate" | "-createdDate"; diff --git a/client/src/app/videos/shared/video.model.ts b/client/src/app/videos/shared/video.model.ts new file mode 100644 index 000000000..614403d79 --- /dev/null +++ b/client/src/app/videos/shared/video.model.ts @@ -0,0 +1,64 @@ +export class Video { + author: string; + by: string; + createdDate: Date; + description: string; + duration: string; + id: string; + isLocal: boolean; + magnetUri: string; + name: string; + podUrl: string; + thumbnailPath: string; + + private static createByString(author: string, podUrl: string) { + let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':'); + + if (port === '80' || port === '443') { + port = ''; + } else { + port = ':' + port; + } + + return author + '@' + host + port; + } + + private static createDurationString(duration: number) { + const minutes = Math.floor(duration / 60); + const seconds = duration % 60; + const minutes_padding = minutes >= 10 ? '' : '0'; + const seconds_padding = seconds >= 10 ? '' : '0'; + + return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString(); + } + + constructor(hash: { + author: string, + createdDate: string, + description: string, + duration: number; + id: string, + isLocal: boolean, + magnetUri: string, + name: string, + podUrl: string, + thumbnailPath: string + }) { + this.author = hash.author; + this.createdDate = new Date(hash.createdDate); + this.description = hash.description; + this.duration = Video.createDurationString(hash.duration); + this.id = hash.id; + this.isLocal = hash.isLocal; + this.magnetUri = hash.magnetUri; + this.name = hash.name; + this.podUrl = hash.podUrl; + this.thumbnailPath = hash.thumbnailPath; + + this.by = Video.createByString(hash.author, hash.podUrl); + } + + isRemovableBy(user) { + return this.isLocal === true && user && this.author === user.username; + } +} diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts new file mode 100644 index 000000000..76d46cbb4 --- /dev/null +++ b/client/src/app/videos/shared/video.service.ts @@ -0,0 +1,82 @@ +import { Injectable } from '@angular/core'; +import { Http, Response, URLSearchParams } from '@angular/http'; +import { Observable } from 'rxjs/Rx'; + +import { Pagination } from './pagination.model'; +import { Search } from '../../shared'; +import { SortField } from './sort-field.type'; +import { AuthService } from '../../shared'; +import { Video } from './video.model'; + +@Injectable() +export class VideoService { + private static BASE_VIDEO_URL = '/api/v1/videos/'; + + constructor( + private authService: AuthService, + private http: Http + ) {} + + getVideo(id: string) { + return this.http.get(VideoService.BASE_VIDEO_URL + id) + .map(res =>