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'
16 selector: 'my-account-history',
17 templateUrl: './my-account-history.component.html',
18 styleUrls: [ './my-account-history.component.scss' ]
20 export class MyAccountHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
22 pagination: ComponentPagination = {
27 videosHistoryEnabled: boolean
30 protected router: Router,
31 protected serverService: ServerService,
32 protected route: ActivatedRoute,
33 protected authService: AuthService,
34 protected userService: UserService,
35 protected notifier: Notifier,
36 protected screenService: ScreenService,
38 private confirmService: ConfirmService,
39 private videoService: VideoService,
40 private userHistoryService: UserHistoryService
44 this.titlePage = this.i18n('My videos history')
50 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
57 getVideosObservable (page: number) {
58 const newPagination = immutableAssign(this.pagination, { currentPage: page })
60 return this.userHistoryService.getUserVideosHistory(newPagination)
63 generateSyndicationList () {
64 throw new Error('Method not implemented.')
67 onVideosHistoryChange () {
68 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
71 const message = this.videosHistoryEnabled === true ?
72 this.i18n('Videos history is enabled') :
73 this.i18n('Videos history is disabled')
75 this.notifier.success(message)
77 this.authService.refreshUserInformation()
80 err => this.notifier.error(err.message)
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?')
88 const res = await this.confirmService.confirm(message, title)
89 if (res !== true) return
91 this.userHistoryService.deleteUserVideosHistory()
94 this.notifier.success(this.i18n('Videos history deleted'))
99 err => this.notifier.error(err.message)