-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTAHelper.js
More file actions
130 lines (116 loc) · 4.13 KB
/
TAHelper.js
File metadata and controls
130 lines (116 loc) · 4.13 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
/**
* @class TAHelper
* @classdesc Class cntaining additional static functions to work with text analytics
*/
class TAHelper{
/**
* @memberof TAHelper
* @function GetGlobals
* @description function to retrieve global parameters from given context
* @param {Object} context
* @returns {Object}
*/
static function GetGlobals(context){
return {
pageContext: context.pageContext,
report: context.report,
user: context.user,
state: context.state,
confirmit: context.confirmit,
log: context.log
};
}
/**
* @memberof TAHelper
* @function GetSelectedCategory
* @description function to get id of selected category, subcategory or attribute
* @param {ReportState} state
* @param {String} categoriesParameterName
* @param {String} subCategoriesParameterName
* @param {String} attribtesPararmeterNam
* @returns {String}
*/
static function GetSelectedCategory(state, categoriesParameterName, subCategoriesParameterName, attribtesPararmeterName){
var categoriesParameter;
if(categoriesParameterName)
categoriesParameter = state.Parameters.GetString(categoriesParameterName);
var subCategoriesParameter;
if(subCategoriesParameterName)
subCategoriesParameter= state.Parameters.GetString("TA_SUB_CATEGORIES_SINGLE");
var attributesParameter;
if(attribtesPararmeterName)
attributesParameter = state.Parameters.GetString("TA_ATTRIBUTES_SINGLE");
var selectedCategory = false;
if(categoriesParameter && categoriesParameter != "emptyv"){
selectedCategory = categoriesParameter;
}
if(subCategoriesParameter && subCategoriesParameter != "emptyv"){
selectedCategory = subCategoriesParameter;
}
if(attributesParameter && attributesParameter != "emptyv"){
selectedCategory = attributesParameter;
}
return selectedCategory;
}
/**
* @memberof TAHelper
* @function GetSelfName
* @description function to trim out parents cateories from the category name
* @param {String} name
* @param {String} separator
* @returns {String}
*/
static function GetSelfName(name, separator){
var index = name.lastIndexOf(separator);
return name.slice((index+1)).Trim();
}
/**
* @memberof TAHelper
* @function GetConfiguredVariables
* @description function to get configured value from TAConfig or survey tags
* @param {Object} globals
* @param {Object} questionConfig
* @param {Object} config
* @param {Object} tag
* @param {Object} defaultValue
* @returns {Object}
*/
static function GetConfiguredVariables(globals,questionConfig, config, tag, defaultValue){
var result = [];
if(!questionConfig || questionConfig.length == 0 || !questionConfig[0]){
if( !config || config.length == 0 || !config[0]){
if(!tag || tag.length == 0 || !tag[0]){
result = defaultValue;
}else{
result = tag
}
}else{
result = config;
}
}else{
result = questionConfig
}
return result;
}
static function GetTagsFromSurvey(globals, datasourceId, tags){
var result = false;
var project = globals.report.DataSource.GetProject(datasourceId);
var questions = project.GetQuestionsWithAnswers(false, tags);
if(questions.length > 0)
result = [];
for (var i = 0; i < questions.length; i++){
result.push(questions[i].QuestionId);
}
return result;
}
/**
* @memberof TAHelper
* @function SetLastVisitedPage
* @description function to set the last visited page to the parameter
* @param {Object} globals
* @param {String} pageId
*/
static function SetLastVisitedPage(globals, pageId){
globals.state.Parameters["TA_LAST_VISITED_PAGE"] = new ParameterValueResponse(pageId);
}
}