Skip to content

Commit 2b4e683

Browse files
authored
Merge pull request #105 from GSA/feature/47_admin_homepage
Ticket 47: Get Admin Panel on Home page
2 parents 44b3ad1 + c652ddc commit 2b4e683

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "srt",
3-
"version": "1.4.0dev0",
3+
"version": "1.4.0dev1",
44
"license": "MIT",
55
"scripts": {
66
"ng": "ng",

src/app/auth-guard.service.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@ export class AuthGuard implements CanActivate {
5959
}
6060
}
6161

62+
/**
63+
* check if user is admin
64+
*/
65+
checkAdmin(): boolean {
66+
if (this.isGSAAdmin) {
67+
return true;
68+
} else {
69+
this.authService.checkToken().subscribe(
70+
(data) => {
71+
this.isGSAAdmin = data.isGSAAdmin;
72+
if (data.isGSAAdmin) {
73+
return true;
74+
} else {
75+
return false;
76+
}
77+
});
78+
}
79+
}
80+
81+
82+
6283

6384
// Kailun's new add
6485

src/app/home/home/home.component.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
22
import { AuthGuard } from '../../auth-guard.service';
3-
43
import { Router } from '@angular/router';
54
import {BaseComponent} from '../../base.component';
65
import {Title} from '@angular/platform-browser';
@@ -16,6 +15,8 @@ export class HomeComponent extends BaseComponent implements OnInit {
1615
currentID: string;
1716
isGSAAdmin = false;
1817

18+
private adminCheckTimes: number = 0;
19+
1920
/* CONSTRUCTORS */
2021

2122
/**
@@ -36,12 +37,32 @@ export class HomeComponent extends BaseComponent implements OnInit {
3637
* lifecycle
3738
*/
3839
ngOnInit() {
39-
this.isGSAAdmin = this.auth.isGSAAdmin;
40+
this.loadAdminComponents();
4041
this.currentID = localStorage.getItem('id');
4142
this.pageName = 'SRT Home Page';
4243
super.ngOnInit();
44+
45+
this.checkAdmin();
4346
}
4447

48+
ngOnChanges(){
49+
}
50+
51+
loadAdminComponents(){
52+
this.isGSAAdmin = this.auth.checkAdmin();
53+
}
4554

55+
checkAdmin(){
56+
const interval = setInterval(() => {
57+
this.loadAdminComponents();
58+
59+
if (this.adminCheckTimes > 1) {
60+
clearInterval(interval);
61+
}
62+
this.adminCheckTimes++;
63+
64+
}, 2000);
65+
66+
}
4667

4768
}

0 commit comments

Comments
 (0)