]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account.component.ts
56373e5f18efd08080eaeb17c8c5476f5b26c734
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { AuthService, ScreenService, ServerService, AuthUser } from '@app/core'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { ServerConfig } from '@shared/models'
5 import { TopMenuDropdownParam } from '../shared/shared-main/misc/top-menu-dropdown.component'
6
7 @Component({
8 selector: 'my-my-account',
9 templateUrl: './my-account.component.html',
10 styleUrls: [ './my-account.component.scss' ]
11 })
12 export class MyAccountComponent implements OnInit {
13 menuEntries: TopMenuDropdownParam[] = []
14 user: AuthUser
15
16 private serverConfig: ServerConfig
17
18 constructor (
19 private serverService: ServerService,
20 private authService: AuthService,
21 private screenService: ScreenService,
22 private i18n: I18n
23 ) { }
24
25 get isBroadcastMessageDisplayed () {
26 return this.screenService.isBroadcastMessageDisplayed
27 }
28
29 ngOnInit (): void {
30 this.serverConfig = this.serverService.getTmpConfig()
31 this.serverService.getConfig()
32 .subscribe(config => this.serverConfig = config)
33
34 this.user = this.authService.getUser()
35
36 this.authService.userInformationLoaded.subscribe(
37 () => this.buildMenu()
38 )
39 }
40
41 isVideoImportEnabled () {
42 const importConfig = this.serverConfig.import.videos
43
44 return importConfig.http.enabled || importConfig.torrent.enabled
45 }
46
47 private buildMenu () {
48 const libraryEntries: TopMenuDropdownParam = {
49 label: this.i18n('My library'),
50 children: [
51 {
52 label: this.i18n('My channels'),
53 routerLink: '/my-account/video-channels',
54 iconName: 'channel'
55 },
56 {
57 label: this.i18n('My videos'),
58 routerLink: '/my-account/videos',
59 iconName: 'videos',
60 isDisplayed: () => this.user.canSeeVideosLink
61 },
62 {
63 label: this.i18n('My playlists'),
64 routerLink: '/my-account/video-playlists',
65 iconName: 'playlists'
66 },
67 {
68 label: this.i18n('My subscriptions'),
69 routerLink: '/my-account/subscriptions',
70 iconName: 'subscriptions'
71 },
72 {
73 label: this.i18n('My history'),
74 routerLink: '/my-account/history/videos',
75 iconName: 'history'
76 }
77 ]
78 }
79
80 if (this.isVideoImportEnabled()) {
81 libraryEntries.children.push({
82 label: 'My imports',
83 routerLink: '/my-account/video-imports',
84 iconName: 'cloud-download',
85 isDisplayed: () => this.user.canSeeVideosLink
86 })
87 }
88
89 const miscEntries: TopMenuDropdownParam = {
90 label: this.i18n('Misc'),
91 children: [
92 {
93 label: this.i18n('Muted accounts'),
94 routerLink: '/my-account/blocklist/accounts',
95 iconName: 'user-x'
96 },
97 {
98 label: this.i18n('Muted servers'),
99 routerLink: '/my-account/blocklist/servers',
100 iconName: 'peertube-x'
101 },
102 {
103 label: this.i18n('My abuse reports'),
104 routerLink: '/my-account/abuses',
105 iconName: 'flag'
106 },
107 {
108 label: this.i18n('Ownership changes'),
109 routerLink: '/my-account/ownership',
110 iconName: 'download'
111 }
112 ]
113 }
114
115 this.menuEntries = [
116 {
117 label: this.i18n('My settings'),
118 routerLink: '/my-account/settings'
119 },
120 {
121 label: this.i18n('My notifications'),
122 routerLink: '/my-account/notifications'
123 },
124 libraryEntries,
125 miscEntries
126 ]
127 }
128 }