From: Chocobozzz Date: Wed, 22 Mar 2017 20:15:55 +0000 (+0100) Subject: Add video category support X-Git-Tag: v0.0.1-alpha~493 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6e07c3de88791a0b342e0cc319590048117f9c2d;p=oweals%2Fpeertube.git Add video category support --- 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