diff options
Diffstat (limited to 'client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts')
-rw-r--r-- | client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts b/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts new file mode 100644 index 000000000..836582609 --- /dev/null +++ b/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts | |||
@@ -0,0 +1,76 @@ | |||
1 | import { mergeMap } from 'rxjs' | ||
2 | import { SelectChannelItem } from 'src/types' | ||
3 | import { Component, OnInit } from '@angular/core' | ||
4 | import { Router } from '@angular/router' | ||
5 | import { AuthService, Notifier } from '@app/core' | ||
6 | import { listUserChannelsForSelect } from '@app/helpers' | ||
7 | import { VIDEO_CHANNEL_EXTERNAL_URL_VALIDATOR } from '@app/shared/form-validators/video-channel-validators' | ||
8 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | ||
9 | import { VideoChannelService, VideoChannelSyncService } from '@app/shared/shared-main' | ||
10 | import { VideoChannelSyncCreate } from '@shared/models/videos' | ||
11 | |||
12 | @Component({ | ||
13 | selector: 'my-video-channel-sync-edit', | ||
14 | templateUrl: './video-channel-sync-edit.component.html', | ||
15 | styleUrls: [ './video-channel-sync-edit.component.scss' ] | ||
16 | }) | ||
17 | export class VideoChannelSyncEditComponent extends FormReactive implements OnInit { | ||
18 | error: string | ||
19 | userVideoChannels: SelectChannelItem[] = [] | ||
20 | existingVideosStrategy: string | ||
21 | |||
22 | constructor ( | ||
23 | protected formValidatorService: FormValidatorService, | ||
24 | private authService: AuthService, | ||
25 | private router: Router, | ||
26 | private notifier: Notifier, | ||
27 | private videoChannelSyncService: VideoChannelSyncService, | ||
28 | private videoChannelService: VideoChannelService | ||
29 | ) { | ||
30 | super() | ||
31 | } | ||
32 | |||
33 | ngOnInit () { | ||
34 | this.buildForm({ | ||
35 | externalChannelUrl: VIDEO_CHANNEL_EXTERNAL_URL_VALIDATOR, | ||
36 | videoChannel: null, | ||
37 | existingVideoStrategy: null | ||
38 | }) | ||
39 | |||
40 | listUserChannelsForSelect(this.authService) | ||
41 | .subscribe(channels => this.userVideoChannels = channels) | ||
42 | } | ||
43 | |||
44 | getFormButtonTitle () { | ||
45 | return $localize`Create` | ||
46 | } | ||
47 | |||
48 | formValidated () { | ||
49 | this.error = undefined | ||
50 | |||
51 | const body = this.form.value | ||
52 | const videoChannelSyncCreate: VideoChannelSyncCreate = { | ||
53 | externalChannelUrl: body.externalChannelUrl, | ||
54 | videoChannelId: body.videoChannel | ||
55 | } | ||
56 | |||
57 | const importExistingVideos = body['existingVideoStrategy'] === 'import' | ||
58 | |||
59 | this.videoChannelSyncService.createSync(videoChannelSyncCreate) | ||
60 | .pipe(mergeMap(({ videoChannelSync }) => { | ||
61 | return importExistingVideos | ||
62 | ? this.videoChannelService.importVideos(videoChannelSync.channel.name, videoChannelSync.externalChannelUrl) | ||
63 | : Promise.resolve(null) | ||
64 | })) | ||
65 | .subscribe({ | ||
66 | next: () => { | ||
67 | this.notifier.success($localize`Synchronization created successfully.`) | ||
68 | this.router.navigate([ '/my-library', 'video-channel-syncs' ]) | ||
69 | }, | ||
70 | |||
71 | error: err => { | ||
72 | this.error = err.message | ||
73 | } | ||
74 | }) | ||
75 | } | ||
76 | } | ||