]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-history/my-account-history.component.ts
Remove uneccessary details to link titles
[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'
80bfd33c
C
3import { immutableAssign } from '@app/shared/misc/utils'
4import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
80bfd33c
C
5import { AuthService } from '../../core/auth'
6import { ConfirmService } from '../../core/confirm'
7import { AbstractVideoList } from '../../shared/video/abstract-video-list'
8import { VideoService } from '../../shared/video/video.service'
9import { I18n } from '@ngx-translate/i18n-polyfill'
10import { ScreenService } from '@app/shared/misc/screen.service'
11import { UserHistoryService } from '@app/shared/users/user-history.service'
276d9652 12import { UserService } from '@app/shared'
489290b8 13import { Notifier, ServerService } from '@app/core'
d3217560 14import { LocalStorageService } from '@app/shared/misc/storage.service'
80bfd33c
C
15
16@Component({
17 selector: 'my-account-history',
18 templateUrl: './my-account-history.component.html',
19 styleUrls: [ './my-account-history.component.scss' ]
20})
21export class MyAccountHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
22 titlePage: string
80bfd33c
C
23 pagination: ComponentPagination = {
24 currentPage: 1,
25 itemsPerPage: 5,
26 totalItems: null
27 }
276d9652 28 videosHistoryEnabled: boolean
80bfd33c 29
80bfd33c 30 constructor (
34c7f429 31 protected i18n: I18n,
80bfd33c 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
C
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()
276d9652
C
51
52 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
80bfd33c
C
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 }
276d9652
C
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
f8b2c1b4 77 this.notifier.success(message)
276d9652
C
78
79 this.authService.refreshUserInformation()
80 },
81
f8b2c1b4 82 err => this.notifier.error(err.message)
276d9652
C
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 () => {
f8b2c1b4 96 this.notifier.success(this.i18n('Videos history deleted'))
276d9652
C
97
98 this.reloadVideos()
99 },
100
f8b2c1b4 101 err => this.notifier.error(err.message)
276d9652
C
102 )
103 }
80bfd33c 104}