From 154898b0b7bc1af41fc5a94974e338a3590c90f3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 17 Jun 2017 11:28:11 +0200 Subject: Share models between server and client --- .../friends/friend-list/friend-list.component.ts | 2 +- .../src/app/+admin/friends/shared/friend.model.ts | 7 ---- .../app/+admin/friends/shared/friend.service.ts | 1 - .../request-stats/request-stats.component.ts | 11 +++---- client/src/app/+admin/requests/shared/index.ts | 2 +- .../shared/request-stats-attributes.model.ts | 37 ++++++++++++++++++++++ .../+admin/requests/shared/request-stats.model.ts | 35 -------------------- .../app/+admin/requests/shared/request.service.ts | 9 +++--- .../video-abuse-list/video-abuse-list.component.ts | 3 +- client/src/app/core/auth/auth.service.ts | 5 +-- client/src/app/core/config/config.service.ts | 7 ++-- .../app/shared/video-abuse/video-abuse.model.ts | 8 ----- .../app/shared/video-abuse/video-abuse.service.ts | 2 +- client/src/app/videos/shared/rate-type.type.ts | 1 - client/src/app/videos/shared/video.service.ts | 6 ++-- .../videos/video-watch/video-watch.component.ts | 10 +++--- 16 files changed, 64 insertions(+), 82 deletions(-) delete mode 100644 client/src/app/+admin/friends/shared/friend.model.ts create mode 100644 client/src/app/+admin/requests/shared/request-stats-attributes.model.ts delete mode 100644 client/src/app/+admin/requests/shared/request-stats.model.ts delete mode 100644 client/src/app/shared/video-abuse/video-abuse.model.ts delete mode 100644 client/src/app/videos/shared/rate-type.type.ts (limited to 'client') diff --git a/client/src/app/+admin/friends/friend-list/friend-list.component.ts b/client/src/app/+admin/friends/friend-list/friend-list.component.ts index 7bf9d2c6b..9f0256d7f 100644 --- a/client/src/app/+admin/friends/friend-list/friend-list.component.ts +++ b/client/src/app/+admin/friends/friend-list/friend-list.component.ts @@ -5,7 +5,7 @@ import { ServerDataSource } from 'ng2-smart-table' import { ConfirmService } from '../../../core' import { Utils } from '../../../shared' -import { Friend, FriendService } from '../shared' +import { FriendService } from '../shared' @Component({ selector: 'my-friend-list', diff --git a/client/src/app/+admin/friends/shared/friend.model.ts b/client/src/app/+admin/friends/shared/friend.model.ts deleted file mode 100644 index 6950405b9..000000000 --- a/client/src/app/+admin/friends/shared/friend.model.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface Friend { - id: string - host: string - score: number - email: string - createdAt: Date -} diff --git a/client/src/app/+admin/friends/shared/friend.service.ts b/client/src/app/+admin/friends/shared/friend.service.ts index f4ecd36ad..79de4470e 100644 --- a/client/src/app/+admin/friends/shared/friend.service.ts +++ b/client/src/app/+admin/friends/shared/friend.service.ts @@ -5,7 +5,6 @@ import 'rxjs/add/operator/map' import { ServerDataSource } from 'ng2-smart-table' -import { Friend } from './friend.model' import { AuthHttp, RestExtractor, RestDataSource, ResultList } from '../../../shared' @Injectable() diff --git a/client/src/app/+admin/requests/request-stats/request-stats.component.ts b/client/src/app/+admin/requests/request-stats/request-stats.component.ts index cca4926cf..140aaf47e 100644 --- a/client/src/app/+admin/requests/request-stats/request-stats.component.ts +++ b/client/src/app/+admin/requests/request-stats/request-stats.component.ts @@ -2,7 +2,8 @@ import { Component, OnInit, OnDestroy } from '@angular/core' import { NotificationsService } from 'angular2-notifications' -import { RequestService, RequestStats } from '../shared' +import { RequestService, RequestSchedulerStatsAttributes } from '../shared' +import { RequestScheduler } from '../../../../../../shared' @Component({ selector: 'my-request-stats', @@ -16,11 +17,7 @@ export class RequestStatsComponent implements OnInit, OnDestroy { requestVideoQaduScheduler: 'Quick and dirty video updates request scheduler' } - stats: { [ id: string ]: RequestStats } = { - requestScheduler: null, - requestVideoEventScheduler: null, - requestVideoQaduScheduler: null - } + stats: RequestScheduler private intervals: { [ id: string ]: number } = { requestScheduler: null, @@ -67,7 +64,7 @@ export class RequestStatsComponent implements OnInit, OnDestroy { private runIntervals () { Object.keys(this.intervals).forEach(requestSchedulerName => { this.intervals[requestSchedulerName] = window.setInterval(() => { - const stats = this.stats[requestSchedulerName] + const stats: RequestSchedulerStatsAttributes = this.stats[requestSchedulerName] stats.remainingMilliSeconds -= 1000 diff --git a/client/src/app/+admin/requests/shared/index.ts b/client/src/app/+admin/requests/shared/index.ts index 2442e810a..857fe9d29 100644 --- a/client/src/app/+admin/requests/shared/index.ts +++ b/client/src/app/+admin/requests/shared/index.ts @@ -1,2 +1,2 @@ -export * from './request-stats.model' +export * from './request-stats-attributes.model' export * from './request.service' diff --git a/client/src/app/+admin/requests/shared/request-stats-attributes.model.ts b/client/src/app/+admin/requests/shared/request-stats-attributes.model.ts new file mode 100644 index 000000000..394acc73d --- /dev/null +++ b/client/src/app/+admin/requests/shared/request-stats-attributes.model.ts @@ -0,0 +1,37 @@ +import { RequestSchedulerAttributes as FormatedRequestSchedulerAttributes } from '../../../../../../shared' + +export interface Request { + request: any + to: any +} + +export class RequestSchedulerStatsAttributes implements FormatedRequestSchedulerAttributes { + requestsLimitPods: number + requestsLimitPerPod: number + milliSecondsInterval: number + remainingMilliSeconds: number + totalRequests: number + + constructor (hash: { + requestsLimitPods: number, + requestsLimitPerPod: number, + milliSecondsInterval: number, + remainingMilliSeconds: number, + totalRequests: number + }) { + this.requestsLimitPods = hash.requestsLimitPods + this.requestsLimitPerPod = hash.requestsLimitPerPod + this.milliSecondsInterval = hash.milliSecondsInterval + this.remainingMilliSeconds = hash.remainingMilliSeconds + this.totalRequests = hash.totalRequests + } + + get remainingSeconds () { + return Math.floor(this.remainingMilliSeconds / 1000) + } + + get secondsInterva () { + return Math.floor(this.milliSecondsInterval / 1000) + } + +} diff --git a/client/src/app/+admin/requests/shared/request-stats.model.ts b/client/src/app/+admin/requests/shared/request-stats.model.ts deleted file mode 100644 index 31550b5c0..000000000 --- a/client/src/app/+admin/requests/shared/request-stats.model.ts +++ /dev/null @@ -1,35 +0,0 @@ -export interface Request { - request: any - to: any -} - -export class RequestStats { - requestsLimitPods: number - requestsLimitPerPod: number - milliSecondsInterval: number - remainingMilliSeconds: number - totalRequests: number - - constructor (hash: { - requestsLimitPods: number, - requestsLimitPerPod: number, - milliSecondsInterval: number, - remainingMilliSeconds: number, - totalRequests: number - }) { - this.requestsLimitPods = hash.requestsLimitPods - this.requestsLimitPerPod = hash.requestsLimitPerPod - this.milliSecondsInterval = hash.milliSecondsInterval - this.remainingMilliSeconds = hash.remainingMilliSeconds - this.totalRequests = hash.totalRequests - } - - get remainingSeconds () { - return Math.floor(this.remainingMilliSeconds / 1000) - } - - get secondsInterva () { - return Math.floor(this.milliSecondsInterval / 1000) - } - -} diff --git a/client/src/app/+admin/requests/shared/request.service.ts b/client/src/app/+admin/requests/shared/request.service.ts index faa6b9383..53682b111 100644 --- a/client/src/app/+admin/requests/shared/request.service.ts +++ b/client/src/app/+admin/requests/shared/request.service.ts @@ -3,8 +3,9 @@ import { Observable } from 'rxjs/Observable' import 'rxjs/add/operator/catch' import 'rxjs/add/operator/map' -import { RequestStats } from './request-stats.model' +import { RequestScheduler } from '../../../../../../shared' import { AuthHttp, RestExtractor } from '../../../shared' +import { RequestSchedulerStatsAttributes } from './request-stats-attributes.model' @Injectable() export class RequestService { @@ -15,18 +16,18 @@ export class RequestService { private restExtractor: RestExtractor ) {} - getStats (): Observable<{ [ id: string ]: RequestStats }> { + getStats (): Observable { return this.authHttp.get(RequestService.BASE_REQUEST_URL + 'stats') .map(this.restExtractor.extractDataGet) .map(this.buildRequestObjects) .catch((res) => this.restExtractor.handleError(res)) } - private buildRequestObjects (data: any) { + private buildRequestObjects (data: RequestScheduler) { const requestSchedulers = {} Object.keys(data).forEach(requestSchedulerName => { - requestSchedulers[requestSchedulerName] = new RequestStats(data[requestSchedulerName]) + requestSchedulers[requestSchedulerName] = new RequestSchedulerStatsAttributes(data[requestSchedulerName]) }) return requestSchedulers diff --git a/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts b/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts index 60eaebb44..7c838fbf0 100644 --- a/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts +++ b/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts @@ -2,7 +2,8 @@ import { Component } from '@angular/core' import { NotificationsService } from 'angular2-notifications' -import { Utils, VideoAbuseService, VideoAbuse } from '../../../shared' +import { Utils, VideoAbuseService } from '../../../shared' +import { VideoAbuse } from '../../../../../shared' @Component({ selector: 'my-video-abuse-list', diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index 32f7a5503..fcc6b9bb6 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -11,6 +11,7 @@ import { NotificationsService } from 'angular2-notifications' import { AuthStatus } from './auth-status.model' import { AuthUser } from './auth-user.model' +import { ClientLocal } from '../../../../../shared' // Do not use the barrel (dependency loop) import { RestExtractor } from '../../shared/rest' @@ -40,9 +41,9 @@ export class AuthService { // FIXME: save in local storage? this.http.get(AuthService.BASE_CLIENT_URL) .map(this.restExtractor.extractDataGet) - .catch((res) => this.restExtractor.handleError(res)) + .catch(res => this.restExtractor.handleError(res)) .subscribe( - result => { + (result: ClientLocal) => { this.clientId = result.client_id this.clientSecret = result.client_secret console.log('Client credentials loaded.') diff --git a/client/src/app/core/config/config.service.ts b/client/src/app/core/config/config.service.ts index a83ec61d2..b8cb15e84 100644 --- a/client/src/app/core/config/config.service.ts +++ b/client/src/app/core/config/config.service.ts @@ -2,16 +2,13 @@ import { Injectable } from '@angular/core' import { Http } from '@angular/http' import { RestExtractor } from '../../shared/rest' +import { ServerConfig } from '../../../../../shared' @Injectable() export class ConfigService { private static BASE_CONFIG_URL = API_URL + '/api/v1/config/' - private config: { - signup: { - enabled: boolean - } - } = { + private config: ServerConfig = { signup: { enabled: false } diff --git a/client/src/app/shared/video-abuse/video-abuse.model.ts b/client/src/app/shared/video-abuse/video-abuse.model.ts deleted file mode 100644 index 49c87d6b8..000000000 --- a/client/src/app/shared/video-abuse/video-abuse.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface VideoAbuse { - id: string - reason: string - reporterPodHost: string - reporterUsername: string - videoId: string - createdAt: Date -} diff --git a/client/src/app/shared/video-abuse/video-abuse.service.ts b/client/src/app/shared/video-abuse/video-abuse.service.ts index 4317f9353..32f13b430 100644 --- a/client/src/app/shared/video-abuse/video-abuse.service.ts +++ b/client/src/app/shared/video-abuse/video-abuse.service.ts @@ -7,7 +7,7 @@ import 'rxjs/add/operator/map' import { AuthService } from '../core' import { AuthHttp } from '../auth' import { RestDataSource, RestExtractor, ResultList } from '../rest' -import { VideoAbuse } from './video-abuse.model' +import { VideoAbuse } from '../../../../../shared' @Injectable() export class VideoAbuseService { diff --git a/client/src/app/videos/shared/rate-type.type.ts b/client/src/app/videos/shared/rate-type.type.ts deleted file mode 100644 index 20eea3ae5..000000000 --- a/client/src/app/videos/shared/rate-type.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type RateType = 'like' | 'dislike' diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts index a4e3d16df..977b82118 100644 --- a/client/src/app/videos/shared/video.service.ts +++ b/client/src/app/videos/shared/video.service.ts @@ -6,7 +6,6 @@ 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, @@ -17,6 +16,7 @@ import { UserService } from '../../shared' import { Video } from './video.model' +import { VideoRateType } from '../../../../../shared' @Injectable() export class VideoService { @@ -145,7 +145,7 @@ export class VideoService { return this.setVideoRate(id, 'dislike') } - getUserVideoRating (id: string) { + getUserVideoRating (id: string): Observable { const url = UserService.BASE_USERS_URL + '/me/videos/' + id + '/rating' return this.authHttp.get(url) @@ -159,7 +159,7 @@ export class VideoService { .catch((res) => this.restExtractor.handleError(res)) } - private setVideoRate (id: string, rateType: RateType) { + private setVideoRate (id: string, rateType: VideoRateType) { const url = VideoService.BASE_VIDEO_URL + id + '/rate' const body = { rating: rateType diff --git a/client/src/app/videos/video-watch/video-watch.component.ts b/client/src/app/videos/video-watch/video-watch.component.ts index 4a547f7e4..808e0eda9 100644 --- a/client/src/app/videos/video-watch/video-watch.component.ts +++ b/client/src/app/videos/video-watch/video-watch.component.ts @@ -11,15 +11,15 @@ import { AuthService, ConfirmService } from '../../core' import { VideoMagnetComponent } from './video-magnet.component' import { VideoShareComponent } from './video-share.component' import { VideoReportComponent } from './video-report.component' -import { RateType, Video, VideoService } from '../shared' +import { Video, VideoService } from '../shared' import { WebTorrentService } from './webtorrent.service' +import { UserVideoRateType, VideoRateType, UserVideoRate } from '../../../../../shared' @Component({ selector: 'my-video-watch', templateUrl: './video-watch.component.html', styleUrls: [ './video-watch.component.scss' ] }) - export class VideoWatchComponent implements OnInit, OnDestroy { private static LOADTIME_TOO_LONG = 20000 @@ -34,7 +34,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { player: videojs.Player playerElement: Element uploadSpeed: number - userRating: RateType = null + userRating: UserVideoRateType = null video: Video = null videoNotFound = false @@ -249,7 +249,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.videoService.getUserVideoRating(this.video.id) .subscribe( - ratingObject => { + (ratingObject: UserVideoRate) => { if (ratingObject) { this.userRating = ratingObject.rating } @@ -282,7 +282,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { ) } - private updateVideoRating (oldRating: RateType, newRating: RateType) { + private updateVideoRating (oldRating: UserVideoRateType, newRating: VideoRateType) { let likesToIncrement = 0 let dislikesToIncrement = 0 -- cgit v1.2.3