]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+my-account/my-account-videos/my-account-videos.component.ts
Fix regressions sub-menu titles on mobile-view
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-videos / my-account-videos.component.ts
index eb5096a5e9319b7c77b86087977d167e132749ef..2274c6a7b0f2a9e50c6b902be70c2d7944f84d03 100644 (file)
@@ -1,18 +1,14 @@
-import { concat, Observable } from 'rxjs'
-import { tap, toArray } from 'rxjs/operators'
-import { Component, Inject, LOCALE_ID, OnDestroy, OnInit, ViewChild } from '@angular/core'
+import { concat, Observable, Subject } from 'rxjs'
+import { debounceTime, tap, toArray } from 'rxjs/operators'
+import { Component, OnInit, ViewChild } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
-import { immutableAssign } from '@app/shared/misc/utils'
-import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
-import { Notifier, ServerService } from '@app/core'
-import { AuthService } from '../../core/auth'
-import { ConfirmService } from '../../core/confirm'
-import { AbstractVideoList } from '../../shared/video/abstract-video-list'
-import { Video } from '../../shared/video/video.model'
-import { VideoService } from '../../shared/video/video.service'
+import { AuthService, ComponentPagination, ConfirmService, Notifier, ScreenService, ServerService } from '@app/core'
+import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook'
+import { immutableAssign } from '@app/helpers'
+import { Video, VideoService } from '@app/shared/shared-main'
+import { MiniatureDisplayOptions, OwnerDisplayType, SelectionType, VideosSelectionComponent } from '@app/shared/shared-video-miniature'
 import { I18n } from '@ngx-translate/i18n-polyfill'
-import { VideoPrivacy, VideoState } from '../../../../../shared/models/videos'
-import { ScreenService } from '@app/shared/misc/screen.service'
+import { VideoSortField } from '@shared/models'
 import { VideoChangeOwnershipComponent } from './video-change-ownership/video-change-ownership.component'
 
 @Component({
@@ -20,16 +16,32 @@ import { VideoChangeOwnershipComponent } from './video-change-ownership/video-ch
   templateUrl: './my-account-videos.component.html',
   styleUrls: [ './my-account-videos.component.scss' ]
 })
-export class MyAccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy {
-  @ViewChild('videoChangeOwnershipModal') videoChangeOwnershipModal: VideoChangeOwnershipComponent
+export class MyAccountVideosComponent implements OnInit, DisableForReuseHook {
+  @ViewChild('videosSelection', { static: true }) videosSelection: VideosSelectionComponent
+  @ViewChild('videoChangeOwnershipModal', { static: true }) videoChangeOwnershipModal: VideoChangeOwnershipComponent
 
   titlePage: string
-  checkedVideos: { [ id: number ]: boolean } = {}
+  selection: SelectionType = {}
   pagination: ComponentPagination = {
     currentPage: 1,
-    itemsPerPage: 5,
+    itemsPerPage: 10,
     totalItems: null
   }
+  miniatureDisplayOptions: MiniatureDisplayOptions = {
+    date: true,
+    views: true,
+    by: true,
+    privacyLabel: false,
+    privacyText: true,
+    state: true,
+    blacklistInfo: true
+  }
+  ownerDisplayType: OwnerDisplayType = 'videoChannel'
+
+  videos: Video[] = []
+  videosSearch: string
+  videosSearchChanged = new Subject<string>()
+  getVideosObservableFunction = this.getVideosObservable.bind(this)
 
   constructor (
     protected router: Router,
@@ -40,43 +52,48 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni
     protected screenService: ScreenService,
     private i18n: I18n,
     private confirmService: ConfirmService,
-    private videoService: VideoService,
-    @Inject(LOCALE_ID) private localeId: string
+    private videoService: VideoService
   ) {
-    super()
-
     this.titlePage = this.i18n('My videos')
   }
 
   ngOnInit () {
-    super.ngOnInit()
+    this.videosSearchChanged
+      .pipe(debounceTime(500))
+      .subscribe(() => {
+        this.videosSelection.reloadVideos()
+      })
   }
 
-  ngOnDestroy () {
-    super.ngOnDestroy()
+  resetSearch () {
+    this.videosSearch = ''
+    this.onVideosSearchChanged()
   }
 
-  abortSelectionMode () {
-    this.checkedVideos = {}
+  onVideosSearchChanged () {
+    this.videosSearchChanged.next()
   }
 
-  isInSelectionMode () {
-    return Object.keys(this.checkedVideos).some(k => this.checkedVideos[ k ] === true)
+  disableForReuse () {
+    this.videosSelection.disableForReuse()
   }
 
-  getVideosObservable (page: number) {
-    const newPagination = immutableAssign(this.pagination, { currentPage: page })
-
-    return this.videoService.getMyVideos(newPagination, this.sort)
+  enabledForReuse () {
+    this.videosSelection.enabledForReuse()
   }
 
-  generateSyndicationList () {
-    throw new Error('Method not implemented.')
+  getVideosObservable (page: number, sort: VideoSortField) {
+    const newPagination = immutableAssign(this.pagination, { currentPage: page })
+
+    return this.videoService.getMyVideos(newPagination, sort, this.videosSearch)
+      .pipe(
+        tap(res => this.pagination.totalItems = res.total)
+      )
   }
 
   async deleteSelectedVideos () {
-    const toDeleteVideosIds = Object.keys(this.checkedVideos)
-                                    .filter(k => this.checkedVideos[ k ] === true)
+    const toDeleteVideosIds = Object.keys(this.selection)
+                                    .filter(k => this.selection[ k ] === true)
                                     .map(k => parseInt(k, 10))
 
     const res = await this.confirmService.confirm(
@@ -99,7 +116,7 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni
         () => {
           this.notifier.success(this.i18n('{{deleteLength}} videos deleted.', { deleteLength: toDeleteVideosIds.length }))
 
-          this.abortSelectionMode()
+          this.selection = {}
         },
 
         err => this.notifier.error(err.message)
@@ -117,7 +134,7 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni
         .subscribe(
           () => {
             this.notifier.success(this.i18n('Video {{videoName}} deleted.', { videoName: video.name }))
-            this.reloadVideos()
+            this.removeVideoFromArray(video.id)
           },
 
           error => this.notifier.error(error.message)
@@ -129,27 +146,6 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni
     this.videoChangeOwnershipModal.show(video)
   }
 
-  getStateLabel (video: Video) {
-    let suffix: string
-
-    if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) {
-      suffix = this.i18n('Published')
-    } else if (video.scheduledUpdate) {
-      const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId)
-      suffix = this.i18n('Publication scheduled on ') + updateAt
-    } else if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) {
-      suffix = this.i18n('Waiting transcoding')
-    } else if (video.state.id === VideoState.TO_TRANSCODE) {
-      suffix = this.i18n('To transcode')
-    } else if (video.state.id === VideoState.TO_IMPORT) {
-      suffix = this.i18n('To import')
-    } else {
-      return ''
-    }
-
-    return ' - ' + suffix
-  }
-
   private removeVideoFromArray (id: number) {
     this.videos = this.videos.filter(v => v.id !== id)
   }