navbar.component.ts 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { Component, OnInit } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
  4. import { JhiLanguageService } from 'ng-jhipster';
  5. import { SessionStorageService } from 'ngx-webstorage';
  6. import { VERSION } from 'app/app.constants';
  7. import { JhiLanguageHelper, Principal, LoginModalService, LoginService } from 'app/core';
  8. import { ProfileService } from '../profiles/profile.service';
  9. @Component({
  10. selector: 'jhi-navbar',
  11. templateUrl: './navbar.component.html',
  12. styleUrls: ['navbar.scss']
  13. })
  14. export class NavbarComponent implements OnInit {
  15. inProduction: boolean;
  16. isNavbarCollapsed: boolean;
  17. languages: any[];
  18. swaggerEnabled: boolean;
  19. modalRef: NgbModalRef;
  20. version: string;
  21. constructor(
  22. private loginService: LoginService,
  23. private languageService: JhiLanguageService,
  24. private languageHelper: JhiLanguageHelper,
  25. private sessionStorage: SessionStorageService,
  26. private principal: Principal,
  27. private loginModalService: LoginModalService,
  28. private profileService: ProfileService,
  29. private router: Router
  30. ) {
  31. this.version = VERSION ? 'v' + VERSION : '';
  32. this.isNavbarCollapsed = true;
  33. }
  34. ngOnInit() {
  35. this.languageHelper.getAll().then(languages => {
  36. this.languages = languages;
  37. });
  38. this.profileService.getProfileInfo().then(profileInfo => {
  39. this.inProduction = profileInfo.inProduction;
  40. this.swaggerEnabled = profileInfo.swaggerEnabled;
  41. });
  42. }
  43. changeLanguage(languageKey: string) {
  44. this.sessionStorage.store('locale', languageKey);
  45. this.languageService.changeLanguage(languageKey);
  46. }
  47. collapseNavbar() {
  48. this.isNavbarCollapsed = true;
  49. }
  50. isAuthenticated() {
  51. return this.principal.isAuthenticated();
  52. }
  53. login() {
  54. this.modalRef = this.loginModalService.open();
  55. }
  56. logout() {
  57. this.collapseNavbar();
  58. this.loginService.logout();
  59. this.router.navigate(['']);
  60. }
  61. toggleNavbar() {
  62. this.isNavbarCollapsed = !this.isNavbarCollapsed;
  63. }
  64. getImageUrl() {
  65. return this.isAuthenticated() ? this.principal.getImageUrl() : null;
  66. }
  67. }