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