@easyquery/core 7.2.5-beta01 → 7.2.5-rc01

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/dist/easyquery.core.cjs.js +6165 -0
  2. package/dist/easyquery.core.esm.js +6126 -0
  3. package/dist/{lib → types}/common/eq_services.d.ts +16 -12
  4. package/dist/{lib → types}/dm/data_model.d.ts +3 -23
  5. package/dist/{lib → types}/dm/operator.d.ts +2 -2
  6. package/dist/{lib → types}/main/context.d.ts +17 -2
  7. package/dist/types/main/context_resolver.d.ts +3 -0
  8. package/dist/types/main/init.d.ts +1 -0
  9. package/dist/{lib → types}/public_api.d.ts +2 -0
  10. package/dist/{lib → types}/query/query.d.ts +19 -8
  11. package/package.json +13 -37
  12. package/dist/bundles/easyquery.core.js +0 -9584
  13. package/dist/bundles/easyquery.core.js.map +0 -1
  14. package/dist/bundles/easyquery.core.min.js +0 -2
  15. package/dist/bundles/easyquery.core.min.js.map +0 -1
  16. package/dist/lib/common/eq_services.js +0 -160
  17. package/dist/lib/common/eq_services.js.map +0 -1
  18. package/dist/lib/common/query_param.js +0 -2
  19. package/dist/lib/common/query_param.js.map +0 -1
  20. package/dist/lib/common/tree.js +0 -58
  21. package/dist/lib/common/tree.js.map +0 -1
  22. package/dist/lib/data/eq_aggr_container.js +0 -109
  23. package/dist/lib/data/eq_aggr_container.js.map +0 -1
  24. package/dist/lib/data/eq_data_loader.js +0 -50
  25. package/dist/lib/data/eq_data_loader.js.map +0 -1
  26. package/dist/lib/data/google_data_converter.js +0 -174
  27. package/dist/lib/data/google_data_converter.js.map +0 -1
  28. package/dist/lib/dm/aggr_function.js +0 -43
  29. package/dist/lib/dm/aggr_function.js.map +0 -1
  30. package/dist/lib/dm/data_model.js +0 -935
  31. package/dist/lib/dm/data_model.js.map +0 -1
  32. package/dist/lib/dm/dto/af_data.js +0 -2
  33. package/dist/lib/dm/dto/af_data.js.map +0 -1
  34. package/dist/lib/dm/dto/dm_data.js +0 -2
  35. package/dist/lib/dm/dto/dm_data.js.map +0 -1
  36. package/dist/lib/dm/dto/entity_data.js +0 -2
  37. package/dist/lib/dm/dto/entity_data.js.map +0 -1
  38. package/dist/lib/dm/dto/operator_data.js +0 -2
  39. package/dist/lib/dm/dto/operator_data.js.map +0 -1
  40. package/dist/lib/dm/dto/ve_data.js +0 -2
  41. package/dist/lib/dm/dto/ve_data.js.map +0 -1
  42. package/dist/lib/dm/entity.js +0 -91
  43. package/dist/lib/dm/entity.js.map +0 -1
  44. package/dist/lib/dm/link.js +0 -2
  45. package/dist/lib/dm/link.js.map +0 -1
  46. package/dist/lib/dm/operator.js +0 -94
  47. package/dist/lib/dm/operator.js.map +0 -1
  48. package/dist/lib/dm/value_editor.js +0 -44
  49. package/dist/lib/dm/value_editor.js.map +0 -1
  50. package/dist/lib/eqs/eqs_data_fetcher.js +0 -37
  51. package/dist/lib/eqs/eqs_data_fetcher.js.map +0 -1
  52. package/dist/lib/eqs/eqs_exporter.js +0 -60
  53. package/dist/lib/eqs/eqs_exporter.js.map +0 -1
  54. package/dist/lib/eqs/eqs_model_loader.js +0 -43
  55. package/dist/lib/eqs/eqs_model_loader.js.map +0 -1
  56. package/dist/lib/eqs/eqs_query_file_loader.js +0 -55
  57. package/dist/lib/eqs/eqs_query_file_loader.js.map +0 -1
  58. package/dist/lib/eqs/eqs_query_synchronizer.js +0 -24
  59. package/dist/lib/eqs/eqs_query_synchronizer.js.map +0 -1
  60. package/dist/lib/eqs/eqs_value_list_resolver.js +0 -29
  61. package/dist/lib/eqs/eqs_value_list_resolver.js.map +0 -1
  62. package/dist/lib/export/exporter.js +0 -7
  63. package/dist/lib/export/exporter.js.map +0 -1
  64. package/dist/lib/i18n/text_resources.js +0 -27
  65. package/dist/lib/i18n/text_resources.js.map +0 -1
  66. package/dist/lib/main/action.js +0 -6
  67. package/dist/lib/main/action.js.map +0 -1
  68. package/dist/lib/main/context.js +0 -1492
  69. package/dist/lib/main/context.js.map +0 -1
  70. package/dist/lib/main/context_options.js +0 -2
  71. package/dist/lib/main/context_options.js.map +0 -1
  72. package/dist/lib/main/data_fetcher.js +0 -2
  73. package/dist/lib/main/data_fetcher.js.map +0 -1
  74. package/dist/lib/main/eq_actions.js +0 -16
  75. package/dist/lib/main/eq_actions.js.map +0 -1
  76. package/dist/lib/main/list_cache.js +0 -2
  77. package/dist/lib/main/list_cache.js.map +0 -1
  78. package/dist/lib/main/model_loader.js +0 -33
  79. package/dist/lib/main/model_loader.js.map +0 -1
  80. package/dist/lib/main/model_storage.js +0 -18
  81. package/dist/lib/main/model_storage.js.map +0 -1
  82. package/dist/lib/main/query_file_loader.js +0 -2
  83. package/dist/lib/main/query_file_loader.js.map +0 -1
  84. package/dist/lib/main/query_storage.js +0 -125
  85. package/dist/lib/main/query_storage.js.map +0 -1
  86. package/dist/lib/main/query_synchronizer.js +0 -2
  87. package/dist/lib/main/query_synchronizer.js.map +0 -1
  88. package/dist/lib/main/value_list_resolver.js +0 -2
  89. package/dist/lib/main/value_list_resolver.js.map +0 -1
  90. package/dist/lib/main/widget.js +0 -102
  91. package/dist/lib/main/widget.js.map +0 -1
  92. package/dist/lib/public_api.js +0 -60
  93. package/dist/lib/public_api.js.map +0 -1
  94. package/dist/lib/query/condition.js +0 -332
  95. package/dist/lib/query/condition.js.map +0 -1
  96. package/dist/lib/query/descriptors.js +0 -2
  97. package/dist/lib/query/descriptors.js.map +0 -1
  98. package/dist/lib/query/dto/condition_data.js +0 -2
  99. package/dist/lib/query/dto/condition_data.js.map +0 -1
  100. package/dist/lib/query/dto/expression_data.js +0 -2
  101. package/dist/lib/query/dto/expression_data.js.map +0 -1
  102. package/dist/lib/query/dto/query_column_data.js +0 -2
  103. package/dist/lib/query/dto/query_column_data.js.map +0 -1
  104. package/dist/lib/query/dto/query_data.js +0 -2
  105. package/dist/lib/query/dto/query_data.js.map +0 -1
  106. package/dist/lib/query/expression.js +0 -203
  107. package/dist/lib/query/expression.js.map +0 -1
  108. package/dist/lib/query/query.js +0 -1503
  109. package/dist/lib/query/query.js.map +0 -1
  110. package/dist/lib/query/query_column.js +0 -205
  111. package/dist/lib/query/query_column.js.map +0 -1
  112. package/dist/lib/query/query_events.js +0 -20
  113. package/dist/lib/query/query_events.js.map +0 -1
  114. package/dist/lib/types/cond_part.js +0 -8
  115. package/dist/lib/types/cond_part.js.map +0 -1
  116. package/dist/lib/types/cond_tag.js +0 -14
  117. package/dist/lib/types/cond_tag.js.map +0 -1
  118. package/dist/lib/types/data_kind.js +0 -17
  119. package/dist/lib/types/data_kind.js.map +0 -1
  120. package/dist/lib/types/eq_editor_tag.js +0 -21
  121. package/dist/lib/types/eq_editor_tag.js.map +0 -1
  122. package/dist/lib/types/expr_tag.js +0 -21
  123. package/dist/lib/types/expr_tag.js.map +0 -1
  124. package/dist/lib/types/link_type.js +0 -19
  125. package/dist/lib/types/link_type.js.map +0 -1
  126. package/dist/lib/types/widget_group.js +0 -19
  127. package/dist/lib/types/widget_group.js.map +0 -1
  128. package/dist/lib/utils/constants.js +0 -51
  129. package/dist/lib/utils/constants.js.map +0 -1
  130. package/dist/lib/utils/format_parser.js +0 -88
  131. package/dist/lib/utils/format_parser.js.map +0 -1
  132. package/dist/lib/utils/utils.js +0 -103
  133. package/dist/lib/utils/utils.js.map +0 -1
  134. package/dist/lib/utils/version_info.js +0 -13
  135. package/dist/lib/utils/version_info.js.map +0 -1
  136. package/tsconfig.json +0 -22
  137. package/webpack.config.js +0 -51
  138. /package/dist/{lib → types}/common/query_param.d.ts +0 -0
  139. /package/dist/{lib → types}/common/tree.d.ts +0 -0
  140. /package/dist/{lib → types}/data/eq_aggr_container.d.ts +0 -0
  141. /package/dist/{lib → types}/data/eq_data_loader.d.ts +0 -0
  142. /package/dist/{lib → types}/data/google_data_converter.d.ts +0 -0
  143. /package/dist/{lib → types}/dm/aggr_function.d.ts +0 -0
  144. /package/dist/{lib → types}/dm/dto/af_data.d.ts +0 -0
  145. /package/dist/{lib → types}/dm/dto/dm_data.d.ts +0 -0
  146. /package/dist/{lib → types}/dm/dto/entity_data.d.ts +0 -0
  147. /package/dist/{lib → types}/dm/dto/operator_data.d.ts +0 -0
  148. /package/dist/{lib → types}/dm/dto/ve_data.d.ts +0 -0
  149. /package/dist/{lib → types}/dm/entity.d.ts +0 -0
  150. /package/dist/{lib → types}/dm/link.d.ts +0 -0
  151. /package/dist/{lib → types}/dm/value_editor.d.ts +0 -0
  152. /package/dist/{lib → types}/eqs/eqs_data_fetcher.d.ts +0 -0
  153. /package/dist/{lib → types}/eqs/eqs_exporter.d.ts +0 -0
  154. /package/dist/{lib → types}/eqs/eqs_model_loader.d.ts +0 -0
  155. /package/dist/{lib → types}/eqs/eqs_query_file_loader.d.ts +0 -0
  156. /package/dist/{lib → types}/eqs/eqs_query_synchronizer.d.ts +0 -0
  157. /package/dist/{lib → types}/eqs/eqs_value_list_resolver.d.ts +0 -0
  158. /package/dist/{lib → types}/export/exporter.d.ts +0 -0
  159. /package/dist/{lib → types}/i18n/text_resources.d.ts +0 -0
  160. /package/dist/{lib → types}/main/action.d.ts +0 -0
  161. /package/dist/{lib → types}/main/context_options.d.ts +0 -0
  162. /package/dist/{lib → types}/main/data_fetcher.d.ts +0 -0
  163. /package/dist/{lib → types}/main/eq_actions.d.ts +0 -0
  164. /package/dist/{lib → types}/main/list_cache.d.ts +0 -0
  165. /package/dist/{lib → types}/main/model_loader.d.ts +0 -0
  166. /package/dist/{lib → types}/main/model_storage.d.ts +0 -0
  167. /package/dist/{lib → types}/main/query_file_loader.d.ts +0 -0
  168. /package/dist/{lib → types}/main/query_storage.d.ts +0 -0
  169. /package/dist/{lib → types}/main/query_synchronizer.d.ts +0 -0
  170. /package/dist/{lib → types}/main/value_list_resolver.d.ts +0 -0
  171. /package/dist/{lib → types}/main/widget.d.ts +0 -0
  172. /package/dist/{lib → types}/query/condition.d.ts +0 -0
  173. /package/dist/{lib → types}/query/descriptors.d.ts +0 -0
  174. /package/dist/{lib → types}/query/dto/condition_data.d.ts +0 -0
  175. /package/dist/{lib → types}/query/dto/expression_data.d.ts +0 -0
  176. /package/dist/{lib → types}/query/dto/query_column_data.d.ts +0 -0
  177. /package/dist/{lib → types}/query/dto/query_data.d.ts +0 -0
  178. /package/dist/{lib → types}/query/expression.d.ts +0 -0
  179. /package/dist/{lib → types}/query/query_column.d.ts +0 -0
  180. /package/dist/{lib → types}/query/query_events.d.ts +0 -0
  181. /package/dist/{lib → types}/types/cond_part.d.ts +0 -0
  182. /package/dist/{lib → types}/types/cond_tag.d.ts +0 -0
  183. /package/dist/{lib → types}/types/data_kind.d.ts +0 -0
  184. /package/dist/{lib → types}/types/eq_editor_tag.d.ts +0 -0
  185. /package/dist/{lib → types}/types/expr_tag.d.ts +0 -0
  186. /package/dist/{lib → types}/types/link_type.d.ts +0 -0
  187. /package/dist/{lib → types}/types/widget_group.d.ts +0 -0
  188. /package/dist/{lib → types}/utils/constants.d.ts +0 -0
  189. /package/dist/{lib → types}/utils/format_parser.d.ts +0 -0
  190. /package/dist/{lib → types}/utils/utils.d.ts +0 -0
  191. /package/dist/{lib → types}/utils/version_info.d.ts +0 -0
