]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
3 | import { immutableAssign } from '@app/shared/misc/utils' | |
4 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | |
5 | import { AuthService } from '../../core/auth' | |
6 | import { ConfirmService } from '../../core/confirm' | |
7 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | |
8 | import { VideoService } from '../../shared/video/video.service' | |
9 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
10 | import { ScreenService } from '@app/shared/misc/screen.service' | |
11 | import { UserHistoryService } from '@app/shared/users/user-history.service' | |
12 | import { UserService } from '@app/shared' | |
13 | import { Notifier, ServerService } from '@app/core' | |
14 | import { LocalStorageService } from '@app/shared/misc/storage.service' | |
15 | ||
16 | @Component({ | |
17 | selector: 'my-account-history', | |
18 | templateUrl: './my-account-history.component.html', | |
19 | styleUrls: [ './my-account-history.component.scss' ] | |
20 | }) | |
21 | export class MyAccountHistoryComponent 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 i18n: I18n, | |
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 videoService: VideoService, | |
42 | private userHistoryService: UserHistoryService | |
43 | ) { | |
44 | super() | |
45 | ||
46 | this.titlePage = this.i18n('My videos history') | |
47 | } | |
48 | ||
49 | ngOnInit () { | |
50 | super.ngOnInit() | |
51 | ||
52 | this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled | |
53 | } | |
54 | ||
55 | ngOnDestroy () { | |
56 | super.ngOnDestroy() | |
57 | } | |
58 | ||
59 | getVideosObservable (page: number) { | |
60 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
61 | ||
62 | return this.userHistoryService.getUserVideosHistory(newPagination) | |
63 | } | |
64 | ||
65 | generateSyndicationList () { | |
66 | throw new Error('Method not implemented.') | |
67 | } | |
68 | ||
69 | onVideosHistoryChange () { | |
70 | this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled }) | |
71 | .subscribe( | |
72 | () => { | |
73 | const message = this.videosHistoryEnabled === true ? | |
74 | this.i18n('Videos history is enabled') : | |
75 | this.i18n('Videos history is disabled') | |
76 | ||
77 | this.notifier.success(message) | |
78 | ||
79 | this.authService.refreshUserInformation() | |
80 | }, | |
81 | ||
82 | err => this.notifier.error(err.message) | |
83 | ) | |
84 | } | |
85 | ||
86 | async deleteHistory () { | |
87 | const title = this.i18n('Delete videos history') | |
88 | const message = this.i18n('Are you sure you want to delete all your videos history?') | |
89 | ||
90 | const res = await this.confirmService.confirm(message, title) | |
91 | if (res !== true) return | |
92 | ||
93 | this.userHistoryService.deleteUserVideosHistory() | |
94 | .subscribe( | |
95 | () => { | |
96 | this.notifier.success(this.i18n('Videos history deleted')) | |
97 | ||
98 | this.reloadVideos() | |
99 | }, | |
100 | ||
101 | err => this.notifier.error(err.message) | |
102 | ) | |
103 | } | |
104 | } |