From: Chocobozzz Date: Fri, 27 May 2016 15:49:18 +0000 (+0200) Subject: Alphabetical X-Git-Tag: v0.0.1-alpha~895 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;ds=sidebyside;h=4fd8aa327004b27530fd96bdde5df60e6745a1f6;p=github%2FChocobozzz%2FPeerTube.git Alphabetical --- diff --git a/client/app/app.component.ts b/client/app/app.component.ts index 20c8c8724..965848105 100644 --- a/client/app/app.component.ts +++ b/client/app/app.component.ts @@ -49,13 +49,13 @@ import { }) export class AppComponent { - isLoggedIn: boolean; - search_field: string = name; 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(); @@ -71,8 +71,8 @@ export class AppComponent { 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 { @@ -100,7 +100,7 @@ export class AppComponent { quitFriends() { this.friendService.quitFriends().subscribe( status => { - alert('Quit friends!'); + alert('Quit friends!'); }, error => alert(error) ); diff --git a/client/app/shared/search.component.ts b/client/app/shared/search.component.ts index 674518aba..e1e30b9af 100644 --- a/client/app/shared/search.component.ts +++ b/client/app/shared/search.component.ts @@ -14,26 +14,21 @@ import { SearchField } from './search-field.type'; export class SearchComponent { @Output() search = new EventEmitter(); - searchCriterias: Search = { - field: 'name', - value: '' - }; - fieldChoices = { name: 'Name', author: 'Author', podUrl: 'Pod Url', magnetUri: 'Magnet Uri' }; + searchCriterias: Search = { + field: 'name', + value: '' + }; get choiceKeys() { return Object.keys(this.fieldChoices); } - getStringChoice(choiceKey: SearchField) { - return this.fieldChoices[choiceKey]; - } - choose($event: MouseEvent, choice: SearchField) { $event.preventDefault(); $event.stopPropagation(); @@ -45,4 +40,7 @@ export class SearchComponent { this.search.emit(this.searchCriterias); } + getStringChoice(choiceKey: SearchField) { + return this.fieldChoices[choiceKey]; + } } diff --git a/client/app/users/login/login.component.ts b/client/app/users/login/login.component.ts index 8e369541d..09c5f1af7 100644 --- a/client/app/users/login/login.component.ts +++ b/client/app/users/login/login.component.ts @@ -10,7 +10,10 @@ import { AuthService, AuthStatus, User } from '../shared/index'; }) 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( diff --git a/client/app/users/shared/auth.service.ts b/client/app/users/shared/auth.service.ts index b1da94436..d63fe38f3 100644 --- a/client/app/users/shared/auth.service.ts +++ b/client/app/users/shared/auth.service.ts @@ -7,14 +7,14 @@ import { User } from './user.model'; @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_LOGIN_URL = '/api/v1/users/token'; loginChangedSource: Observable; - private loginChanged: Subject; private clientId: string; private clientSecret: string; + private loginChanged: Subject; constructor(private http: Http) { this.loginChanged = new Subject(); @@ -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()}` }); } - getAuthRequestOptions(): RequestOptions { - return new RequestOptions({ headers: this.getRequestHeader() }); - } - 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); } 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 @@ export class Video { - id: string; - name: string; + author: string; + by: string; + createdDate: Date; description: string; + duration: string; + id: string; + isLocal: boolean; magnetUri: string; + name: string; podUrl: string; - isLocal: boolean; 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(':'); @@ -32,28 +23,38 @@ export class Video { 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: { - id: string, - name: string, - description: string, - magnetUri: string, - podUrl: string, - isLocal: boolean, - thumbnailPath: string, author: string, createdDate: string, + description: string, 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.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.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); } 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'; 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 =>