forked from microsoft/PowerBI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilterBuilder.ts
103 lines (94 loc) · 2.9 KB
/
filterBuilder.ts
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { IFilterTarget } from "powerbi-models";
/**
* Generic filter builder for BasicFilter, AdvancedFilter, RelativeDate, RelativeTime and TopN
*
* @class
*/
export class FilterBuilder {
public target: IFilterTarget;
/**
* Sets target property for filter with target object
*
* ```javascript
* const target = {
* table: 'table1',
* column: 'column1'
* };
*
* const filterBuilder = new FilterBuilder().withTargetObject(target);
* ```
*
* @returns {FilterBuilder}
*/
withTargetObject(target: IFilterTarget): this {
this.target = target;
return this;
}
/**
* Sets target property for filter with column target object
*
* ```
* const filterBuilder = new FilterBuilder().withColumnTarget(tableName, columnName);
* ```
*
* @returns {FilterBuilder}
*/
withColumnTarget(tableName: string, columnName: string): this {
this.target = { table: tableName, column: columnName };
return this;
}
/**
* Sets target property for filter with measure target object
*
* ```
* const filterBuilder = new FilterBuilder().withMeasureTarget(tableName, measure);
* ```
*
* @returns {FilterBuilder}
*/
withMeasureTarget(tableName: string, measure: string): this {
this.target = { table: tableName, measure: measure };
return this;
}
/**
* Sets target property for filter with hierarchy level target object
*
* ```
* const filterBuilder = new FilterBuilder().withHierarchyLevelTarget(tableName, hierarchy, hierarchyLevel);
* ```
*
* @returns {FilterBuilder}
*/
withHierarchyLevelTarget(tableName: string, hierarchy: string, hierarchyLevel: string): this {
this.target = { table: tableName, hierarchy: hierarchy, hierarchyLevel: hierarchyLevel };
return this;
}
/**
* Sets target property for filter with column aggregation target object
*
* ```
* const filterBuilder = new FilterBuilder().withColumnAggregation(tableName, columnName, aggregationFunction);
* ```
*
* @returns {FilterBuilder}
*/
withColumnAggregation(tableName: string, columnName: string, aggregationFunction: string): this {
this.target = { table: tableName, column: columnName, aggregationFunction: aggregationFunction };
return this;
}
/**
* Sets target property for filter with hierarchy level aggregation target object
*
* ```
* const filterBuilder = new FilterBuilder().withHierarchyLevelAggregationTarget(tableName, hierarchy, hierarchyLevel, aggregationFunction);
* ```
*
* @returns {FilterBuilder}
*/
withHierarchyLevelAggregationTarget(tableName: string, hierarchy: string, hierarchyLevel: string, aggregationFunction: string): this {
this.target = { table: tableName, hierarchy: hierarchy, hierarchyLevel: hierarchyLevel, aggregationFunction: aggregationFunction };
return this;
}
}