File

src/app/data/issue-graph/issue-graph-state.service.ts

Index

Properties
Methods

Constructor

constructor(apiService: IssueGraphApiService, ss: StateService)
Parameters :
Name Type Optional
apiService IssueGraphApiService No
ss StateService No

Methods

addConsumedInterface
addConsumedInterface(componentId: string, interfaceId: string)

Make the interface with interfaceId a consumed interface of the component with id componentId

Parameters :
Name Type Optional
componentId string No
interfaceId string No
Returns : Observable<any>
graphDataForFilter
graphDataForFilter(filter$: BehaviorSubject<FilterState>, reload$: BehaviorSubject, destroy$: ReplaySubject)

Maps an observable of the state of the graph filters (toggles and queries in search bar) onto an observable emitting graph state for these filters retrieved from the backend. the filter$ or reload$ observables emit a value.

Parameters :
Name Type Optional Description
filter$ BehaviorSubject<FilterState> No

an observable emitting a sequence of values describing the state of the filter bar above the graph

reload$ BehaviorSubject<void> No

an observable emitting irrelevant values to signal a reload is required, after a manipulation of graph data

destroy$ ReplaySubject<void> No

used to signal that the caller is no longer interested. On emission the returned observable finishes.

observable emitting sequence of graph states containing e.g. components and interfaces. It will emit new values when the filter$ or reload$ observables emit a value.

removeConsumedInterface
removeConsumedInterface(componentId: string, interfaceId: string)

Remove the interface with interfaceId from consumed interfaces of the component with id componentId

Parameters :
Name Type Optional
componentId string No
interfaceId string No
Returns : Observable<any>

Properties

state$
Type : Observable<GraphData>
import {Injectable} from '@angular/core';
import {BehaviorSubject, combineLatest, Observable, ReplaySubject} from 'rxjs';
import {StateService} from '@app/state.service';
import {GraphData} from './graph-data';
import {filter, shareReplay, switchMap, takeUntil} from 'rxjs/operators';
import {IssueGraphApiService} from './issue-graph-api.service';
import {FilterState} from '@app/graphs/shared';

@Injectable({
  providedIn: 'root'
})
export class IssueGraphStateService {
  state$: Observable<GraphData>;

  constructor(private apiService: IssueGraphApiService, private ss: StateService) {}

  /**
   * Maps an observable of the state of the graph filters (toggles and queries in search bar) onto an observable
   * emitting graph state for these filters retrieved from the backend.
   * @param filter$ an observable emitting a sequence of values describing the state of the filter bar above the graph
   * @param reload$ an observable emitting irrelevant values to signal a reload is required, after a manipulation of graph data
   * @param destroy$ used to signal that the caller is no longer interested. On emission the returned observable finishes.
   * @returns observable emitting sequence of graph states containing e.g. components and interfaces. It will emit new values when
   * the filter$ or reload$ observables emit a value.
   */
  graphDataForFilter(
    filter$: BehaviorSubject<FilterState>,
    reload$: BehaviorSubject<void>,
    destroy$: ReplaySubject<void>
  ): Observable<GraphData> {
    // Whenever a new value arrives from reload$, loadIssueGraphData is executed
    this.state$ = combineLatest([this.ss.state$, filter$, reload$]).pipe(
      takeUntil(destroy$),
      filter(([appState]) => appState.project?.node.id != null),
      switchMap(([appState, filterState]) =>
        this.apiService.loadIssueGraphData(
          appState.project.node.id,
          filterState.selectedCategories,
          filterState.selectedFilter.labels,
          filterState.selectedFilter.texts
        )
      ),
      shareReplay(1)
    );
    return this.state$;
  }

  /**
   * Make the interface with interfaceId a consumed interface of the component with id componentId
   */
  addConsumedInterface(componentId: string, interfaceId: string): Observable<any> {
    return this.apiService.addConsumedInterface(componentId, interfaceId);
  }

  /**
   * Remove the interface with interfaceId from consumed interfaces of the component with id componentId
   */
  removeConsumedInterface(componentId: string, interfaceId: string): Observable<any> {
    return this.apiService.removeConsumedInterface(componentId, interfaceId);
  }
}

results matching ""

    No results matching ""