From 41a2aee38cf812510010da09de9bae53590ec119 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 27 May 2016 16:23:10 +0200 Subject: Follow the angular styleguide for the directories structure --- .../components/add/videos-add.component.html | 41 --------- .../components/add/videos-add.component.scss | 33 ------- .../videos/components/add/videos-add.component.ts | 69 -------------- client/angular/videos/components/list/sort.ts | 3 - .../components/list/video-miniature.component.html | 22 ----- .../components/list/video-miniature.component.scss | 55 ------------ .../components/list/video-miniature.component.ts | 47 ---------- .../components/list/video-sort.component.html | 5 -- .../videos/components/list/video-sort.component.ts | 36 -------- .../components/list/videos-list.component.html | 18 ---- .../components/list/videos-list.component.scss | 37 -------- .../components/list/videos-list.component.ts | 100 --------------------- .../components/watch/videos-watch.component.html | 10 --- .../components/watch/videos-watch.component.scss | 13 --- .../components/watch/videos-watch.component.ts | 78 ---------------- client/angular/videos/loader.component.html | 3 - client/angular/videos/loader.component.scss | 26 ------ client/angular/videos/loader.component.ts | 11 --- client/angular/videos/pagination.ts | 5 -- client/angular/videos/video.ts | 63 ------------- client/angular/videos/videos.service.ts | 79 ---------------- 21 files changed, 754 deletions(-) delete mode 100644 client/angular/videos/components/add/videos-add.component.html delete mode 100644 client/angular/videos/components/add/videos-add.component.scss delete mode 100644 client/angular/videos/components/add/videos-add.component.ts delete mode 100644 client/angular/videos/components/list/sort.ts delete mode 100644 client/angular/videos/components/list/video-miniature.component.html delete mode 100644 client/angular/videos/components/list/video-miniature.component.scss delete mode 100644 client/angular/videos/components/list/video-miniature.component.ts delete mode 100644 client/angular/videos/components/list/video-sort.component.html delete mode 100644 client/angular/videos/components/list/video-sort.component.ts delete mode 100644 client/angular/videos/components/list/videos-list.component.html delete mode 100644 client/angular/videos/components/list/videos-list.component.scss delete mode 100644 client/angular/videos/components/list/videos-list.component.ts delete mode 100644 client/angular/videos/components/watch/videos-watch.component.html delete mode 100644 client/angular/videos/components/watch/videos-watch.component.scss delete mode 100644 client/angular/videos/components/watch/videos-watch.component.ts delete mode 100644 client/angular/videos/loader.component.html delete mode 100644 client/angular/videos/loader.component.scss delete mode 100644 client/angular/videos/loader.component.ts delete mode 100644 client/angular/videos/pagination.ts delete mode 100644 client/angular/videos/video.ts delete mode 100644 client/angular/videos/videos.service.ts (limited to 'client/angular/videos') 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 @@ -

Upload a video

