-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFilterComponents.js
More file actions
147 lines (134 loc) · 5.05 KB
/
FilterComponents.js
File metadata and controls
147 lines (134 loc) · 5.05 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* @class FilterComponents
* @classdesc Class to process filters on Filter page
*
* @constructs FilterComponents
* @param {Object} globals - object of global report variables {pageContext: this.pageContext, report: report, user: user, state: state, confirmit: confirmit, log: log}
* @param {String[]} questionsArray
* @param {String} dataSource - ds id
*/
class FilterComponents{
private var _globals;
private var _filterQuestions;
private var _parameterUtilities;
function FilterComponents(globals,questionsArray, dataSource){
_globals = globals;
_filterQuestions = [];
var project = _globals.report.DataSource.GetProject(dataSource);
for( var i = 0; i < questionsArray.length; i++ ){
_filterQuestions.push(project.GetQuestion( questionsArray[i]))
}
_parameterUtilities = new ParameterUtilities(_globals);
}
/**
* @memberof FilterComponents
* @instance
* @function GetFilterQuestion
* @description function to get Question object for the particular filter
* @param {Number} filterNumber
* @returns {Question}
*/
function GetFilterQuestion(filterNumber){
var filterQuestion = false;
if(_filterQuestions.length > filterNumber && ( _filterQuestions[(filterNumber)].QuestionType == QuestionType.Multi || _filterQuestions[(filterNumber)].QuestionType == QuestionType.Single )){
var filterQuestion = _filterQuestions[(filterNumber)];
}
return filterQuestion
}
/**
* @memberof FilterComponents
* @instance
* @function GetFilterTitle
* @description function to get Title for the particular filter
* @param {Number} filterNumber
* @returns {String}
*/
function GetFilterTitle(filterNumber){
var filterQuestion = GetFilterQuestion(filterNumber);
var label = "";
if(filterQuestion)
var label = filterQuestion.Title ? filterQuestion.Title : filterQuestion.QuestionId;
return label
}
/**
* @memberof FilterComponents
* @instance
* @function GetGlobalsFilterExpression
* @description function to get filter expression for all selected filters
* @returns {String}
*/
function GetGlobalsFilterExpression(){
var fExpr;
var filterExpressionSegments = [];
var codes = GetAllAnsweredFilterCodes()
for (var i = 0; i < codes.length; i++){
if( codes[i].questionType == QuestionType.Multi ) {
filterExpressionSegments.push ('ANY(' + codes[i].questionId + ',"' + codes[i].values.join('","') + '")');
}
else
{
filterExpressionSegments.push ('IN(' + codes[i].questionId + ',"' + codes[i].values.join('","') + '")');
}
}
fExpr = filterExpressionSegments.join(" AND ")
return fExpr
}
/**
* @memberof FilterComponents
* @instance
* @function GetAllAnsweredFilterCodes
* @description function to get selected filters information
* @returns {Object[]} - array of Objects with Filter information and answers like { questionTitle: "Title", questionId: "qId", values: [1,2], texts: ["one", "two"]}
*/
function GetAllAnsweredFilterCodes(){
var answeredCodes = [];
for (var i = 0; i < _filterQuestions.length; i++){
var codes = GetFilterInformation(i);
if(codes && codes.values.length > 0){
answeredCodes.push(codes);
}
}
return answeredCodes
}
/**
* @memberof FilterComponents
* @instance
* @function GetFilterInformation
* @description function to get filter information
* @param {Number} filterNumber
* @returns {Object} - Object with Filter information and answers like { questionTitle: "Title", questionId: "qId", values: [1,2], texts: ["one", "two"]}
*/
function GetFilterInformation(filterNumber){
var result = false;
var parameterName = 'FILTER' + (filterNumber +1);
var codes = _parameterUtilities.GetParameterCodes(parameterName);
if ( codes.length > 0 ){
var fTitle = GetFilterTitle(filterNumber);
var fId = _filterQuestions[filterNumber].QuestionId;
var fType = _filterQuestions[filterNumber].QuestionType
result = {
questionTitle: fTitle,
questionId: fId,
questionType: fType,
values: [],
texts: []
};
for ( var i = 0; i < codes.length; i++){
result.values.push(codes[i]);
result.texts.push(_filterQuestions[filterNumber].GetAnswer(codes[i]).Text)
}
}
return result
}
/**
* @memberof FilterComponents
* @instance
* @function ClearFilters
* @description function to set all filter parameters to null
*/
function ClearFilters(){
for (var i = 0; i < _filterQuestions.length; i++){
_globals.state.Parameters["FILTER"+(i+1)] = null;
}
}
}