From df98563e2104b82b119c00a3cd83cd0dc1242d25 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jun 2017 14:32:15 +0200 Subject: Use typescript standard and lint all files --- client/src/app/videos/shared/index.ts | 8 +- client/src/app/videos/shared/rate-type.type.ts | 2 +- client/src/app/videos/shared/sort-field.type.ts | 3 +- client/src/app/videos/shared/video.model.ts | 150 ++++++++++++------------ client/src/app/videos/shared/video.service.ts | 146 +++++++++++------------ 5 files changed, 154 insertions(+), 155 deletions(-) (limited to 'client/src/app/videos/shared') diff --git a/client/src/app/videos/shared/index.ts b/client/src/app/videos/shared/index.ts index a68491022..0fa14f641 100644 --- a/client/src/app/videos/shared/index.ts +++ b/client/src/app/videos/shared/index.ts @@ -1,4 +1,4 @@ -export * from './sort-field.type'; -export * from './rate-type.type'; -export * from './video.model'; -export * from './video.service'; +export * from './sort-field.type' +export * from './rate-type.type' +export * from './video.model' +export * from './video.service' diff --git a/client/src/app/videos/shared/rate-type.type.ts b/client/src/app/videos/shared/rate-type.type.ts index 88034d1ff..20eea3ae5 100644 --- a/client/src/app/videos/shared/rate-type.type.ts +++ b/client/src/app/videos/shared/rate-type.type.ts @@ -1 +1 @@ -export type RateType = 'like' | 'dislike'; +export type RateType = 'like' | 'dislike' diff --git a/client/src/app/videos/shared/sort-field.type.ts b/client/src/app/videos/shared/sort-field.type.ts index 6cc598d8b..776f360f8 100644 --- a/client/src/app/videos/shared/sort-field.type.ts +++ b/client/src/app/videos/shared/sort-field.type.ts @@ -2,5 +2,4 @@ export type SortField = 'name' | '-name' | 'duration' | '-duration' | 'createdAt' | '-createdAt' | 'views' | '-views' - | 'likes' | '-likes'; - + | 'likes' | '-likes' diff --git a/client/src/app/videos/shared/video.model.ts b/client/src/app/videos/shared/video.model.ts index e897eb175..f5e16fc13 100644 --- a/client/src/app/videos/shared/video.model.ts +++ b/client/src/app/videos/shared/video.model.ts @@ -1,56 +1,56 @@ -import { Video as VideoServerModel } from '../../../../../shared'; -import { User } from '../../shared'; +import { Video as VideoServerModel } from '../../../../../shared' +import { User } from '../../shared' export class Video implements VideoServerModel { - author: string; - by: string; - createdAt: Date; - categoryLabel: string; - category: number; - licenceLabel: string; - licence: number; - languageLabel: string; - language: number; - description: string; - duration: number; - durationLabel: string; - id: string; - isLocal: boolean; - magnetUri: string; - name: string; - podHost: string; - tags: string[]; - thumbnailPath: string; - thumbnailUrl: string; - views: number; - likes: number; - dislikes: number; - nsfw: boolean; + author: string + by: string + createdAt: Date + categoryLabel: string + category: number + licenceLabel: string + licence: number + languageLabel: string + language: number + description: string + duration: number + durationLabel: string + id: string + isLocal: boolean + magnetUri: string + name: string + podHost: string + tags: string[] + thumbnailPath: string + thumbnailUrl: string + views: number + likes: number + dislikes: number + nsfw: boolean - private static createByString(author: string, podHost: string) { - return author + '@' + podHost; + private static createByString (author: string, podHost: string) { + return author + '@' + podHost } - 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'; + private static createDurationString (duration: number) { + const minutes = Math.floor(duration / 60) + const seconds = duration % 60 + const minutesPadding = minutes >= 10 ? '' : '0' + const secondsPadding = seconds >= 10 ? '' : '0' - return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString(); + return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString() } - constructor(hash: { + constructor (hash: { author: string, createdAt: string, categoryLabel: string, category: number, licenceLabel: string, licence: number, - languageLabel: string; - language: number; + languageLabel: string + language: number description: string, - duration: number; + duration: number id: string, isLocal: boolean, magnetUri: string, @@ -63,57 +63,57 @@ export class Video implements VideoServerModel { dislikes: number, nsfw: boolean }) { - this.author = hash.author; - this.createdAt = new Date(hash.createdAt); - this.categoryLabel = hash.categoryLabel; - this.category = hash.category; - this.licenceLabel = hash.licenceLabel; - this.licence = hash.licence; - this.languageLabel = hash.languageLabel; - this.language = hash.language; - this.description = hash.description; - this.duration = hash.duration; - this.durationLabel = Video.createDurationString(hash.duration); - this.id = hash.id; - this.isLocal = hash.isLocal; - this.magnetUri = hash.magnetUri; - this.name = hash.name; - this.podHost = hash.podHost; - this.tags = hash.tags; - this.thumbnailPath = hash.thumbnailPath; - this.thumbnailUrl = API_URL + hash.thumbnailPath; - this.views = hash.views; - this.likes = hash.likes; - this.dislikes = hash.dislikes; - this.nsfw = hash.nsfw; + this.author = hash.author + this.createdAt = new Date(hash.createdAt) + this.categoryLabel = hash.categoryLabel + this.category = hash.category + this.licenceLabel = hash.licenceLabel + this.licence = hash.licence + this.languageLabel = hash.languageLabel + this.language = hash.language + this.description = hash.description + this.duration = hash.duration + this.durationLabel = Video.createDurationString(hash.duration) + this.id = hash.id + this.isLocal = hash.isLocal + this.magnetUri = hash.magnetUri + this.name = hash.name + this.podHost = hash.podHost + this.tags = hash.tags + this.thumbnailPath = hash.thumbnailPath + this.thumbnailUrl = API_URL + hash.thumbnailPath + this.views = hash.views + this.likes = hash.likes + this.dislikes = hash.dislikes + this.nsfw = hash.nsfw - this.by = Video.createByString(hash.author, hash.podHost); + this.by = Video.createByString(hash.author, hash.podHost) } - isRemovableBy(user) { - return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true); + isRemovableBy (user) { + return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true) } - isBlackistableBy(user) { - return user && user.isAdmin() === true && this.isLocal === false; + isBlackistableBy (user) { + return user && user.isAdmin() === true && this.isLocal === false } - isUpdatableBy(user) { - return user && this.isLocal === true && user.username === this.author; + isUpdatableBy (user) { + return user && this.isLocal === true && user.username === this.author } - isVideoNSFWForUser(user: User) { + isVideoNSFWForUser (user: User) { // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos... - return (this.nsfw && (!user || user.displayNSFW === false)); + return (this.nsfw && (!user || user.displayNSFW === false)) } - patch(values: Object) { + patch (values: Object) { Object.keys(values).forEach((key) => { - this[key] = values[key]; - }); + this[key] = values[key] + }) } - toJSON() { + toJSON () { return { author: this.author, createdAt: this.createdAt, @@ -133,6 +133,6 @@ export class Video implements VideoServerModel { likes: this.likes, dislikes: this.dislikes, nsfw: this.nsfw - }; + } } } diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts index a53ea1064..a4e3d16df 100644 --- a/client/src/app/videos/shared/video.service.ts +++ b/client/src/app/videos/shared/video.service.ts @@ -1,13 +1,13 @@ -import { Injectable } from '@angular/core'; -import { Http, Headers, RequestOptions } from '@angular/http'; -import { Observable } from 'rxjs/Observable'; -import 'rxjs/add/operator/catch'; -import 'rxjs/add/operator/map'; - -import { Search } from '../../shared'; -import { SortField } from './sort-field.type'; -import { RateType } from './rate-type.type'; -import { AuthService } from '../../core'; +import { Injectable } from '@angular/core' +import { Http, Headers, RequestOptions } from '@angular/http' +import { Observable } from 'rxjs/Observable' +import 'rxjs/add/operator/catch' +import 'rxjs/add/operator/map' + +import { Search } from '../../shared' +import { SortField } from './sort-field.type' +import { RateType } from './rate-type.type' +import { AuthService } from '../../core' import { AuthHttp, RestExtractor, @@ -15,18 +15,18 @@ import { RestService, ResultList, UserService -} from '../../shared'; -import { Video } from './video.model'; +} from '../../shared' +import { Video } from './video.model' @Injectable() export class VideoService { - private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'; + private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/' - videoCategories: Array<{ id: number, label: string }> = []; - videoLicences: Array<{ id: number, label: string }> = []; - videoLanguages: Array<{ id: number, label: string }> = []; + videoCategories: Array<{ id: number, label: string }> = [] + videoLicences: Array<{ id: number, label: string }> = [] + videoLanguages: Array<{ id: number, label: string }> = [] - constructor( + constructor ( private authService: AuthService, private authHttp: AuthHttp, private http: Http, @@ -34,54 +34,54 @@ export class VideoService { private restService: RestService ) {} - loadVideoCategories() { + loadVideoCategories () { return this.http.get(VideoService.BASE_VIDEO_URL + 'categories') .map(this.restExtractor.extractDataGet) .subscribe(data => { Object.keys(data).forEach(categoryKey => { this.videoCategories.push({ - id: parseInt(categoryKey), + id: parseInt(categoryKey, 10), label: data[categoryKey] - }); - }); - }); + }) + }) + }) } - loadVideoLicences() { + loadVideoLicences () { return this.http.get(VideoService.BASE_VIDEO_URL + 'licences') .map(this.restExtractor.extractDataGet) .subscribe(data => { Object.keys(data).forEach(licenceKey => { this.videoLicences.push({ - id: parseInt(licenceKey), + id: parseInt(licenceKey, 10), label: data[licenceKey] - }); - }); - }); + }) + }) + }) } - loadVideoLanguages() { + loadVideoLanguages () { return this.http.get(VideoService.BASE_VIDEO_URL + 'languages') .map(this.restExtractor.extractDataGet) .subscribe(data => { Object.keys(data).forEach(languageKey => { this.videoLanguages.push({ - id: parseInt(languageKey), + id: parseInt(languageKey, 10), label: data[languageKey] - }); - }); - }); + }) + }) + }) } - getVideo(id: string): Observable