- -
-
- - -
- Name is required -
-
- -
-
- Select the video... - -
- - {{ fileToUpload.name }} -
- -
- - -
- A description is required -
-
- -
- {{ progressBar.value | bytes }} / {{ progressBar.max | bytes }} -
- - -
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 @@ -.btn-file { - position: relative; - overflow: hidden; -} - -.btn-file input[type=file] { - position: absolute; - top: 0; - right: 0; - min-width: 100%; - min-height: 100%; - font-size: 100px; - text-align: right; - filter: alpha(opacity=0); - opacity: 0; - outline: none; - background: white; - cursor: inherit; - display: block; -} - -.name_file { - display: inline-block; - margin-left: 10px; -} - -.form-group { - margin-bottom: 10px; -} - -#progress { - margin-bottom: 10px; -} 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 @@ -import { Component, ElementRef, OnInit } from '@angular/core'; -import { Router } from '@angular/router-deprecated'; - -import { PROGRESSBAR_DIRECTIVES } from 'ng2-bootstrap/components/progressbar'; -import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; - -import { AuthService } from '../../../users/services/auth.service'; -import { User } from '../../../users/models/user'; - -// TODO: import it with systemjs -declare var jQuery:any; - -@Component({ - selector: 'my-videos-add', - styleUrls: [ 'app/angular/videos/components/add/videos-add.component.css' ], - templateUrl: 'app/angular/videos/components/add/videos-add.component.html', - directives: [ PROGRESSBAR_DIRECTIVES ], - pipes: [ BytesPipe ] -}) - -export class VideosAddComponent implements OnInit { - user: User; - fileToUpload: any; - progressBar: { value: number; max: number; } = { value: 0, max: 0 }; - - private _form: any; - - constructor( - private _router: Router, private _elementRef: ElementRef, - private _authService: AuthService - ) {} - - ngOnInit() { - this.user = User.load(); - jQuery(this._elementRef.nativeElement).find('#videofile').fileupload({ - url: '/api/v1/videos', - dataType: 'json', - singleFileUploads: true, - multipart: true, - autoupload: false, - - add: (e, data) => { - this._form = data; - this.fileToUpload = data['files'][0]; - }, - - progressall: (e, data) => { - this.progressBar.value = data.loaded; - // The server is a little bit slow to answer (has to seed the video) - // So we add more time to the progress bar (+10%) - this.progressBar.max = data.total + (0.1 * data.total); - }, - - done: (e, data) => { - this.progressBar.value = this.progressBar.max; - console.log('Video uploaded.'); - - // Print all the videos once it's finished - this._router.navigate(['VideosList']); - } - }); - } - - uploadFile() { - this._form.headers = this._authService.getRequestHeader().toJSON(); - this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray(); - this._form.submit(); - } -} 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 @@ -export type SortField = "name" | "-name" - | "duration" | "-duration" - | "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 @@ -
- - video thumbnail - {{ video.duration }} - - - -
- - {{ video.name }} - - - by {{ video.by }} - on {{ video.createdDate | date:'short' }} -
-
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 @@ -.video-miniature { - height: 200px; - display: inline-block; - position: relative; - - .video-miniature-thumbnail { - display: block; - position: relative; - - .video-miniature-duration { - position: absolute; - right: 60px; - bottom: 2px; - display: inline-block; - background-color: rgba(0, 0, 0, 0.8); - color: rgba(255, 255, 255, 0.8); - padding: 2px; - font-size: 11px; - } - } - - .video-miniature-remove { - display: inline-block; - position: absolute; - left: 16px; - background-color: rgba(0, 0, 0, 0.8); - color: rgba(255, 255, 255, 0.8); - padding: 2px; - cursor: pointer; - - &:hover { - color: rgba(255, 255, 255, 0.9); - } - } - - .video-miniature-informations { - margin-left: 3px; - - .video-miniature-name { - display: block; - font-weight: bold; - - &:hover { - text-decoration: none; - } - } - - .video-miniature-author, .video-miniature-created-date { - display: block; - margin-left: 1px; - font-size: 11px; - color: rgba(0, 0, 0, 0.5); - } - } -} 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 @@ -import { Component, Input, Output, EventEmitter } from '@angular/core'; -import { DatePipe } from '@angular/common'; -import { ROUTER_DIRECTIVES } from '@angular/router-deprecated'; - -import { Video } from '../../video'; -import { VideosService } from '../../videos.service'; -import { User } from '../../../users/models/user'; - -@Component({ - selector: 'my-video-miniature', - styleUrls: [ 'app/angular/videos/components/list/video-miniature.component.css' ], - templateUrl: 'app/angular/videos/components/list/video-miniature.component.html', - directives: [ ROUTER_DIRECTIVES ], - pipes: [ DatePipe ] -}) - -export class VideoMiniatureComponent { - @Output() removed = new EventEmitter(); - - @Input() video: Video; - @Input() user: User; - - hovering: boolean = false; - - constructor(private _videosService: VideosService) {} - - onHover() { - this.hovering = true; - } - - onBlur() { - this.hovering = false; - } - - displayRemoveIcon(): boolean { - return this.hovering && this.video.isRemovableBy(this.user); - } - - removeVideo(id: string) { - if (confirm('Do you really want to remove this video?')) { - this._videosService.removeVideo(id).subscribe( - status => this.removed.emit(true), - error => alert(error) - ); - } - } -} 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 @@ - 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 @@ -import { Component, Input, Output, EventEmitter } from '@angular/core'; - -import { SortField } from './sort'; - -@Component({ - selector: 'my-video-sort', - // styleUrls: [ 'app/angular/videos/components/list/video-sort.component.css' ], - templateUrl: 'app/angular/videos/components/list/video-sort.component.html' -}) - -export class VideoSortComponent { - @Output() sort = new EventEmitter(); - - @Input() currentSort: SortField; - - sortChoices = { - 'name': 'Name - Asc', - '-name': 'Name - Desc', - 'duration': 'Duration - Asc', - '-duration': 'Duration - Desc', - 'createdDate': 'Created Date - Asc', - '-createdDate': 'Created Date - Desc' - }; - - get choiceKeys() { - return Object.keys(this.sortChoices); - } - - getStringChoice(choiceKey: SortField): string { - return this.sortChoices[choiceKey]; - } - - onSortChange() { - this.sort.emit(this.currentSort); - } -} 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 @@ -
-
{{ pagination.total }} videos
- -
- -
- - -
There is no video.
- - - -
- - 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 @@ -.videos-info { - - padding-bottom: 20px; - margin-bottom: 20px; - border-bottom: 1px solid #f1f1f1; - height: 40px; - line-height: 40px; - width: 765px; - margin-left: 15px; - - my-video-sort { - padding-right: 0; - } - - .videos-total-results { - font-size: 13px; - padding-left: 0; - } -} - -.videos-miniatures { - min-height: 600px; - - my-videos-miniature { - display: inline-block; - } - - .no-video { - margin-top: 50px; - text-align: center; - } -} - -pagination { - display: block; - text-align: center; -} 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 @@ -import { Component, OnInit } from '@angular/core'; -import { ROUTER_DIRECTIVES, RouteParams, Router } from '@angular/router-deprecated'; - -import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination'; - -import { AuthService } from '../../../users/services/auth.service'; -import { Pagination } from '../../pagination'; -import { User } from '../../../users/models/user'; -import { VideosService } from '../../videos.service'; -import { Video } from '../../video'; -import { VideoMiniatureComponent } from './video-miniature.component'; -import { Search, SearchField } from '../../../app/search'; -import { VideoSortComponent } from './video-sort.component'; -import { SortField } from './sort'; -import { LoaderComponent } from '../../loader.component'; - -@Component({ - selector: 'my-videos-list', - styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ], - templateUrl: 'app/angular/videos/components/list/videos-list.component.html', - directives: [ ROUTER_DIRECTIVES, PAGINATION_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent, LoaderComponent ] -}) - -export class VideosListComponent implements OnInit { - user: User = null; - videos: Video[] = []; - pagination: Pagination = { - currentPage: 1, - itemsPerPage: 9, - total: 0 - }; - sort: SortField; - loading: boolean = false; - - private search: Search; - - constructor( - private _authService: AuthService, - private _videosService: VideosService, - private _routeParams: RouteParams, - private _router: Router - ) { - this.search = { - value: this._routeParams.get('search'), - field: this._routeParams.get('field') - }; - - this.sort = this._routeParams.get('sort') || '-createdDate'; - } - - ngOnInit() { - if (this._authService.isLoggedIn()) { - this.user = User.load(); - } - - this.getVideos(); - } - - getVideos() { - this.loading = true; - this.videos = []; - - let observable = null; - - if (this.search.value !== null) { - observable = this._videosService.searchVideos(this.search, this.pagination, this.sort); - } else { - observable = this._videosService.getVideos(this.pagination, this.sort); - } - - observable.subscribe( - ({ videos, totalVideos }) => { - this.videos = videos; - this.pagination.total = totalVideos; - this.loading = false; - }, - error => alert(error) - ); - } - - onRemoved(video: Video): void { - this.videos.splice(this.videos.indexOf(video), 1); - } - - onSort(sort: SortField) { - this.sort = sort; - - const params: any = { - sort: this.sort - }; - - if (this.search.value) { - params.search = this.search.value; - params.field = this.search.field; - } - - this._router.navigate(['VideosList', params]); - this.getVideos(); - } -} 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 @@ - - -
-
- -
-
Download: {{ downloadSpeed | bytes }}/s
-
Upload: {{ uploadSpeed | bytes }}/s
-
Number of peers: {{ numPeers }}
-
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 @@ -.embed-responsive { - height: 500px; -} - -#torrent-info { - font-size: 10px; - - div { - display: inline-block; - width: 33%; - text-align: center; - } -} 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 @@ -import { Component, OnInit, ElementRef } from '@angular/core'; -import { RouteParams, CanDeactivate, ComponentInstruction } from '@angular/router-deprecated'; - -import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; - -import { LoaderComponent } from '../../loader.component'; - -// TODO import it with systemjs -declare var WebTorrent: any; - -import { Video } from '../../video'; -import { VideosService } from '../../videos.service'; - -@Component({ - selector: 'my-video-watch', - templateUrl: 'app/angular/videos/components/watch/videos-watch.component.html', - styleUrls: [ 'app/angular/videos/components/watch/videos-watch.component.css' ], - directives: [ LoaderComponent ], - pipes: [ BytesPipe ] -}) - -export class VideosWatchComponent implements OnInit, CanDeactivate { - video: Video; - downloadSpeed: number; - uploadSpeed: number; - numPeers: number; - loading: boolean = false; - - private _interval: NodeJS.Timer; - private client: any; - - constructor( - private _videosService: VideosService, - private _routeParams: RouteParams, - private _elementRef: ElementRef - ) { - // TODO: use a service - this.client = new WebTorrent({ dht: false }); - } - - ngOnInit() { - let id = this._routeParams.get('id'); - this._videosService.getVideo(id).subscribe( - video => this.loadVideo(video), - error => alert(error) - ); - } - - loadVideo(video: Video) { - this.loading = true; - this.video = video; - console.log('Adding ' + this.video.magnetUri + '.'); - this.client.add(this.video.magnetUri, (torrent) => { - this.loading = false; - console.log('Added ' + this.video.magnetUri + '.'); - torrent.files[0].appendTo(this._elementRef.nativeElement.querySelector('.embed-responsive'), (err) => { - if (err) { - alert('Cannot append the file.'); - console.error(err); - } - }); - - // Refresh each second - this._interval = setInterval(() => { - this.downloadSpeed = torrent.downloadSpeed; - this.uploadSpeed = torrent.uploadSpeed; - this.numPeers = torrent.numPeers; - }, 1000); - }); - } - - routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) : any { - console.log('Removing video from webtorrent.'); - clearInterval(this._interval); - this.client.remove(this.video.magnetUri); - return true; - } -} 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 @@ -
-
-
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 @@ -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/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 @@ -import { Component, Input } from '@angular/core'; - -@Component({ - selector: 'my-loader', - styleUrls: [ 'app/angular/videos/loader.component.css' ], - templateUrl: 'app/angular/videos/loader.component.html' -}) - -export class LoaderComponent { - @Input() loading: boolean; -} 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 @@ -export interface Pagination { - currentPage: number; - itemsPerPage: number; - total: number; -} 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 @@ -export class Video { - id: string; - name: string; - description: string; - magnetUri: string; - podUrl: string; - isLocal: boolean; - thumbnailPath: string; - author: string; - createdDate: Date; - by: string; - duration: string; - - private static createDurationString(duration: number): string { - 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(); - } - - private static createByString(author: string, podUrl: string): string { - let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':'); - - if (port === '80' || port === '443') { - port = ''; - } else { - port = ':' + port; - } - - return author + '@' + host + port; - } - - constructor(hash: { - id: string, - name: string, - description: string, - magnetUri: string, - podUrl: string, - isLocal: boolean, - thumbnailPath: string, - author: string, - createdDate: string, - duration: number; - }) { - this.id = hash.id; - this.name = hash.name; - this.description = hash.description; - this.magnetUri = hash.magnetUri; - this.podUrl = hash.podUrl; - this.isLocal = hash.isLocal; - this.thumbnailPath = hash.thumbnailPath; - this.author = hash.author; - this.createdDate = new Date(hash.createdDate); - this.duration = Video.createDurationString(hash.duration); - this.by = Video.createByString(hash.author, hash.podUrl); - } - - isRemovableBy(user): boolean { - return this.isLocal === true && user && this.author === user.username; - } -} 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 @@ -import { Injectable } from '@angular/core'; -import { Http, Response, URLSearchParams } from '@angular/http'; -import { Observable } from 'rxjs/Rx'; - -import { Pagination } from './pagination'; -import { Video } from './video'; -import { AuthService } from '../users/services/auth.service'; -import { Search } from '../app/search'; -import { SortField } from './components/list/sort'; - -@Injectable() -export class VideosService { - private _baseVideoUrl = '/api/v1/videos/'; - - constructor (private http: Http, private _authService: AuthService) {} - - getVideos(pagination: Pagination, sort: SortField) { - const params = this.createPaginationParams(pagination); - - if (sort) params.set('sort', sort); - - return this.http.get(this._baseVideoUrl, { search: params }) - .map(res => res.json()) - .map(this.extractVideos) - .catch(this.handleError); - } - - getVideo(id: string) { - return this.http.get(this._baseVideoUrl + id) - .map(res =>