1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { Location } from '@angular/common'
4 import { immutableAssign } from '@app/shared/misc/utils'
5 import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
6 import { NotificationsService } from 'angular2-notifications'
7 import { AuthService } from '../../core/auth'
8 import { ConfirmService } from '../../core/confirm'
9 import { AbstractVideoList } from '../../shared/video/abstract-video-list'
10 import { VideoService } from '../../shared/video/video.service'
11 import { I18n } from '@ngx-translate/i18n-polyfill'
12 import { ScreenService } from '@app/shared/misc/screen.service'
13 import { UserHistoryService } from '@app/shared/users/user-history.service'
14 import { UserService } from '@app/shared'
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 currentRoute = '/my-account/history/videos'
24 pagination: ComponentPagination = {
29 videosHistoryEnabled: boolean
31 protected baseVideoWidth = -1
32 protected baseVideoHeight = 155
35 protected router: Router,
36 protected route: ActivatedRoute,
37 protected authService: AuthService,
38 protected userService: UserService,
39 protected notificationsService: NotificationsService,
40 protected location: Location,
41 protected screenService: ScreenService,
43 private confirmService: ConfirmService,
44 private videoService: VideoService,
45 private userHistoryService: UserHistoryService
49 this.titlePage = this.i18n('My videos history')
55 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
62 getVideosObservable (page: number) {
63 const newPagination = immutableAssign(this.pagination, { currentPage: page })
65 return this.userHistoryService.getUserVideosHistory(newPagination)
68 generateSyndicationList () {
69 throw new Error('Method not implemented.')
72 onVideosHistoryChange () {
73 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
76 const message = this.videosHistoryEnabled === true ?
77 this.i18n('Videos history is enabled') :
78 this.i18n('Videos history is disabled')
80 this.notificationsService.success(this.i18n('Success'), message)
82 this.authService.refreshUserInformation()
85 err => this.notificationsService.error(this.i18n('Error'), err.message)
89 async deleteHistory () {
90 const title = this.i18n('Delete videos history')
91 const message = this.i18n('Are you sure you want to delete all your videos history?')
93 const res = await this.confirmService.confirm(message, title)
94 if (res !== true) return
96 this.userHistoryService.deleteUserVideosHistory()
99 this.notificationsService.success(this.i18n('Success'), this.i18n('Videos history deleted'))
104 err => this.notificationsService.error(this.i18n('Error'), err.message)