]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts
Migrate to $localize
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-video-playlists / my-account-video-playlist-elements.component.ts
index 22c9af566b5984910b62bf507fee4a0f3cc64f96..f6cdf10674edcbe36414abe6c74e3efddce18afa 100644 (file)
@@ -1,15 +1,12 @@
-import { Component, OnDestroy, OnInit } from '@angular/core'
-import { Notifier, ServerService } from '@app/core'
-import { AuthService } from '../../core/auth'
-import { ConfirmService } from '../../core/confirm'
-import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
 import { Subject, Subscription } from 'rxjs'
-import { ActivatedRoute } from '@angular/router'
-import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
-import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
-import { I18n } from '@ngx-translate/i18n-polyfill'
 import { CdkDragDrop } from '@angular/cdk/drag-drop'
-import { VideoPlaylistElement } from '@app/shared/video-playlist/video-playlist-element.model'
+import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
+import { ActivatedRoute, Router } from '@angular/router'
+import { ComponentPagination, ConfirmService, Notifier, ScreenService } from '@app/core'
+import { DropdownAction } from '@app/shared/shared-main'
+import { VideoShareComponent } from '@app/shared/shared-share-modal'
+import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist'
+import { VideoPlaylistType } from '@shared/models'
 
 @Component({
   selector: 'my-account-video-playlist-elements',
@@ -17,9 +14,13 @@ import { VideoPlaylistElement } from '@app/shared/video-playlist/video-playlist-
   styleUrls: [ './my-account-video-playlist-elements.component.scss' ]
 })
 export class MyAccountVideoPlaylistElementsComponent implements OnInit, OnDestroy {
+  @ViewChild('videoShareModal') videoShareModal: VideoShareComponent
+
   playlistElements: VideoPlaylistElement[] = []
   playlist: VideoPlaylist
 
+  playlistActions: DropdownAction<VideoPlaylist>[][] = []
+
   pagination: ComponentPagination = {
     currentPage: 1,
     itemsPerPage: 10,
@@ -32,16 +33,30 @@ export class MyAccountVideoPlaylistElementsComponent implements OnInit, OnDestro
   private paramsSub: Subscription
 
   constructor (
-    private authService: AuthService,
-    private serverService: ServerService,
     private notifier: Notifier,
+    private router: Router,
     private confirmService: ConfirmService,
     private route: ActivatedRoute,
-    private i18n: I18n,
+    private screenService: ScreenService,
     private videoPlaylistService: VideoPlaylistService
   ) {}
 
   ngOnInit () {
+    this.playlistActions = [
+      [
+        {
+          label: $localize`Update playlist`,
+          iconName: 'edit',
+          linkBuilder: playlist => [ '/my-account', 'video-playlists', 'update', playlist.uuid ]
+        },
+        {
+          label: $localize`Delete playlist`,
+          iconName: 'delete',
+          handler: playlist => this.deleteVideoPlaylist(playlist)
+        }
+      ]
+    ]
+
     this.paramsSub = this.route.params.subscribe(routeParams => {
       this.videoPlaylistId = routeParams[ 'videoPlaylistId' ]
       this.loadElements()
@@ -99,6 +114,49 @@ export class MyAccountVideoPlaylistElementsComponent implements OnInit, OnDestro
     return elem.id
   }
 
+  isRegularPlaylist (playlist: VideoPlaylist) {
+    return playlist?.type.id === VideoPlaylistType.REGULAR
+  }
+
+  showShareModal () {
+    this.videoShareModal.show()
+  }
+
+  async deleteVideoPlaylist (videoPlaylist: VideoPlaylist) {
+    const res = await this.confirmService.confirm(
+      $localize`Do you really want to delete ${videoPlaylist.displayName}?`,
+      $localize`Delete`
+    )
+    if (res === false) return
+
+    this.videoPlaylistService.removeVideoPlaylist(videoPlaylist)
+      .subscribe(
+        () => {
+          this.router.navigate([ '/my-account', 'video-playlists' ])
+          this.notifier.success($localize`Playlist ${videoPlaylist.displayName} deleted.`)
+        },
+
+        error => this.notifier.error(error.message)
+      )
+  }
+
+  /**
+   * Returns null to not have drag and drop delay.
+   * In small views, where elements are about 100% wide,
+   * we add a delay to prevent unwanted drag&drop.
+   *
+   * @see {@link https://github.com/Chocobozzz/PeerTube/issues/2078}
+   *
+   * @returns {null|number} Null for no delay, or a number in milliseconds.
+   */
+  getDragStartDelay (): null | number {
+    if (this.screenService.isInTouchScreen()) {
+      return 500
+    }
+
+    return null
+  }
+
   private loadElements () {
     this.videoPlaylistService.getPlaylistVideos(this.videoPlaylistId, this.pagination)
         .subscribe(({ total, data }) => {