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