]>
Commit | Line | Data |
---|---|---|
80bfd33c C |
1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
67ed6552 C |
3 | import { |
4 | AuthService, | |
5 | ComponentPagination, | |
6 | ConfirmService, | |
7 | LocalStorageService, | |
8 | Notifier, | |
9 | ScreenService, | |
10 | ServerService, | |
11 | UserService | |
12 | } from '@app/core' | |
13 | import { immutableAssign } from '@app/helpers' | |
14 | import { UserHistoryService } from '@app/shared/shared-main' | |
15 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | |
80bfd33c C |
16 | |
17 | @Component({ | |
17119e4a C |
18 | templateUrl: './my-history.component.html', |
19 | styleUrls: [ './my-history.component.scss' ] | |
80bfd33c | 20 | }) |
17119e4a | 21 | export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy { |
80bfd33c | 22 | titlePage: string |
80bfd33c C |
23 | pagination: ComponentPagination = { |
24 | currentPage: 1, | |
25 | itemsPerPage: 5, | |
26 | totalItems: null | |
27 | } | |
276d9652 | 28 | videosHistoryEnabled: boolean |
80bfd33c | 29 | |
80bfd33c C |
30 | constructor ( |
31 | protected router: Router, | |
489290b8 | 32 | protected serverService: ServerService, |
80bfd33c C |
33 | protected route: ActivatedRoute, |
34 | protected authService: AuthService, | |
276d9652 | 35 | protected userService: UserService, |
f8b2c1b4 | 36 | protected notifier: Notifier, |
80bfd33c | 37 | protected screenService: ScreenService, |
d3217560 | 38 | protected storageService: LocalStorageService, |
80bfd33c | 39 | private confirmService: ConfirmService, |
80bfd33c C |
40 | private userHistoryService: UserHistoryService |
41 | ) { | |
42 | super() | |
43 | ||
66357162 | 44 | this.titlePage = $localize`My videos history` |
80bfd33c C |
45 | } |
46 | ||
47 | ngOnInit () { | |
48 | super.ngOnInit() | |
276d9652 C |
49 | |
50 | this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled | |
80bfd33c C |
51 | } |
52 | ||
53 | ngOnDestroy () { | |
54 | super.ngOnDestroy() | |
55 | } | |
56 | ||
57 | getVideosObservable (page: number) { | |
58 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
59 | ||
60 | return this.userHistoryService.getUserVideosHistory(newPagination) | |
61 | } | |
62 | ||
63 | generateSyndicationList () { | |
64 | throw new Error('Method not implemented.') | |
65 | } | |
276d9652 C |
66 | |
67 | onVideosHistoryChange () { | |
68 | this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled }) | |
69 | .subscribe( | |
70 | () => { | |
71 | const message = this.videosHistoryEnabled === true ? | |
66357162 C |
72 | $localize`Videos history is enabled` : |
73 | $localize`Videos history is disabled` | |
276d9652 | 74 | |
f8b2c1b4 | 75 | this.notifier.success(message) |
276d9652 C |
76 | |
77 | this.authService.refreshUserInformation() | |
78 | }, | |
79 | ||
f8b2c1b4 | 80 | err => this.notifier.error(err.message) |
276d9652 C |
81 | ) |
82 | } | |
83 | ||
84 | async deleteHistory () { | |
66357162 C |
85 | const title = $localize`Delete videos history` |
86 | const message = $localize`Are you sure you want to delete all your videos history?` | |
276d9652 C |
87 | |
88 | const res = await this.confirmService.confirm(message, title) | |
89 | if (res !== true) return | |
90 | ||
91 | this.userHistoryService.deleteUserVideosHistory() | |
92 | .subscribe( | |
93 | () => { | |
66357162 | 94 | this.notifier.success($localize`Videos history deleted`) |
276d9652 C |
95 | |
96 | this.reloadVideos() | |
97 | }, | |
98 | ||
f8b2c1b4 | 99 | err => this.notifier.error(err.message) |
276d9652 C |
100 | ) |
101 | } | |
80bfd33c | 102 | } |