profile.service.ts 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient, HttpResponse } from '@angular/common/http';
  3. import { SERVER_API_URL } from 'app/app.constants';
  4. import { ProfileInfo } from './profile-info.model';
  5. import { map } from 'rxjs/operators';
  6. @Injectable({ providedIn: 'root' })
  7. export class ProfileService {
  8. private infoUrl = SERVER_API_URL + 'management/info';
  9. private profileInfo: Promise<ProfileInfo>;
  10. constructor(private http: HttpClient) {}
  11. getProfileInfo(): Promise<ProfileInfo> {
  12. if (!this.profileInfo) {
  13. this.profileInfo = this.http
  14. .get<ProfileInfo>(this.infoUrl, { observe: 'response' })
  15. .pipe(
  16. map((res: HttpResponse<ProfileInfo>) => {
  17. const data = res.body;
  18. const pi = new ProfileInfo();
  19. pi.activeProfiles = data['activeProfiles'];
  20. const displayRibbonOnProfiles = data['display-ribbon-on-profiles'].split(',');
  21. if (pi.activeProfiles) {
  22. const ribbonProfiles = displayRibbonOnProfiles.filter(profile => pi.activeProfiles.includes(profile));
  23. if (ribbonProfiles.length !== 0) {
  24. pi.ribbonEnv = ribbonProfiles[0];
  25. }
  26. pi.inProduction = pi.activeProfiles.includes('prod');
  27. pi.swaggerEnabled = pi.activeProfiles.includes('swagger');
  28. }
  29. return pi;
  30. })
  31. )
  32. .toPromise();
  33. }
  34. return this.profileInfo;
  35. }
  36. }