@wavemaker-ai/variables 1.0.0-rc.309
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.
- package/index.d.ts +14 -0
- package/index.js +15 -0
- package/index.js.map +1 -0
- package/npm-shrinkwrap.json +1994 -0
- package/package-lock.json +1994 -0
- package/package.json +48 -0
- package/scripts/build.d.ts +1 -0
- package/scripts/build.js +183 -0
- package/scripts/build.js.map +1 -0
- package/src/advanced-options.d.ts +4 -0
- package/src/advanced-options.js +2 -0
- package/src/advanced-options.js.map +1 -0
- package/src/constants/variables.constants.d.ts +307 -0
- package/src/constants/variables.constants.js +334 -0
- package/src/constants/variables.constants.js.map +1 -0
- package/src/factory/variable-manager.factory.d.ts +3 -0
- package/src/factory/variable-manager.factory.js +26 -0
- package/src/factory/variable-manager.factory.js.map +1 -0
- package/src/manager/action/timer-action.manager.d.ts +4 -0
- package/src/manager/action/timer-action.manager.js +38 -0
- package/src/manager/action/timer-action.manager.js.map +1 -0
- package/src/manager/variable/base-variable.manager.d.ts +24 -0
- package/src/manager/variable/base-variable.manager.js +79 -0
- package/src/manager/variable/base-variable.manager.js.map +1 -0
- package/src/manager/variable/crud-variable.manager.d.ts +85 -0
- package/src/manager/variable/crud-variable.manager.js +415 -0
- package/src/manager/variable/crud-variable.manager.js.map +1 -0
- package/src/manager/variable/live-variable.manager.d.ts +154 -0
- package/src/manager/variable/live-variable.manager.js +1078 -0
- package/src/manager/variable/live-variable.manager.js.map +1 -0
- package/src/manager/variable/model-variable.manager.d.ts +4 -0
- package/src/manager/variable/model-variable.manager.js +56 -0
- package/src/manager/variable/model-variable.manager.js.map +1 -0
- package/src/manager/variable/service-variable.manager.d.ts +113 -0
- package/src/manager/variable/service-variable.manager.js +713 -0
- package/src/manager/variable/service-variable.manager.js.map +1 -0
- package/src/model/action/timer-action.d.ts +12 -0
- package/src/model/action/timer-action.js +60 -0
- package/src/model/action/timer-action.js.map +1 -0
- package/src/model/base-action.d.ts +32 -0
- package/src/model/base-action.js +89 -0
- package/src/model/base-action.js.map +1 -0
- package/src/model/base-variable.d.ts +58 -0
- package/src/model/base-variable.js +180 -0
- package/src/model/base-variable.js.map +1 -0
- package/src/model/crud-create.d.ts +8 -0
- package/src/model/crud-create.js +17 -0
- package/src/model/crud-create.js.map +1 -0
- package/src/model/crud-delete.d.ts +8 -0
- package/src/model/crud-delete.js +17 -0
- package/src/model/crud-delete.js.map +1 -0
- package/src/model/crud-list.d.ts +8 -0
- package/src/model/crud-list.js +17 -0
- package/src/model/crud-list.js.map +1 -0
- package/src/model/crud-update.d.ts +8 -0
- package/src/model/crud-update.js +17 -0
- package/src/model/crud-update.js.map +1 -0
- package/src/model/variable/api-aware-variable.d.ts +23 -0
- package/src/model/variable/api-aware-variable.js +25 -0
- package/src/model/variable/api-aware-variable.js.map +1 -0
- package/src/model/variable/crud-variable.d.ts +30 -0
- package/src/model/variable/crud-variable.js +181 -0
- package/src/model/variable/crud-variable.js.map +1 -0
- package/src/model/variable/live-variable.d.ts +40 -0
- package/src/model/variable/live-variable.js +262 -0
- package/src/model/variable/live-variable.js.map +1 -0
- package/src/model/variable/model-variable.d.ts +11 -0
- package/src/model/variable/model-variable.js +83 -0
- package/src/model/variable/model-variable.js.map +1 -0
- package/src/model/variable/service-variable.d.ts +35 -0
- package/src/model/variable/service-variable.js +147 -0
- package/src/model/variable/service-variable.js.map +1 -0
- package/src/types/date-formatter.d.ts +3 -0
- package/src/types/date-formatter.js +2 -0
- package/src/types/date-formatter.js.map +1 -0
- package/src/types/event-notifier.d.ts +9 -0
- package/src/types/event-notifier.js +25 -0
- package/src/types/event-notifier.js.map +1 -0
- package/src/types/http-client.service.d.ts +8 -0
- package/src/types/http-client.service.js +2 -0
- package/src/types/http-client.service.js.map +1 -0
- package/src/types/types.d.ts +50 -0
- package/src/types/types.js +54 -0
- package/src/types/types.js.map +1 -0
- package/src/util/dataset-util.d.ts +27 -0
- package/src/util/dataset-util.js +147 -0
- package/src/util/dataset-util.js.map +1 -0
- package/src/util/file-upload.util.d.ts +11 -0
- package/src/util/file-upload.util.js +183 -0
- package/src/util/file-upload.util.js.map +1 -0
- package/src/util/inflight-queue.d.ts +35 -0
- package/src/util/inflight-queue.js +102 -0
- package/src/util/inflight-queue.js.map +1 -0
- package/src/util/notify-promise.d.ts +3 -0
- package/src/util/notify-promise.js +37 -0
- package/src/util/notify-promise.js.map +1 -0
- package/src/util/oAuth.utils.d.ts +3 -0
- package/src/util/oAuth.utils.js +11 -0
- package/src/util/oAuth.utils.js.map +1 -0
- package/src/util/utils.d.ts +69 -0
- package/src/util/utils.js +364 -0
- package/src/util/utils.js.map +1 -0
- package/src/util/variable/live-variable.http.utils.d.ts +21 -0
- package/src/util/variable/live-variable.http.utils.js +212 -0
- package/src/util/variable/live-variable.http.utils.js.map +1 -0
- package/src/util/variable/live-variable.utils.d.ts +72 -0
- package/src/util/variable/live-variable.utils.js +667 -0
- package/src/util/variable/live-variable.utils.js.map +1 -0
- package/src/util/variable/pagination.utils.d.ts +91 -0
- package/src/util/variable/pagination.utils.js +493 -0
- package/src/util/variable/pagination.utils.js.map +1 -0
- package/src/util/variable/service-variable.utils.d.ts +17 -0
- package/src/util/variable/service-variable.utils.js +394 -0
- package/src/util/variable/service-variable.utils.js.map +1 -0
- package/src/util/variable/variables.utils.d.ts +120 -0
- package/src/util/variable/variables.utils.js +544 -0
- package/src/util/variable/variables.utils.js.map +1 -0
- package/src/wm-namespace.d.ts +11 -0
- package/src/wm-namespace.js +13 -0
- package/src/wm-namespace.js.map +1 -0
- package/webpack.config.d.ts +21 -0
- package/webpack.config.js +28 -0
- package/webpack.config.js.map +1 -0
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { getClonedObject, getValidJSON, isDefined, isPageable, isValidWebURL, noop, triggerFn, xmlToJson } from "../../util/utils";
|
|
17
|
+
import { upload } from '../../util/file-upload.util';
|
|
18
|
+
import { ServiceVariableUtils } from '../../util/variable/service-variable.utils';
|
|
19
|
+
import { $queue } from '../../util/inflight-queue';
|
|
20
|
+
import { BaseVariableManager } from './base-variable.manager';
|
|
21
|
+
import { CONSTANTS, VARIABLE_CONSTANTS, WS_CONSTANTS } from '../../constants/variables.constants';
|
|
22
|
+
import { appManager, decodeData, formatExportExpression, getErrMessage, metadataService, setInput } from './../../util/variable/variables.utils';
|
|
23
|
+
import { getEvaluatedOrderBy, initiateCallback, securityService } from '../../util/variable/variables.utils';
|
|
24
|
+
import { getAccessToken, performAuthorization, removeAccessToken } from '../../util/oAuth.utils';
|
|
25
|
+
import { PaginationUtils } from '../../util/variable/pagination.utils';
|
|
26
|
+
import { VariableEvents } from "../../model/base-variable";
|
|
27
|
+
import { isEmpty, get, head, last, hasIn, isObject, isArray, values, find, forEach, isString, includes, omit, extend, map, split } from 'lodash-es';
|
|
28
|
+
var ServiceVariableManager = /** @class */ (function (_super) {
|
|
29
|
+
__extends(ServiceVariableManager, _super);
|
|
30
|
+
function ServiceVariableManager() {
|
|
31
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
32
|
+
_this.fileUploadResponse = [];
|
|
33
|
+
_this.fileUploadCount = 0;
|
|
34
|
+
_this.totalFilesCount = 0;
|
|
35
|
+
_this.successFileUploadCount = 0;
|
|
36
|
+
_this.failedFileUploadCount = 0;
|
|
37
|
+
return _this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* function to process error response from a service
|
|
41
|
+
* @param {ServiceVariable} variable
|
|
42
|
+
* @param {string} errMsg
|
|
43
|
+
* @param {Function} errorCB
|
|
44
|
+
* @param xhrObj
|
|
45
|
+
* @param {boolean} skipNotification
|
|
46
|
+
* @param {boolean} skipDefaultNotification
|
|
47
|
+
*/
|
|
48
|
+
ServiceVariableManager.prototype.processErrorResponse = function (variable, errMsg, errorCB, xhrObj, skipNotification, skipDefaultNotification) {
|
|
49
|
+
var methodInfo = this.getMethodInfo(variable, {}, {});
|
|
50
|
+
var securityDefnObj = get(methodInfo, 'securityDefinitions.0');
|
|
51
|
+
var advancedOptions = this.prepareCallbackOptions(xhrObj);
|
|
52
|
+
// EVENT: ON_ERROR
|
|
53
|
+
if (!skipNotification) {
|
|
54
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.ERROR, variable, errMsg, advancedOptions, skipDefaultNotification);
|
|
55
|
+
}
|
|
56
|
+
if (get(securityDefnObj, 'type') === VARIABLE_CONSTANTS.REST_SERVICE.SECURITY_DEFN.OAUTH2
|
|
57
|
+
&& includes([VARIABLE_CONSTANTS.HTTP_STATUS_CODE.UNAUTHORIZED, VARIABLE_CONSTANTS.HTTP_STATUS_CODE.FORBIDDEN], get(xhrObj, 'status'))) {
|
|
58
|
+
removeAccessToken(securityDefnObj['x-WM-PROVIDER_ID']);
|
|
59
|
+
}
|
|
60
|
+
/* trigger error callback */
|
|
61
|
+
triggerFn(errorCB, errMsg);
|
|
62
|
+
variable.notify(VariableEvents.AFTER_INVOKE, [this, errMsg]);
|
|
63
|
+
if (!CONSTANTS.isStudioMode) {
|
|
64
|
+
/* process next requests in the queue */
|
|
65
|
+
variable.canUpdate = true;
|
|
66
|
+
$queue.process(variable);
|
|
67
|
+
// EVENT: ON_CAN_UPDATE
|
|
68
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.CAN_UPDATE, variable, errMsg, advancedOptions);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* function to process success response from a service
|
|
73
|
+
* @param response
|
|
74
|
+
* @param variable
|
|
75
|
+
* @param options
|
|
76
|
+
* @param success
|
|
77
|
+
*/
|
|
78
|
+
ServiceVariableManager.prototype.processSuccessResponse = function (response, variable, options, success, resHeaders, operationInf) {
|
|
79
|
+
var dataSet;
|
|
80
|
+
var newDataSet;
|
|
81
|
+
var pagination = {};
|
|
82
|
+
var advancedOptions;
|
|
83
|
+
var jsonParsedResponse = getValidJSON(response);
|
|
84
|
+
response = isDefined(jsonParsedResponse) ? jsonParsedResponse : (response && xmlToJson(response) || response);
|
|
85
|
+
var isResponsePageable = isPageable(response);
|
|
86
|
+
if (variable.serviceType === 'DataService' || variable.serviceType === 'JavaService') {
|
|
87
|
+
var decodedData = decodeData(response);
|
|
88
|
+
if (isString(response)) {
|
|
89
|
+
response = decodedData;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (isResponsePageable) {
|
|
93
|
+
dataSet = response.content;
|
|
94
|
+
pagination = omit(response, 'content');
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
dataSet = response;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* send pagination object with advancedOptions all the time.
|
|
101
|
+
* With this, user can provide pagination option, even if it is not there.
|
|
102
|
+
* applicable to 3rd party services that do not support pagination out of the box.
|
|
103
|
+
*/
|
|
104
|
+
advancedOptions = this.prepareCallbackOptions(options.xhrObj, { pagination: pagination, rawData: dataSet });
|
|
105
|
+
// EVENT: ON_RESULT
|
|
106
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.RESULT, variable, response, advancedOptions);
|
|
107
|
+
// trigger success callback, pass data received from server as it is.
|
|
108
|
+
triggerFn(success, response, pagination);
|
|
109
|
+
/* if dataTransformation enabled, transform the data */
|
|
110
|
+
if (variable.transformationColumns) {
|
|
111
|
+
this.transformData(response, variable);
|
|
112
|
+
}
|
|
113
|
+
// if a primitive type response is returned, wrap it in an object
|
|
114
|
+
dataSet = (!isObject(dataSet)) ? { 'value': dataSet } : dataSet;
|
|
115
|
+
// EVENT: ON_PREPARE_SETDATA
|
|
116
|
+
newDataSet = initiateCallback(VARIABLE_CONSTANTS.EVENT.PREPARE_SETDATA, variable, dataSet, advancedOptions);
|
|
117
|
+
if (isDefined(newDataSet)) {
|
|
118
|
+
// setting newDataSet as the response to service variable onPrepareSetData
|
|
119
|
+
dataSet = newDataSet;
|
|
120
|
+
}
|
|
121
|
+
var inputFields = getClonedObject(options.inputFields || variable.dataBinding);
|
|
122
|
+
// WMS-22361 : For crud variable, apply operation info recived else deduce for service variables
|
|
123
|
+
var operationInfo = operationInf ? operationInf : this.getMethodInfo(variable, inputFields, options);
|
|
124
|
+
var paginationInfo = PaginationUtils.getPaginationInfo(operationInfo, variable);
|
|
125
|
+
if (paginationInfo) {
|
|
126
|
+
var res = PaginationUtils.generatePaginationRes(operationInfo, paginationInfo, response, resHeaders, options, variable);
|
|
127
|
+
if (!isEmpty(res)) {
|
|
128
|
+
PaginationUtils.setVariablePagination(variable, res, options);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/* update the dataset against the variable, if response is non-object, insert the response in 'value' field of dataSet */
|
|
132
|
+
if (!options.forceRunMode && !options.skipDataSetUpdate) {
|
|
133
|
+
if (!variable._paginationConfig) {
|
|
134
|
+
variable.pagination = pagination;
|
|
135
|
+
}
|
|
136
|
+
variable.dataSet = dataSet;
|
|
137
|
+
// legacy properties in dataSet, [content]
|
|
138
|
+
if (isResponsePageable) {
|
|
139
|
+
Object.defineProperty(variable.dataSet, 'content', {
|
|
140
|
+
get: function () {
|
|
141
|
+
return variable.dataSet;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
variable.notify(VariableEvents.AFTER_INVOKE, [this, dataSet]);
|
|
147
|
+
setTimeout(function () {
|
|
148
|
+
// EVENT: ON_SUCCESS
|
|
149
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.SUCCESS, variable, dataSet, advancedOptions);
|
|
150
|
+
if (!CONSTANTS.isStudioMode) {
|
|
151
|
+
/* process next requests in the queue */
|
|
152
|
+
variable.canUpdate = true;
|
|
153
|
+
$queue.process(variable);
|
|
154
|
+
}
|
|
155
|
+
// EVENT: ON_CAN_UPDATE
|
|
156
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.CAN_UPDATE, variable, dataSet, advancedOptions);
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
data: variable.dataSet,
|
|
160
|
+
pagination: variable.pagination
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
ServiceVariableManager.prototype.uploadFileInFormData = function (variable, options, success, error, file, requestParams) {
|
|
164
|
+
var _this = this;
|
|
165
|
+
var promise = upload(file, variable, requestParams.data, {
|
|
166
|
+
fileParamName: 'files',
|
|
167
|
+
url: requestParams.url
|
|
168
|
+
});
|
|
169
|
+
promise.then(function (data) {
|
|
170
|
+
_this.fileUploadCount++;
|
|
171
|
+
_this.successFileUploadCount++;
|
|
172
|
+
_this.fileUploadResponse.push(data[0]);
|
|
173
|
+
file._response = data[0];
|
|
174
|
+
if (data && data[0] && data[0].success === false) {
|
|
175
|
+
if (variable._progressObservable) {
|
|
176
|
+
variable._progressObservable.next({
|
|
177
|
+
'status': "error",
|
|
178
|
+
'fileName': file.name,
|
|
179
|
+
'errMsg': data[0].errorMessage,
|
|
180
|
+
'uniqueId': file.uniqueId
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
_this.fileUploadResponse = [];
|
|
184
|
+
_this.processErrorResponse(variable, data[0].errorMessage, error, data, options.skipNotification);
|
|
185
|
+
}
|
|
186
|
+
if (_this.totalFilesCount === _this.fileUploadCount && data[0].success === true) {
|
|
187
|
+
if (_this.failedFileUploadCount === 0) {
|
|
188
|
+
_this.processSuccessResponse(_this.fileUploadResponse, variable, options, success);
|
|
189
|
+
_this.fileUploadResponse = [];
|
|
190
|
+
if (!variable.onSuccess) {
|
|
191
|
+
appManager && appManager.notifyApp(appManager.getAppLocale().MESSAGE_FILE_UPLOAD_SUCCESS, 'success');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.ERROR, variable, _this.fileUploadResponse);
|
|
196
|
+
_this.fileUploadResponse = [];
|
|
197
|
+
appManager && appManager.notifyApp(appManager.getAppLocale().MESSAGE_FILE_UPLOAD_ERROR, 'error');
|
|
198
|
+
}
|
|
199
|
+
_this.fileUploadCount = 0;
|
|
200
|
+
_this.successFileUploadCount = 0;
|
|
201
|
+
_this.totalFilesCount = 0;
|
|
202
|
+
}
|
|
203
|
+
return data;
|
|
204
|
+
}, function (e) {
|
|
205
|
+
_this.fileUploadCount++;
|
|
206
|
+
_this.failedFileUploadCount++;
|
|
207
|
+
_this.fileUploadResponse.push(e);
|
|
208
|
+
var errMsg = getErrMessage(e, variable.httpService.getLocale());
|
|
209
|
+
// if a file upload failed, notify the progress listener to take action
|
|
210
|
+
if (variable._progressObservable) {
|
|
211
|
+
variable._progressObservable.next({
|
|
212
|
+
'status': "error",
|
|
213
|
+
'fileName': file.name,
|
|
214
|
+
'errMsg': errMsg,
|
|
215
|
+
'uniqueId': file.uniqueId
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
if (_this.totalFilesCount === _this.fileUploadCount) {
|
|
219
|
+
_this.processErrorResponse(variable, errMsg, error, e, options.skipNotification);
|
|
220
|
+
_this.fileUploadResponse = [];
|
|
221
|
+
_this.fileUploadCount = 0;
|
|
222
|
+
_this.failedFileUploadCount = 0;
|
|
223
|
+
_this.totalFilesCount = 0;
|
|
224
|
+
}
|
|
225
|
+
return e;
|
|
226
|
+
}, function (data) {
|
|
227
|
+
if (variable._progressObservable) {
|
|
228
|
+
variable._progressObservable.next({
|
|
229
|
+
'progress': data,
|
|
230
|
+
'status': VARIABLE_CONSTANTS.EVENT.PROGRESS,
|
|
231
|
+
'fileName': file.name,
|
|
232
|
+
'uniqueId': file.uniqueId
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.PROGRESS, variable, data);
|
|
236
|
+
return data;
|
|
237
|
+
});
|
|
238
|
+
return promise;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Checks if the user is logged in or not and returns appropriate error
|
|
242
|
+
* If user is not logged in, Session timeout logic is run, for user to login
|
|
243
|
+
* @param variable
|
|
244
|
+
* @returns {any}
|
|
245
|
+
*/
|
|
246
|
+
ServiceVariableManager.prototype.handleAuthError = function (variable, success, errorCB, options) {
|
|
247
|
+
var isUserAuthenticated = get(securityService.get(), 'authenticated');
|
|
248
|
+
var info;
|
|
249
|
+
if (isUserAuthenticated) {
|
|
250
|
+
info = {
|
|
251
|
+
error: {
|
|
252
|
+
message: 'You\'re not authorised to access the resource "' + variable.service + '".'
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
info = {
|
|
258
|
+
error: {
|
|
259
|
+
message: 'You\'re not authenticated to access the resource "' + variable.service + '".',
|
|
260
|
+
skipDefaultNotification: true
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
appManager.pushToSessionFailureRequests(variable.invoke.bind(variable, options, success, errorCB));
|
|
264
|
+
appManager.handle401();
|
|
265
|
+
}
|
|
266
|
+
console.warn(variable.name + ': ' + info.error.message);
|
|
267
|
+
return info;
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Handles error, when variable's metadata is not found. The reason for this can be:
|
|
271
|
+
* - API is secure and user is not logged in
|
|
272
|
+
* - API is secure and user is logged in but not authorized
|
|
273
|
+
* - The servicedefs are not generated properly at the back end (need to edit the variable and re-run the project)
|
|
274
|
+
* @param info
|
|
275
|
+
* @param variable
|
|
276
|
+
* @param errorCB
|
|
277
|
+
* @param options
|
|
278
|
+
*/
|
|
279
|
+
ServiceVariableManager.prototype.handleRequestMetaError = function (info, variable, success, errorCB, options) {
|
|
280
|
+
try {
|
|
281
|
+
var err_type = get(info, 'error.type');
|
|
282
|
+
switch (err_type) {
|
|
283
|
+
case VARIABLE_CONSTANTS.REST_SERVICE.ERR_TYPE.NO_ACCESSTOKEN:
|
|
284
|
+
performAuthorization(undefined, info.securityDefnObj[VARIABLE_CONSTANTS.REST_SERVICE.OAUTH_PROVIDER_KEY], this.invoke.bind(this, variable, options, success, errorCB), null, this.getProviderInfo(variable, info.securityDefnObj['x-WM-PROVIDER_ID']));
|
|
285
|
+
this.processErrorResponse(variable, info.error.message, errorCB, options.xhrObj, true, true);
|
|
286
|
+
break;
|
|
287
|
+
case VARIABLE_CONSTANTS.REST_SERVICE.ERR_TYPE.USER_UNAUTHORISED:
|
|
288
|
+
info = this.handleAuthError(variable, success, errorCB, options);
|
|
289
|
+
this.processErrorResponse(variable, info.error.message, errorCB, options.xhrObj, options.skipNotification, info.error.skipDefaultNotification);
|
|
290
|
+
break;
|
|
291
|
+
case VARIABLE_CONSTANTS.REST_SERVICE.ERR_TYPE.METADATA_MISSING:
|
|
292
|
+
case VARIABLE_CONSTANTS.REST_SERVICE.ERR_TYPE.CRUD_OPERATION_MISSING:
|
|
293
|
+
if (info.error.message) {
|
|
294
|
+
info.error.message = info.error.message.replace('$variable', variable.name);
|
|
295
|
+
var reasons = void 0;
|
|
296
|
+
if (err_type === VARIABLE_CONSTANTS.REST_SERVICE.ERR_TYPE.METADATA_MISSING) {
|
|
297
|
+
reasons = ['1. You did not Preview the app after creating a Variable for the imported service.', '2. You deleted the imported service this Variable is linked to.'];
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
reasons = ['1. You haven\'t chosen an endpoint for ' + options.operation + ' operation for this Entity.'];
|
|
301
|
+
}
|
|
302
|
+
console.warn(info.error.message + '\n Possible reasons for this:\n ' + reasons.join('\n '));
|
|
303
|
+
}
|
|
304
|
+
this.processErrorResponse(variable, info.error.message, errorCB, options.xhrObj, options.skipNotification, info.error.skipDefaultNotification);
|
|
305
|
+
break;
|
|
306
|
+
default:
|
|
307
|
+
if (info.error.message) {
|
|
308
|
+
console.warn(info.error.message, variable.name);
|
|
309
|
+
this.processErrorResponse(variable, info.error.message, errorCB, options.xhrObj, options.skipNotification, info.error.skipDefaultNotification);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
catch (err) {
|
|
314
|
+
console.error(err);
|
|
315
|
+
}
|
|
316
|
+
return info;
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* function to transform the service data as according to the variable configuration
|
|
320
|
+
* this is used when 'transformationColumns' property is set on the variable
|
|
321
|
+
* @param data: data returned from the service
|
|
322
|
+
* @variable: variable object triggering the service
|
|
323
|
+
*/
|
|
324
|
+
ServiceVariableManager.prototype.transformData = function (data, variable) {
|
|
325
|
+
data.wmTransformedData = [];
|
|
326
|
+
var columnsArray = variable.transformationColumns, dataArray = get(data, variable.dataField) || [], transformedData = data.wmTransformedData;
|
|
327
|
+
forEach(dataArray, function (datum, index) {
|
|
328
|
+
transformedData[index] = {};
|
|
329
|
+
forEach(columnsArray, function (column, columnIndex) {
|
|
330
|
+
transformedData[index][column] = datum[columnIndex];
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* gets the service operation info against a service variable
|
|
336
|
+
* this is extracted from the metadataservice
|
|
337
|
+
* @param variable
|
|
338
|
+
* @param inputFields: sample values, if provided, will be set against params in the definition
|
|
339
|
+
* @param options
|
|
340
|
+
* @returns {any}
|
|
341
|
+
*/
|
|
342
|
+
ServiceVariableManager.prototype.getMethodInfo = function (variable, inputFields, options) {
|
|
343
|
+
var methodInfo;
|
|
344
|
+
if (!isEmpty(metadataService)) {
|
|
345
|
+
var serviceDef = getClonedObject(metadataService.getByOperationId(variable.operationId, variable.getPrefabName()));
|
|
346
|
+
methodInfo = serviceDef === null ? null : get(serviceDef, 'wmServiceOperationInfo');
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
methodInfo = variable.serviceInfo;
|
|
350
|
+
}
|
|
351
|
+
if (!methodInfo) {
|
|
352
|
+
return methodInfo;
|
|
353
|
+
}
|
|
354
|
+
var securityDefnObj = get(methodInfo.securityDefinitions, '0'), isOAuthTypeService = securityDefnObj && (securityDefnObj.type === VARIABLE_CONSTANTS.REST_SERVICE.SECURITY_DEFN.OAUTH2);
|
|
355
|
+
if (methodInfo.parameters) {
|
|
356
|
+
methodInfo.parameters.forEach(function (param) {
|
|
357
|
+
var _a, _b;
|
|
358
|
+
// Ignore readOnly params in case of formData file params will be duplicated
|
|
359
|
+
if (param.readOnly) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
param.sampleValue = inputFields[param.name];
|
|
363
|
+
/* supporting pagination for query service variable */
|
|
364
|
+
if (VARIABLE_CONSTANTS.PAGINATION_PARAMS.indexOf(param.name) !== -1) {
|
|
365
|
+
if (param.name === 'size') {
|
|
366
|
+
param.sampleValue = options.size || param.sampleValue || ((_b = (_a = variable === null || variable === void 0 ? void 0 : variable._paginationConfig) === null || _a === void 0 ? void 0 : _a.input) === null || _b === void 0 ? void 0 : _b.size) || parseInt(variable.maxResults, 10);
|
|
367
|
+
}
|
|
368
|
+
else if (param.name === 'page') {
|
|
369
|
+
param.sampleValue = options.page || param.sampleValue || 1;
|
|
370
|
+
}
|
|
371
|
+
else if (param.name === 'sort') {
|
|
372
|
+
param.sampleValue = getEvaluatedOrderBy(variable.orderBy, options.orderBy) || param.sampleValue || '';
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else if (param.name === 'access_token' && isOAuthTypeService) {
|
|
376
|
+
param.sampleValue = getAccessToken(securityDefnObj[VARIABLE_CONSTANTS.REST_SERVICE.OAUTH_PROVIDER_KEY], null);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
return methodInfo;
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* gets the provider info against a service variable's provider
|
|
384
|
+
* this is extracted from the metadataservice
|
|
385
|
+
* @param variable
|
|
386
|
+
* @param providerId
|
|
387
|
+
* @returns {any}
|
|
388
|
+
*/
|
|
389
|
+
ServiceVariableManager.prototype.getProviderInfo = function (variable, providerId) {
|
|
390
|
+
return getClonedObject(metadataService === null || metadataService === void 0 ? void 0 : metadataService.getByProviderId(providerId, variable.getPrefabName()));
|
|
391
|
+
};
|
|
392
|
+
/**
|
|
393
|
+
* Returns true if any of the files are in onProgress state
|
|
394
|
+
*/
|
|
395
|
+
ServiceVariableManager.prototype.isFileUploadInProgress = function (dataBindings) {
|
|
396
|
+
var filesStatus = false;
|
|
397
|
+
forEach(dataBindings, function (dataBinding) {
|
|
398
|
+
if (isArray(dataBinding) && dataBinding[0] instanceof File) {
|
|
399
|
+
forEach(dataBinding, function (file) {
|
|
400
|
+
if (file.status === 'onProgress') {
|
|
401
|
+
filesStatus = true;
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
return filesStatus;
|
|
408
|
+
};
|
|
409
|
+
// Makes the call for Uploading file/ files
|
|
410
|
+
ServiceVariableManager.prototype.uploadFile = function (variable, options, success, error, inputFields, requestParams) {
|
|
411
|
+
var _this = this;
|
|
412
|
+
var fileParamCount = 0;
|
|
413
|
+
var fileArr = [], promArr = [];
|
|
414
|
+
forEach(inputFields, function (inputField) {
|
|
415
|
+
if (isArray(inputField)) {
|
|
416
|
+
if (inputField[0] instanceof File) {
|
|
417
|
+
fileParamCount++;
|
|
418
|
+
}
|
|
419
|
+
forEach(inputField, function (input) {
|
|
420
|
+
if (input instanceof File || find(values(input), function (o) { return o instanceof Blob; })) {
|
|
421
|
+
fileArr.push(input);
|
|
422
|
+
_this.totalFilesCount++;
|
|
423
|
+
fileParamCount = fileParamCount || 1;
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
if (inputField instanceof File) {
|
|
429
|
+
fileParamCount++;
|
|
430
|
+
_this.totalFilesCount++;
|
|
431
|
+
fileArr.push(inputField);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
if (fileParamCount === 1) {
|
|
436
|
+
if (inputFields.files.length > 1) {
|
|
437
|
+
forEach(fileArr, function (file) {
|
|
438
|
+
promArr.push(_this.uploadFileInFormData(variable, options, success, error, file, requestParams));
|
|
439
|
+
});
|
|
440
|
+
return Promise.all(promArr);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
return this.uploadFileInFormData(variable, options, success, error, fileArr[0], requestParams);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* proxy for the invoke call
|
|
449
|
+
* Request Info is constructed
|
|
450
|
+
* if error found, error is thrown
|
|
451
|
+
* else, call is made
|
|
452
|
+
* @param {ServiceVariable} variable
|
|
453
|
+
* @param options
|
|
454
|
+
* @param {Function} success
|
|
455
|
+
* @param {Function} error
|
|
456
|
+
* @returns {any}
|
|
457
|
+
* @private
|
|
458
|
+
*/
|
|
459
|
+
ServiceVariableManager.prototype._invoke = function (variable, options, success, error) {
|
|
460
|
+
var _this = this;
|
|
461
|
+
var inputFields = getClonedObject(options.inputFields || variable.dataBinding);
|
|
462
|
+
// EVENT: ON_BEFORE_UPDATE
|
|
463
|
+
var output = initiateCallback(VARIABLE_CONSTANTS.EVENT.BEFORE_UPDATE, variable, inputFields, options);
|
|
464
|
+
var successHandler;
|
|
465
|
+
var errorHandler;
|
|
466
|
+
if (output === false) {
|
|
467
|
+
$queue.process(variable);
|
|
468
|
+
triggerFn(error);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (isObject(output)) {
|
|
472
|
+
inputFields = output;
|
|
473
|
+
}
|
|
474
|
+
var operationInfo = this.getMethodInfo(variable, inputFields, options);
|
|
475
|
+
var requestParams = ServiceVariableUtils.constructRequestParams(variable, operationInfo, inputFields, options);
|
|
476
|
+
// check errors
|
|
477
|
+
if (requestParams.error) {
|
|
478
|
+
var info = this.handleRequestMetaError(requestParams, variable, success, error, options);
|
|
479
|
+
var reason = (get(info, 'error.message') || 'An error occurred while triggering the variable: ') + ': ' + variable.name;
|
|
480
|
+
triggerFn(error);
|
|
481
|
+
$queue.process(variable);
|
|
482
|
+
return Promise.reject(reason);
|
|
483
|
+
}
|
|
484
|
+
// file upload
|
|
485
|
+
if (ServiceVariableUtils.isFileUploadRequest(variable)) {
|
|
486
|
+
var uploadPromise = this.uploadFile(variable, options, success, error, inputFields, requestParams);
|
|
487
|
+
if (uploadPromise) {
|
|
488
|
+
return uploadPromise;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
// file download
|
|
492
|
+
if (operationInfo && isArray(operationInfo.produces) && includes(operationInfo.produces, WS_CONSTANTS.CONTENT_TYPES.OCTET_STREAM) && variable.simulateFileDownload) {
|
|
493
|
+
// ToDo - variable seperation
|
|
494
|
+
return variable.simulateFileDownload(requestParams, variable.dataBinding.file || variable.name, variable.dataBinding.exportType, function () {
|
|
495
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.SUCCESS, variable, null, null, null);
|
|
496
|
+
$queue.process(variable);
|
|
497
|
+
triggerFn(success);
|
|
498
|
+
}, function (data) {
|
|
499
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.ERROR, variable, data ? getErrMessage(data, variable.httpService.getLocale()) : null, null, null);
|
|
500
|
+
$queue.process(variable);
|
|
501
|
+
triggerFn(error);
|
|
502
|
+
}, variable.dataBinding);
|
|
503
|
+
}
|
|
504
|
+
// notify variable progress
|
|
505
|
+
this.notifyInflight(variable, !options.skipToggleState);
|
|
506
|
+
successHandler = function (response, resolve) {
|
|
507
|
+
if (response && response.type || response && response.status) {
|
|
508
|
+
var res = response.body || response.data;
|
|
509
|
+
var data = _this.processSuccessResponse(res, variable, extend(options, { 'xhrObj': response }), success, response.headers);
|
|
510
|
+
// notify variable success
|
|
511
|
+
_this.notifyInflight(variable, false, data);
|
|
512
|
+
if (ServiceVariableUtils.isFileDeleteRequest(variable) && variable._deleteFileObservable) {
|
|
513
|
+
variable._deleteFileObservable.next({ 'status': "success", response: res });
|
|
514
|
+
appManager && appManager.notifyApp(appManager.getAppLocale().MESSAGE_FILE_DELETE_SUCCESS || "File delete success", 'success');
|
|
515
|
+
}
|
|
516
|
+
resolve(response);
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
errorHandler = function (err, reject) {
|
|
520
|
+
var errMsg = getErrMessage(err, variable.httpService.getLocale());
|
|
521
|
+
// notify variable error
|
|
522
|
+
_this.notifyInflight(variable, false);
|
|
523
|
+
_this.processErrorResponse(variable, errMsg, error, err, options.skipNotification);
|
|
524
|
+
if (ServiceVariableUtils.isFileDeleteRequest(variable) && variable._deleteFileObservable) {
|
|
525
|
+
variable._deleteFileObservable.error({
|
|
526
|
+
status: "error",
|
|
527
|
+
error: errMsg,
|
|
528
|
+
details: err
|
|
529
|
+
});
|
|
530
|
+
appManager && appManager.notifyApp(appManager.getAppLocale().MESSAGE_FILE_DELETE_ERROR || 'File delete failed', 'error');
|
|
531
|
+
}
|
|
532
|
+
reject({
|
|
533
|
+
error: errMsg,
|
|
534
|
+
details: err
|
|
535
|
+
});
|
|
536
|
+
};
|
|
537
|
+
// make the call and return a promise to the user to support script calls made by users
|
|
538
|
+
return new Promise(function (resolve, reject) {
|
|
539
|
+
requestParams.responseType = 'text'; // this is to return text response. JSON & XML-to-JSON parsing is handled in success handler.
|
|
540
|
+
// ToDo - variable seperation
|
|
541
|
+
// this.httpCall(requestParams, variable).then((response) => {
|
|
542
|
+
// successHandler(response, resolve);
|
|
543
|
+
// }, err => {
|
|
544
|
+
// const validJSON = getValidJSON(err.error);
|
|
545
|
+
// err.error = isDefined(validJSON) ? validJSON : err.error;
|
|
546
|
+
// errorHandler(err, reject);
|
|
547
|
+
// });
|
|
548
|
+
// the _observable property on variable is used store the observable using which the network call is made
|
|
549
|
+
// this can be used to cancel the variable calls.
|
|
550
|
+
variable.httpService.sendCall(requestParams, variable).then(function (response) {
|
|
551
|
+
successHandler(response, resolve);
|
|
552
|
+
}).catch(function (err) {
|
|
553
|
+
err = err || {};
|
|
554
|
+
err.error = err.error || '{}';
|
|
555
|
+
var validJSON = getValidJSON(err.error);
|
|
556
|
+
err.error = isDefined(validJSON) ? validJSON : err.error;
|
|
557
|
+
errorHandler(err, reject);
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
};
|
|
561
|
+
// *********************************************************** PUBLIC ***********************************************************//
|
|
562
|
+
ServiceVariableManager.prototype.invoke = function (variable, options, success, error) {
|
|
563
|
+
options = options || {};
|
|
564
|
+
// appManager.notify('check-state-persistence-options', {
|
|
565
|
+
// options: options,
|
|
566
|
+
// variable: variable
|
|
567
|
+
// });
|
|
568
|
+
options.inputFields = options.inputFields || getClonedObject(variable.dataBinding);
|
|
569
|
+
return $queue.submit(variable).then(this._invoke.bind(this, variable, options, success, error), error);
|
|
570
|
+
};
|
|
571
|
+
ServiceVariableManager.prototype.setPagination = function (variable, data) {
|
|
572
|
+
variable._paginationConfig = data;
|
|
573
|
+
};
|
|
574
|
+
ServiceVariableManager.prototype.download = function (variable, options, successHandler, errorHandler) {
|
|
575
|
+
options = options || {};
|
|
576
|
+
var inputParams = getClonedObject(variable.dataBinding);
|
|
577
|
+
var inputData = options.data || {};
|
|
578
|
+
var methodInfo = this.getMethodInfo(variable, inputParams, options);
|
|
579
|
+
var requestParams;
|
|
580
|
+
methodInfo.relativePath += '/export';
|
|
581
|
+
requestParams = ServiceVariableUtils.constructRequestParams(variable, methodInfo, inputParams);
|
|
582
|
+
requestParams.data = inputData;
|
|
583
|
+
requestParams.data.fields = formatExportExpression(inputData.fields || []);
|
|
584
|
+
// extra options provided, these may be used in future for integrating export feature with ext. services
|
|
585
|
+
requestParams.method = options.httpMethod || 'POST';
|
|
586
|
+
requestParams.url = options.url || requestParams.url;
|
|
587
|
+
// If request params returns error then show an error toaster
|
|
588
|
+
if (hasIn(requestParams, 'error.message')) {
|
|
589
|
+
triggerFn(errorHandler, requestParams.error.message);
|
|
590
|
+
return Promise.reject(requestParams.error.message);
|
|
591
|
+
}
|
|
592
|
+
return variable.httpService.send(requestParams).then(function (response) {
|
|
593
|
+
if (response && isValidWebURL(response.body.result)) {
|
|
594
|
+
window.location.href = response.body.result;
|
|
595
|
+
triggerFn(successHandler, response);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.ERROR, variable, response);
|
|
599
|
+
triggerFn(errorHandler, response);
|
|
600
|
+
}
|
|
601
|
+
}, function (response, xhrObj) {
|
|
602
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.ERROR, variable, response, xhrObj);
|
|
603
|
+
triggerFn(errorHandler, response);
|
|
604
|
+
});
|
|
605
|
+
};
|
|
606
|
+
ServiceVariableManager.prototype.getInputParms = function (variable) {
|
|
607
|
+
var wmServiceOperationInfo;
|
|
608
|
+
if (!isEmpty(metadataService)) {
|
|
609
|
+
wmServiceOperationInfo = get(metadataService.getByOperationId(variable.operationId, variable.getPrefabName()), 'wmServiceOperationInfo');
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
wmServiceOperationInfo = variable.serviceInfo;
|
|
613
|
+
}
|
|
614
|
+
return get(wmServiceOperationInfo, 'parameters');
|
|
615
|
+
};
|
|
616
|
+
ServiceVariableManager.prototype.setInput = function (variable, key, val, options) {
|
|
617
|
+
return setInput(variable.dataBinding, key, val, options);
|
|
618
|
+
};
|
|
619
|
+
/**
|
|
620
|
+
* Cancels an on going service request
|
|
621
|
+
* @param variable
|
|
622
|
+
* @param $file
|
|
623
|
+
*/
|
|
624
|
+
ServiceVariableManager.prototype.cancel = function (variable, $file) {
|
|
625
|
+
// CHecks if there is any pending requests in the queue
|
|
626
|
+
if ($queue.requestsQueue.has(variable)) {
|
|
627
|
+
// If the request is a File upload request then modify the elements associated with file upload
|
|
628
|
+
// else unsubscribe from the observable on the variable.
|
|
629
|
+
if (ServiceVariableUtils.isFileUploadRequest(variable)) {
|
|
630
|
+
variable.httpService.cancel(variable, $file);
|
|
631
|
+
$file.status = 'abort';
|
|
632
|
+
this.totalFilesCount--;
|
|
633
|
+
initiateCallback(VARIABLE_CONSTANTS.EVENT.ABORT, variable, $file);
|
|
634
|
+
if (!this.isFileUploadInProgress(variable.dataBinding) && this.totalFilesCount === 0) {
|
|
635
|
+
$queue.process(variable);
|
|
636
|
+
// notify inflight variable
|
|
637
|
+
this.notifyInflight(variable, false);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
if (variable.httpService.cancel) {
|
|
642
|
+
variable.httpService.cancel(variable);
|
|
643
|
+
$queue.process(variable);
|
|
644
|
+
// notify inflight variable
|
|
645
|
+
this.notifyInflight(variable, false);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
ServiceVariableManager.prototype.defineFirstLastRecord = function (variable) {
|
|
651
|
+
if (variable.isList) {
|
|
652
|
+
Object.defineProperty(variable, 'firstRecord', {
|
|
653
|
+
'configurable': true,
|
|
654
|
+
'get': function () {
|
|
655
|
+
var dataSet = variable.dataSet;
|
|
656
|
+
// For procedure(v1) data doesn't come under content
|
|
657
|
+
return head(dataSet && dataSet.content) || head(dataSet) || {};
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
Object.defineProperty(variable, 'lastRecord', {
|
|
661
|
+
'configurable': true,
|
|
662
|
+
'get': function () {
|
|
663
|
+
var dataSet = variable.dataSet;
|
|
664
|
+
// For procedure(v1) data doesn't come under content
|
|
665
|
+
return last(dataSet && dataSet.content) || last(dataSet) || {};
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
// Gets the input params of the service variable and also add params from the searchKeys (filterfields)
|
|
671
|
+
ServiceVariableManager.prototype.getQueryParams = function (filterFields, searchValue, variable) {
|
|
672
|
+
var inputParams = this.getInputParms(variable);
|
|
673
|
+
var queryParams = ServiceVariableUtils.excludePaginationParams(inputParams);
|
|
674
|
+
var inputFields = {};
|
|
675
|
+
// check if some param value is already available in databinding and update the inputFields accordingly
|
|
676
|
+
map(variable.dataBinding, function (value, key) {
|
|
677
|
+
inputFields[key] = value;
|
|
678
|
+
});
|
|
679
|
+
// add the query params mentioned in the searchkey to inputFields
|
|
680
|
+
forEach(filterFields, function (value) {
|
|
681
|
+
if (includes(queryParams, value)) {
|
|
682
|
+
inputFields[value] = searchValue;
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
return inputFields;
|
|
686
|
+
};
|
|
687
|
+
/**
|
|
688
|
+
* This method returns filtered records based on searchKey and queryText.
|
|
689
|
+
* @param variable
|
|
690
|
+
* @param options
|
|
691
|
+
* @param success
|
|
692
|
+
* @param error
|
|
693
|
+
* @returns {Promise<any>}
|
|
694
|
+
*/
|
|
695
|
+
ServiceVariableManager.prototype.searchRecords = function (variable, options, success, error) {
|
|
696
|
+
var inputFields = this.getQueryParams(split(options.searchKey, ','), options.query, variable);
|
|
697
|
+
var requestParams = {
|
|
698
|
+
page: options.page,
|
|
699
|
+
pagesize: options.pagesize,
|
|
700
|
+
skipDataSetUpdate: true, // dont update the actual variable dataset,
|
|
701
|
+
skipToggleState: true, // Dont change the varibale toggle state as this is a independent call
|
|
702
|
+
inFlightBehavior: 'executeAll',
|
|
703
|
+
inputFields: inputFields
|
|
704
|
+
};
|
|
705
|
+
if (options.onBeforeservicecall) {
|
|
706
|
+
options.onBeforeservicecall(inputFields);
|
|
707
|
+
}
|
|
708
|
+
return this.invoke(variable, requestParams, success, error).catch(noop);
|
|
709
|
+
};
|
|
710
|
+
return ServiceVariableManager;
|
|
711
|
+
}(BaseVariableManager));
|
|
712
|
+
export { ServiceVariableManager };
|
|
713
|
+
//# sourceMappingURL=service-variable.manager.js.map
|