diff options
Diffstat (limited to 'client/src/app/+my-account/my-account-videos/my-account-videos.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-videos/my-account-videos.component.ts | 72 |
1 files changed, 20 insertions, 52 deletions
diff --git a/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts index bbe86af73..5f29364a8 100644 --- a/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts +++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts | |||
@@ -1,31 +1,33 @@ | |||
1 | import { concat, Observable } from 'rxjs' | 1 | import { concat, Observable } from 'rxjs' |
2 | import { tap, toArray } from 'rxjs/operators' | 2 | import { tap, toArray } from 'rxjs/operators' |
3 | import { Component, Inject, LOCALE_ID, OnDestroy, OnInit, ViewChild } from '@angular/core' | 3 | import { Component, ViewChild } from '@angular/core' |
4 | import { ActivatedRoute, Router } from '@angular/router' | 4 | import { ActivatedRoute, Router } from '@angular/router' |
5 | import { immutableAssign } from '@app/shared/misc/utils' | 5 | import { immutableAssign } from '@app/shared/misc/utils' |
6 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | 6 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' |
7 | import { Notifier, ServerService } from '@app/core' | 7 | import { Notifier, ServerService } from '@app/core' |
8 | import { AuthService } from '../../core/auth' | 8 | import { AuthService } from '../../core/auth' |
9 | import { ConfirmService } from '../../core/confirm' | 9 | import { ConfirmService } from '../../core/confirm' |
10 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | ||
11 | import { Video } from '../../shared/video/video.model' | 10 | import { Video } from '../../shared/video/video.model' |
12 | import { VideoService } from '../../shared/video/video.service' | 11 | import { VideoService } from '../../shared/video/video.service' |
13 | import { I18n } from '@ngx-translate/i18n-polyfill' | 12 | import { I18n } from '@ngx-translate/i18n-polyfill' |
14 | import { VideoPrivacy, VideoState } from '../../../../../shared/models/videos' | ||
15 | import { ScreenService } from '@app/shared/misc/screen.service' | 13 | import { ScreenService } from '@app/shared/misc/screen.service' |
16 | import { VideoChangeOwnershipComponent } from './video-change-ownership/video-change-ownership.component' | 14 | import { VideoChangeOwnershipComponent } from './video-change-ownership/video-change-ownership.component' |
17 | import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component' | 15 | import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component' |
16 | import { SelectionType, VideosSelectionComponent } from '@app/shared/video/videos-selection.component' | ||
17 | import { VideoSortField } from '@app/shared/video/sort-field.type' | ||
18 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' | ||
18 | 19 | ||
19 | @Component({ | 20 | @Component({ |
20 | selector: 'my-account-videos', | 21 | selector: 'my-account-videos', |
21 | templateUrl: './my-account-videos.component.html', | 22 | templateUrl: './my-account-videos.component.html', |
22 | styleUrls: [ './my-account-videos.component.scss' ] | 23 | styleUrls: [ './my-account-videos.component.scss' ] |
23 | }) | 24 | }) |
24 | export class MyAccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { | 25 | export class MyAccountVideosComponent implements DisableForReuseHook { |
26 | @ViewChild('videosSelection') videosSelection: VideosSelectionComponent | ||
25 | @ViewChild('videoChangeOwnershipModal') videoChangeOwnershipModal: VideoChangeOwnershipComponent | 27 | @ViewChild('videoChangeOwnershipModal') videoChangeOwnershipModal: VideoChangeOwnershipComponent |
26 | 28 | ||
27 | titlePage: string | 29 | titlePage: string |
28 | checkedVideos: { [ id: number ]: boolean } = {} | 30 | selection: SelectionType = {} |
29 | pagination: ComponentPagination = { | 31 | pagination: ComponentPagination = { |
30 | currentPage: 1, | 32 | currentPage: 1, |
31 | itemsPerPage: 5, | 33 | itemsPerPage: 5, |
@@ -40,6 +42,8 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
40 | state: true, | 42 | state: true, |
41 | blacklistInfo: true | 43 | blacklistInfo: true |
42 | } | 44 | } |
45 | videos: Video[] = [] | ||
46 | getVideosObservableFunction = this.getVideosObservable.bind(this) | ||
43 | 47 | ||
44 | constructor ( | 48 | constructor ( |
45 | protected router: Router, | 49 | protected router: Router, |
@@ -50,43 +54,28 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
50 | protected screenService: ScreenService, | 54 | protected screenService: ScreenService, |
51 | private i18n: I18n, | 55 | private i18n: I18n, |
52 | private confirmService: ConfirmService, | 56 | private confirmService: ConfirmService, |
53 | private videoService: VideoService, | 57 | private videoService: VideoService |
54 | @Inject(LOCALE_ID) private localeId: string | ||
55 | ) { | 58 | ) { |
56 | super() | ||
57 | |||
58 | this.titlePage = this.i18n('My videos') | 59 | this.titlePage = this.i18n('My videos') |
59 | } | 60 | } |
60 | 61 | ||
61 | ngOnInit () { | 62 | disableForReuse () { |
62 | super.ngOnInit() | 63 | this.videosSelection.disableForReuse() |
63 | } | ||
64 | |||
65 | ngOnDestroy () { | ||
66 | super.ngOnDestroy() | ||
67 | } | 64 | } |
68 | 65 | ||
69 | abortSelectionMode () { | 66 | enabledForReuse () { |
70 | this.checkedVideos = {} | 67 | this.videosSelection.enabledForReuse() |
71 | } | 68 | } |
72 | 69 | ||
73 | isInSelectionMode () { | 70 | getVideosObservable (page: number, sort: VideoSortField) { |
74 | return Object.keys(this.checkedVideos).some(k => this.checkedVideos[ k ] === true) | ||
75 | } | ||
76 | |||
77 | getVideosObservable (page: number) { | ||
78 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | 71 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) |
79 | 72 | ||
80 | return this.videoService.getMyVideos(newPagination, this.sort) | 73 | return this.videoService.getMyVideos(newPagination, sort) |
81 | } | ||
82 | |||
83 | generateSyndicationList () { | ||
84 | throw new Error('Method not implemented.') | ||
85 | } | 74 | } |
86 | 75 | ||
87 | async deleteSelectedVideos () { | 76 | async deleteSelectedVideos () { |
88 | const toDeleteVideosIds = Object.keys(this.checkedVideos) | 77 | const toDeleteVideosIds = Object.keys(this.selection) |
89 | .filter(k => this.checkedVideos[ k ] === true) | 78 | .filter(k => this.selection[ k ] === true) |
90 | .map(k => parseInt(k, 10)) | 79 | .map(k => parseInt(k, 10)) |
91 | 80 | ||
92 | const res = await this.confirmService.confirm( | 81 | const res = await this.confirmService.confirm( |
@@ -109,7 +98,7 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
109 | () => { | 98 | () => { |
110 | this.notifier.success(this.i18n('{{deleteLength}} videos deleted.', { deleteLength: toDeleteVideosIds.length })) | 99 | this.notifier.success(this.i18n('{{deleteLength}} videos deleted.', { deleteLength: toDeleteVideosIds.length })) |
111 | 100 | ||
112 | this.abortSelectionMode() | 101 | this.selection = {} |
113 | }, | 102 | }, |
114 | 103 | ||
115 | err => this.notifier.error(err.message) | 104 | err => this.notifier.error(err.message) |
@@ -127,7 +116,7 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
127 | .subscribe( | 116 | .subscribe( |
128 | () => { | 117 | () => { |
129 | this.notifier.success(this.i18n('Video {{videoName}} deleted.', { videoName: video.name })) | 118 | this.notifier.success(this.i18n('Video {{videoName}} deleted.', { videoName: video.name })) |
130 | this.reloadVideos() | 119 | this.removeVideoFromArray(video.id) |
131 | }, | 120 | }, |
132 | 121 | ||
133 | error => this.notifier.error(error.message) | 122 | error => this.notifier.error(error.message) |
@@ -139,27 +128,6 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
139 | this.videoChangeOwnershipModal.show(video) | 128 | this.videoChangeOwnershipModal.show(video) |
140 | } | 129 | } |
141 | 130 | ||
142 | getStateLabel (video: Video) { | ||
143 | let suffix: string | ||
144 | |||
145 | if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) { | ||
146 | suffix = this.i18n('Published') | ||
147 | } else if (video.scheduledUpdate) { | ||
148 | const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId) | ||
149 | suffix = this.i18n('Publication scheduled on ') + updateAt | ||
150 | } else if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) { | ||
151 | suffix = this.i18n('Waiting transcoding') | ||
152 | } else if (video.state.id === VideoState.TO_TRANSCODE) { | ||
153 | suffix = this.i18n('To transcode') | ||
154 | } else if (video.state.id === VideoState.TO_IMPORT) { | ||
155 | suffix = this.i18n('To import') | ||
156 | } else { | ||
157 | return '' | ||
158 | } | ||
159 | |||
160 | return ' - ' + suffix | ||
161 | } | ||
162 | |||
163 | private removeVideoFromArray (id: number) { | 131 | private removeVideoFromArray (id: number) { |
164 | this.videos = this.videos.filter(v => v.id !== id) | 132 | this.videos = this.videos.filter(v => v.id !== id) |
165 | } | 133 | } |