diff options
Diffstat (limited to 'client/src/app/shared/video-playlist/video-add-to-playlist.component.ts')
-rw-r--r-- | client/src/app/shared/video-playlist/video-add-to-playlist.component.ts | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/client/src/app/shared/video-playlist/video-add-to-playlist.component.ts b/client/src/app/shared/video-playlist/video-add-to-playlist.component.ts index 6380c2e51..25ba8cbca 100644 --- a/client/src/app/shared/video-playlist/video-add-to-playlist.component.ts +++ b/client/src/app/shared/video-playlist/video-add-to-playlist.component.ts | |||
@@ -1,7 +1,8 @@ | |||
1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core' | 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core' |
2 | import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service' | 2 | import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service' |
3 | import { AuthService, Notifier } from '@app/core' | 3 | import { AuthService, Notifier } from '@app/core' |
4 | import { forkJoin } from 'rxjs' | 4 | import { forkJoin, Subject } from 'rxjs' |
5 | import { debounceTime } from 'rxjs/operators' | ||
5 | import { Video, VideoPlaylistCreate, VideoPlaylistElementCreate, VideoPlaylistPrivacy } from '@shared/models' | 6 | import { Video, VideoPlaylistCreate, VideoPlaylistElementCreate, VideoPlaylistPrivacy } from '@shared/models' |
6 | import { FormReactive, FormValidatorService, VideoPlaylistValidatorsService } from '@app/shared/forms' | 7 | import { FormReactive, FormValidatorService, VideoPlaylistValidatorsService } from '@app/shared/forms' |
7 | import { I18n } from '@ngx-translate/i18n-polyfill' | 8 | import { I18n } from '@ngx-translate/i18n-polyfill' |
@@ -29,6 +30,8 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, | |||
29 | @Input() lazyLoad = false | 30 | @Input() lazyLoad = false |
30 | 31 | ||
31 | isNewPlaylistBlockOpened = false | 32 | isNewPlaylistBlockOpened = false |
33 | videoPlaylistSearch: string | ||
34 | videoPlaylistSearchChanged = new Subject<string>() | ||
32 | videoPlaylists: PlaylistSummary[] = [] | 35 | videoPlaylists: PlaylistSummary[] = [] |
33 | timestampOptions: { | 36 | timestampOptions: { |
34 | startTimestampEnabled: boolean | 37 | startTimestampEnabled: boolean |
@@ -58,6 +61,13 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, | |||
58 | this.buildForm({ | 61 | this.buildForm({ |
59 | displayName: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME | 62 | displayName: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME |
60 | }) | 63 | }) |
64 | |||
65 | this.videoPlaylistSearchChanged | ||
66 | .pipe( | ||
67 | debounceTime(500)) | ||
68 | .subscribe(() => { | ||
69 | this.load() | ||
70 | }) | ||
61 | } | 71 | } |
62 | 72 | ||
63 | ngOnChanges (simpleChanges: SimpleChanges) { | 73 | ngOnChanges (simpleChanges: SimpleChanges) { |
@@ -74,6 +84,7 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, | |||
74 | 84 | ||
75 | reload () { | 85 | reload () { |
76 | this.videoPlaylists = [] | 86 | this.videoPlaylists = [] |
87 | this.videoPlaylistSearch = undefined | ||
77 | 88 | ||
78 | this.init() | 89 | this.init() |
79 | 90 | ||
@@ -82,11 +93,12 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, | |||
82 | 93 | ||
83 | load () { | 94 | load () { |
84 | forkJoin([ | 95 | forkJoin([ |
85 | this.videoPlaylistService.listAccountPlaylists(this.user.account, undefined,'-updatedAt'), | 96 | this.videoPlaylistService.listAccountPlaylists(this.user.account, undefined, '-updatedAt', this.videoPlaylistSearch), |
86 | this.videoPlaylistService.doesVideoExistInPlaylist(this.video.id) | 97 | this.videoPlaylistService.doesVideoExistInPlaylist(this.video.id) |
87 | ]) | 98 | ]) |
88 | .subscribe( | 99 | .subscribe( |
89 | ([ playlistsResult, existResult ]) => { | 100 | ([ playlistsResult, existResult ]) => { |
101 | this.videoPlaylists = [] | ||
90 | for (const playlist of playlistsResult.data) { | 102 | for (const playlist of playlistsResult.data) { |
91 | const existingPlaylist = existResult[ this.video.id ].find(p => p.playlistId === playlist.id) | 103 | const existingPlaylist = existResult[ this.video.id ].find(p => p.playlistId === playlist.id) |
92 | 104 | ||
@@ -178,6 +190,10 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, | |||
178 | return `(${start}-${stop})` | 190 | return `(${start}-${stop})` |
179 | } | 191 | } |
180 | 192 | ||
193 | onVideoPlaylistSearchChanged () { | ||
194 | this.videoPlaylistSearchChanged.next() | ||
195 | } | ||
196 | |||
181 | private removeVideoFromPlaylist (playlist: PlaylistSummary) { | 197 | private removeVideoFromPlaylist (playlist: PlaylistSummary) { |
182 | if (!playlist.playlistElementId) return | 198 | if (!playlist.playlistElementId) return |
183 | 199 | ||