]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-history/my-account-history.component.ts
Reorganize client shared modules
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-history / my-account-history.component.ts
1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import {
4 AuthService,
5 ComponentPagination,
6 ConfirmService,
7 LocalStorageService,
8 Notifier,
9 ScreenService,
10 ServerService,
11 UserService
12 } from '@app/core'
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'
17
18 @Component({
19 selector: 'my-account-history',
20 templateUrl: './my-account-history.component.html',
21 styleUrls: [ './my-account-history.component.scss' ]
22 })
23 export class MyAccountHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
24 titlePage: string
25 pagination: ComponentPagination = {
26 currentPage: 1,
27 itemsPerPage: 5,
28 totalItems: null
29 }
30 videosHistoryEnabled: boolean
31
32 constructor (
33 protected i18n: I18n,
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
44 ) {
45 super()
46
47 this.titlePage = this.i18n('My videos history')
48 }
49
50 ngOnInit () {
51 super.ngOnInit()
52
53 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
54 }
55
56 ngOnDestroy () {
57 super.ngOnDestroy()
58 }
59
60 getVideosObservable (page: number) {
61 const newPagination = immutableAssign(this.pagination, { currentPage: page })
62
63 return this.userHistoryService.getUserVideosHistory(newPagination)
64 }
65
66 generateSyndicationList () {
67 throw new Error('Method not implemented.')
68 }
69
70 onVideosHistoryChange () {
71 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
72 .subscribe(
73 () => {
74 const message = this.videosHistoryEnabled === true ?
75 this.i18n('Videos history is enabled') :
76 this.i18n('Videos history is disabled')
77
78 this.notifier.success(message)
79
80 this.authService.refreshUserInformation()
81 },
82
83 err => this.notifier.error(err.message)
84 )
85 }
86
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?')
90
91 const res = await this.confirmService.confirm(message, title)
92 if (res !== true) return
93
94 this.userHistoryService.deleteUserVideosHistory()
95 .subscribe(
96 () => {
97 this.notifier.success(this.i18n('Videos history deleted'))
98
99 this.reloadVideos()
100 },
101
102 err => this.notifier.error(err.message)
103 )
104 }
105 }