]>
Commit | Line | Data |
---|---|---|
80bfd33c C |
1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
80bfd33c C |
3 | import { immutableAssign } from '@app/shared/misc/utils' |
4 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | |
80bfd33c C |
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' | |
276d9652 | 12 | import { UserService } from '@app/shared' |
489290b8 | 13 | import { Notifier, ServerService } from '@app/core' |
80bfd33c C |
14 | |
15 | @Component({ | |
16 | selector: 'my-account-history', | |
17 | templateUrl: './my-account-history.component.html', | |
18 | styleUrls: [ './my-account-history.component.scss' ] | |
19 | }) | |
20 | export class MyAccountHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
21 | titlePage: string | |
80bfd33c C |
22 | pagination: ComponentPagination = { |
23 | currentPage: 1, | |
24 | itemsPerPage: 5, | |
25 | totalItems: null | |
26 | } | |
276d9652 | 27 | videosHistoryEnabled: boolean |
80bfd33c | 28 | |
80bfd33c | 29 | constructor ( |
34c7f429 | 30 | protected i18n: I18n, |
80bfd33c | 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, |
80bfd33c C |
38 | private confirmService: ConfirmService, |
39 | private videoService: VideoService, | |
40 | private userHistoryService: UserHistoryService | |
41 | ) { | |
42 | super() | |
43 | ||
44 | this.titlePage = this.i18n('My videos history') | |
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 ? | |
72 | this.i18n('Videos history is enabled') : | |
73 | this.i18n('Videos history is disabled') | |
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 () { | |
85 | const title = this.i18n('Delete videos history') | |
86 | const message = this.i18n('Are you sure you want to delete all your videos history?') | |
87 | ||
88 | const res = await this.confirmService.confirm(message, title) | |
89 | if (res !== true) return | |
90 | ||
91 | this.userHistoryService.deleteUserVideosHistory() | |
92 | .subscribe( | |
93 | () => { | |
f8b2c1b4 | 94 | this.notifier.success(this.i18n('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 | } |