From 6e07c3de88791a0b342e0cc319590048117f9c2d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 22 Mar 2017 21:15:55 +0100 Subject: [PATCH] Add video category support --- client/src/app/app.component.ts | 4 ++ .../app/shared/forms/form-validators/video.ts | 6 ++ client/src/app/videos/shared/video.model.ts | 3 + client/src/app/videos/shared/video.service.ts | 15 +++++ .../videos/video-add/video-add.component.html | 12 ++++ .../videos/video-add/video-add.component.ts | 20 ++++++- .../video-watch/video-watch.component.html | 7 +++ .../video-watch/video-watch.component.scss | 10 +++- server/controllers/api/remote/videos.js | 2 + server/controllers/api/videos.js | 8 +++ .../custom-validators/remote/videos.js | 1 + server/helpers/custom-validators/videos.js | 5 ++ server/initializers/constants.js | 24 +++++++- .../migrations/0030-video-category.js | 34 +++++++++++ server/middlewares/validators/videos.js | 2 + server/models/video.js | 18 ++++++ server/tests/api/check-params/users.js | 3 +- server/tests/api/check-params/video-abuses.js | 3 +- server/tests/api/check-params/videos.js | 58 +++++++++++++++++++ server/tests/api/friends-advanced.js | 3 +- server/tests/api/multiple-pods.js | 25 ++++++-- server/tests/api/requests.js | 3 +- server/tests/api/single-pod.js | 42 ++++++++++++-- server/tests/api/users.js | 12 ++-- server/tests/api/video-abuse.js | 6 +- server/tests/real-world/real-world.js | 3 +- server/tests/real-world/tools/upload.js | 7 ++- server/tests/utils/videos.js | 18 +++++- 28 files changed, 324 insertions(+), 30 deletions(-) create mode 100644 server/initializers/migrations/0030-video-category.js diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 8b4b4118b..c7310690f 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit, ViewContainerRef } from '@angular/core'; import { Router } from '@angular/router'; import { AuthService } from './core'; +import { VideoService } from './videos'; import { UserService } from './shared'; @Component({ @@ -27,6 +28,7 @@ export class AppComponent implements OnInit { private router: Router, private authService: AuthService, private userService: UserService, + private videoService: VideoService, viewContainerRef: ViewContainerRef ) {} @@ -35,6 +37,8 @@ export class AppComponent implements OnInit { // The service will automatically redirect to the login page if the token is not valid anymore this.userService.checkTokenValidity(); } + + this.videoService.loadVideoCategories(); } isInAdmin() { diff --git a/client/src/app/shared/forms/form-validators/video.ts b/client/src/app/shared/forms/form-validators/video.ts index b2e612c62..d972ee44b 100644 --- a/client/src/app/shared/forms/form-validators/video.ts +++ b/client/src/app/shared/forms/form-validators/video.ts @@ -8,6 +8,12 @@ export const VIDEO_NAME = { 'maxlength': 'Video name cannot be more than 50 characters long.' } }; +export const VIDEO_CATEGORY = { + VALIDATORS: [ Validators.required ], + MESSAGES: { + 'required': 'Video category is required.' + } +}; export const VIDEO_DESCRIPTION = { VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ], MESSAGES: { diff --git a/client/src/app/videos/shared/video.model.ts b/client/src/app/videos/shared/video.model.ts index 3eef936eb..b5d96f63a 100644 --- a/client/src/app/videos/shared/video.model.ts +++ b/client/src/app/videos/shared/video.model.ts @@ -2,6 +2,7 @@ export class Video { author: string; by: string; createdAt: Date; + categoryLabel: string; description: string; duration: string; id: string; @@ -31,6 +32,7 @@ export class Video { constructor(hash: { author: string, createdAt: string, + categoryLabel: string, description: string, duration: number; id: string, @@ -46,6 +48,7 @@ export class Video { }) { this.author = hash.author; this.createdAt = new Date(hash.createdAt); + this.categoryLabel = hash.categoryLabel; this.description = hash.description; this.duration = Video.createDurationString(hash.duration); this.id = hash.id; diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts index 8bb5a2933..debc114aa 100644 --- a/client/src/app/videos/shared/video.service.ts +++ b/client/src/app/videos/shared/video.service.ts @@ -22,6 +22,8 @@ import { Video } from './video.model'; export class VideoService { private static BASE_VIDEO_URL = '/api/v1/videos/'; + videoCategories: Array<{ id: number, label: string }> = []; + constructor( private authService: AuthService, private authHttp: AuthHttp, @@ -30,6 +32,19 @@ export class VideoService { private restService: RestService ) {} + 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), + label: data[categoryKey] + }); + }); + }); + } + getVideo(id: string): Observable