src/app/data/label/label-store.service.ts
Methods |
|
constructor(getLabelsGQL: GetLabelsGQL)
|
||||||
Defined in src/app/data/label/label-store.service.ts:9
|
||||||
Parameters :
|
Private getAllFilter | ||||||||
getAllFilter(projectId: string)
|
||||||||
Defined in src/app/data/label/label-store.service.ts:32
|
||||||||
Retrieve all labels from backend
Parameters :
Returns :
Observable<FilterLabel[]>
|
getMatchingLabels | |||||||||||||||
getMatchingLabels(projectId: string, term: string)
|
|||||||||||||||
Defined in src/app/data/label/label-store.service.ts:19
|
|||||||||||||||
Retrieve labels matching term. whoose name contains term
Parameters :
Returns :
Observable<FilterLabel[]>
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;
}