]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+accounts/accounts.component.ts
Reinstate routerLink property of upload button
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / accounts.component.ts
CommitLineData
79bd2632 1import { Component, OnDestroy, OnInit } from '@angular/core'
0626e7af
C
2import { ActivatedRoute } from '@angular/router'
3import { AccountService } from '@app/shared/account/account.service'
4import { Account } from '@app/shared/account/account.model'
79bd2632
C
5import { RestExtractor, UserService } from '@app/shared'
6import { catchError, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators'
734a5ceb 7import { Subscription } from 'rxjs'
f8b2c1b4 8import { AuthService, Notifier, RedirectService } from '@app/core'
79bd2632 9import { User, UserRight } from '../../../../shared'
ee1d0dfb 10import { I18n } from '@ngx-translate/i18n-polyfill'
41eb700f
RK
11import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
12import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
0626e7af
C
13
14@Component({
170726f5
C
15 templateUrl: './accounts.component.html',
16 styleUrls: [ './accounts.component.scss' ]
0626e7af 17})
3baf9be2 18export class AccountsComponent implements OnInit, OnDestroy {
6b738c7a 19 account: Account
79bd2632 20 user: User
41eb700f 21 videoChannels: VideoChannel[]
0626e7af 22
734a5ceb
C
23 private routeSub: Subscription
24
0626e7af
C
25 constructor (
26 private route: ActivatedRoute,
79bd2632 27 private userService: UserService,
a51bad1a 28 private accountService: AccountService,
41eb700f 29 private videoChannelService: VideoChannelService,
f8b2c1b4 30 private notifier: Notifier,
79bd2632
C
31 private restExtractor: RestExtractor,
32 private redirectService: RedirectService,
ee1d0dfb
C
33 private authService: AuthService,
34 private i18n: I18n
0626e7af
C
35 ) {}
36
37 ngOnInit () {
734a5ceb
C
38 this.routeSub = this.route.params
39 .pipe(
40 map(params => params[ 'accountId' ]),
41 distinctUntilChanged(),
42 switchMap(accountId => this.accountService.getAccount(accountId)),
9270ccf6
RK
43 tap(account => {
44 this.account = account
45 this.getUserIfNeeded(account)
46 }),
47 switchMap(account => this.videoChannelService.listAccountVideoChannels(account)),
734a5ceb
C
48 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
49 )
79bd2632 50 .subscribe(
9270ccf6 51 videoChannels => this.videoChannels = videoChannels.data,
79bd2632 52
f8b2c1b4 53 err => this.notifier.error(err.message)
79bd2632 54 )
734a5ceb 55 }
0626e7af 56
734a5ceb
C
57 ngOnDestroy () {
58 if (this.routeSub) this.routeSub.unsubscribe()
0626e7af 59 }
79bd2632
C
60
61 onUserChanged () {
62 this.getUserIfNeeded(this.account)
63 }
64
65 onUserDeleted () {
66 this.redirectService.redirectToHomepage()
67 }
68
ee1d0dfb
C
69 activateCopiedMessage () {
70 this.notifier.success(this.i18n('Username copied'))
71 }
72
79bd2632
C
73 private getUserIfNeeded (account: Account) {
74 if (!account.userId) return
75 if (!this.authService.isLoggedIn()) return
76
77 const user = this.authService.getUser()
78 if (user.hasRight(UserRight.MANAGE_USERS)) {
79 this.userService.getUser(account.userId)
80 .subscribe(
81 user => this.user = user,
82
f8b2c1b4 83 err => this.notifier.error(err.message)
79bd2632
C
84 )
85 }
86 }
0626e7af 87}