]>
Commit | Line | Data |
---|---|---|
2e46eb97 C |
1 | import { Subject } from 'rxjs' |
2 | import { tap } from 'rxjs/operators' | |
3 | import { Component, ComponentFactoryResolver, OnInit, ViewChild } from '@angular/core' | |
80bfd33c | 4 | import { ActivatedRoute, Router } from '@angular/router' |
67ed6552 C |
5 | import { |
6 | AuthService, | |
7 | ComponentPagination, | |
8 | ConfirmService, | |
2e46eb97 | 9 | DisableForReuseHook, |
67ed6552 C |
10 | LocalStorageService, |
11 | Notifier, | |
12 | ScreenService, | |
13 | ServerService, | |
2e46eb97 | 14 | User, |
67ed6552 C |
15 | UserService |
16 | } from '@app/core' | |
17 | import { immutableAssign } from '@app/helpers' | |
2e46eb97 C |
18 | import { UserHistoryService, Video } from '@app/shared/shared-main' |
19 | import { MiniatureDisplayOptions, VideosSelectionComponent } from '@app/shared/shared-video-miniature' | |
80bfd33c C |
20 | |
21 | @Component({ | |
17119e4a C |
22 | templateUrl: './my-history.component.html', |
23 | styleUrls: [ './my-history.component.scss' ] | |
80bfd33c | 24 | }) |
2e46eb97 C |
25 | export class MyHistoryComponent implements OnInit, DisableForReuseHook { |
26 | @ViewChild('videosSelection', { static: true }) videosSelection: VideosSelectionComponent | |
27 | ||
80bfd33c | 28 | titlePage: string |
80bfd33c C |
29 | pagination: ComponentPagination = { |
30 | currentPage: 1, | |
31 | itemsPerPage: 5, | |
32 | totalItems: null | |
33 | } | |
2e46eb97 | 34 | |
276d9652 | 35 | videosHistoryEnabled: boolean |
d8b34ee5 | 36 | |
2e46eb97 C |
37 | miniatureDisplayOptions: MiniatureDisplayOptions = { |
38 | date: true, | |
39 | views: true, | |
40 | by: true, | |
41 | privacyLabel: false, | |
42 | privacyText: true, | |
43 | state: true, | |
44 | blacklistInfo: true | |
45 | } | |
46 | ||
47 | getVideosObservableFunction = this.getVideosObservable.bind(this) | |
48 | ||
49 | user: User | |
50 | ||
51 | videos: Video[] = [] | |
52 | search: string | |
80bfd33c | 53 | |
80bfd33c C |
54 | constructor ( |
55 | protected router: Router, | |
489290b8 | 56 | protected serverService: ServerService, |
80bfd33c C |
57 | protected route: ActivatedRoute, |
58 | protected authService: AuthService, | |
276d9652 | 59 | protected userService: UserService, |
f8b2c1b4 | 60 | protected notifier: Notifier, |
80bfd33c | 61 | protected screenService: ScreenService, |
d3217560 | 62 | protected storageService: LocalStorageService, |
80bfd33c | 63 | private confirmService: ConfirmService, |
5bcbcbe3 RK |
64 | private userHistoryService: UserHistoryService, |
65 | protected cfr: ComponentFactoryResolver | |
80bfd33c | 66 | ) { |
d8b34ee5 | 67 | this.titlePage = $localize`My watch history` |
80bfd33c C |
68 | } |
69 | ||
70 | ngOnInit () { | |
2e46eb97 | 71 | this.user = this.authService.getUser() |
276d9652 | 72 | |
4f926722 | 73 | this.authService.userInformationLoaded |
2e46eb97 C |
74 | .subscribe(() => this.videosHistoryEnabled = this.user.videosHistoryEnabled) |
75 | } | |
d8b34ee5 | 76 | |
2e46eb97 C |
77 | disableForReuse () { |
78 | this.videosSelection.disableForReuse() | |
d8b34ee5 RK |
79 | } |
80 | ||
2e46eb97 C |
81 | enabledForReuse () { |
82 | this.videosSelection.enabledForReuse() | |
d8b34ee5 RK |
83 | } |
84 | ||
2e46eb97 C |
85 | reloadData () { |
86 | this.videosSelection.reloadVideos() | |
80bfd33c C |
87 | } |
88 | ||
2e46eb97 C |
89 | onSearch (search: string) { |
90 | this.search = search | |
91 | this.reloadData() | |
80bfd33c C |
92 | } |
93 | ||
94 | getVideosObservable (page: number) { | |
95 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
96 | ||
d8b34ee5 RK |
97 | return this.userHistoryService.getUserVideosHistory(newPagination, this.search) |
98 | .pipe( | |
99 | tap(res => this.pagination.totalItems = res.total) | |
100 | ) | |
80bfd33c C |
101 | } |
102 | ||
103 | generateSyndicationList () { | |
5bcbcbe3 | 104 | /* method disabled */ |
80bfd33c C |
105 | throw new Error('Method not implemented.') |
106 | } | |
276d9652 C |
107 | |
108 | onVideosHistoryChange () { | |
109 | this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled }) | |
1378c0d3 C |
110 | .subscribe({ |
111 | next: () => { | |
276d9652 | 112 | const message = this.videosHistoryEnabled === true ? |
66357162 C |
113 | $localize`Videos history is enabled` : |
114 | $localize`Videos history is disabled` | |
276d9652 | 115 | |
f8b2c1b4 | 116 | this.notifier.success(message) |
276d9652 C |
117 | |
118 | this.authService.refreshUserInformation() | |
119 | }, | |
120 | ||
1378c0d3 C |
121 | error: err => this.notifier.error(err.message) |
122 | }) | |
276d9652 C |
123 | } |
124 | ||
125 | async deleteHistory () { | |
66357162 C |
126 | const title = $localize`Delete videos history` |
127 | const message = $localize`Are you sure you want to delete all your videos history?` | |
276d9652 C |
128 | |
129 | const res = await this.confirmService.confirm(message, title) | |
130 | if (res !== true) return | |
131 | ||
132 | this.userHistoryService.deleteUserVideosHistory() | |
1378c0d3 C |
133 | .subscribe({ |
134 | next: () => { | |
66357162 | 135 | this.notifier.success($localize`Videos history deleted`) |
276d9652 | 136 | |
2e46eb97 | 137 | this.reloadData() |
276d9652 C |
138 | }, |
139 | ||
1378c0d3 C |
140 | error: err => this.notifier.error(err.message) |
141 | }) | |
276d9652 | 142 | } |
80bfd33c | 143 | } |