From 830b4faff15fb9c81d88e8e69fcdf94aad32bef8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 6 Mar 2019 15:36:44 +0100 Subject: Add/update/delete/list my playlists --- .../my-account-video-playlist-create.component.ts | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts (limited to 'client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts') diff --git a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts new file mode 100644 index 000000000..61b61e221 --- /dev/null +++ b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts @@ -0,0 +1,89 @@ +import { Component, OnInit } from '@angular/core' +import { Router } from '@angular/router' +import { AuthService, Notifier, ServerService } from '@app/core' +import { MyAccountVideoPlaylistEdit } from './my-account-video-playlist-edit' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' +import { VideoPlaylistValidatorsService } from '@app/shared' +import { VideoPlaylistCreate } from '@shared/models/videos/playlist/video-playlist-create.model' +import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service' +import { VideoConstant } from '@shared/models' +import { VideoPlaylistPrivacy } from '@shared/models/videos/playlist/video-playlist-privacy.model' +import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils' + +@Component({ + selector: 'my-account-video-playlist-create', + templateUrl: './my-account-video-playlist-edit.component.html', + styleUrls: [ './my-account-video-playlist-edit.component.scss' ] +}) +export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylistEdit implements OnInit { + error: string + videoPlaylistPrivacies: VideoConstant[] = [] + + constructor ( + protected formValidatorService: FormValidatorService, + private authService: AuthService, + private videoPlaylistValidatorsService: VideoPlaylistValidatorsService, + private notifier: Notifier, + private router: Router, + private videoPlaylistService: VideoPlaylistService, + private serverService: ServerService, + private i18n: I18n + ) { + super() + } + + ngOnInit () { + this.buildForm({ + 'display-name': this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME, + privacy: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_PRIVACY, + description: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DESCRIPTION, + videoChannelId: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_CHANNEL_ID, + thumbnailfile: null + }) + + populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) + + this.serverService.videoPlaylistPrivaciesLoaded.subscribe( + () => { + this.videoPlaylistPrivacies = this.serverService.getVideoPlaylistPrivacies() + + this.form.patchValue({ + privacy: VideoPlaylistPrivacy.PRIVATE + }) + } + ) + } + + formValidated () { + this.error = undefined + + const body = this.form.value + const videoPlaylistCreate: VideoPlaylistCreate = { + displayName: body['display-name'], + privacy: body.privacy, + description: body.description || null, + videoChannelId: body.videoChannelId || null, + thumbnailfile: body.thumbnailfile || null + } + + this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate).subscribe( + () => { + this.notifier.success( + this.i18n('Playlist {{playlistName}} created.', { playlistName: videoPlaylistCreate.displayName }) + ) + this.router.navigate([ '/my-account', 'video-playlists' ]) + }, + + err => this.error = err.message + ) + } + + isCreation () { + return true + } + + getFormButtonTitle () { + return this.i18n('Create') + } +} -- cgit v1.2.3