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