]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/+my-account/my-account-video-channels/my-account-video-channel-update.component.ts
Add ability to schedule video publication
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-video-channels / my-account-video-channel-update.component.ts
... / ...
CommitLineData
1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router'
3import { NotificationsService } from 'angular2-notifications'
4import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
5import { VideoChannelUpdate } from '../../../../../shared/models/videos'
6import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
7import { Subscription } from 'rxjs'
8import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
9import { AuthService } from '@app/core'
10import { I18n } from '@ngx-translate/i18n-polyfill'
11import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
12import { VideoChannelValidatorsService } from '@app/shared/forms/form-validators/video-channel-validators.service'
13
14@Component({
15 selector: 'my-account-video-channel-update',
16 templateUrl: './my-account-video-channel-edit.component.html',
17 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
18})
19export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy {
20 error: string
21
22 private videoChannelToUpdate: VideoChannel
23 private paramsSub: Subscription
24
25 constructor (
26 protected formValidatorService: FormValidatorService,
27 private authService: AuthService,
28 private videoChannelValidatorsService: VideoChannelValidatorsService,
29 private notificationsService: NotificationsService,
30 private router: Router,
31 private route: ActivatedRoute,
32 private videoChannelService: VideoChannelService,
33 private i18n: I18n
34 ) {
35 super()
36 }
37
38 ngOnInit () {
39 this.buildForm({
40 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
41 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
42 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT
43 })
44
45 this.paramsSub = this.route.params.subscribe(routeParams => {
46 const videoChannelId = routeParams['videoChannelId']
47
48 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
49 videoChannelToUpdate => {
50 this.videoChannelToUpdate = videoChannelToUpdate
51
52 this.form.patchValue({
53 'display-name': videoChannelToUpdate.displayName,
54 description: videoChannelToUpdate.description,
55 support: videoChannelToUpdate.support
56 })
57 },
58
59 err => this.error = err.message
60 )
61 })
62 }
63
64 ngOnDestroy () {
65 if (this.paramsSub) this.paramsSub.unsubscribe()
66 }
67
68 formValidated () {
69 this.error = undefined
70
71 const body = this.form.value
72 const videoChannelUpdate: VideoChannelUpdate = {
73 displayName: body['display-name'],
74 description: body.description || null,
75 support: body.support || null
76 }
77
78 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.uuid, videoChannelUpdate).subscribe(
79 () => {
80 this.authService.refreshUserInformation()
81 this.notificationsService.success(
82 this.i18n('Success'),
83 this.i18n('Video channel {{videoChannelName}} updated.', { videoChannelName: videoChannelUpdate.displayName })
84 )
85 this.router.navigate([ '/my-account', 'video-channels' ])
86 },
87
88 err => this.error = err.message
89 )
90 }
91
92 isCreation () {
93 return false
94 }
95
96 getFormButtonTitle () {
97 return this.i18n('Update')
98 }
99}