From 17119e4a546522468878cf115558b17949ab50d0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 12 Nov 2020 15:28:54 +0100 Subject: Reorganize left menu and account menu Add my-settings and my-library in left menu Move administration below my-library Split account menu: my-setting and my library --- .../my-video-playlist-create.component.ts | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts (limited to 'client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts') diff --git a/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts b/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts new file mode 100644 index 000000000..5abea54b0 --- /dev/null +++ b/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts @@ -0,0 +1,91 @@ +import { Component, OnInit } from '@angular/core' +import { Router } from '@angular/router' +import { AuthService, Notifier, ServerService } from '@app/core' +import { populateAsyncUserVideoChannels } from '@app/helpers' +import { + setPlaylistChannelValidator, + VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR, + VIDEO_PLAYLIST_DESCRIPTION_VALIDATOR, + VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR, + VIDEO_PLAYLIST_PRIVACY_VALIDATOR +} from '@app/shared/form-validators/video-playlist-validators' +import { FormValidatorService } from '@app/shared/shared-forms' +import { VideoPlaylistService } from '@app/shared/shared-video-playlist' +import { VideoPlaylistCreate } from '@shared/models/videos/playlist/video-playlist-create.model' +import { VideoPlaylistPrivacy } from '@shared/models/videos/playlist/video-playlist-privacy.model' +import { MyVideoPlaylistEdit } from './my-video-playlist-edit' + +@Component({ + templateUrl: './my-video-playlist-edit.component.html', + styleUrls: [ './my-video-playlist-edit.component.scss' ] +}) +export class MyVideoPlaylistCreateComponent extends MyVideoPlaylistEdit implements OnInit { + error: string + + constructor ( + protected formValidatorService: FormValidatorService, + private authService: AuthService, + private notifier: Notifier, + private router: Router, + private videoPlaylistService: VideoPlaylistService, + private serverService: ServerService + ) { + super() + } + + ngOnInit () { + this.buildForm({ + displayName: VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR, + privacy: VIDEO_PLAYLIST_PRIVACY_VALIDATOR, + description: VIDEO_PLAYLIST_DESCRIPTION_VALIDATOR, + videoChannelId: VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR, + thumbnailfile: null + }) + + this.form.get('privacy').valueChanges.subscribe(privacy => { + setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy) + }) + + populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) + .catch(err => console.error('Cannot populate user video channels.', err)) + + this.serverService.getVideoPlaylistPrivacies() + .subscribe(videoPlaylistPrivacies => { + this.videoPlaylistPrivacies = videoPlaylistPrivacies + + this.form.patchValue({ + privacy: VideoPlaylistPrivacy.PRIVATE + }) + }) + } + + formValidated () { + this.error = undefined + + const body = this.form.value + const videoPlaylistCreate: VideoPlaylistCreate = { + displayName: body.displayName, + privacy: body.privacy, + description: body.description || null, + videoChannelId: body.videoChannelId || null, + thumbnailfile: body.thumbnailfile || null + } + + this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate).subscribe( + () => { + this.notifier.success($localize`Playlist ${videoPlaylistCreate.displayName} created.`) + this.router.navigate([ '/my-library', 'video-playlists' ]) + }, + + err => this.error = err.message + ) + } + + isCreation () { + return true + } + + getFormButtonTitle () { + return $localize`Create` + } +} -- cgit v1.2.3