]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Alphabetical
authorChocobozzz <florian.bigard@gmail.com>
Fri, 27 May 2016 15:49:18 +0000 (17:49 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 27 May 2016 15:49:18 +0000 (17:49 +0200)
client/app/app.component.ts
client/app/shared/search.component.ts
client/app/users/login/login.component.ts
client/app/users/shared/auth.service.ts
client/app/videos/shared/video.model.ts
client/app/videos/shared/video.service.ts
client/app/videos/video-add/video-add.component.ts
client/app/videos/video-list/video-list.component.ts
client/app/videos/video-list/video-miniature.component.ts
client/app/videos/video-watch/video-watch.component.ts

index 20c8c8724ff352cdab75eebd2f82946ff4a0f65a..965848105d032eaad1c7c77ce87da4f3ac0bf991 100644 (file)
@@ -49,13 +49,13 @@ import {
 })
 
 export class AppComponent {
 })
 
 export class AppComponent {
-  isLoggedIn: boolean;
-  search_field: string = name;
   choices = [];
   choices = [];
+  isLoggedIn: boolean;
 
 
-  constructor(private friendService: FriendService,
-              private authService: AuthService,
-              private router: Router
+  constructor(
+    private authService: AuthService,
+    private friendService: FriendService,
+    private router: Router
   ) {
     this.isLoggedIn = this.authService.isLoggedIn();
 
   ) {
     this.isLoggedIn = this.authService.isLoggedIn();
 
@@ -71,8 +71,8 @@ export class AppComponent {
   onSearch(search: Search) {
     if (search.value !== '') {
       const params = {
   onSearch(search: Search) {
     if (search.value !== '') {
       const params = {
-        search: search.value,
-        field: search.field
+        field: search.field,
+        search: search.value
       };
       this.router.navigate(['VideosList', params]);
     } else {
       };
       this.router.navigate(['VideosList', params]);
     } else {
@@ -100,7 +100,7 @@ export class AppComponent {
   quitFriends() {
     this.friendService.quitFriends().subscribe(
       status => {
   quitFriends() {
     this.friendService.quitFriends().subscribe(
       status => {
-          alert('Quit friends!');
+        alert('Quit friends!');
       },
       error => alert(error)
     );
       },
       error => alert(error)
     );
index 674518aba81004268550d98d2ceb3634acd7413b..e1e30b9af04bca26da7e7c473ccc183ff540e641 100644 (file)
@@ -14,26 +14,21 @@ import { SearchField } from './search-field.type';
 export class SearchComponent {
   @Output() search = new EventEmitter<Search>();
 
 export class SearchComponent {
   @Output() search = new EventEmitter<Search>();
 
-  searchCriterias: Search = {
-    field: 'name',
-    value: ''
-  };
-
   fieldChoices = {
     name: 'Name',
     author: 'Author',
     podUrl: 'Pod Url',
     magnetUri: 'Magnet Uri'
   };
   fieldChoices = {
     name: 'Name',
     author: 'Author',
     podUrl: 'Pod Url',
     magnetUri: 'Magnet Uri'
   };
+  searchCriterias: Search = {
+    field: 'name',
+    value: ''
+  };
 
   get choiceKeys() {
     return Object.keys(this.fieldChoices);
   }
 
 
   get choiceKeys() {
     return Object.keys(this.fieldChoices);
   }
 
-  getStringChoice(choiceKey: SearchField) {
-    return this.fieldChoices[choiceKey];
-  }
-
   choose($event: MouseEvent, choice: SearchField) {
     $event.preventDefault();
     $event.stopPropagation();
   choose($event: MouseEvent, choice: SearchField) {
     $event.preventDefault();
     $event.stopPropagation();
@@ -45,4 +40,7 @@ export class SearchComponent {
     this.search.emit(this.searchCriterias);
   }
 
     this.search.emit(this.searchCriterias);
   }
 
+  getStringChoice(choiceKey: SearchField) {
+    return this.fieldChoices[choiceKey];
+  }
 }
 }
index 8e369541d2912f0d0680b093cecfcb7693387cd4..09c5f1af7070cc91391b4624a348b02228cb4a1d 100644 (file)
@@ -10,7 +10,10 @@ import { AuthService, AuthStatus, User } from '../shared/index';
 })
 
 export class UserLoginComponent {
 })
 
 export class UserLoginComponent {
-  constructor(private authService: AuthService, private router: Router) {}
+  constructor(
+    private authService: AuthService,
+    private router: Router
+  ) {}
 
   login(username: string, password: string) {
     this.authService.login(username, password).subscribe(
 
   login(username: string, password: string) {
     this.authService.login(username, password).subscribe(
index b1da94436396670e74471993dac65738fbcd147d..d63fe38f3cb92fab3e73dc0f25029d666d588ae6 100644 (file)
@@ -7,14 +7,14 @@ import { User } from './user.model';
 
 @Injectable()
 export class AuthService {
 
 @Injectable()
 export class AuthService {
-  private static BASE_LOGIN_URL = '/api/v1/users/token';
   private static BASE_CLIENT_URL = '/api/v1/users/client';
   private static BASE_CLIENT_URL = '/api/v1/users/client';
+  private static BASE_LOGIN_URL = '/api/v1/users/token';
 
   loginChangedSource: Observable<AuthStatus>;
 
 
   loginChangedSource: Observable<AuthStatus>;
 
-  private loginChanged: Subject<AuthStatus>;
   private clientId: string;
   private clientSecret: string;
   private clientId: string;
   private clientSecret: string;
+  private loginChanged: Subject<AuthStatus>;
 
   constructor(private http: Http) {
     this.loginChanged = new Subject<AuthStatus>();
 
   constructor(private http: Http) {
     this.loginChanged = new Subject<AuthStatus>();
@@ -37,40 +37,14 @@ export class AuthService {
       );
   }
 
       );
   }
 
-  login(username: string, password: string) {
-    let body = new URLSearchParams();
-    body.set('client_id', this.clientId);
-    body.set('client_secret', this.clientSecret);
-    body.set('response_type', 'code');
-    body.set('grant_type', 'password');
-    body.set('scope', 'upload');
-    body.set('username', username);
-    body.set('password', password);
-
-    let headers = new Headers();
-    headers.append('Content-Type', 'application/x-www-form-urlencoded');
-
-    let options = {
-      headers: headers
-    };
-
-    return this.http.post(AuthService.BASE_LOGIN_URL, body.toString(), options)
-                    .map(res => res.json())
-                    .catch(this.handleError);
-  }
-
-  logout() {
-    // TODO make HTTP request
+  getAuthRequestOptions(): RequestOptions {
+    return new RequestOptions({ headers: this.getRequestHeader() });
   }
 
   getRequestHeader() {
     return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` });
   }
 
   }
 
   getRequestHeader() {
     return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` });
   }
 
-  getAuthRequestOptions(): RequestOptions {
-    return new RequestOptions({ headers: this.getRequestHeader() });
-  }
-
   getToken() {
     return localStorage.getItem('access_token');
   }
   getToken() {
     return localStorage.getItem('access_token');
   }
@@ -97,6 +71,32 @@ export class AuthService {
     }
   }
 
     }
   }
 
+  login(username: string, password: string) {
+    let body = new URLSearchParams();
+    body.set('client_id', this.clientId);
+    body.set('client_secret', this.clientSecret);
+    body.set('response_type', 'code');
+    body.set('grant_type', 'password');
+    body.set('scope', 'upload');
+    body.set('username', username);
+    body.set('password', password);
+
+    let headers = new Headers();
+    headers.append('Content-Type', 'application/x-www-form-urlencoded');
+
+    let options = {
+      headers: headers
+    };
+
+    return this.http.post(AuthService.BASE_LOGIN_URL, body.toString(), options)
+                    .map(res => res.json())
+                    .catch(this.handleError);
+  }
+
+  logout() {
+    // TODO make HTTP request
+  }
+
   setStatus(status: AuthStatus) {
     this.loginChanged.next(status);
   }
   setStatus(status: AuthStatus) {
     this.loginChanged.next(status);
   }
index 2b018ad864f676cdf9e3495f4c154bd642de8ea8..614403d799394c24d0387ea0151724514dd3ebde 100644 (file)
@@ -1,24 +1,15 @@
 export class Video {
 export class Video {
-  id: string;
-  name: string;
+  author: string;
+  by: string;
+  createdDate: Date;
   description: string;
   description: string;
+  duration: string;
+  id: string;
+  isLocal: boolean;
   magnetUri: string;
   magnetUri: string;
+  name: string;
   podUrl: string;
   podUrl: string;
-  isLocal: boolean;
   thumbnailPath: string;
   thumbnailPath: string;
-  author: string;
-  createdDate: Date;
-  by: string;
-  duration: string;
-
-  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();
-  }
 
   private static createByString(author: string, podUrl: string) {
     let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
 
   private static createByString(author: string, podUrl: string) {
     let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
@@ -32,28 +23,38 @@ export class Video {
     return author + '@' + host + 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: {
   constructor(hash: {
-    id: string,
-    name: string,
-    description: string,
-    magnetUri: string,
-    podUrl: string,
-    isLocal: boolean,
-    thumbnailPath: string,
     author: string,
     createdDate: string,
     author: string,
     createdDate: string,
+    description: string,
     duration: number;
     duration: number;
+    id: string,
+    isLocal: boolean,
+    magnetUri: string,
+    name: string,
+    podUrl: string,
+    thumbnailPath: string
   }) {
   }) {
-    this.id = hash.id;
-    this.name = hash.name;
+    this.author  = hash.author;
+    this.createdDate = new Date(hash.createdDate);
     this.description = hash.description;
     this.description = hash.description;
+    this.duration = Video.createDurationString(hash.duration);
+    this.id = hash.id;
+    this.isLocal = hash.isLocal;
     this.magnetUri = hash.magnetUri;
     this.magnetUri = hash.magnetUri;
+    this.name = hash.name;
     this.podUrl = hash.podUrl;
     this.podUrl = hash.podUrl;
-    this.isLocal = hash.isLocal;
     this.thumbnailPath = hash.thumbnailPath;
     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);
   }
 
     this.by = Video.createByString(hash.author, hash.podUrl);
   }
 
index b6e0800a073f3f91eb9c518ea1c4268b720652f3..7b6519f007a01f807f7c4f9a83ff6b377a1b9106 100644 (file)
@@ -12,7 +12,16 @@ import { Video } from './video.model';
 export class VideoService {
   private static BASE_VIDEO_URL = '/api/v1/videos/';
 
 export class VideoService {
   private static BASE_VIDEO_URL = '/api/v1/videos/';
 
-  constructor(private http: Http, private authService: AuthService) {}
+  constructor(
+    private authService: AuthService,
+    private http: Http
+  ) {}
+
+  getVideo(id: string) {
+    return this.http.get(VideoService.BASE_VIDEO_URL + id)
+                    .map(res => <Video> res.json())
+                    .catch(this.handleError);
+  }
 
   getVideos(pagination: Pagination, sort: SortField) {
     const params = this.createPaginationParams(pagination);
 
   getVideos(pagination: Pagination, sort: SortField) {
     const params = this.createPaginationParams(pagination);
@@ -25,12 +34,6 @@ export class VideoService {
                     .catch(this.handleError);
   }
 
                     .catch(this.handleError);
   }
 
-  getVideo(id: string) {
-    return this.http.get(VideoService.BASE_VIDEO_URL + id)
-                    .map(res => <Video> res.json())
-                    .catch(this.handleError);
-  }
-
   removeVideo(id: string) {
     const options = this.authService.getAuthRequestOptions();
     return this.http.delete(VideoService.BASE_VIDEO_URL + id, options)
   removeVideo(id: string) {
     const options = this.authService.getAuthRequestOptions();
     return this.http.delete(VideoService.BASE_VIDEO_URL + id, options)
@@ -50,6 +53,17 @@ export class VideoService {
                     .catch(this.handleError);
   }
 
                     .catch(this.handleError);
   }
 
+  private createPaginationParams(pagination: Pagination) {
+    const params = new URLSearchParams();
+    const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage;
+    const count: number = pagination.itemsPerPage;
+
+    params.set('start', start.toString());
+    params.set('count', count.toString());
+
+    return params;
+  }
+
   private extractVideos(body: any) {
     const videos_json = body.data;
     const totalVideos = body.total;
   private extractVideos(body: any) {
     const videos_json = body.data;
     const totalVideos = body.total;
@@ -65,15 +79,4 @@ export class VideoService {
     console.error(error);
     return Observable.throw(error.json().error || 'Server error');
   }
     console.error(error);
     return Observable.throw(error.json().error || 'Server error');
   }
-
-  private createPaginationParams(pagination: Pagination) {
-    const params = new URLSearchParams();
-    const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage;
-    const count: number = pagination.itemsPerPage;
-
-    params.set('start', start.toString());
-    params.set('count', count.toString());
-
-    return params;
-  }
 }
 }
index 67a04a2b49217497b0db3658c92515df61fb790c..b11475ae9f1339e6fa2cd9354cfcbf66081cfeb9 100644 (file)
@@ -18,20 +18,21 @@ declare var jQuery: any;
 })
 
 export class VideoAddComponent implements OnInit {
 })
 
 export class VideoAddComponent implements OnInit {
-  user: User;
   fileToUpload: any;
   progressBar: { value: number; max: number; } = { value: 0, max: 0 };
   fileToUpload: any;
   progressBar: { value: number; max: number; } = { value: 0, max: 0 };
+  user: User;
 
 
-  private _form: any;
+  private form: any;
 
   constructor(
 
   constructor(
-    private _router: Router, private _elementRef: ElementRef,
-    private _authService: AuthService
+    private router: Router,
+    private elementRef: ElementRef,
+    private authService: AuthService
   ) {}
 
   ngOnInit() {
     this.user = User.load();
   ) {}
 
   ngOnInit() {
     this.user = User.load();
-    jQuery(this._elementRef.nativeElement).find('#videofile').fileupload({
+    jQuery(this.elementRef.nativeElement).find('#videofile').fileupload({
       url: '/api/v1/videos',
       dataType: 'json',
       singleFileUploads: true,
       url: '/api/v1/videos',
       dataType: 'json',
       singleFileUploads: true,
@@ -39,7 +40,7 @@ export class VideoAddComponent implements OnInit {
       autoupload: false,
 
       add: (e, data) => {
       autoupload: false,
 
       add: (e, data) => {
-        this._form = data;
+        this.form = data;
         this.fileToUpload = data['files'][0];
       },
 
         this.fileToUpload = data['files'][0];
       },
 
@@ -55,14 +56,14 @@ export class VideoAddComponent implements OnInit {
         console.log('Video uploaded.');
 
         // Print all the videos once it's finished
         console.log('Video uploaded.');
 
         // Print all the videos once it's finished
-        this._router.navigate(['VideosList']);
+        this.router.navigate(['VideosList']);
       }
     });
   }
 
   uploadFile() {
       }
     });
   }
 
   uploadFile() {
-    this._form.headers = this._authService.getRequestHeader().toJSON();
-    this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray();
-    this._form.submit();
+    this.form.headers = this.authService.getRequestHeader().toJSON();
+    this.form.formData = jQuery(this.elementRef.nativeElement).find('form').serializeArray();
+    this.form.submit();
   }
 }
   }
 }
index 3f54c98ceda6ca94e54785865d7360608e2836c9..23b97df32f62bebfeaf1d3b8df9572a375337383 100644 (file)
@@ -23,23 +23,23 @@ import { VideoSortComponent } from './video-sort.component';
 })
 
 export class VideoListComponent implements OnInit {
 })
 
 export class VideoListComponent implements OnInit {
-  user: User = null;
-  videos: Video[] = [];
+  loading = false;
   pagination: Pagination = {
     currentPage: 1,
     itemsPerPage: 9,
     total: 0
   };
   sort: SortField;
   pagination: Pagination = {
     currentPage: 1,
     itemsPerPage: 9,
     total: 0
   };
   sort: SortField;
-  loading = false;
+  user: User = null;
+  videos: Video[] = [];
 
   private search: Search;
 
   constructor(
     private authService: AuthService,
 
   private search: Search;
 
   constructor(
     private authService: AuthService,
-    private videoService: VideoService,
+    private router: Router,
     private routeParams: RouteParams,
     private routeParams: RouteParams,
-    private router: Router
+    private videoService: VideoService
   ) {
     this.search = {
       value: this.routeParams.get('search'),
   ) {
     this.search = {
       value: this.routeParams.get('search'),
@@ -73,6 +73,7 @@ export class VideoListComponent implements OnInit {
       ({ videos, totalVideos }) => {
         this.videos = videos;
         this.pagination.total = totalVideos;
       ({ videos, totalVideos }) => {
         this.videos = videos;
         this.pagination.total = totalVideos;
+
         this.loading = false;
       },
       error => alert(error)
         this.loading = false;
       },
       error => alert(error)
@@ -91,8 +92,8 @@ export class VideoListComponent implements OnInit {
     };
 
     if (this.search.value) {
     };
 
     if (this.search.value) {
-      params.search = this.search.value;
       params.field = this.search.field;
       params.field = this.search.field;
+      params.search = this.search.value;
     }
 
     this.router.navigate(['VideosList', params]);
     }
 
     this.router.navigate(['VideosList', params]);
index 73416607a8cc11823bba696b65a74109cd785268..3baa1ddd648a6210063907819232c25857533af7 100644 (file)
@@ -16,23 +16,23 @@ import { User } from '../../users/index';
 export class VideoMiniatureComponent {
   @Output() removed = new EventEmitter<any>();
 
 export class VideoMiniatureComponent {
   @Output() removed = new EventEmitter<any>();
 
-  @Input() video: Video;
   @Input() user: User;
   @Input() user: User;
+  @Input() video: Video;
 
   hovering = false;
 
   constructor(private videoService: VideoService) {}
 
 
   hovering = false;
 
   constructor(private videoService: VideoService) {}
 
-  onHover() {
-    this.hovering = true;
+  displayRemoveIcon() {
+    return this.hovering && this.video.isRemovableBy(this.user);
   }
 
   onBlur() {
     this.hovering = false;
   }
 
   }
 
   onBlur() {
     this.hovering = false;
   }
 
-  displayRemoveIcon() {
-    return this.hovering && this.video.isRemovableBy(this.user);
+  onHover() {
+    this.hovering = true;
   }
 
   removeVideo(id: string) {
   }
 
   removeVideo(id: string) {
index c159b4004e9fa664b0a1ef3f37768b63a806d7cf..137db8f0b23987a064370ddf4ec0be68e6dc73b6 100644 (file)
@@ -17,32 +17,24 @@ declare var WebTorrent: any;
 })
 
 export class VideoWatchComponent implements OnInit, CanDeactivate {
 })
 
 export class VideoWatchComponent implements OnInit, CanDeactivate {
-  video: Video;
   downloadSpeed: number;
   downloadSpeed: number;
-  uploadSpeed: number;
-  numPeers: number;
   loading: boolean = false;
   loading: boolean = false;
+  numPeers: number;
+  uploadSpeed: number;
+  video: Video;
 
 
-  private interval: NodeJS.Timer;
   private client: any;
   private client: any;
+  private interval: NodeJS.Timer;
 
   constructor(
 
   constructor(
-    private videoService: VideoService,
+    private elementRef: ElementRef,
     private routeParams: RouteParams,
     private routeParams: RouteParams,
-    private elementRef: ElementRef
+    private videoService: VideoService
   ) {
     // TODO: use a service
     this.client = new WebTorrent({ dht: false });
   }
 
   ) {
     // TODO: use a service
     this.client = new WebTorrent({ dht: false });
   }
 
-  ngOnInit() {
-    let id = this.routeParams.get('id');
-    this.videoService.getVideo(id).subscribe(
-      video => this.loadVideo(video),
-      error => alert(error)
-    );
-  }
-
   loadVideo(video: Video) {
     this.loading = true;
     this.video = video;
   loadVideo(video: Video) {
     this.loading = true;
     this.video = video;
@@ -60,12 +52,20 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
       // Refresh each second
       this.interval = setInterval(() => {
         this.downloadSpeed = torrent.downloadSpeed;
       // Refresh each second
       this.interval = setInterval(() => {
         this.downloadSpeed = torrent.downloadSpeed;
-        this.uploadSpeed = torrent.uploadSpeed;
         this.numPeers = torrent.numPeers;
         this.numPeers = torrent.numPeers;
+        this.uploadSpeed = torrent.uploadSpeed;
       }, 1000);
     });
   }
 
       }, 1000);
     });
   }
 
+  ngOnInit() {
+    let id = this.routeParams.get('id');
+    this.videoService.getVideo(id).subscribe(
+      video => this.loadVideo(video),
+      error => alert(error)
+    );
+  }
+
   routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
     console.log('Removing video from webtorrent.');
     clearInterval(this.interval);
   routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
     console.log('Removing video from webtorrent.');
     clearInterval(this.interval);