File

src/app/shared/services/shared-about.service.ts

Description

Common service used by multiple modules such as AboutModule and the AuthModule. Provides feature information and general meta-data information about the Spring Cloud Data Flow server.

Example

Index

Properties
Methods

Constructor

constructor(httpClient: HttpClient, errorHandler: ErrorHandler)
Parameters :
Name Type Optional Description
httpClient HttpClient
errorHandler ErrorHandler

Methods

Public extractData
extractData(responseJson: any)
Parameters :
Name Type Optional Description
responseJson any
Returns : AboutInfo
getAboutInfo
getAboutInfo()
getFeatureInfo
getFeatureInfo()
loadAboutInfo
loadAboutInfo(reload?: boolean)
Parameters :
Name Type Optional Description
reload boolean true

Properties

Public aboutInfo
aboutInfo: AboutInfo
Type : AboutInfo
Public aboutInfo$
aboutInfo$:
Public aboutUrl
aboutUrl:
Default value : /about
Public featureInfo
featureInfo:
Public featureInfoSubject
featureInfoSubject:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of, Subject, BehaviorSubject } from 'rxjs';
import { ErrorHandler } from '../model';
import { FeatureInfo } from '../model/about/feature-info.model';
import { AboutInfo } from '../model/about/about-info.model';
import { catchError, map } from 'rxjs/operators';

/**
 * Common service used by multiple modules such as
 * {@link AboutModule} and the {@link AuthModule}. Provides
 * feature information and general meta-data information about
 * the Spring Cloud Data Flow server.
 *
 * @author Gunnar Hillert
 */
@Injectable()
export class SharedAboutService {

  public aboutUrl = '/about';
  public featureInfo;
  public featureInfoSubject = new BehaviorSubject<FeatureInfo>(undefined);

  public aboutInfo: AboutInfo;
  public aboutInfo$ = new BehaviorSubject<AboutInfo>(undefined);

  constructor(private httpClient: HttpClient, private errorHandler: ErrorHandler) {
  }

  getAboutInfo(): Observable<AboutInfo> {
    return this.aboutInfo$.asObservable();
  }

  getFeatureInfo(): Observable<FeatureInfo> {
    return this.getAboutInfo().map(result => {
      if (!result) {
        return new FeatureInfo();
      }
      return new FeatureInfo().deserialize(result.featureInfo);
    });
  }

  loadAboutInfo(reload?: boolean): Observable<AboutInfo> {
    if (!this.aboutInfo || reload) {
      this.httpClient
        .get<any>(this.aboutUrl)
        .pipe(
          map(this.extractData.bind(this)),
          catchError(this.errorHandler.handleError)
        ).subscribe();
    }
    return of(this.aboutInfo);
  }

  public extractData(responseJson: any): AboutInfo {
    this.aboutInfo = new AboutInfo().deserialize(responseJson);
    this.aboutInfo$.next(this.aboutInfo);
    this.featureInfo = this.aboutInfo.featureInfo;
    this.featureInfoSubject.next(this.aboutInfo.featureInfo);
    return this.aboutInfo;
  }
}

results matching ""

    No results matching ""