summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.ts
blob: 313ac4c0dc2db83c0683e4306a3f625abd00ab35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'filter'
})
export class FilterPipe implements PipeTransform {
  transform(value: any, args?: any): any {
    return value.filter((row: any) => {
      let result = true;

      args.forEach((filter: any): boolean | void => {
        if (!filter.value) {
          return undefined;
        }

        result = result && filter.applyFilter(row, filter.value);
        if (!result) {
          return result;
        }
      });

      return result;
    });
  }
}