From 6e07c3de88791a0b342e0cc319590048117f9c2d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 22 Mar 2017 21:15:55 +0100 Subject: Add video category support --- client/src/app/app.component.ts | 4 ++++ client/src/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 +++++++++++++++ .../app/videos/video-add/video-add.component.html | 12 ++++++++++++ .../src/app/videos/video-add/video-add.component.ts | 20 ++++++++++++++++++-- .../videos/video-watch/video-watch.component.html | 7 +++++++ .../videos/video-watch/video-watch.component.scss | 10 +++++++++- 8 files changed, 74 insertions(+), 3 deletions(-) (limited to 'client/src') 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