1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
13 import { immutableAssign } from '@app/helpers'
14 import { UserHistoryService } from '@app/shared/shared-main'
15 import { AbstractVideoList } from '@app/shared/shared-video-miniature'
16 import { I18n } from '@ngx-translate/i18n-polyfill'
19 selector: 'my-account-history',
20 templateUrl: './my-account-history.component.html',
21 styleUrls: [ './my-account-history.component.scss' ]
23 export class MyAccountHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
25 pagination: ComponentPagination = {
30 videosHistoryEnabled: boolean
34 protected router: Router,
35 protected serverService: ServerService,
36 protected route: ActivatedRoute,
37 protected authService: AuthService,
38 protected userService: UserService,
39 protected notifier: Notifier,
40 protected screenService: ScreenService,
41 protected storageService: LocalStorageService,
42 private confirmService: ConfirmService,
43 private userHistoryService: UserHistoryService
47 this.titlePage = this.i18n('My videos history')
53 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
60 getVideosObservable (page: number) {
61 const newPagination = immutableAssign(this.pagination, { currentPage: page })
63 return this.userHistoryService.getUserVideosHistory(newPagination)
66 generateSyndicationList () {
67 throw new Error('Method not implemented.')
70 onVideosHistoryChange () {
71 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
74 const message = this.videosHistoryEnabled === true ?
75 this.i18n('Videos history is enabled') :
76 this.i18n('Videos history is disabled')
78 this.notifier.success(message)
80 this.authService.refreshUserInformation()
83 err => this.notifier.error(err.message)
87 async deleteHistory () {
88 const title = this.i18n('Delete videos history')
89 const message = this.i18n('Are you sure you want to delete all your videos history?')
91 const res = await this.confirmService.confirm(message, title)
92 if (res !== true) return
94 this.userHistoryService.deleteUserVideosHistory()
97 this.notifier.success(this.i18n('Videos history deleted'))
102 err => this.notifier.error(err.message)