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'
17 selector: 'my-account-history',
18 templateUrl: './my-account-history.component.html',
19 styleUrls: [ './my-account-history.component.scss' ]
21 export class MyAccountHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
23 pagination: ComponentPagination = {
28 videosHistoryEnabled: boolean
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
46 this.titlePage = this.i18n('My videos history')
52 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
59 getVideosObservable (page: number) {
60 const newPagination = immutableAssign(this.pagination, { currentPage: page })
62 return this.userHistoryService.getUserVideosHistory(newPagination)
65 generateSyndicationList () {
66 throw new Error('Method not implemented.')
69 onVideosHistoryChange () {
70 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
73 const message = this.videosHistoryEnabled === true ?
74 this.i18n('Videos history is enabled') :
75 this.i18n('Videos history is disabled')
77 this.notifier.success(message)
79 this.authService.refreshUserInformation()
82 err => this.notifier.error(err.message)
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?')
90 const res = await this.confirmService.confirm(message, title)
91 if (res !== true) return
93 this.userHistoryService.deleteUserVideosHistory()
96 this.notifier.success(this.i18n('Videos history deleted'))
101 err => this.notifier.error(err.message)