diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-12-11 11:06:32 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-12-11 11:06:32 +0100 |
commit | fada8d75550dc7365f7e18ee1569b9406251d660 (patch) | |
tree | db9dc01c18693824f83fce5020f4c1f3ae7c0865 /client/src/app/account/account-videos/account-videos.component.ts | |
parent | 492fd28167f770d79a430fc57451b5a9e075d8e7 (diff) | |
parent | c2830fa8f84f61462098bf36add824f89436dfa9 (diff) | |
download | PeerTube-fada8d75550dc7365f7e18ee1569b9406251d660.tar.gz PeerTube-fada8d75550dc7365f7e18ee1569b9406251d660.tar.zst PeerTube-fada8d75550dc7365f7e18ee1569b9406251d660.zip |
Merge branch 'feature/design' into develop
Diffstat (limited to 'client/src/app/account/account-videos/account-videos.component.ts')
-rw-r--r-- | client/src/app/account/account-videos/account-videos.component.ts | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/client/src/app/account/account-videos/account-videos.component.ts b/client/src/app/account/account-videos/account-videos.component.ts new file mode 100644 index 000000000..5f12cfce0 --- /dev/null +++ b/client/src/app/account/account-videos/account-videos.component.ts | |||
@@ -0,0 +1,97 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { ActivatedRoute, Router } from '@angular/router' | ||
3 | import { NotificationsService } from 'angular2-notifications' | ||
4 | import 'rxjs/add/observable/from' | ||
5 | import 'rxjs/add/operator/concatAll' | ||
6 | import { Observable } from 'rxjs/Observable' | ||
7 | import { ConfirmService } from '../../core/confirm' | ||
8 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | ||
9 | import { Video } from '../../shared/video/video.model' | ||
10 | import { VideoService } from '../../shared/video/video.service' | ||
11 | |||
12 | @Component({ | ||
13 | selector: 'my-account-videos', | ||
14 | templateUrl: './account-videos.component.html', | ||
15 | styleUrls: [ './account-videos.component.scss' ] | ||
16 | }) | ||
17 | export class AccountVideosComponent extends AbstractVideoList implements OnInit { | ||
18 | titlePage = 'My videos' | ||
19 | currentRoute = '/account/videos' | ||
20 | checkedVideos: { [ id: number ]: boolean } = {} | ||
21 | |||
22 | constructor (protected router: Router, | ||
23 | protected route: ActivatedRoute, | ||
24 | protected notificationsService: NotificationsService, | ||
25 | protected confirmService: ConfirmService, | ||
26 | private videoService: VideoService) { | ||
27 | super() | ||
28 | } | ||
29 | |||
30 | ngOnInit () { | ||
31 | super.ngOnInit() | ||
32 | } | ||
33 | |||
34 | abortSelectionMode () { | ||
35 | this.checkedVideos = {} | ||
36 | } | ||
37 | |||
38 | isInSelectionMode () { | ||
39 | return Object.keys(this.checkedVideos).some(k => this.checkedVideos[k] === true) | ||
40 | } | ||
41 | |||
42 | getVideosObservable () { | ||
43 | return this.videoService.getMyVideos(this.pagination, this.sort) | ||
44 | } | ||
45 | |||
46 | deleteSelectedVideos () { | ||
47 | const toDeleteVideosIds = Object.keys(this.checkedVideos) | ||
48 | .filter(k => this.checkedVideos[k] === true) | ||
49 | .map(k => parseInt(k, 10)) | ||
50 | |||
51 | this.confirmService.confirm(`Do you really want to delete ${toDeleteVideosIds.length} videos?`, 'Delete').subscribe( | ||
52 | res => { | ||
53 | if (res === false) return | ||
54 | |||
55 | const observables: Observable<any>[] = [] | ||
56 | for (const videoId of toDeleteVideosIds) { | ||
57 | const o = this.videoService | ||
58 | .removeVideo(videoId) | ||
59 | .do(() => this.spliceVideosById(videoId)) | ||
60 | |||
61 | observables.push(o) | ||
62 | } | ||
63 | |||
64 | Observable.from(observables) | ||
65 | .concatAll() | ||
66 | .subscribe( | ||
67 | res => this.notificationsService.success('Success', `${toDeleteVideosIds.length} videos deleted.`), | ||
68 | |||
69 | err => this.notificationsService.error('Error', err.text) | ||
70 | ) | ||
71 | } | ||
72 | ) | ||
73 | } | ||
74 | |||
75 | deleteVideo (video: Video) { | ||
76 | this.confirmService.confirm(`Do you really want to delete ${video.name}?`, 'Delete').subscribe( | ||
77 | res => { | ||
78 | if (res === false) return | ||
79 | |||
80 | this.videoService.removeVideo(video.id) | ||
81 | .subscribe( | ||
82 | status => { | ||
83 | this.notificationsService.success('Success', `Video ${video.name} deleted.`) | ||
84 | this.spliceVideosById(video.id) | ||
85 | }, | ||
86 | |||
87 | error => this.notificationsService.error('Error', error.text) | ||
88 | ) | ||
89 | } | ||
90 | ) | ||
91 | } | ||
92 | |||
93 | private spliceVideosById (id: number) { | ||
94 | const index = this.videos.findIndex(v => v.id === id) | ||
95 | this.videos.splice(index, 1) | ||
96 | } | ||
97 | } | ||