]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/my-history/my-history.component.ts
Fix live/upload redirection
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-history / my-history.component.ts
CommitLineData
2e46eb97
C
1import { tap } from 'rxjs/operators'
2import { Component, ComponentFactoryResolver, OnInit, ViewChild } from '@angular/core'
80bfd33c 3import { ActivatedRoute, Router } from '@angular/router'
67ed6552
C
4import {
5 AuthService,
6 ComponentPagination,
7 ConfirmService,
2e46eb97 8 DisableForReuseHook,
67ed6552
C
9 LocalStorageService,
10 Notifier,
11 ScreenService,
12 ServerService,
2e46eb97 13 User,
67ed6552
C
14 UserService
15} from '@app/core'
16import { immutableAssign } from '@app/helpers'
2e46eb97
C
17import { UserHistoryService, Video } from '@app/shared/shared-main'
18import { MiniatureDisplayOptions, VideosSelectionComponent } from '@app/shared/shared-video-miniature'
80bfd33c
C
19
20@Component({
17119e4a
C
21 templateUrl: './my-history.component.html',
22 styleUrls: [ './my-history.component.scss' ]
80bfd33c 23})
2e46eb97
C
24export class MyHistoryComponent implements OnInit, DisableForReuseHook {
25 @ViewChild('videosSelection', { static: true }) videosSelection: VideosSelectionComponent
26
80bfd33c 27 titlePage: string
80bfd33c
C
28 pagination: ComponentPagination = {
29 currentPage: 1,
30 itemsPerPage: 5,
31 totalItems: null
32 }
2e46eb97 33
276d9652 34 videosHistoryEnabled: boolean
d8b34ee5 35
2e46eb97
C
36 miniatureDisplayOptions: MiniatureDisplayOptions = {
37 date: true,
38 views: true,
39 by: true,
40 privacyLabel: false,
41 privacyText: true,
42 state: true,
43 blacklistInfo: true
44 }
45
46 getVideosObservableFunction = this.getVideosObservable.bind(this)
47
48 user: User
49
50 videos: Video[] = []
51 search: string
80bfd33c 52
80bfd33c
C
53 constructor (
54 protected router: Router,
489290b8 55 protected serverService: ServerService,
80bfd33c
C
56 protected route: ActivatedRoute,
57 protected authService: AuthService,
276d9652 58 protected userService: UserService,
f8b2c1b4 59 protected notifier: Notifier,
80bfd33c 60 protected screenService: ScreenService,
d3217560 61 protected storageService: LocalStorageService,
80bfd33c 62 private confirmService: ConfirmService,
5bcbcbe3
RK
63 private userHistoryService: UserHistoryService,
64 protected cfr: ComponentFactoryResolver
80bfd33c 65 ) {
d8b34ee5 66 this.titlePage = $localize`My watch history`
80bfd33c
C
67 }
68
69 ngOnInit () {
2e46eb97 70 this.user = this.authService.getUser()
276d9652 71
4f926722 72 this.authService.userInformationLoaded
2e46eb97
C
73 .subscribe(() => this.videosHistoryEnabled = this.user.videosHistoryEnabled)
74 }
d8b34ee5 75
2e46eb97
C
76 disableForReuse () {
77 this.videosSelection.disableForReuse()
d8b34ee5
RK
78 }
79
2e46eb97
C
80 enabledForReuse () {
81 this.videosSelection.enabledForReuse()
d8b34ee5
RK
82 }
83
2e46eb97
C
84 reloadData () {
85 this.videosSelection.reloadVideos()
80bfd33c
C
86 }
87
2e46eb97
C
88 onSearch (search: string) {
89 this.search = search
90 this.reloadData()
80bfd33c
C
91 }
92
93 getVideosObservable (page: number) {
94 const newPagination = immutableAssign(this.pagination, { currentPage: page })
95
d8b34ee5
RK
96 return this.userHistoryService.getUserVideosHistory(newPagination, this.search)
97 .pipe(
98 tap(res => this.pagination.totalItems = res.total)
99 )
80bfd33c
C
100 }
101
102 generateSyndicationList () {
5bcbcbe3 103 /* method disabled */
80bfd33c
C
104 throw new Error('Method not implemented.')
105 }
276d9652
C
106
107 onVideosHistoryChange () {
108 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
1378c0d3
C
109 .subscribe({
110 next: () => {
9df52d66
C
111 const message = this.videosHistoryEnabled === true
112 ? $localize`Videos history is enabled`
113 : $localize`Videos history is disabled`
276d9652 114
f8b2c1b4 115 this.notifier.success(message)
276d9652
C
116
117 this.authService.refreshUserInformation()
118 },
119
1378c0d3
C
120 error: err => this.notifier.error(err.message)
121 })
276d9652
C
122 }
123
124 async deleteHistory () {
66357162
C
125 const title = $localize`Delete videos history`
126 const message = $localize`Are you sure you want to delete all your videos history?`
276d9652
C
127
128 const res = await this.confirmService.confirm(message, title)
129 if (res !== true) return
130
131 this.userHistoryService.deleteUserVideosHistory()
1378c0d3
C
132 .subscribe({
133 next: () => {
66357162 134 this.notifier.success($localize`Videos history deleted`)
276d9652 135
2e46eb97 136 this.reloadData()
276d9652
C
137 },
138
1378c0d3
C
139 error: err => this.notifier.error(err.message)
140 })
276d9652 141 }
80bfd33c 142}