import { Component, OnInit, Output, EventEmitter } from '@angular/core'; import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; import { Observable, Subscription } from 'rxjs'; import { map, shareReplay } from 'rxjs/operators'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { IssueService } from "../issue.service"; import { RoleService, Roles } from '../role.service'; import { AuthenticationService, AuthLevel } from '../authentication.service'; import { ServerDataService } from '../server-data.service'; @Component({ selector: 'app-nav', templateUrl: './nav.component.html', styleUrls: ['./nav.component.css'] }) export class NavComponent implements OnInit { // used for issue pulling for http request public issues: any; public vms: any; public works: any; public auth: AuthLevel = AuthLevel.None; public auths = AuthLevel; public role: Roles = Roles.NA; public roles = Roles; public issueType = this.role; public issueString = "None"; public vmString = "Your Reservations"; public vmFilter = 0; userID: string = ""; isHandset$: Observable = this.breakpointObserver.observe(Breakpoints.Handset) .pipe( map(result => result.matches), shareReplay() ); // nav constructor with Client and Issue Service constructor(private breakpointObserver: BreakpointObserver, private http: HttpClient, private issue: IssueService, public authenticationService: AuthenticationService, private roleService: RoleService, private dataService: ServerDataService) {} ngOnInit() { this.authenticationService.status.subscribe( (result: AuthLevel) => { this.auth = result; }); this.authenticationService.user.subscribe( (result: string) => { this.userID = result; }); this.roleService.currentRole.subscribe( (result: Roles) => { this.role = result; this.issueType = result; }); this.dataService.issueList .subscribe( (data:any) => { this.issues = data; }); this.dataService.vmList .subscribe( (data:any) => { this.vms = data; }); this.dataService.workList .subscribe( (data:any) => { this.works = data; }); } sendID(id: string) { this.issue.changeIssue(id); } sendWork(id: number) { this.issue.changeRequest(id); } swapRole(role: Roles) { this.roleService.changeRole(role); } swapIssue(issue: Roles, str: string) { this.issueType = issue; this.issueString = str; } swapVMs(type: number) { switch(type) { case 0: this.vmString = "Your Reservations"; this.vmFilter = type; break; case 1: this.vmString = "Reserved"; this.vmFilter = type; break; case 2: this.vmString = "Unreserved"; this.vmFilter = type; break; } } gotoVM(vm: any, vmLink: string) { if(vm.ownerID == this.userID) { alert("Opening VM: " + vmLink); } else { alert("You do not have a reservation for this VM"); } } logout() { this.swapRole(this.roles.NA); this.authenticationService.deauthenticate(); } }