aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/menu/menu.component.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-12-01 09:20:19 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-12-01 10:55:56 +0100
commitb33f657c304b77938c1f68164d8e754787f5aae5 (patch)
tree93c47cfff0124a1084e7c5344969a82ed60ee926 /client/src/app/menu/menu.component.ts
parentfef2c7164e025b12a64185dbab058ef4129733c6 (diff)
downloadPeerTube-b33f657c304b77938c1f68164d8e754787f5aae5.tar.gz
PeerTube-b33f657c304b77938c1f68164d8e754787f5aae5.tar.zst
PeerTube-b33f657c304b77938c1f68164d8e754787f5aae5.zip
Begin new menu design
Diffstat (limited to 'client/src/app/menu/menu.component.ts')
-rw-r--r--client/src/app/menu/menu.component.ts97
1 files changed, 97 insertions, 0 deletions
diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts
new file mode 100644
index 000000000..4c35bb3a5
--- /dev/null
+++ b/client/src/app/menu/menu.component.ts
@@ -0,0 +1,97 @@
1import { Component, OnInit } from '@angular/core'
2import { Router } from '@angular/router'
3import { UserRight } from '../../../../shared/models/users/user-right.enum'
4import { AuthService, AuthStatus, ServerService } from '../core'
5import { User } from '../shared/users/user.model'
6
7@Component({
8 selector: 'my-menu',
9 templateUrl: './menu.component.html',
10 styleUrls: [ './menu.component.scss' ]
11})
12export class MenuComponent implements OnInit {
13 user: User
14 isLoggedIn: boolean
15 userHasAdminAccess = false
16
17 private routesPerRight = {
18 [UserRight.MANAGE_USERS]: '/admin/users',
19 [UserRight.MANAGE_SERVER_FOLLOW]: '/admin/friends',
20 [UserRight.MANAGE_VIDEO_ABUSES]: '/admin/video-abuses',
21 [UserRight.MANAGE_VIDEO_BLACKLIST]: '/admin/video-blacklist'
22 }
23
24 constructor (
25 private authService: AuthService,
26 private serverService: ServerService,
27 private router: Router
28 ) {}
29
30 ngOnInit () {
31 this.isLoggedIn = this.authService.isLoggedIn()
32 if (this.isLoggedIn === true) this.user = this.authService.getUser()
33 this.computeIsUserHasAdminAccess()
34
35 this.authService.loginChangedSource.subscribe(
36 status => {
37 if (status === AuthStatus.LoggedIn) {
38 this.isLoggedIn = true
39 this.user = this.authService.getUser()
40 this.computeIsUserHasAdminAccess()
41 console.log('Logged in.')
42 } else if (status === AuthStatus.LoggedOut) {
43 this.isLoggedIn = false
44 this.user = undefined
45 this.computeIsUserHasAdminAccess()
46 console.log('Logged out.')
47 } else {
48 console.error('Unknown auth status: ' + status)
49 }
50 }
51 )
52 }
53
54 isRegistrationAllowed () {
55 return this.serverService.getConfig().signup.allowed
56 }
57
58 getFirstAdminRightAvailable () {
59 const user = this.authService.getUser()
60 if (!user) return undefined
61
62 const adminRights = [
63 UserRight.MANAGE_USERS,
64 UserRight.MANAGE_SERVER_FOLLOW,
65 UserRight.MANAGE_VIDEO_ABUSES,
66 UserRight.MANAGE_VIDEO_BLACKLIST
67 ]
68
69 for (const adminRight of adminRights) {
70 if (user.hasRight(adminRight)) {
71 return adminRight
72 }
73 }
74
75 return undefined
76 }
77
78 getFirstAdminRouteAvailable () {
79 const right = this.getFirstAdminRightAvailable()
80
81 return this.routesPerRight[right]
82 }
83
84 logout (event: Event) {
85 event.preventDefault()
86
87 this.authService.logout()
88 // Redirect to home page
89 this.router.navigate(['/videos/list'])
90 }
91
92 private computeIsUserHasAdminAccess () {
93 const right = this.getFirstAdminRightAvailable()
94
95 this.userHasAdminAccess = right !== undefined
96 }
97}