]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-history/my-account-history.component.ts
Add unicode emoji to markdown
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-history / my-account-history.component.ts
CommitLineData
80bfd33c
C
1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router'
67ed6552
C
3import {
4 AuthService,
5 ComponentPagination,
6 ConfirmService,
7 LocalStorageService,
8 Notifier,
9 ScreenService,
10 ServerService,
11 UserService
12} from '@app/core'
13import { immutableAssign } from '@app/helpers'
14import { UserHistoryService } from '@app/shared/shared-main'
15import { AbstractVideoList } from '@app/shared/shared-video-miniature'
80bfd33c
C
16
17@Component({
18 selector: 'my-account-history',
19 templateUrl: './my-account-history.component.html',
20 styleUrls: [ './my-account-history.component.scss' ]
21})
22export class MyAccountHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
23 titlePage: string
80bfd33c
C
24 pagination: ComponentPagination = {
25 currentPage: 1,
26 itemsPerPage: 5,
27 totalItems: null
28 }
276d9652 29 videosHistoryEnabled: boolean
80bfd33c 30
80bfd33c
C
31 constructor (
32 protected router: Router,
489290b8 33 protected serverService: ServerService,
80bfd33c
C
34 protected route: ActivatedRoute,
35 protected authService: AuthService,
276d9652 36 protected userService: UserService,
f8b2c1b4 37 protected notifier: Notifier,
80bfd33c 38 protected screenService: ScreenService,
d3217560 39 protected storageService: LocalStorageService,
80bfd33c 40 private confirmService: ConfirmService,
80bfd33c
C
41 private userHistoryService: UserHistoryService
42 ) {
43 super()
44
66357162 45 this.titlePage = $localize`My videos history`
80bfd33c
C
46 }
47
48 ngOnInit () {
49 super.ngOnInit()
276d9652
C
50
51 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
80bfd33c
C
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 }
276d9652
C
67
68 onVideosHistoryChange () {
69 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
70 .subscribe(
71 () => {
72 const message = this.videosHistoryEnabled === true ?
66357162
C
73 $localize`Videos history is enabled` :
74 $localize`Videos history is disabled`
276d9652 75
f8b2c1b4 76 this.notifier.success(message)
276d9652
C
77
78 this.authService.refreshUserInformation()
79 },
80
f8b2c1b4 81 err => this.notifier.error(err.message)
276d9652
C
82 )
83 }
84
85 async deleteHistory () {
66357162
C
86 const title = $localize`Delete videos history`
87 const message = $localize`Are you sure you want to delete all your videos history?`
276d9652
C
88
89 const res = await this.confirmService.confirm(message, title)
90 if (res !== true) return
91
92 this.userHistoryService.deleteUserVideosHistory()
93 .subscribe(
94 () => {
66357162 95 this.notifier.success($localize`Videos history deleted`)
276d9652
C
96
97 this.reloadVideos()
98 },
99
f8b2c1b4 100 err => this.notifier.error(err.message)
276d9652
C
101 )
102 }
80bfd33c 103}