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