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