@@ -1,1492 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import { EasyDataTable, EventEmitter, utils as dataUtils } from '@easydata/core';
13
- import { i18n } from '@easydata/core';
14
- import { equtils } from '../utils/utils';
15
- import { EqServiceProvider } from '../common/eq_services';
16
- import { ExprTag } from '../types/expr_tag';
17
- import { QueryChangePart } from '../query/query_events';
18
- import { WidgetGroup } from '../types/widget_group';
19
- import { EmptyChunk } from '../export/exporter';
20
- import { EqServerExporter } from '../eqs/eqs_exporter';
21
- import { EasyQueryDataLoader } from '../data/eq_data_loader';
22
- import { EqActionResult } from './action';
23
- import { EqAction } from './eq_actions';
24
- /**
25
- * Encapsulates all information about EasyQuery components on some webpage
26
- * and provides some basic operation over those components
27
- * Each context includes the following main components:
28
- * - one data model,
29
- * - one query,
30
- * - one result set
31
- * - several UI widgets.
32
- */
33
- var EqContext = /** @class */ (function () {
34
- function EqContext() {
35
- var _this = this;
36
- this.options = {
37
- syncSortOrderWithColumnsOrder: true,
38
- attributeFormat: '{entity} {attr}',
39
- columnTitleFormat: null //means it will be the same as attributeFormat
40
- };
41
- this.servicesInitialized = false;
42
- this.internalListCache = {};
43
- this.loadModelOnStart = true;
44
- this.loadQueryOnStart = false;
45
- this.useStoredQueryOnFetch = false;
46
- this.debugMode = false;
47
- this._backendInfo = {
48
- type: 'EQN-ANC',
49
- subType: 'asp-net-core-razor'
50
- };
51
- //----------- endpoint processing functions --------------
52
- this.endpointVarsRegex = /\{.*?\}/g;
53
- this.elasticPaging = false;
54
- this._predefinedListRequestHandlers = {
55
- '_DSDE': function (params, onResult) {
56
- var data = _this.getModel().getAllDateMacros()
57
- .map(function (macroId) {
58
- return { id: '${{' + macroId + '}}', text: i18n.getText(macroId) };
59
- });
60
- onResult(data);
61
- return true;
62
- },
63
- '_DSTE': function (params, onResult) {
64
- var data = _this.getModel().getAllTimeMacros()
65
- .map(function (macroId) {
66
- return { id: '${{' + macroId + '}}', text: i18n.getText(macroId) };
67
- });
68
- onResult(data);
69
- return true;
70
- }
71
- };
72
- this._listRequestHandler = function (options, onResult) {
73
- if (options == null || !options.listName)
74
- return;
75
- var query = _this.getQuery();
76
- var params = dataUtils.assign({ listName: options.listName }, options.editorParams);
77
- var reqParams = {};
78
- var attrPattern = /@{{(.+?)}}/;
79
- for (var prop in params) {
80
- if (!params[prop])
81
- continue;
82
- var match = params[prop].match(attrPattern);
83
- if (match) {
84
- var paramValue = query.getOneValueForAttr(match[1]);
85
- if (!paramValue) {
86
- paramValue = '';
87
- }
88
- reqParams[prop] = params[prop].replace(attrPattern, paramValue);
89
- }
90
- }
91
- var requestParams = {
92
- listName: reqParams.listName,
93
- editorId: options.editorId,
94
- queryParams: reqParams
95
- };
96
- var list = _this.getListFromCache(options);
97
- if (list && list.length > 0) {
98
- onResult(list);
99
- return;
100
- }
101
- var processed = false;
102
- var predefinedHandler = _this._predefinedListRequestHandlers[options.editorId];
103
- if (predefinedHandler) {
104
- processed = predefinedHandler(options, onResult);
105
- }
106
- if (!processed && _this.clientListRequestHandler) {
107
- processed = _this.clientListRequestHandler(options, onResult);
108
- }
109
- if (!processed) {
110
- _this.loadValueList({
111
- params: requestParams,
112
- success: function (data) {
113
- if (data) {
114
- _this.addListToCache(options, data);
115
- }
116
- onResult(data);
117
- },
118
- error: function (message) {
119
- onResult(null);
120
- }
121
- });
122
- }
123
- };
124
- this.baseEndpoint = 'api/easyquery';
125
- this.eqServices = new EqServiceProvider(this);
126
- this.widgets = new Array();
127
- this.eventEmitter = new EventEmitter(this);
128
- this.exporters = new Map();
129
- this.endpoints = new Map();
130
- this.dataLoader = new EasyQueryDataLoader(this);
131
- this.resultTable = new EasyDataTable({
132
- loader: this.dataLoader,
133
- onUpdate: this.onResultTableUpdate.bind(this)
134
- });
135
- this.resultTable.id = 'ResultTable';
136
- this.errorHandlerId = this.addEventListener('error', function (context, status) {
137
- status.result = EqActionResult.Error;
138
- var msgTitle = status.action ? status.action + ' error' : 'Error';
139
- var msgText = status.text ? status.text : '';
140
- if (status.sourceError && status.sourceError.message !== msgText) {
141
- msgText += '\n' + status.sourceError;
142
- }
143
- console.error(msgTitle + ': ' + msgText);
144
- });
145
- }
146
- EqContext.prototype.getServices = function () {
147
- return this.eqServices;
148
- };
149
- EqContext.prototype.registerExporter = function (format, resolver) {
150
- this.exporters.set(format, resolver);
151
- };
152
- EqContext.prototype.registerServerExporter = function (format, responseType) {
153
- this.registerExporter(format, function (context) {
154
- var exporter = new EqServerExporter(context);
155
- exporter.setFormat(format, responseType);
156
- return exporter;
157
- });
158
- };
159
- EqContext.prototype.getExporter = function (format) {
160
- var resolver = this.exporters.get(format);
161
- if (resolver) {
162
- return resolver(this);
163
- }
164
- return null;
165
- };
166
- EqContext.prototype.getExportFormats = function () {
167
- return Array.from(this.exporters.keys());
168
- };
169
- EqContext.prototype.addDefaultExporters = function () {
170
- this.registerServerExporter('csv', 'arraybuffer');
171
- this.registerServerExporter('excel-html', 'arraybuffer');
172
- };
173
- EqContext.prototype.resolveEndpoint = function (endpointKey, options) {
174
- options = options || {};
175
- var result = this.endpoints.get(endpointKey);
176
- if (!result) {
177
- throw endpointKey + ' endpoint is not defined';
178
- }
179
- var matches = result.match(this.endpointVarsRegex);
180
- if (matches) {
181
- for (var _i = 0, matches_1 = matches; _i < matches_1.length; _i++) {
182
- var match = matches_1[_i];
183
- var opt = match.substring(1, match.length - 1);
184
- var optVal = options[opt];
185
- if (!optVal) {
186
- if (opt == 'modelId') {
187
- optVal = this.getModel().getId();
188
- }
189
- else if (opt == 'queryId') {
190
- optVal = this.getQuery().getId();
191
- }
192
- else {
193
- throw "Parameter [".concat(opt, "] is not defined");
194
- }
195
- }
196
- result = result.replace(match, optVal);
197
- }
198
- }
199
- return result;
200
- };
201
- EqContext.prototype.setEndpoint = function (key, value) {
202
- this.endpoints.set(key, value);
203
- };
204
- EqContext.prototype.setEnpointIfNotExist = function (key, value) {
205
- if (!this.endpoints.has(key))
206
- this.endpoints.set(key, value);
207
- };
208
- EqContext.prototype.setDefaultEndpoints = function (endpointBase) {
209
- this.setEnpointIfNotExist('GetModel', equtils.combinePath(endpointBase, 'models/{modelId}'));
210
- this.setEnpointIfNotExist('GetQuery', equtils.combinePath(endpointBase, 'models/{modelId}/queries/{queryId}'));
211
- this.setEnpointIfNotExist('SaveQuery', equtils.combinePath(endpointBase, 'models/{modelId}/queries/{queryId}'));
212
- this.setEnpointIfNotExist('SyncQuery', equtils.combinePath(endpointBase, 'models/{modelId}/queries/{queryId}/sync'));
213
- this.setEnpointIfNotExist('NewQuery', equtils.combinePath(endpointBase, 'models/{modelId}/queries'));
214
- this.setEnpointIfNotExist('RemoveQuery', equtils.combinePath(endpointBase, 'models/{modelId}/queries/{queryId}'));
215
- this.setEnpointIfNotExist('GetQueryList', equtils.combinePath(endpointBase, 'models/{modelId}/queries'));
216
- this.setEnpointIfNotExist('FetchData', equtils.combinePath(endpointBase, 'models/{modelId}/fetch'));
217
- this.setEnpointIfNotExist('GetValueList', equtils.combinePath(endpointBase, 'models/{modelId}/valuelists/{listId}'));
218
- this.setEnpointIfNotExist('ExportResult', equtils.combinePath(endpointBase, 'models/{modelId}/export/{format}'));
219
- this.setEnpointIfNotExist('GetQueryFile', equtils.combinePath(endpointBase, 'models/{modelId}/getqueryfile/{format}'));
220
- this.setEnpointIfNotExist('UploadQueryFile', equtils.combinePath(endpointBase, 'models/{modelId}/uploadqueryfile'));
221
- };
222
- EqContext.prototype.initStart = function () {
223
- this.servicesInitialized = true;
224
- };
225
- /**
226
- * Initializes the context
227
- * @param options
228
- */
229
- EqContext.prototype.init = function (options) {
230
- var _this = this;
231
- if (!this.servicesInitialized)
232
- this.initStart();
233
- options = options || {};
234
- this.setOptions(options);
235
- if (typeof (options.debugMode) !== 'undefined') {
236
- this.debugMode = options.debugMode;
237
- }
238
- if (typeof (options.chunkSize) !== 'undefined') {
239
- this.resultTable.chunkSize = options.chunkSize;
240
- }
241
- if (typeof (options.elasticPaging) !== 'undefined') {
242
- this.elasticPaging = options.elasticPaging;
243
- }
244
- if (options.listCache) {
245
- this.setExternalListCache(options.listCache);
246
- }
247
- if (options.locale) {
248
- i18n.setCurrentLocale(options.locale);
249
- }
250
- if (options.localeSettings) {
251
- i18n.updateLocaleSettings(options.localeSettings);
252
- }
253
- if (options.endpoint) {
254
- this.baseEndpoint = options.endpoint;
255
- console.warn('The `endpoint` option is deprecated.\n'
256
- + 'Please use `context.useEndpoint(endpointURL)` function instead.');
257
- }
258
- this.setDefaultEndpoints(this.baseEndpoint);
259
- if (options.modelStorageResolver) {
260
- var eqServices = this.getServices();
261
- eqServices.registerModelStorageResolver(options.modelStorageResolver);
262
- }
263
- this.loadQueryOnStart = false;
264
- if (options.loadQueryOnStart) {
265
- this.loadQueryOnStart = options.loadQueryOnStart;
266
- }
267
- this.loadModelOnStart = true;
268
- if (typeof options.loadModelOnStart !== 'undefined') {
269
- this.loadModelOnStart = options.loadModelOnStart;
270
- }
271
- if (options.handlers) {
272
- if (options.handlers.onInit) {
273
- this.addEventListener('ready', options.handlers.onInit);
274
- }
275
- if (options.handlers.afterLoadModel) {
276
- this.addEventListener('loadModel', options.handlers.afterLoadModel);
277
- }
278
- if (options.handlers.afterLoadQuery) {
279
- this.addEventListener('loadQuery', options.handlers.afterLoadQuery);
280
- }
281
- if (options.handlers.afterSyncQuery) {
282
- this.addEventListener('syncQuery', options.handlers.afterSyncQuery);
283
- }
284
- if (options.handlers.afterFetchData) {
285
- this.addEventListener('fetchData', options.handlers.afterFetchData);
286
- }
287
- if (options.handlers.afterExportResult) {
288
- this.addEventListener('exportResult', options.handlers.afterExportResult);
289
- }
290
- if (options.handlers.onProcessStart) {
291
- this.addEventListener('processStart', options.handlers.onProcessStart);
292
- }
293
- if (options.handlers.onProcessEnd) {
294
- this.addEventListener('processEnd', options.handlers.onProcessEnd);
295
- }
296
- if (options.handlers.onError) {
297
- this.removeEventListener('error', this.errorHandlerId);
298
- this.addEventListener('error', options.handlers.onError);
299
- }
300
- if (options.handlers.onListRequest) {
301
- this.clientListRequestHandler = options.handlers.onListRequest;
302
- }
303
- if (options.handlers.beforeLoadModel) {
304
- this.beforeLoadModel = options.handlers.beforeLoadModel;
305
- }
306
- if (options.handlers.beforeLoadQuery) {
307
- this.beforeLoadQuery = options.handlers.beforeLoadQuery;
308
- }
309
- if (options.handlers.beforeSyncQuery) {
310
- this.beforeSyncQuery = options.handlers.beforeSyncQuery;
311
- }
312
- if (options.handlers.beforeFetchData) {
313
- this.beforeFetchData = options.handlers.beforeFetchData;
314
- }
315
- if (options.handlers.beforeExportResult) {
316
- this.beforeExportResult = options.handlers.beforeExportResult;
317
- }
318
- }
319
- this.initialQuery = options.initialQuery;
320
- this.defaultQueryId = options.defaultQueryId || '';
321
- this.defaultModelId = options.defaultModelId || '__default';
322
- var modelLoader = this.eqServices.getModelLoader();
323
- modelLoader.init(options);
324
- var queryStorage = this.eqServices.getQueryStorage();
325
- queryStorage.init(options);
326
- if (options.useDefaultExporters !== false) {
327
- this.addDefaultExporters();
328
- }
329
- if (options.serverExporters) {
330
- this.exporters.clear();
331
- for (var _i = 0, _a = options.serverExporters; _i < _a.length; _i++) {
332
- var format = _a[_i];
333
- this.registerServerExporter(format, "arraybuffer");
334
- }
335
- }
336
- var query = this.getQuery();
337
- if (options.defaultQueryId) {
338
- query.setId(options.defaultQueryId);
339
- }
340
- //init widgets
341
- this.widgets.forEach(function (widget) {
342
- var widgetOptions = {};
343
- if (options.widgets && options.widgets[widget.getWidgetType()]) {
344
- widgetOptions = options.widgets[widget.getWidgetType()];
345
- }
346
- widget.init(_this, widgetOptions);
347
- });
348
- if (this.loadModelOnStart) {
349
- this.loadDefaultModel();
350
- }
351
- else {
352
- this.fireEvent('ready');
353
- }
354
- };
355
- EqContext.prototype.setOptions = function (options) {
356
- dataUtils.assignDeep(this.options, options);
357
- };
358
- Object.defineProperty(EqContext.prototype, "backendInfo", {
359
- get: function () {
360
- return this._backendInfo;
361
- },
362
- enumerable: false,
363
- configurable: true
364
- });
365
- /**
366
- * Sets endpoint for all EasyQuery actions. Should be called before `init` and
367
- * `useEnterprise` methods
368
- * @param endpoint
369
- * @example
370
- * ```
371
- * view.getContext()
372
- * .useEndpoint('/api/easyquery')
373
- * .useEnterprise(function () {
374
- * view.init();
375
- * });
376
- * ```
377
- */
378
- EqContext.prototype.useEndpoint = function (endpoint) {
379
- this.baseEndpoint = endpoint;
380
- return this;
381
- };
382
- /**
383
- * Allows to specify the type of backend service.
384
- *
385
- * @param backendInfo - the structure that contains information about the app used on the backend
386
- * Possible values for `ptag` property: 'EQN-ANC' - ASP.NET Core or 'EQN-ASP' - for ASP.NET 4 backend
387
- */
388
- EqContext.prototype.useBackend = function (backendInfo) {
389
- if (backendInfo.type) {
390
- this._backendInfo.type = backendInfo.type;
391
- }
392
- if (backendInfo.subType) {
393
- this._backendInfo.subType = backendInfo.subType;
394
- }
395
- else {
396
- switch (this._backendInfo.type) {
397
- case 'EQN-ANC':
398
- this._backendInfo.subType = 'asp-net-core-razor';
399
- break;
400
- case 'EQN-ASP':
401
- this._backendInfo.subType = 'asp-net-4-mvc';
402
- break;
403
- default:
404
- this._backendInfo.subType = 'other';
405
- break;
406
- }
407
- }
408
- return this;
409
- };
410
- /**
411
- * Add a new widget to the context.
412
- * After that the widget will start to receive messages from other context components.
413
- * @param widget
414
- */
415
- EqContext.prototype.addWidget = function (widget) {
416
- this.widgets.push(widget);
417
- };
418
- /**
419
- * Returns all widgets with current type.
420
- * @param widgetType The widget type
421
- */
422
- EqContext.prototype.getAllWidgetsByType = function (widgetType) {
423
- return this.widgets
424
- .filter(function (widget) { return widget.getWidgetType() === widgetType; });
425
- };
426
- /**
427
- * Returns first registerd widget with current type
428
- * @param widgetType The widget type
429
- */
430
- EqContext.prototype.getWidgetByType = function (widgetType) {
431
- var widgets = this.getAllWidgetsByType(widgetType);
432
- return widgets.length > 0 ? widgets[0] : null;
433
- };
434
- /**
435
- * This method is called automatically when some change was made either in context's data model or query
436
- * @param groups
437
- */
438
- EqContext.prototype.refreshWidgets = function (groups) {
439
- if (groups === void 0) { groups = WidgetGroup.All; }
440
- this.widgets.forEach(function (widget) {
441
- if (widget.belongsToGroup(groups)) {
442
- widget.refresh();
443
- }
444
- });
445
- };
446
- /**
447
- * Register a new handler for 'query changed' event
448
- * @param callback
449
- */
450
- EqContext.prototype.addQueryChangedCallback = function (callback) {
451
- this.getQuery().addChangedCallback(callback);
452
- };
453
- /**
454
- * Removes the function from the list of registerd handlers for 'query changed' event
455
- * @param callback
456
- */
457
- EqContext.prototype.removeQueryChangedCallback = function (callback) {
458
- this.getQuery().removeChangedCallback(callback);
459
- };
460
- /**
461
- * Creates a new query object using the current instance of EqServices
462
- */
463
- EqContext.prototype.createQuery = function () {
464
- return this.eqServices.createQuery();
465
- };
466
- /**
467
- * Gets the current query
468
- */
469
- EqContext.prototype.getQuery = function () {
470
- if (!this.query) {
471
- if (!this.servicesInitialized) {
472
- throw new Error("Can't create query until the context is initialized");
473
- }
474
- this.query = this.createQuery();
475
- }
476
- return this.query;
477
- };
478
- /**
479
- * Gets the current data model
480
- */
481
- EqContext.prototype.getModel = function () {
482
- if (!this.dataModel) {
483
- this.dataModel = this.eqServices.createDataModel();
484
- }
485
- return this.dataModel;
486
- };
487
- /**
488
- * Sets the content of the current data model
489
- */
490
- EqContext.prototype.loadModelFromData = function (modelPlainData) {
491
- this.getQuery().loadModelData(modelPlainData);
492
- this.dataModel = this.getQuery().getModel();
493
- };
494
- /**
495
- * Sets the ID of the default model
496
- * @param modelId
497
- */
498
- EqContext.prototype.setDefaultModelId = function (modelId) {
499
- this.defaultModelId = modelId;
500
- };
501
- /**
502
- * Notifies context components about starting of some long process (e.g. model loading)
503
- * This method raises onProcessStart event in the context and all its widgets
504
- * @param message
505
- * @param groups
506
- */
507
- EqContext.prototype.startProcess = function (message, groups) {
508
- this.eventEmitter.fire('processStart', message);
509
- this.widgets.forEach(function (widget) {
510
- if (widget.belongsToGroup(groups)) {
511
- widget.onProcessStart();
512
- }
513
- });
514
- };
515
- /**
516
- * Notifies all context components about the finishing of some long process
517
- * @param status
518
- * @param groups
519
- */
520
- EqContext.prototype.endProcess = function (status, groups) {
521
- this.eventEmitter.fire('processEnd', status);
522
- if (status.result === EqActionResult.Error) {
523
- this.throwError(status);
524
- }
525
- this.widgets.forEach(function (widget) {
526
- if (widget.belongsToGroup(groups)) {
527
- widget.onProcessEnd();
528
- }
529
- });
530
- };
531
- /**
532
- * Throws the error passed in the function parameter.
533
- * If onError event handler is defined - we call that method.
534
- * Otherwise - just place the error message to the browser console.
535
- * @param error
536
- */
537
- EqContext.prototype.throwError = function (status) {
538
- status.result = EqActionResult.Error;
539
- this.eventEmitter.fire('error', status);
540
- };
541
- /**
542
- * If `defaultModelId` property is define - this method calls `loadModel` function in the broker
543
- * to load the model with such ID.
544
- */
545
- EqContext.prototype.loadDefaultModel = function () {
546
- var _this = this;
547
- this.loadModel({
548
- modelId: this.defaultModelId,
549
- silent: true,
550
- success: function () {
551
- _this.refreshWidgets(WidgetGroup.Model);
552
- var query = _this.getQuery();
553
- _this.fireEvent('initialModelLoad');
554
- if (_this.initialQuery) {
555
- query.loadFromData(_this.initialQuery, {
556
- changeStatus: false
557
- });
558
- }
559
- if (_this.loadQueryOnStart) {
560
- _this.loadQuery({
561
- queryId: _this.defaultQueryId,
562
- modelId: _this.defaultModelId,
563
- success: function () {
564
- _this.refreshWidgets(WidgetGroup.Query);
565
- //if we load query on start - then we should call 'ready' event only after its successful loading
566
- _this.fireEvent('ready');
567
- }
568
- });
569
- }
570
- else {
571
- _this.refreshWidgets(WidgetGroup.Query);
572
- _this.fireEvent('ready');
573
- }
574
- }
575
- });
576
- };
577
- /**
578
- * Clears the content of the current query
579
- */
580
- EqContext.prototype.clearQuery = function () {
581
- var query = this.getQuery();
582
- query.clear();
583
- query.fireChangedEvent({
584
- part: QueryChangePart.All
585
- });
586
- };
587
- /**
588
- * Clears all query results (the data set and the statement, if any)
589
- */
590
- EqContext.prototype.clearResult = function () {
591
- this.resultTable.clear(); // do not set resultTable to null. Just clear
592
- this.resultStatement = null;
593
- this.resultContent = null;
594
- };
595
- /**
596
- * Sets the external 'list cache' provider - an object which implements `ExternalListCache` inteface
597
- * @param cache
598
- */
599
- EqContext.prototype.setExternalListCache = function (cache) {
600
- this.externalListCache = cache;
601
- };
602
- EqContext.prototype.getListFromCache = function (params) {
603
- var key = this.getListCacheKey(params);
604
- if (this.externalListCache) {
605
- return this.externalListCache.get(key);
606
- }
607
- else {
608
- return this.internalListCache[key];
609
- }
610
- };
611
- EqContext.prototype.getListCacheKey = function (params) {
612
- var key = params.listName == 'SQL' ? 'SQL_' + params.editorId : params.listName;
613
- if (params.queryParams) {
614
- key += '_' + Object.keys(params.queryParams).filter(function (k) { return k != 'listName'; })
615
- .map(function (k) { return params.queryParams[k]; })
616
- .join('_');
617
- }
618
- return key;
619
- };
620
- EqContext.prototype.addListToCache = function (params, list) {
621
- var key = this.getListCacheKey(params);
622
- if (this.externalListCache) {
623
- this.externalListCache.set(key, list);
624
- }
625
- else {
626
- this.internalListCache[key] = list;
627
- }
628
- };
629
- /**
630
- * Clears the current list cache.
631
- */
632
- EqContext.prototype.resetListCache = function () {
633
- if (this.externalListCache) {
634
- this.externalListCache.clear();
635
- }
636
- else {
637
- this.internalListCache = {};
638
- }
639
- };
640
- /**
641
- * Gets the handler for 'GetList' requests
642
- */
643
- EqContext.prototype.getListRequestHandler = function () {
644
- return this._listRequestHandler;
645
- };
646
- /**
647
- * Adds the translations of the EasyQuery messages for some locale
648
- * @param locale - the ISO code of the locale (like `en` or `uk`)
649
- * @param localeInfo - Locale settings and translations of EasyQuery texts and messages.
650
- * We expected an object with the struture of LocaleInfo interface here.
651
- */
652
- EqContext.prototype.addLocale = function (locale, localeInfo) {
653
- i18n.addLocale(locale, localeInfo);
654
- };
655
- EqContext.prototype.addEventListener = function (eventType, handler) {
656
- var _this = this;
657
- return this.eventEmitter.subscribe(eventType, function (event) { return handler(_this, event.data); });
658
- };
659
- /**
660
- * Remove event handler for event type .
661
- * @param eventType The event type.
662
- * @param handlerId The handler id.
663
- */
664
- EqContext.prototype.removeEventListener = function (eventType, handlerId) {
665
- this.eventEmitter.unsubscribe(eventType, handlerId);
666
- };
667
- EqContext.prototype.fireEvent = function (eventType, data) {
668
- this.eventEmitter.fire(eventType, data);
669
- };
670
- EqContext.prototype.getBaseEndpoint = function () {
671
- return this.baseEndpoint;
672
- };
673
- /**
674
- * Sends a `loadValueList` requesthe server and processes the response.
675
- * @param options A map of options to pass to `loadValueList` function.
676
- */
677
- EqContext.prototype.loadValueList = function (options) {
678
- var _this = this;
679
- options = options || {};
680
- this.startProcess({
681
- action: EqAction.GetValueList,
682
- text: 'Loading values'
683
- }, WidgetGroup.Result);
684
- var valueListResolver = this.eqServices.getValueListResolver();
685
- valueListResolver.loadValueList(options)
686
- .then(function (values) {
687
- _this.endProcess({
688
- result: EqActionResult.Success,
689
- action: EqAction.GetValueList,
690
- text: 'Values loaded'
691
- }, WidgetGroup.Result);
692
- if (options.success) {
693
- options.success(values);
694
- }
695
- })
696
- .catch(function (error) {
697
- var editorId = options && options.params ? options.params.editorId : 'undefined';
698
- var errorMessage = "Can't load the value list for editor ".concat(editorId, ".\n ").concat(error.message);
699
- _this.endProcess({
700
- result: EqActionResult.Error,
701
- action: EqAction.GetValueList,
702
- text: errorMessage,
703
- sourceError: error
704
- }, WidgetGroup.Result);
705
- if (options.error) {
706
- options.error(errorMessage, 'GetValueList');
707
- }
708
- });
709
- };
710
- /**
711
- * Starts the process of the model loading.
712
- * This method can initiate a request to EasyQueryServer backend or get the model from OData or GraphQL endpoint
713
- * The content of the `options` parameter depends on concrete loader implementation.
714
- * @param options A map of options to pass to `loadModel` function (can be ommited)
715
- * @example
716
- * context.loadModel()
717
- * .then(model => {
718
- * alert("Model loaded!");
719
- * });
720
- */
721
- EqContext.prototype.loadModel = function (options) {
722
- var _this = this;
723
- if (this.beforeLoadModel) {
724
- this.beforeLoadModel(this, options);
725
- }
726
- var modelId = options.modelId || '__default';
727
- var silent = options.silent || false;
728
- this.startProcess({
729
- action: EqAction.LoadModel,
730
- text: 'Loading model: ' + modelId
731
- }, WidgetGroup.Model);
732
- var modelLoader = this.eqServices.getModelLoader();
733
- return modelLoader.startModelLoading(options)
734
- .then(function (value) {
735
- if (value) {
736
- _this.loadModelFromData(value);
737
- if (_this.dataModel.isEmpty()) {
738
- console.warn("Empty model has been loaded. Model ID: ".concat(_this.dataModel.getId()));
739
- }
740
- }
741
- else {
742
- console.warn('Model has not been changed.');
743
- }
744
- _this.fireEvent('loadModel');
745
- _this.endProcess({
746
- result: EqActionResult.Success,
747
- action: EqAction.LoadModel,
748
- text: 'Model loaded: ' + modelId
749
- }, WidgetGroup.Model);
750
- if (!silent) {
751
- _this.clearQuery();
752
- _this.clearResult();
753
- _this.refreshWidgets();
754
- }
755
- if (options.success) {
756
- options.success(_this.getModel());
757
- }
758
- return _this.getModel();
759
- })
760
- .catch(function (error) {
761
- var errorMessage = "Can't load model ".concat(modelId, ".\n ").concat(error.message);
762
- _this.endProcess({
763
- result: EqActionResult.Error,
764
- action: EqAction.LoadModel,
765
- text: errorMessage,
766
- sourceError: error
767
- }, WidgetGroup.Model);
768
- if (options.error) {
769
- options.error(errorMessage, "LoadModel");
770
- }
771
- return _this.getModel();
772
- });
773
- };
774
- EqContext.prototype.callWhenModelLoaded = function (callFunc) {
775
- var modelLoader = this.eqServices.getModelLoader();
776
- modelLoader.getModelPromise().then(function () {
777
- callFunc();
778
- });
779
- };
780
- /**
781
- * Loads the query
782
- * @param options
783
- * The content of the `options` parameter depends on `QueryStorage` implementation.
784
- * Usually it contains `success`, `error` callbacks and `queryId` property of the query to load.
785
- * @example
786
- * context.loadQuery({
787
- * queryId: "query-id"
788
- * });
789
- */
790
- EqContext.prototype.loadQuery = function (options) {
791
- var _this = this;
792
- options = options || {};
793
- var modelLoader = this.eqServices.getModelLoader();
794
- this.clearResult();
795
- modelLoader.getModelPromise()
796
- .then(function () {
797
- options = options || {};
798
- var queryId = options.queryId;
799
- var silent = options.silent || false;
800
- if (_this.beforeLoadQuery) {
801
- _this.beforeLoadQuery(_this, options);
802
- }
803
- _this.startProcess({
804
- action: EqAction.LoadQuery,
805
- text: "Query loading: " + queryId
806
- }, WidgetGroup.Query);
807
- var queryStorage = _this.eqServices.getQueryStorage();
808
- queryStorage.loadQuery(options)
809
- .then(function (data) {
810
- if (data) {
811
- _this.query.loadFromData(data, {
812
- validate: false
813
- });
814
- }
815
- _this.limitCustomSqlColumns();
816
- _this.fireEvent('loadQuery');
817
- _this.endProcess({
818
- result: EqActionResult.Success,
819
- action: EqAction.LoadQuery,
820
- text: 'Query loaded: ' + queryId
821
- }, WidgetGroup.Query);
822
- _this.query.resetModified();
823
- if (!silent) {
824
- _this.query.fireChangedEvent({
825
- part: QueryChangePart.Properties,
826
- wasModified: _this.query.isModified()
827
- });
828
- _this.refreshWidgets();
829
- }
830
- if (options.success) {
831
- options.success(_this.query);
832
- }
833
- })
834
- .catch(function (error) {
835
- var query = _this.getQuery();
836
- error.message = "Can't load query [" + query.getId() + "]\n" + (error.message || "");
837
- if (options.error) {
838
- options.error(error.message, EqAction.LoadQuery);
839
- }
840
- _this.endProcess({
841
- result: EqActionResult.Error,
842
- action: EqAction.LoadQuery,
843
- text: error.message,
844
- sourceError: error
845
- }, WidgetGroup.Query);
846
- });
847
- })
848
- .catch(function (error) {
849
- console.error(error);
850
- });
851
- };
852
- /**
853
- * Loads the list of queries available for the current user.
854
- * @param options
855
- * The content of the `options` parameter depends on `QueryStorage` implementation.
856
- * Usually it contains `success`, `error` callbacks
857
- */
858
- EqContext.prototype.loadQueryList = function (options) {
859
- var _this = this;
860
- var modelLoader = this.eqServices.getModelLoader();
861
- modelLoader.getModelPromise()
862
- .then(function () {
863
- _this.startQueryListLoading(options);
864
- })
865
- .catch(function (error) {
866
- var errorMessage = "Can't load the list of available queries.\n ".concat(error.message);
867
- _this.throwError({
868
- action: EqAction.LoadQueryList,
869
- text: errorMessage,
870
- sourceError: error
871
- });
872
- });
873
- };
874
- EqContext.prototype.startQueryListLoading = function (options) {
875
- var _this = this;
876
- options = options || {};
877
- var queryStorage = this.eqServices.getQueryStorage();
878
- var queryListLoadingPromise = queryStorage.getQueryList(options);
879
- queryListLoadingPromise
880
- .then(function (queries) {
881
- if (options.success) {
882
- options.success(queries);
883
- }
884
- })
885
- .catch(function (error) {
886
- var errorMessage = "Can't load the list of available queries.\n ".concat(error.message);
887
- if (options.error) {
888
- options.error(errorMessage, 'LoadQueryList');
889
- }
890
- else {
891
- _this.throwError({
892
- action: EqAction.LoadQueryList,
893
- text: errorMessage,
894
- sourceError: error
895
- });
896
- }
897
- });
898
- };
899
- /**
900
- * Creates a new query and returns its content back to the client-side.
901
- * @param options
902
- * The content of the `options` parameter depends on `QueryStorage` implementation.
903
- * Usually it contains `success`, `error` callbacks and `silent` option
904
- * @example
905
- * context.newQuery({
906
- * silent: true
907
- * });
908
- */
909
- EqContext.prototype.newQuery = function (options) {
910
- var _this = this;
911
- options = options || {};
912
- var clearQuery = typeof options.clearQuery !== 'undefined' ? options.clearQuery : true;
913
- this.query.reset(clearQuery);
914
- if (options.queryId) {
915
- this.query.setId(options.queryId);
916
- }
917
- if (options.name) {
918
- this.query.setName(options.name);
919
- }
920
- if (options.description) {
921
- this.query.setDescription(options.description);
922
- }
923
- var silent = options.silent || false;
924
- var useStorage = true;
925
- if (typeof options.useStorage !== 'undefined') {
926
- useStorage = options.useStorage;
927
- }
928
- var onNewQuery = function () {
929
- var query = _this.getQuery();
930
- query.isNewbie = true;
931
- if (!silent) {
932
- query.fireChangedEvent({
933
- part: QueryChangePart.All,
934
- wasModified: query.isModified()
935
- });
936
- }
937
- };
938
- if (useStorage) {
939
- this.startProcess({
940
- action: EqAction.NewQuery,
941
- text: 'New query creation...'
942
- }, WidgetGroup.Query);
943
- var queryStorage = this.eqServices.getQueryStorage();
944
- queryStorage.newQuery(options)
945
- .then(function (queryData) {
946
- if (queryData) {
947
- _this.query.loadFromData(queryData);
948
- }
949
- _this.endProcess({
950
- result: EqActionResult.Success,
951
- action: EqAction.NewQuery,
952
- text: 'A new query has been created'
953
- }, WidgetGroup.Query);
954
- onNewQuery();
955
- if (options.success) {
956
- options.success();
957
- }
958
- })
959
- .catch(function (error) {
960
- var errorMessage = "Can't create a new query.\n".concat(error.message);
961
- _this.endProcess({
962
- result: EqActionResult.Error,
963
- action: EqAction.NewQuery,
964
- text: errorMessage,
965
- sourceError: error
966
- }, WidgetGroup.Query);
967
- if (options.error) {
968
- options.error(errorMessage, "NewQuery");
969
- }
970
- });
971
- }
972
- else {
973
- onNewQuery();
974
- }
975
- return this.query;
976
- };
977
- /**
978
- * Saves the current query to some storage on the server-side.
979
- * @param options
980
- * The content of the `options` parameter depends on `QueryStorage` implementation.
981
- * Usually it contains `success` and `error` callbacks
982
- */
983
- EqContext.prototype.saveQuery = function (options) {
984
- var _this = this;
985
- options = options || {};
986
- var query = this.getQuery();
987
- this.startProcess({
988
- action: EqAction.SaveQuery,
989
- text: 'Query saving: ' + query.getId()
990
- }, WidgetGroup.Query);
991
- var queryStorage = this.eqServices.getQueryStorage();
992
- queryStorage.saveQuery(options)
993
- .then(function (data) {
994
- _this.endProcess({
995
- action: EqAction.SaveQuery,
996
- result: EqActionResult.Success,
997
- text: "Query saved: " + query.getId()
998
- }, WidgetGroup.Query);
999
- if (data) {
1000
- query.loadFromData(data);
1001
- }
1002
- query.resetModified();
1003
- query.isNewbie = false;
1004
- if (options.success) {
1005
- options.success();
1006
- }
1007
- })
1008
- .catch(function (error) {
1009
- var errorMessage = "Can't save query ".concat(query.getId(), ".\n ").concat(error.message);
1010
- _this.endProcess({
1011
- action: EqAction.SaveQuery,
1012
- result: EqActionResult.Error,
1013
- text: errorMessage,
1014
- sourceError: error
1015
- }, WidgetGroup.Query);
1016
- if (options.error) {
1017
- options.error(errorMessage, EqAction.SaveQuery);
1018
- }
1019
- });
1020
- };
1021
- /**
1022
- * Removes the current query from some storage on the server-side.
1023
- * @param options
1024
- * The content of the `options` parameter depends on `QueryStorage` implementation.
1025
- * Usually it contains `success` and `error` callbacks
1026
- */
1027
- EqContext.prototype.removeQuery = function (options) {
1028
- var _this = this;
1029
- options = options || {};
1030
- var query = this.getQuery();
1031
- this.startProcess({
1032
- action: EqAction.RemoveQuery,
1033
- text: 'Query deleting: ' + query.getId()
1034
- }, WidgetGroup.Query);
1035
- var queryStorage = this.eqServices.getQueryStorage();
1036
- queryStorage.removeQuery(options)
1037
- .then(function () {
1038
- query.reset();
1039
- _this.endProcess({
1040
- action: EqAction.RemoveQuery,
1041
- result: EqActionResult.Success,
1042
- text: "Query deleted: " + query.getId()
1043
- }, WidgetGroup.Query);
1044
- if (options.success) {
1045
- options.success();
1046
- }
1047
- })
1048
- .catch(function (error) {
1049
- var errorMessage = "Can't remove query ".concat(query.getId(), ".\n ").concat(error.message);
1050
- _this.endProcess({
1051
- action: EqAction.RemoveQuery,
1052
- result: EqActionResult.Error,
1053
- text: errorMessage,
1054
- sourceError: error
1055
- }, WidgetGroup.Query);
1056
- if (options.error) {
1057
- options.error(errorMessage, 'RemoveQuery');
1058
- }
1059
- });
1060
- };
1061
- /**
1062
- * Syncronizes the current query.
1063
- * @param options
1064
- * The content of the `options` parameter depends on `QuerySyncronizer` implementation.
1065
- * Usually it contains `success` and `error` callbacks
1066
- */
1067
- EqContext.prototype.syncQuery = function (options) {
1068
- var _this = this;
1069
- options = options || {};
1070
- var query = this.getQuery();
1071
- if (this.beforeSyncQuery) {
1072
- this.beforeSyncQuery(this, options);
1073
- }
1074
- this.startProcess({
1075
- action: EqAction.SyncQuery,
1076
- text: 'Query syncing: ' + query.getId()
1077
- }, WidgetGroup.Query);
1078
- var querySyncrhonizer = this.eqServices.getQuerySynchronizer();
1079
- querySyncrhonizer.syncQuery(options)
1080
- .then(function (result) {
1081
- _this.resultStatement = result && result.statement
1082
- ? result.statement
1083
- : '';
1084
- _this.fireEvent('syncQuery');
1085
- _this.refreshWidgets(WidgetGroup.Statement);
1086
- _this.endProcess({
1087
- result: EqActionResult.Success,
1088
- action: EqAction.SyncQuery,
1089
- text: 'Query synced: ' + query.getId()
1090
- }, WidgetGroup.Query);
1091
- if (result) {
1092
- if (result.querySaved) {
1093
- var q = result.query;
1094
- if (q) {
1095
- query.setId(q.id);
1096
- query.setName(q.name);
1097
- query.setDescription(q.desc);
1098
- query.extraData = q.extraData;
1099
- }
1100
- query.resetModified();
1101
- _this.refreshWidgets(WidgetGroup.QueryStatus);
1102
- }
1103
- if (options.success) {
1104
- options.success(result);
1105
- }
1106
- }
1107
- })
1108
- .catch(function (error) {
1109
- var errorMessage = "Can't synchronize query ".concat(query.getId(), ".\n ").concat(error.message);
1110
- _this.endProcess({
1111
- result: EqActionResult.Error,
1112
- action: EqAction.SyncQuery,
1113
- text: errorMessage,
1114
- sourceError: error
1115
- }, WidgetGroup.Query);
1116
- if (options.error) {
1117
- options.error(errorMessage, 'SyncQuery');
1118
- }
1119
- });
1120
- };
1121
- /**
1122
- * Fetches the data (usuall by executing current query) and processes the result.
1123
- * @param options
1124
- * The `options` parameter in addition to the options defined in FetchDataOptions structure may also contain `success` and `error` callbacks.
1125
- * @example
1126
- * context.fetchData({ success: function(result) {
1127
- * //do whatever you want with the result
1128
- * }})
1129
- *
1130
- */
1131
- EqContext.prototype.fetchData = function (options) {
1132
- var _this = this;
1133
- options = options || {};
1134
- var elasticPaging = typeof (options.elasticPaging) !== 'undefined'
1135
- ? options.elasticPaging
1136
- : this.elasticPaging;
1137
- this.resultTable.elasticChunks = elasticPaging;
1138
- options.chunk = options.chunk ||
1139
- {
1140
- offset: 0,
1141
- limit: this.resultTable.chunkSize,
1142
- needTotal: !elasticPaging
1143
- };
1144
- if (this.debugMode) {
1145
- options.debug = 'Fetching the result set. Initial chunk';
1146
- }
1147
- if (!this.query.tryValidate({
1148
- checkExpressions: true
1149
- })) {
1150
- return;
1151
- }
1152
- //just to support the old way of catching "group fetch" operation finish
1153
- if (options.groupFetchSuccess) {
1154
- this.afterGroupFetch = options.groupFetchSuccess;
1155
- }
1156
- if (this.resultTable.elasticChunks) {
1157
- options.chunk.limit++;
1158
- }
1159
- this.fetchDataChunk(__assign(__assign({}, options), { success: function (result) {
1160
- if (result.statement) {
1161
- _this.resultStatement = result.statement;
1162
- _this.refreshWidgets(WidgetGroup.Statement);
1163
- }
1164
- var aggrCalculator = _this.getServices().getAggregatesCalculator();
1165
- aggrCalculator.reset();
1166
- _this.resultContent = result;
1167
- if (result.resultSet) {
1168
- _this.resultTable.clear();
1169
- _this.resultTable.id = _this.query.getId();
1170
- var resultSet = result.resultSet;
1171
- for (var _i = 0, _a = resultSet.cols; _i < _a.length; _i++) {
1172
- var col = _a[_i];
1173
- _this.resultTable.columns.add(col);
1174
- }
1175
- if (result.meta && typeof (result.meta.totalRecords) !== 'undefined') {
1176
- _this.resultTable.setTotal(result.meta.totalRecords);
1177
- }
1178
- var count = resultSet.rows.length;
1179
- if (_this.resultTable.elasticChunks && count === options.chunk.limit) {
1180
- resultSet.rows.splice(resultSet.rows.length - 1, 1);
1181
- }
1182
- for (var _b = 0, _c = resultSet.rows; _b < _c.length; _b++) {
1183
- var row = _c[_b];
1184
- _this.resultTable.addRow(row);
1185
- }
1186
- if (_this.resultTable.elasticChunks) {
1187
- _this.resultTable['total'] = (count < options.chunk.limit)
1188
- ? resultSet.rows.length
1189
- : 0;
1190
- }
1191
- _this.resultTable.fireUpdated();
1192
- }
1193
- if (options.success) {
1194
- options.success(result);
1195
- }
1196
- } }));
1197
- };
1198
- EqContext.prototype.getQueryFile = function (options) {
1199
- var _this = this;
1200
- var query = this.getQuery();
1201
- this.startProcess({
1202
- action: EqAction.GetQueryFile,
1203
- text: 'Getting query file: ' + query.getId()
1204
- }, WidgetGroup.Query);
1205
- var queryFileLoader = this.getServices().getQueryFileLoader();
1206
- queryFileLoader.getQueryFile(options)
1207
- .then(function () {
1208
- _this.endProcess({
1209
- result: EqActionResult.Success,
1210
- action: EqAction.GetQueryFile,
1211
- text: 'Getting query file: ' + query.getId()
1212
- }, WidgetGroup.Query);
1213
- if (options.success) {
1214
- options.success();
1215
- }
1216
- })
1217
- .catch(function (error) {
1218
- var errorMessage = "Can't get file for query ".concat(query.getId(), ".\n ").concat(error.message);
1219
- _this.endProcess({
1220
- result: EqActionResult.Error,
1221
- action: EqAction.GetQueryFile,
1222
- text: errorMessage,
1223
- sourceError: error
1224
- }, WidgetGroup.Query);
1225
- if (options.error) {
1226
- options.error(errorMessage, 'GetQueryFile');
1227
- }
1228
- });
1229
- };
1230
- EqContext.prototype.uploadQueryFile = function (options) {
1231
- var _this = this;
1232
- var query = this.getQuery();
1233
- this.startProcess({
1234
- action: EqAction.UploadQueryFile,
1235
- text: 'Uploading query file: ' + query.getId()
1236
- }, WidgetGroup.Query);
1237
- var queryFileLoader = this.getServices().getQueryFileLoader();
1238
- queryFileLoader.uploadQueryFile(options)
1239
- .then(function (data) {
1240
- query.loadFromData(data);
1241
- _this.fireEvent('loadQuery');
1242
- _this.refreshWidgets();
1243
- _this.endProcess({
1244
- result: EqActionResult.Success,
1245
- action: EqAction.UploadQueryFile,
1246
- text: 'Uploading query file: ' + query.getId()
1247
- }, WidgetGroup.Query);
1248
- if (options.success) {
1249
- options.success();
1250
- }
1251
- })
1252
- .catch(function (error) {
1253
- var errorMessage = "Can't upload a file for query ".concat(query.getId(), ".\n ").concat(error.message);
1254
- _this.endProcess({
1255
- result: EqActionResult.Error,
1256
- action: EqAction.UploadQueryFile,
1257
- text: errorMessage,
1258
- sourceError: error
1259
- }, WidgetGroup.Query);
1260
- if (options.error) {
1261
- options.error(errorMessage, 'UploadQueryFile');
1262
- }
1263
- });
1264
- };
1265
- EqContext.prototype.fetchDataChunk = function (options) {
1266
- var _this = this;
1267
- var queryId = this.getQuery().getId();
1268
- var fetchOptions = options || {};
1269
- if (this.useStoredQueryOnFetch) {
1270
- fetchOptions.queryId = this.query.getId();
1271
- }
1272
- if (this.beforeFetchData) {
1273
- this.beforeFetchData(this, fetchOptions);
1274
- }
1275
- this.startProcess({
1276
- action: EqAction.FetchData,
1277
- text: 'Fetching data for the query: ' + queryId
1278
- }, WidgetGroup.Result);
1279
- var dataFetcher = this.eqServices.getDataFetcher();
1280
- dataFetcher.fetchData(fetchOptions)
1281
- .then(function (result) {
1282
- if (result.statement) {
1283
- _this.resultStatement = result.statement;
1284
- }
1285
- _this.resultContent = result;
1286
- // we need to call success callback before firing fetchData,
1287
- // because otherwise, it won't update the result table
1288
- // in the context before afterFetchData callback is called.
1289
- if (fetchOptions.success) {
1290
- fetchOptions.success(result);
1291
- }
1292
- _this.fireEvent('fetchData');
1293
- _this.endProcess({
1294
- result: EqActionResult.Success,
1295
- action: EqAction.FetchData,
1296
- text: 'Data fetching is finished for the query: ' + queryId
1297
- }, WidgetGroup.Result);
1298
- })
1299
- .catch(function (error) {
1300
- var errorMessage = "Data fetching error for the query ".concat(queryId, ". \n").concat(error.message);
1301
- _this.endProcess({
1302
- result: EqActionResult.Error,
1303
- action: EqAction.FetchData,
1304
- text: errorMessage,
1305
- sourceError: error
1306
- }, WidgetGroup.Result);
1307
- if (fetchOptions.error) {
1308
- fetchOptions.error(errorMessage, EqAction.FetchData);
1309
- }
1310
- });
1311
- };
1312
- EqContext.prototype.onResultTableUpdate = function () {
1313
- var _this = this;
1314
- var aggrSettings = this.query.getAggregationSettings();
1315
- var calculator = this.getServices().getAggregatesCalculator();
1316
- if (aggrSettings.needAggrCalculation() && calculator.needRecalculation()) {
1317
- calculator.calculate({
1318
- maxLevel: aggrSettings.getGroups().length + 1,
1319
- resultObtained: function (result, level) {
1320
- if (_this.afterGroupFetch) {
1321
- _this.afterGroupFetch(result);
1322
- }
1323
- },
1324
- errorOccurred: function (error) {
1325
- var errorMessage = "Data fetching error on group level ".concat(error.level, " query. \n").concat(error.message);
1326
- _this.throwError({
1327
- action: EqAction.FetchData,
1328
- text: errorMessage,
1329
- sourceError: error
1330
- });
1331
- }
1332
- });
1333
- }
1334
- };
1335
- /**
1336
- * Fetches the data for a drill-down query (if defined) and processes the result.
1337
- * @param options
1338
- */
1339
- EqContext.prototype.fetchDrillDownData = function (options) {
1340
- var _this = this;
1341
- options = options || {};
1342
- options.chunk = options.chunk ||
1343
- {
1344
- offset: 0,
1345
- limit: this.resultTable.chunkSize,
1346
- needTotal: true
1347
- };
1348
- var query = options.query;
1349
- var queryId = query.getId();
1350
- this.startProcess({
1351
- action: EqAction.FetchData,
1352
- text: 'DrillDown executing: ' + queryId
1353
- }, WidgetGroup.Result);
1354
- var queryExecutor = this.eqServices.getDataFetcher();
1355
- queryExecutor.fetchData(options)
1356
- .then(function (result) {
1357
- _this.endProcess({
1358
- result: EqActionResult.Success,
1359
- action: EqAction.FetchData,
1360
- text: 'DrillDown execution error: ' + queryId
1361
- }, WidgetGroup.Result);
1362
- if (options.success) {
1363
- options.success(result);
1364
- }
1365
- })
1366
- .catch(function (error) {
1367
- var errorMessage = "Drill-down data fetching error for query ".concat(queryId, ". \n").concat(error.message);
1368
- _this.endProcess({
1369
- result: EqActionResult.Error,
1370
- action: EqAction.FetchData,
1371
- text: errorMessage,
1372
- }, WidgetGroup.Result);
1373
- if (options.error) {
1374
- options.error(errorMessage, 'DrillDown');
1375
- }
1376
- else {
1377
- _this.throwError({
1378
- action: EqAction.FetchData,
1379
- text: errorMessage
1380
- });
1381
- }
1382
- });
1383
- };
1384
- /**
1385
- * Fetches the data for defined by this context and exports them to the specified format.
1386
- * @param options
1387
- * The content of the `options` parameter depends on `EqExporter` implementation.
1388
- * Usually it contains `format` property which defines the format of the exported data (e.g. `csv`),
1389
- * and `success` and `error` callbacks
1390
- * @example
1391
- * context.exportResult({
1392
- * format: csv
1393
- * });
1394
- *
1395
- */
1396
- EqContext.prototype.exportResult = function (options) {
1397
- var _this = this;
1398
- options = options || {};
1399
- options.chunk = options.chunk || EmptyChunk;
1400
- if (this.beforeExportResult) {
1401
- this.beforeExportResult(this, options);
1402
- }
1403
- var format = options.format;
1404
- if (format) {
1405
- var exporter = this.getExporter(format);
1406
- if (exporter) {
1407
- var queryId_1 = this.getQuery().getId();
1408
- if (this.useStoredQueryOnFetch) {
1409
- options.queryId = queryId_1;
1410
- }
1411
- this.startProcess({
1412
- action: EqAction.ExportResult,
1413
- text: 'Exporting result for query: ' + queryId_1
1414
- }, WidgetGroup.Result);
1415
- var localeSettings = i18n.getLocaleSettings();
1416
- options.settings = localeSettings;
1417
- var aggrSettings = this.query.getAggregationSettings();
1418
- if (aggrSettings.hasAggregates()
1419
- && (aggrSettings.hasGrandTotals() || aggrSettings.hasGroups())) {
1420
- options.aggregates = aggrSettings.saveToData();
1421
- }
1422
- exporter.export(options)
1423
- .then(function (result) {
1424
- _this.fireEvent('exportResult');
1425
- _this.endProcess({
1426
- result: EqActionResult.Success,
1427
- action: EqAction.ExportResult,
1428
- text: "The result set for query [".concat(queryId_1, "] has been successfully exported")
1429
- }, WidgetGroup.Result);
1430
- if (options.success) {
1431
- options.success();
1432
- }
1433
- })
1434
- .catch(function (error) {
1435
- var errorMessage = "Error on exporting data for query ".concat(queryId_1, ". \n").concat(error.message);
1436
- _this.endProcess({
1437
- result: EqActionResult.Error,
1438
- action: EqAction.ExportResult,
1439
- text: errorMessage,
1440
- sourceError: error
1441
- }, WidgetGroup.Result);
1442
- if (options.error) {
1443
- options.error(errorMessage, 'ExportResult');
1444
- }
1445
- });
1446
- }
1447
- }
1448
- };
1449
- EqContext.prototype.limitCustomSqlColumns = function () {
1450
- if (!this.options.allowCustomExpressions) {
1451
- this.query.getColumns().forEach(function (col) {
1452
- if (col.expr.tag === ExprTag.CustomSql) {
1453
- col.enabled = false;
1454
- }
1455
- });
1456
- }
1457
- };
1458
- EqContext.prototype.getAttributeTitle = function (attr) {
1459
- var format = this.options.attributeFormat;
1460
- return this.getModel().getAttributeText(attr, format);
1461
- };
1462
- EqContext.prototype.getColumnTitle = function (attr) {
1463
- var format = this.options.columnTitleFormat || this.options.attributeFormat;
1464
- return this.getModel().getAttributeText(attr, format);
1465
- };
1466
- EqContext.prototype.getDefaultColumnCaption = function (column) {
1467
- var attr;
1468
- var model = this.getModel();
1469
- switch (column.expr.tag) {
1470
- case ExprTag.Constant:
1471
- return "Contant Column";
1472
- case ExprTag.CustomSql:
1473
- return "SQL Column";
1474
- case ExprTag.ParentColumn:
1475
- return "Parent Column";
1476
- case ExprTag.Query:
1477
- return "Query Column";
1478
- case ExprTag.EntityAttribute:
1479
- case ExprTag.ParentEntityAttribute:
1480
- attr = model.getAttributeById(column.expr.value);
1481
- return this.getColumnTitle(attr);
1482
- case ExprTag.AggregateFunction:
1483
- attr = model.getAttributeById(column.expr.args[0].value);
1484
- return this.getColumnTitle(attr) + ' ' + model.getAggrFunctionCaption(column.expr.func);
1485
- default:
1486
- return 'Column';
1487
- }
1488
- };
1489
- return EqContext;
1490
- }());
1491
- export { EqContext };
1492
- //# sourceMappingURL=context.js.map