File

src/app/data/label/label-store.service.ts

Index

Methods

Constructor

constructor(getLabelsGQL: GetLabelsGQL)
Parameters :
Name Type Optional
getLabelsGQL GetLabelsGQL No

Methods

Private getAllFilter
getAllFilter(projectId: string)

Retrieve all labels from backend

Parameters :
Name Type Optional Description
projectId string No

id of current project

getMatchingLabels
getMatchingLabels(projectId: string, term: string)

Retrieve labels matching term. whoose name contains term

Parameters :
Name Type Optional Default value Description
projectId string No

id of current project

term string No null

coming from search bar above graph

observable emitting objects standing for labels that exist on backend whoose name contains term

import {Injectable} from '@angular/core';
import {map} from 'rxjs/operators';
import {GetLabelsGQL, Label} from '../../../generated/graphql';
import {Observable} from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class LabelStoreService {
  constructor(private getLabelsGQL: GetLabelsGQL) {}

  /**
   * Retrieve labels matching term.
   * @param projectId id of current project
   * @param term coming from search bar above graph
   * @returns observable emitting objects standing for labels that exist on backend
   * whoose name contains term
   */
  getMatchingLabels(projectId: string, term: string = null): Observable<FilterLabel[]> {
    if (!term) {
      return this.getAllFilter(projectId);
    }
    return this.getAllFilter(projectId).pipe(
      map((items) => items.filter((x) => x.name.toLocaleLowerCase().indexOf(term.toLocaleLowerCase()) > -1))
    );
  }

  /**
   * Retrieve all labels from backend
   * @param projectId id of current project
   */
  private getAllFilter(projectId: string): Observable<FilterLabel[]> {
    return this.getLabelsGQL.fetch({projectId}).pipe(map(({data}) => data.node.labels.nodes));
  }
}

export type FilterLabel = Pick<Label, 'id' | 'name' | 'color'>;

export function isFilterLabel(label: any): boolean {
  return 'id' in label && 'name' in label && 'color' in label;
}

results matching ""

    No results matching ""