1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { AuthService, Notifier } from '@app/core'
5 VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
6 VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
7 VIDEO_CHANNEL_NAME_VALIDATOR,
8 VIDEO_CHANNEL_SUPPORT_VALIDATOR
9 } from '@app/shared/form-validators/video-channel-validators'
10 import { FormValidatorService } from '@app/shared/shared-forms'
11 import { VideoChannelService } from '@app/shared/shared-main'
12 import { VideoChannelCreate } from '@shared/models'
13 import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
14 import { MyVideoChannelEdit } from './my-video-channel-edit'
17 templateUrl: './my-video-channel-edit.component.html',
18 styleUrls: [ './my-video-channel-edit.component.scss' ]
20 export class MyVideoChannelCreateComponent extends MyVideoChannelEdit implements OnInit {
24 protected formValidatorService: FormValidatorService,
25 private authService: AuthService,
26 private notifier: Notifier,
27 private router: Router,
28 private videoChannelService: VideoChannelService
35 name: VIDEO_CHANNEL_NAME_VALIDATOR,
36 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
37 description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
38 support: VIDEO_CHANNEL_SUPPORT_VALIDATOR
43 this.error = undefined
45 const body = this.form.value
46 const videoChannelCreate: VideoChannelCreate = {
48 displayName: body['display-name'],
49 description: body.description || null,
50 support: body.support || null
53 this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
55 this.authService.refreshUserInformation()
57 this.notifier.success($localize`Video channel ${videoChannelCreate.displayName} created.`)
58 this.router.navigate([ '/my-library', 'video-channels' ])
62 if (err.status === HttpStatusCode.CONFLICT_409) {
63 this.error = $localize`This name already exists on this instance.`
67 this.error = err.message
76 getFormButtonTitle () {
77 return $localize`Create`