diff options
Diffstat (limited to 'client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts index 0add81c38..e278d9ed2 100644 --- a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts +++ b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts | |||
@@ -1,9 +1,13 @@ | |||
1 | import { Subject, Subscription } from 'rxjs' | 1 | import { Subject, Subscription } from 'rxjs' |
2 | import { CdkDragDrop } from '@angular/cdk/drag-drop' | 2 | import { CdkDragDrop } from '@angular/cdk/drag-drop' |
3 | import { Component, OnDestroy, OnInit } from '@angular/core' | 3 | import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core' |
4 | import { ActivatedRoute } from '@angular/router' | 4 | import { ActivatedRoute, Router } from '@angular/router' |
5 | import { ComponentPagination, Notifier, ScreenService } from '@app/core' | 5 | import { ComponentPagination, ConfirmService, Notifier, ScreenService } from '@app/core' |
6 | import { DropdownAction } from '@app/shared/shared-main' | ||
7 | import { VideoShareComponent } from '@app/shared/shared-share-modal' | ||
6 | import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist' | 8 | import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist' |
9 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
10 | import { VideoPlaylistType } from '@shared/models' | ||
7 | 11 | ||
8 | @Component({ | 12 | @Component({ |
9 | selector: 'my-account-video-playlist-elements', | 13 | selector: 'my-account-video-playlist-elements', |
@@ -11,9 +15,13 @@ import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/ | |||
11 | styleUrls: [ './my-account-video-playlist-elements.component.scss' ] | 15 | styleUrls: [ './my-account-video-playlist-elements.component.scss' ] |
12 | }) | 16 | }) |
13 | export class MyAccountVideoPlaylistElementsComponent implements OnInit, OnDestroy { | 17 | export class MyAccountVideoPlaylistElementsComponent implements OnInit, OnDestroy { |
18 | @ViewChild('videoShareModal') videoShareModal: VideoShareComponent | ||
19 | |||
14 | playlistElements: VideoPlaylistElement[] = [] | 20 | playlistElements: VideoPlaylistElement[] = [] |
15 | playlist: VideoPlaylist | 21 | playlist: VideoPlaylist |
16 | 22 | ||
23 | playlistActions: DropdownAction<VideoPlaylist>[][] = [] | ||
24 | |||
17 | pagination: ComponentPagination = { | 25 | pagination: ComponentPagination = { |
18 | currentPage: 1, | 26 | currentPage: 1, |
19 | itemsPerPage: 10, | 27 | itemsPerPage: 10, |
@@ -27,12 +35,30 @@ export class MyAccountVideoPlaylistElementsComponent implements OnInit, OnDestro | |||
27 | 35 | ||
28 | constructor ( | 36 | constructor ( |
29 | private notifier: Notifier, | 37 | private notifier: Notifier, |
38 | private i18n: I18n, | ||
39 | private router: Router, | ||
40 | private confirmService: ConfirmService, | ||
30 | private route: ActivatedRoute, | 41 | private route: ActivatedRoute, |
31 | private screenService: ScreenService, | 42 | private screenService: ScreenService, |
32 | private videoPlaylistService: VideoPlaylistService | 43 | private videoPlaylistService: VideoPlaylistService |
33 | ) {} | 44 | ) {} |
34 | 45 | ||
35 | ngOnInit () { | 46 | ngOnInit () { |
47 | this.playlistActions = [ | ||
48 | [ | ||
49 | { | ||
50 | label: this.i18n('Update playlist'), | ||
51 | iconName: 'edit', | ||
52 | linkBuilder: playlist => [ '/my-account', 'video-playlists', 'update', playlist.uuid ] | ||
53 | }, | ||
54 | { | ||
55 | label: this.i18n('Delete playlist'), | ||
56 | iconName: 'delete', | ||
57 | handler: playlist => this.deleteVideoPlaylist(playlist) | ||
58 | } | ||
59 | ] | ||
60 | ] | ||
61 | |||
36 | this.paramsSub = this.route.params.subscribe(routeParams => { | 62 | this.paramsSub = this.route.params.subscribe(routeParams => { |
37 | this.videoPlaylistId = routeParams[ 'videoPlaylistId' ] | 63 | this.videoPlaylistId = routeParams[ 'videoPlaylistId' ] |
38 | this.loadElements() | 64 | this.loadElements() |
@@ -90,6 +116,38 @@ export class MyAccountVideoPlaylistElementsComponent implements OnInit, OnDestro | |||
90 | return elem.id | 116 | return elem.id |
91 | } | 117 | } |
92 | 118 | ||
119 | isRegularPlaylist (playlist: VideoPlaylist) { | ||
120 | return playlist?.type.id === VideoPlaylistType.REGULAR | ||
121 | } | ||
122 | |||
123 | showShareModal () { | ||
124 | this.videoShareModal.show() | ||
125 | } | ||
126 | |||
127 | async deleteVideoPlaylist (videoPlaylist: VideoPlaylist) { | ||
128 | const res = await this.confirmService.confirm( | ||
129 | this.i18n( | ||
130 | 'Do you really want to delete {{playlistDisplayName}}?', | ||
131 | { playlistDisplayName: videoPlaylist.displayName } | ||
132 | ), | ||
133 | this.i18n('Delete') | ||
134 | ) | ||
135 | if (res === false) return | ||
136 | |||
137 | this.videoPlaylistService.removeVideoPlaylist(videoPlaylist) | ||
138 | .subscribe( | ||
139 | () => { | ||
140 | this.router.navigate([ '/my-account', 'video-playlists' ]) | ||
141 | |||
142 | this.notifier.success( | ||
143 | this.i18n('Playlist {{playlistDisplayName}} deleted.', { playlistDisplayName: videoPlaylist.displayName }) | ||
144 | ) | ||
145 | }, | ||
146 | |||
147 | error => this.notifier.error(error.message) | ||
148 | ) | ||
149 | } | ||
150 | |||
93 | /** | 151 | /** |
94 | * Returns null to not have drag and drop delay. | 152 | * Returns null to not have drag and drop delay. |
95 | * In small views, where elements are about 100% wide, | 153 | * In small views, where elements are about 100% wide, |