@xuda.io/runtime-bundle 1.0.375 → 1.0.377

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.
@@ -6024,2030 +6024,7 @@ func.datasource.get_args_property_value = async function (SESSION_ID, dsSession,
6024
6024
 
6025
6025
  return _value;
6026
6026
  };
6027
- func.utils = {};
6028
-
6029
- func.utils.debug = {};
6030
- func.utils.debug.watch = async function (SESSION_ID, key, type, info, result, condition, not_executed) {
6031
- if (!glb.DEBUG_MODE) return;
6032
-
6033
- const debug_utils = await func.common.get_module(SESSION_ID, 'xuda-debug-utils-module.mjs');
6034
-
6035
- debug_utils.watch(SESSION_ID, key, type, info, result, condition, not_executed);
6036
- };
6037
- func.utils.debug.log = async function (SESSION_ID, node_idP, jsonP) {
6038
- if (typeof IS_PROCESS_SERVER !== 'undefined') return;
6039
-
6040
- if (!glb.DEBUG_MODE && !glb.TRACE_ON) return;
6041
-
6042
- const debug_utils = await func.common.get_module(SESSION_ID, 'xuda-debug-utils-module.mjs');
6043
-
6044
- debug_utils.log(SESSION_ID, node_idP, jsonP);
6045
- };
6046
- func.utils.debug.write = async function (SESSION_ID, logP, callbackP) {
6047
- if (!glb.DEBUG_MODE) return;
6048
-
6049
- const debug_utils = await func.common.get_module(SESSION_ID, 'xuda-debug-utils-module.mjs');
6050
-
6051
- debug_utils.write(SESSION_ID, logP, callbackP);
6052
- };
6053
-
6054
- func.utils.debug.read_command = async function (data) {
6055
- if (!glb.DEBUG_MODE) return;
6056
-
6057
- const debug_utils = await func.common.get_module(SESSION_ID, 'xuda-debug-utils-module.mjs');
6058
-
6059
- debug_utils.read_command(data);
6060
- };
6061
- func.utils.DOCS_OBJ = {};
6062
- func.utils.DOCS_OBJ.get = async function (SESSION_ID, idP) {
6063
- if (!idP || idP === '0') return;
6064
-
6065
- var _session = SESSION_OBJ[SESSION_ID];
6066
- const _app_id = _session.app_id;
6067
- if (!DOCS_OBJ[_app_id]) {
6068
- DOCS_OBJ[_app_id] = {};
6069
- }
6070
-
6071
- if (DOCS_OBJ[_app_id][idP]) {
6072
- return DOCS_OBJ[_app_id][idP];
6073
- }
6074
-
6075
- if (_session.project_data) {
6076
- if (idP === 'system') {
6077
- if (_session.project_data.globals) {
6078
- DOCS_OBJ[_app_id][idP] = _session.project_data.globals;
6079
- } else {
6080
- DOCS_OBJ[_app_id][idP] = {};
6081
- }
6082
- return DOCS_OBJ[_app_id][idP];
6083
- }
6084
- let val = _session.project_data?.programs?.[idP];
6085
- if (val) {
6086
- return (DOCS_OBJ[_app_id][idP] = val);
6087
- }
6088
- }
6089
-
6090
- if (typeof _session.SLIM_BUNDLE === 'undefined' || !_session.SLIM_BUNDLE) {
6091
- const module = await func.common.get_module(SESSION_ID, `xuda-progs-loader-module.mjs`);
6092
-
6093
- if (idP !== 'system') {
6094
- DOCS_OBJ[_app_id][idP] = await module.DOCS_OBJ_get(SESSION_ID, idP);
6095
- if (DOCS_OBJ[_app_id][idP] && _.isEmpty(DOCS_OBJ[_app_id][idP])) {
6096
- await func.utils.remove_cached_objects(SESSION_ID);
6097
-
6098
- delete DOCS_OBJ[_app_id][idP];
6099
- }
6100
- return DOCS_OBJ[_app_id][idP];
6101
- }
6102
-
6103
- DOCS_OBJ[_app_id][idP] = await module.DOCS_OBJ_get(SESSION_ID, 'global_' + (APP_OBJ[_app_id].app_replicate || _app_id));
6104
- if (APP_OBJ[_app_id].app_imported_projects) {
6105
- for await (const imported_app_id of APP_OBJ[_app_id].app_imported_projects) {
6106
- var view_ret = await module.DOCS_OBJ_get(SESSION_ID, 'global_' + imported_app_id);
6107
- DOCS_OBJ[_app_id][idP] = _.merge(DOCS_OBJ[_app_id][idP], view_ret);
6108
- }
6109
- }
6110
- return DOCS_OBJ[_app_id][idP];
6111
- }
6112
-
6113
- console.error(`${idP} not found`);
6114
- };
6115
-
6116
- func.utils.FILES_OBJ = {};
6117
- func.utils.FILES_OBJ.get = async function (SESSION_ID, idP) {
6118
- if (!idP) return;
6119
- return await func.utils.DOCS_OBJ.get(SESSION_ID, idP);
6120
- };
6121
- func.utils.VIEWS_OBJ = {};
6122
- func.utils.VIEWS_OBJ.get = async function (SESSION_ID, idP) {
6123
- if (!idP) return;
6124
-
6125
- return await func.utils.DOCS_OBJ.get(SESSION_ID, idP);
6126
- };
6127
-
6128
- func.utils.TREE_OBJ = {};
6129
- func.utils.TREE_OBJ.get = async function (SESSION_ID, idP) {
6130
- if (!idP) return;
6131
- var ret = await func.utils.DOCS_OBJ.get(SESSION_ID, idP);
6132
- if (ret?.properties) {
6133
- ret.properties.id = idP;
6134
- }
6135
-
6136
- return ret.properties;
6137
- };
6138
-
6139
- func.utils.get_dateTime = async function (SESSION_ID, typeP, dateP) {
6140
- // const getUTC = function (ts) {
6141
- // var date = new Date(ts);
6142
- // var utc_date = new Date(
6143
- // date.getUTCFullYear(),
6144
- // date.getUTCMonth(),
6145
- // date.getUTCDate(),
6146
- // date.getUTCHours(),
6147
- // date.getUTCMinutes(),
6148
- // date.getUTCSeconds(),
6149
- // date.getUTCMilliseconds()
6150
- // );
6151
- // return utc_date;
6152
- // };
6153
- const get_server_ts = async function () {
6154
- var _session = SESSION_OBJ[SESSION_ID];
6155
-
6156
- const response = await fetch(`https://${_session.domain}/cpi/get_utc_ts`, {
6157
- method: 'POST',
6158
- headers: {
6159
- Accept: 'application/json',
6160
- 'Content-Type': 'application/json',
6161
- },
6162
- body: JSON.stringify({}),
6163
- });
6164
- const json = await response.json();
6165
- return json.data;
6166
- // }
6167
- };
6168
-
6169
- function getWeekNumber(d) {
6170
- // Copy date so don't modify original
6171
- d = new Date(+d);
6172
- d.setHours(0, 0, 0);
6173
- // Set to nearest Thursday: current date + 4 - current day number
6174
- // Make Sunday's day number 7
6175
- d.setDate(d.getDate() + 4 - (d.getDay() || 7));
6176
- // Get first day of year
6177
- var yearStart = new Date(d.getFullYear(), 0, 1);
6178
- // Calculate full weeks to nearest Thursday
6179
- var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
6180
- // Return array of year and week number
6181
- return weekNo;
6182
- }
6183
- var sysDate = new Date(dateP); // getUTC(dateP); //new Date(dateP);
6184
-
6185
- if (!dateP) {
6186
- let ts = await get_server_ts();
6187
- sysDate = new Date(ts);
6188
- }
6189
- var day = _.padStart(sysDate.getDate(), 2, '0');
6190
- var month = _.padStart(sysDate.getMonth() + 1, 2, '0');
6191
- var year = sysDate.getFullYear();
6192
- var week = _.padStart(getWeekNumber(sysDate), 2, '0');
6193
- var hour = _.padStart(sysDate.getHours(), 2, '0');
6194
- var minute = _.padStart(sysDate.getMinutes(), 2, '0');
6195
- var second = _.padStart(sysDate.getSeconds(), 2, '0');
6196
- if (typeP === 'SYS_DATE') return year + '-' + month + '-' + day;
6197
- if (typeP === 'SYS_DATE_TIME') return year + '-' + month + '-' + day + 'T' + hour + ':' + minute;
6198
- if (typeP === 'SYS_DATE_VALUE') return sysDate.valueOf();
6199
- if (typeP === 'SYS_DATE_WEEK_YEAR') return year + 'W' + week;
6200
- if (typeP === 'SYS_DATE_MONTH_YEAR') return year + '-' + month;
6201
- if (typeP === 'SYS_TIME') return hour + ':' + minute + ':' + second;
6202
- if (typeP === 'SYS_TIME_SHORT') return hour + ':' + minute;
6203
- };
6204
- func.utils.is_onscreen_event = function (functionP) {
6205
- const arr = ['invoke_action', 'cache_refresh', 'call_popover', 'call_modal', 'call_page', 'loader_on', 'loader_off', 'emit_event'];
6206
-
6207
- return arr.includes(functionP);
6208
- };
6209
-
6210
- func.utils.get_screen_obj = async function (SESSION_ID, id) {
6211
- const prog_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, id);
6212
- if (!prog_obj) return console.error('prog not found: ' + id);
6213
-
6214
- if (prog_obj.properties.menuType === 'screen' || prog_obj.properties.menuType === 'api' || glb.FUNCTION_NODES_ARR.includes(prog_obj.properties.menuType) || glb.MOBILE_ARR.includes(prog_obj.properties.menuType)) {
6215
- return prog_obj;
6216
- }
6217
- return;
6218
- };
6219
-
6220
- func.utils.clean_returned_datasource = function (SESSION_ID, DS) {
6221
- const clean_object_functions = function (obj) {
6222
- for (const [key, val] of Object.entries(obj)) {
6223
- if (typeof val === 'function') {
6224
- delete obj[key];
6225
- }
6226
- }
6227
- };
6228
-
6229
- var _session = SESSION_OBJ[SESSION_ID];
6230
- if (!_session.DS_GLB[DS]) return;
6231
-
6232
- var obj = _.clone(_session.DS_GLB[DS]);
6233
-
6234
- delete obj.screen_params;
6235
-
6236
- try {
6237
- clean_object_functions(obj);
6238
-
6239
- obj = JSON.parse(JSON.stringify(obj, func.utils.clean_stringify_null, '\t'));
6240
- } catch (e) {
6241
- console.error(e);
6242
- }
6243
-
6244
- delete obj.pre_init_fields;
6245
- delete obj.oninit_triggers_to_run;
6246
- // delete obj.raw_data;
6247
-
6248
- delete obj.debug;
6249
-
6250
- const clean_empty_objects = function () {
6251
- for (const [key, val] of Object.entries(obj)) {
6252
- if (typeof val === 'object' && !Array.isArray(val) && _.isEmpty(val)) {
6253
- delete obj[key];
6254
- }
6255
- }
6256
-
6257
- for (const [key, val] of Object.entries(obj)) {
6258
- if (typeof val === 'object' && Array.isArray(val) && !val.length) {
6259
- delete obj[key];
6260
- }
6261
- }
6262
- };
6263
-
6264
- delete obj.screenInfo;
6265
-
6266
- delete obj.viewEventsProp;
6267
- delete obj.viewSourceDesc;
6268
- delete obj.viewSourceProp;
6269
-
6270
- delete obj.v;
6271
- clean_empty_objects();
6272
- // clean_dataset();
6273
- return obj;
6274
- };
6275
- func.utils.post_back_to_client = function (SESSION_ID, service, id, data) {
6276
- if (typeof IS_PROCESS_SERVER !== 'undefined') return;
6277
- worker_post_message({
6278
- fx_to_execute: service,
6279
- params: data,
6280
- session_id: SESSION_ID,
6281
- worker_id: id,
6282
- });
6283
- };
6284
- func.utils.job_worker = {};
6285
-
6286
- func.utils.job_worker = function (session_id) {
6287
- var SESSION_ID = session_id;
6288
- var _session = SESSION_OBJ[SESSION_ID];
6289
- var is_progressScreen_on;
6290
- var is_not_responding;
6291
- var attempt = 0;
6292
-
6293
- const lock = function (dsP) {
6294
- if (!_session.WORKER_OBJ.jobs[_session.WORKER_OBJ.stat] || _session.WORKER_OBJ.jobs[_session.WORKER_OBJ.stat].typeP === 'system_interval' || _session.WORKER_OBJ.jobs[_session.WORKER_OBJ.stat].typeP === 'system event') {
6295
- return;
6296
- }
6297
- if (glb.IS_WORKER) {
6298
- func.utils.post_back_to_client(SESSION_ID, 'screen_blocker_on', _session.worker_id, null);
6299
- } else {
6300
- func.UI.utils.screen_blocker(true, 'Worker', dsP);
6301
- }
6302
- };
6303
- const unlock = function () {
6304
- if (glb.IS_WORKER) {
6305
- } else {
6306
- func.UI.utils.screen_blocker(false, 'Worker');
6307
- }
6308
- };
6309
- const not_responding = function () {
6310
- is_not_responding = true;
6311
- func.UI.utils.progressScreen.hide('Working, Please wait..');
6312
- setTimeout(function () {
6313
- if (!is_not_responding) return;
6314
-
6315
- reset();
6316
- }, 500);
6317
- };
6318
- const idle = function () {
6319
- if (is_progressScreen_on) {
6320
- setTimeout(function () {
6321
- if (!attempt && is_progressScreen_on) {
6322
- is_progressScreen_on = false;
6323
- is_not_responding = false;
6324
-
6325
- func.UI.utils.progressScreen.hide('Working, Please wait..');
6326
- } else if (attempt > 300 && is_not_responding) {
6327
- is_not_responding = false;
6328
- busy();
6329
- }
6330
- }, 310);
6331
- } else {
6332
- if (!glb.IS_WORKER) {
6333
- // func.UI.screen.garbage_collector(SESSION_ID);
6334
- }
6335
- }
6336
- };
6337
- const busy = function () {
6338
- if (glb.IS_WORKER) return;
6339
- func.utils.debug_report(SESSION_ID, 'utils.worker.busy', 'worker processing more then 10 second', 'W', '', _session.WORKER_OBJ.jobs);
6340
-
6341
- is_progressScreen_on = true;
6342
- };
6343
- const reset = function () {
6344
- func.utils.debug_report(SESSION_ID, 'utils.worker.reset', 'worker not responding', 'E', '', _session.WORKER_OBJ.jobs);
6345
- _session.WORKER_OBJ.jobs = [];
6346
- _session.WORKER_OBJ.stat = null;
6347
- $('.screen_blocker').remove();
6348
- };
6349
- return {
6350
- _interval: null,
6351
- _was_busy: null,
6352
- init: async function () {
6353
- var _this = this;
6354
- this._interval = setInterval(async function () {
6355
- var _session = SESSION_OBJ[SESSION_ID];
6356
- if (!_session?.WORKER_OBJ) return;
6357
- if (typeof _session.WORKER_OBJ.stat === 'undefined' || _session.WORKER_OBJ.stat === 'undefined' || _session.WORKER_OBJ.stat === null) {
6358
- // idle
6359
-
6360
- // if (_this._was_busy) {
6361
- // if (glb.IS_WORKER) {
6362
- // func.utils.post_back_to_client(
6363
- // SESSION_ID,
6364
- // "worker_busy_off",
6365
- // _session.worker_id,
6366
- // null
6367
- // );
6368
- // } else {
6369
- // func.UI.utils.indicator.worker.normal();
6370
- // }
6371
- // _this._was_busy = false;
6372
- // }
6373
- unlock();
6374
- if (_session.WORKER_OBJ.jobs.length) {
6375
- for await (const [key, val] of Object.entries(_session.WORKER_OBJ.jobs)) {
6376
- if (val.stat) {
6377
- break;
6378
- }
6379
- // if (!_session.WORKER_OBJ.stat) {
6380
- if (!_session.WORKER_OBJ.jobs[Number(key)] || val.job_num === 9999999) {
6381
- continue;
6382
- }
6383
- if (val.dsSessionP && !_session.DS_GLB[val.dsSessionP]) {
6384
- func.events.delete_job(SESSION_ID, val.job_num);
6385
- break;
6386
- }
6387
- await func.events.execute(
6388
- SESSION_ID,
6389
- val.job_num,
6390
- val.eventIdP,
6391
- val.triggerP,
6392
- val.functionP,
6393
- val.refIdP,
6394
- val.containerP,
6395
- val.elementP,
6396
- val.rowP,
6397
- val.evt,
6398
- val.descP,
6399
- val.rootScreenIdP,
6400
- val.dsSessionP,
6401
- null,
6402
- val.typeP,
6403
- null,
6404
- val.event_propertiesP,
6405
- val.calling_triggerP,
6406
- null,
6407
- val.paramsP,
6408
- val.target_frame_idP,
6409
- val.calling_trigger_prop,
6410
- val.calling_program,
6411
- val.argumentsP,
6412
- val.prog_id,
6413
- val.nodeId,
6414
- val.parentDataSourceNo,
6415
- '', //dismissed val.$div creating bug in alter ui
6416
- val.$container,
6417
- );
6418
- }
6419
- _this._was_busy = true;
6420
- } else {
6421
- // idle
6422
- if (_this._was_busy) {
6423
- if (glb.IS_WORKER) {
6424
- func.utils.post_back_to_client(SESSION_ID, 'worker_busy_off', _session.worker_id, null);
6425
- } else {
6426
- func.UI.utils.indicator.worker.normal();
6427
- }
6428
- }
6429
- _this._was_busy = false;
6430
- }
6431
- attempt = 0;
6432
- is_not_responding = false;
6433
- idle();
6434
- } else {
6435
- //busy
6436
- _this._was_busy = true;
6437
- if (glb.IS_WORKER) {
6438
- func.utils.post_back_to_client(SESSION_ID, 'worker_busy_on', _session.worker_id, null);
6439
- } else {
6440
- func.UI.utils.indicator.worker.busy();
6441
- }
6442
- if (glb.WORKER_PAUSE) return;
6443
- attempt++;
6444
- if (!is_progressScreen_on && attempt > glb.WORKER_TIMEOUT) busy();
6445
- if (!is_not_responding && attempt >= glb.WORKER_ATTEMPTS_NOT_RESPONDING) {
6446
- not_responding();
6447
- }
6448
- var ds = null;
6449
- if (_session.WORKER_OBJ.jobs[0]) ds = _session.WORKER_OBJ.jobs[0].dsSessionP;
6450
- lock(ds);
6451
- }
6452
- }, 1);
6453
- },
6454
- stop: function () {
6455
- clearInterval(this._interval);
6456
- },
6457
- };
6458
- };
6459
-
6460
- func.utils.base64MimeType = function (encoded) {
6461
- var result = null;
6462
-
6463
- if (typeof encoded !== 'string') {
6464
- return result;
6465
- }
6466
-
6467
- var mime = encoded.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);
6468
-
6469
- if (mime && mime.length) {
6470
- result = mime[1];
6471
- }
6472
-
6473
- return result;
6474
- };
6475
-
6476
- func.utils.makeid = function (length) {
6477
- var result = '';
6478
- var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
6479
- var charactersLength = characters.length;
6480
- for (var i = 0; i < length; i++) {
6481
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
6482
- }
6483
- return result;
6484
- };
6485
-
6486
- func.utils.get_device = function () {
6487
- var device;
6488
- try {
6489
- if (window.cordova) {
6490
- device = window.cordova.platformId;
6491
- }
6492
- } catch (e) {
6493
- console.error('error using ui element in server side request');
6494
- }
6495
- return device;
6496
- };
6497
-
6498
- func.utils.ws_worker = {};
6499
-
6500
- func.utils.ws_worker.functions = {
6501
- init: async function (data) {
6502
- var SESSION_ID = data.SESSION_ID;
6503
-
6504
- APP_OBJ[data.app_id] = data.APP_OBJ;
6505
- PROJECT_OBJ[data.app_id] = data.PROJECT_OBJ;
6506
-
6507
- if (data.SESSION_INFO.engine_mode === 'live_preview') {
6508
- DOCS_OBJ[data.app_id] = data.DOCS_OBJ;
6509
- } else if (typeof IS_DOCKER === 'undefined' && typeof IS_PROCESS_SERVER === 'undefined') {
6510
- if (!DOCS_OBJ[data.app_id]) {
6511
- DOCS_OBJ[data.app_id] = {};
6512
- }
6513
- }
6514
-
6515
- glb.APP_INFO[data.app_id] = data.APP_INFO;
6516
- glb.DEBUG_MODE = data.DEBUG_MODE;
6517
- glb.DEBUG_INFO_OBJ = data.DEBUG_INFO_OBJ;
6518
-
6519
- glb.WINDOW_LOCATION_SEARCH = data.WINDOW_LOCATION_SEARCH;
6520
- glb.ROOT_ELEMENT_ATTRIBUTES = data.ROOT_ELEMENT_ATTRIBUTES;
6521
-
6522
- DATASOURCE_INTERVALS[SESSION_ID] = {};
6523
-
6524
- SESSION_OBJ[SESSION_ID] = data.SESSION_INFO;
6525
-
6526
- var _session = SESSION_OBJ[SESSION_ID];
6527
- glb.SESSION_INFO = data.SESSION_INFO;
6528
-
6529
- _session.engine_mode = data.engine_mode;
6530
- STUDIO_WEBSOCKET_CONNECTION_ID = data.STUDIO_WEBSOCKET_CONNECTION_ID;
6531
-
6532
- for (let [key, val] of Object.entries(_session.DS_GLB)) {
6533
- if (Number(key) > _session.dataSourceSessionGlobal) {
6534
- _session.dataSourceSessionGlobal = Number(key);
6535
- }
6536
- }
6537
- if (typeof _session.SLIM_BUNDLE === 'undefined' || !_session.SLIM_BUNDLE) {
6538
- const db_adapter = await func.common.get_module(SESSION_ID, 'xuda-db-adapter-module.mjs');
6539
-
6540
- func.db = db_adapter._db;
6541
- }
6542
-
6543
- _session.WORKER_OBJ.fx = new func.utils.job_worker(SESSION_ID);
6544
- _session.WORKER_OBJ.fx.init();
6545
-
6546
- if (_session.app_id === 'unknown') {
6547
- worker_post_message({
6548
- fx_to_execute: 'init_done',
6549
- worker_id: ws_worker_id,
6550
- session_id: SESSION_ID,
6551
- });
6552
- } else {
6553
- const module = await func.common.get_module(SESSION_ID, `xuda-progs-loader-module.mjs`);
6554
- await module.load_objects_cache(SESSION_ID);
6555
- worker_post_message({
6556
- fx_to_execute: 'init_done',
6557
- worker_id: ws_worker_id,
6558
- session_id: SESSION_ID,
6559
- });
6560
- }
6561
-
6562
- WEB_WORKER_CALLBACK_QUEUE[SESSION_ID] = {};
6563
- },
6564
- datasource_create: async function (params, promise_queue_id) {
6565
- var SESSION_ID = params.session_id;
6566
- var _session = SESSION_OBJ[SESSION_ID];
6567
- _session.ts = new Date().getTime();
6568
- var args = params;
6569
- args.SESSION_ID = SESSION_ID;
6570
-
6571
- if (show_log) {
6572
- console.log('DATASOURCE EXECUTING SESSION_ID: ' + SESSION_ID, APP_OBJ[_session.app_id].app_name);
6573
- }
6574
- if (Number(params.dataSourceSessionGlobal) > _session.dataSourceSessionGlobal) {
6575
- _session.dataSourceSessionGlobal = Number(params.dataSourceSessionGlobal);
6576
- }
6577
-
6578
- const ret = await func.datasource.prepare(
6579
- args.SESSION_ID,
6580
- args.prog_id,
6581
- args.dataSourceNoP,
6582
- args.parentDataSourceNoP,
6583
- args.containerIdP,
6584
- args.rowIdP,
6585
- args.jobNoP,
6586
- args.calling_trigger_prop,
6587
- null,
6588
- null,
6589
- args.callingSourceP,
6590
- args.calling_jobP,
6591
- args.screen_dsP,
6592
- args.is_panelP,
6593
- args.parameters_obj_inP,
6594
- args.static_refreshP,
6595
- args.run_atP,
6596
- args.worker_id,
6597
- );
6598
-
6599
- if (show_log) console.log('DATASOURCE EXECUTION DONE ' + ret.dsSessionP + ' ' + _session.DS_GLB[ret.dsSessionP]?.tree_obj?.menuName || '' + ' SESSION_ID: ' + SESSION_ID, APP_OBJ[_session.app_id].app_name);
6600
- var obj = func.utils.clean_returned_datasource(SESSION_ID, ret?.dsSessionP);
6601
- obj.dataSourceSessionGlobal = _session.dataSourceSessionGlobal;
6602
-
6603
- worker_post_message({
6604
- promise_queue_id,
6605
- params: obj,
6606
- worker_id: ws_worker_id,
6607
- session_id: SESSION_ID,
6608
- process_pid: params.process_pid,
6609
- service: params.service,
6610
- });
6611
- },
6612
- datasource_delete: function (params, promise_queue_id) {
6613
- var SESSION_ID = params.session_id;
6614
- var _session = SESSION_OBJ[SESSION_ID];
6615
- if (DATASOURCE_INTERVALS[SESSION_ID] && DATASOURCE_INTERVALS[SESSION_ID][params.dssession]) {
6616
- DATASOURCE_INTERVALS[SESSION_ID][params.dssession].clear();
6617
- }
6618
- delete _session.DS_GLB[params.dssession];
6619
- if (show_log) console.log('DATASOURCE DELETE SESSION_ID: ' + SESSION_ID, APP_OBJ[_session.app_id].app_name, params.dssession);
6620
- // debugger;
6621
- worker_post_message({
6622
- promise_queue_id,
6623
- worker_id: ws_worker_id,
6624
- session_id: SESSION_ID,
6625
- process_pid: params.process_pid,
6626
- service: params.service,
6627
- });
6628
- },
6629
- update_datasource_changes_from_client: async function (params, promise_queue_id) {
6630
- if (_.isEmpty(SESSION_OBJ)) return;
6631
- var SESSION_ID = params.session_id;
6632
- var _session = SESSION_OBJ[SESSION_ID];
6633
- if (!_session) {
6634
- _session = {};
6635
- _session.app_id = params.app_id;
6636
- _session.dataSourceSessionGlobal = -1;
6637
- _session.DS_GLB = {};
6638
- }
6639
- if (show_log) console.log('DATASOURCE UPDATE SESSION_ID: ' + SESSION_ID, APP_OBJ[_session.app_id].app_name, params.dssession);
6640
-
6641
- await func.datasource.update(SESSION_ID, params.datasource_changes, true);
6642
-
6643
- worker_post_message({
6644
- promise_queue_id,
6645
- params: params.dssession,
6646
- worker_id: ws_worker_id,
6647
- session_id: SESSION_ID,
6648
- process_pid: params.process_pid,
6649
- service: params.service,
6650
- });
6651
- },
6652
-
6653
- return_to_data_source: function (params, promise_queue_id) {
6654
- var SESSION_ID = params.session_id;
6655
- var _session = SESSION_OBJ[SESSION_ID];
6656
- var ds = _session.DS_GLB[params.dssession];
6657
- var type = params.return_to_data_source_type;
6658
- var args = ds.args;
6659
- if (show_log) console.log('DATASOURCE RETURN TO DATASOURCE ' + params.dssession + ' SESSION_ID: ' + SESSION_ID, APP_OBJ[_session.app_id].app_name);
6660
- _session.DS_GLB[params.dssession].v.onscreen_events_active = params.onscreen_events_active;
6661
- if (params.viewEventExec_arr) _session.DS_GLB[params.dssession].viewEventExec_arr = JSON.parse(params.viewEventExec_arr);
6662
- var done = function (SESSION_ID, DS) {
6663
- if (show_log) console.log('DATASOURCE RETURN TO DATASOURCE DONE ' + DS + ' SESSION_ID: ' + SESSION_ID, APP_OBJ[_session.app_id].app_name);
6664
- var obj = func.utils.clean_returned_datasource(SESSION_ID, DS);
6665
- obj.dataSourceSessionGlobal = _session.dataSourceSessionGlobal;
6666
- worker_post_message({
6667
- fx_to_execute: 'post_datasource',
6668
- params: {
6669
- ds_obj: obj,
6670
- dsSessionP: params.dssession,
6671
- },
6672
- worker_id: ws_worker_id,
6673
- session_id: SESSION_ID,
6674
- process_pid: params.process_pid,
6675
- service: params.service,
6676
- });
6677
- };
6678
-
6679
- done(SESSION_ID, params.dssession);
6680
- },
6681
- acknowledged_worker_with_eventChangesResults_done: function (params) {
6682
- var SESSION_ID = params.session_id;
6683
- var _session = SESSION_OBJ[SESSION_ID];
6684
- var ds = _session.DS_GLB[params.dssession];
6685
-
6686
- if (show_log) console.log('UPDATE CHANGE EVENT DONE TO DATASOURCE ' + params.dssession + ' SESSION_ID: ' + SESSION_ID, APP_OBJ[_session.app_id].app_name);
6687
- ds.eventChangesResults_done = true;
6688
- },
6689
- return_from_db_query: function (params) {
6690
- var SESSION_ID = params.session_id;
6691
- var _session = SESSION_OBJ[SESSION_ID];
6692
- var id = params.id;
6693
- if (show_log) console.log('RETURN FROM DB_QUERY ' + params.dssession + ' SESSION_ID: ' + SESSION_ID, APP_OBJ[_session.app_id].app_name);
6694
- debugger;
6695
- var callback = func.utils.get_callback_queue(SESSION_ID, params.callback_id);
6696
- if (callback) callback(params.data);
6697
- },
6698
- return_from_sava_data: function (params) {
6699
- var SESSION_ID = params.session_id;
6700
- var _session = SESSION_OBJ[SESSION_ID];
6701
- var id = params.id;
6702
- if (show_log) console.log('RETURN FROM SAVE_DATA ' + params.dssession + ' SESSION_ID: ' + SESSION_ID, APP_OBJ[_session.app_id].app_name);
6703
- func.utils.get_callback_queue(SESSION_ID, params.callback_id)();
6704
- },
6705
- update_debug_info: function (params) {
6706
- glb.DEBUG_INFO_OBJ = params;
6707
- },
6708
- // update_VIEWS_OBJ: function (params) {
6709
- // delete VIEWS_OBJ[APP_ID][params.id];
6710
- // },
6711
- // update_TREE_OBJ: function (params) {
6712
- // delete TREE_OBJ[APP_ID][params.id];
6713
- // },
6714
- // send_object_to_worker: function (params) {
6715
- // if (RESPONSE_FROM_STUDIO_QUEUE[params.req_id]) {
6716
- // RESPONSE_FROM_STUDIO_QUEUE[params.req_id].data = params;
6717
- // }
6718
- // },
6719
- get_dataSourceSessionGlobal: function (params) {
6720
- var SESSION_ID = params.session_id;
6721
- SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal++;
6722
- let new_dataSourceSessionGlobal = SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal;
6723
- return { new_dataSourceSessionGlobal };
6724
- },
6725
- create_webworker_globals: function (params) {
6726
- var SESSION_ID = params.session_id;
6727
- SESSION_OBJ[SESSION_ID].DS_GLB[0] = params.ds_data;
6728
- },
6729
- return_doc_from_studio: function (params) {
6730
- var SESSION_ID = params.session_id;
6731
- function emitCustomEvent(eventName, detail) {
6732
- const event = new CustomEvent(eventName, { detail });
6733
- self.dispatchEvent(event);
6734
- }
6735
- emitCustomEvent('live_preview_get_obj_response_worker_' + params._id, {
6736
- data: params,
6737
- });
6738
- },
6739
- return_doc_from_websocket: function (params) {
6740
- var SESSION_ID = params.session_id;
6741
- function emitCustomEvent(eventName, detail) {
6742
- const event = new CustomEvent(eventName, { detail });
6743
- self.dispatchEvent(event);
6744
- }
6745
- emitCustomEvent('get_doc_obj_from_build_worker_' + params._id, {
6746
- data: params,
6747
- });
6748
- },
6749
- return_dbs_data_from_websocket: function (params) {
6750
- var SESSION_ID = params.session_id;
6751
- function emitCustomEvent(eventName, detail) {
6752
- const event = new CustomEvent(eventName, { detail });
6753
- self.dispatchEvent(event);
6754
- }
6755
- emitCustomEvent('get_ws_data_worker_' + params.websocket_queue_num, {
6756
- data: params.data,
6757
- });
6758
- },
6759
- heartbeat: async function (params) {
6760
- var SESSION_ID = params.session_id;
6761
-
6762
- try {
6763
- const do_heartbeat = async function (app_replicate, app_id, token_id, fingerprint, device_name, stat) {
6764
- try {
6765
- module.exports.close_expired_device_log_sessions(app_id);
6766
-
6767
- return await update_device(app_replicate, app_id, token_id, fingerprint, device_name, stat);
6768
- } catch (err) {
6769
- return { code: -400, data: err.message };
6770
- }
6771
- };
6772
- let ret = await do_heartbeat(params.app_replicate, params.app_id, params.gtp_token || req.body.app_token, params.fingerprint, params.device_name, params.stat);
6773
-
6774
- // session_status: ret_session.data.stat
6775
- if (params.token) {
6776
- try {
6777
- const couch = await __.rpi.get_app_couch(req.body.app_id);
6778
- const session_doc = await couch.get(req.body.app_token);
6779
- ret.session_stat = session_doc.stat;
6780
- } catch (error) {}
6781
- }
6782
- } catch (error) {
6783
- debugger;
6784
- }
6785
- },
6786
- return_rpi_request_from_studio: function (params) {
6787
- var SESSION_ID = params.session_id;
6788
- function emitCustomEvent(eventName, detail) {
6789
- const event = new CustomEvent(eventName, { detail });
6790
- self.dispatchEvent(event);
6791
- }
6792
- emitCustomEvent('rpi_request_response_worker_' + params.table_id, {
6793
- data: params.data,
6794
- });
6795
- },
6796
- };
6797
-
6798
- func.utils.set_callback_queue = function (SESSION_ID, func) {
6799
- var t = new Date().valueOf().toString() + Math.random().toString();
6800
- try {
6801
- WEB_WORKER_CALLBACK_QUEUE[SESSION_ID][t] = func;
6802
- } catch (e) {
6803
- console.error(id);
6804
- func.utils.remove_cached_objects(SESSION_ID);
6805
- }
6806
- return t;
6807
- };
6808
- func.utils.get_callback_queue = function (SESSION_ID, t) {
6809
- var func = WEB_WORKER_CALLBACK_QUEUE[SESSION_ID][t];
6810
- setTimeout(function () {
6811
- if (WEB_WORKER_CALLBACK_QUEUE[SESSION_ID][t]) delete WEB_WORKER_CALLBACK_QUEUE[SESSION_ID][t];
6812
- }, 1000);
6813
- return func;
6814
- };
6815
-
6816
- func.utils.clean_stringify_null = function (key, value) {
6817
- // Filtering out properties
6818
- if (value === null) {
6819
- return undefined;
6820
- }
6821
- return value;
6822
- };
6823
-
6824
- func.utils.load_js_on_demand = async function (js_src, type) {
6825
- const get_script = function (callback) {
6826
- function getScript(scriptUrl, callback) {
6827
- const script = document.createElement('script');
6828
- script.src = scriptUrl;
6829
- if (type) script.type = type;
6830
- script.onload = callback;
6831
-
6832
- document.head.appendChild(script);
6833
- }
6834
- if (glb.IS_WORKER) {
6835
- callback(script);
6836
- return;
6837
- }
6838
- function isScriptLoaded(src) {
6839
- return GLB_JS_SCRIPTS_LOADED.includes(src);
6840
- }
6841
-
6842
- if (isScriptLoaded(js_src)) {
6843
- callback(false);
6844
- } else {
6845
- getScript(js_src, function (response, status) {
6846
- // console.log(response,status)
6847
- callback(true);
6848
- GLB_JS_SCRIPTS_LOADED.push(js_src);
6849
- });
6850
- }
6851
- };
6852
-
6853
- return new Promise((resolve) => {
6854
- get_script(resolve);
6855
- });
6856
- };
6857
-
6858
- func.utils.load_css_on_demand = function (css_href) {
6859
- function isCssLoaded(src) {
6860
- try {
6861
- return document.querySelector('link[href="' + src + '"]') ? true : false;
6862
- } catch (err) {
6863
- console.warn(`load css ${css_href} failed`);
6864
- return true;
6865
- }
6866
- }
6867
-
6868
- if (isCssLoaded(css_href)) {
6869
- return;
6870
- }
6871
- return $('<link/>', {
6872
- rel: 'stylesheet',
6873
- type: 'text/css',
6874
- href: css_href,
6875
- }).prependTo('head');
6876
- };
6877
-
6878
- func.utils.remove_js_css_file = function (filename, filetype) {
6879
- var targetelement = filetype == 'js' ? 'script' : filetype == 'css' ? 'link' : 'none'; //determine element type to create nodelist from
6880
- var targetattr = filetype == 'js' ? 'src' : filetype == 'css' ? 'href' : 'none'; //determine corresponding attribute to test for
6881
- var allsuspects = document.getElementsByTagName(targetelement);
6882
- for (var i = allsuspects.length; i >= 0; i--) {
6883
- //search backwards within node list for matching elements to remove
6884
- if (allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(targetattr).indexOf(filename) != -1) allsuspects[i].parentNode.removeChild(allsuspects[i]); //remove element by calling parentNode.removeChild()
6885
- }
6886
- };
6887
-
6888
- func.utils.replace_studio_drive_url = function (SESSION_ID, val) {
6889
- var _session = SESSION_OBJ[SESSION_ID];
6890
- if (!_session.is_deployment) return val;
6891
- try {
6892
- return val.replaceAll(`https://xuda.io/studio-drive/${APP_OBJ[_session.app_id].app_replicate}`, `https://${_session.domain}/studio-drive/${APP_OBJ[_session.app_id].app_replicate}`);
6893
- } catch (err) {
6894
- return val;
6895
- }
6896
- };
6897
-
6898
- func.utils.get_drive_url = function (SESSION_ID, val, wrap) {
6899
- // wrap = false; // tbd bypass
6900
-
6901
- var _session = SESSION_OBJ[SESSION_ID];
6902
- function replaceFiletoURL(fileString) {
6903
- const _app = APP_OBJ[_session.app_id];
6904
-
6905
- let url = `https://${_session.domain}/workspace-drive/${_app.is_deployment ? _app.app_datacenter_id : _app.app_id_reference}/`;
6906
-
6907
- let FILE_REPLACE_URL = `${url}${val}`;
6908
-
6909
- if (!_app.is_deployment) {
6910
- // the deployment server will handle the app_token
6911
- FILE_REPLACE_URL += `?app_token=${_session.app_token}`;
6912
- }
6913
-
6914
- let match = `drv_${_app.app_replicate || _session.app_id}_[0-9a-f\\-]+\\.[a-zA-Z0-9]+`;
6915
-
6916
- let pat = new RegExp(match, 'g');
6917
- let URLString = fileString.replace(pat, function (match, idx) {
6918
- // debugger;
6919
- const hasURLbefore = fileString.substring(idx - url.length, idx) === url;
6920
-
6921
- if (hasURLbefore) {
6922
- return match;
6923
- }
6924
-
6925
- return FILE_REPLACE_URL.replace('{val}', match);
6926
- });
6927
-
6928
- return URLString;
6929
- }
6930
-
6931
- if (typeof val === 'string' || typeof val === 'object') {
6932
- if (typeof val === 'string') {
6933
- if (val.includes('.') && val.includes('drv_') && val.length > 30) {
6934
- var ret = replaceFiletoURL(val);
6935
- if (wrap) {
6936
- return { value: '"' + ret + '"', changed: true };
6937
- } else {
6938
- return { value: ret, changed: true };
6939
- }
6940
- } else {
6941
- return { value: val, changed: false };
6942
- }
6943
- }
6944
-
6945
- if (typeof val === 'object') {
6946
- let str = JSON.stringify(val);
6947
- if (str.includes('.') && str.includes('drv_') && str.length > 30) {
6948
- let new_val = replaceFiletoURL(str);
6949
-
6950
- return { value: new_val, changed: true };
6951
- } else {
6952
- return { value: val, changed: false };
6953
- }
6954
- }
6955
- } else {
6956
- return { value: val, changed: false };
6957
- }
6958
- };
6959
-
6960
- func.utils.debug_report = async function (SESSION_ID, sourceP, msgP, typeP, errP, objP) {
6961
- var _session = SESSION_OBJ[SESSION_ID];
6962
- var details = [sourceP];
6963
- if (errP) details.push(errP);
6964
- if (objP) details.push(objP);
6965
- if (!typeP || typeP === 'E') {
6966
- setTimeout(() => {
6967
- // if (
6968
- // typeof IS_DOCKER === "undefined" &&
6969
- // typeof IS_API_SERVER === "undefined" &&
6970
- // typeof IS_PROCESS_SERVER === "undefined" &&
6971
- // !glb?.IS_WORKER
6972
- // ) {
6973
- // func.index.delete_pouch(SESSION_ID);
6974
- // }
6975
- }, 1000);
6976
-
6977
- // // temp inactive cause to loop
6978
-
6979
- // func.utils.alerts.invoke(
6980
- // SESSION_ID,
6981
- // "system_msg",
6982
- // "SYS_MSG_1240",
6983
- // "debug",
6984
- // null,
6985
- // msgP,
6986
- // sourceP //arguments.callee.caller.toString()- deprecated es6
6987
- // );
6988
- console.error('XUDA', 'ERROR', sourceP, msgP, details);
6989
-
6990
- if (typeof IS_API_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
6991
- return __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id, 'error', 'worker', 'runtime', msgP, null, objP, sourceP);
6992
- }
6993
-
6994
- if (glb.IS_WORKER) {
6995
- let obj = {
6996
- service: 'write_log',
6997
- data: msgP,
6998
- log_type: 'error',
6999
- id: STUDIO_WEBSOCKET_CONNECTION_ID,
7000
- uid: _session.USR_OBJ._id,
7001
- source: 'runtime',
7002
- app_id: _session.app_id,
7003
- gtp_token: _session.gtp_token,
7004
- app_token: _session.app_token,
7005
- };
7006
-
7007
- return func.utils.post_back_to_client(SESSION_ID, 'write_log', _session.worker_id, obj);
7008
- }
7009
-
7010
- // // temp inactive cause to loop
7011
- // if (!glb.IS_WORKER) {
7012
- // await func.common.db(SESSION_ID, "write_log", {
7013
- // client_id: _session?.SYS_GLOBAL_OBJ_CLIENT_INFO?.fingerprint,
7014
- // source: sourceP,
7015
- // log_type: "error",
7016
- // msg: msgP,
7017
- // });
7018
- // }
7019
- }
7020
- if (typeP === 'W') console.warn('XUDA', 'WARNING', msgP, details);
7021
- if (typeP === 'I') console.log('XUDA', 'INFO', msgP, details);
7022
- };
7023
-
7024
- func.utils.request_error = function (SESSION_ID, type, e) {
7025
- var _session = SESSION_OBJ[SESSION_ID];
7026
- console.error(type, e);
7027
- if (typeof IS_PROCESS_SERVER !== 'undefined') return;
7028
- if (!glb.IS_WORKER) {
7029
- func.utils.debug_report(SESSION_ID, type, e, 'E');
7030
- setTimeout(function () {
7031
- if (!glb.debug_js) {
7032
- // location.reload();
7033
- console.warn('** reload request');
7034
- }
7035
- }, 2000);
7036
- } else {
7037
- func.utils.post_back_to_client(SESSION_ID, 'ajax_error', _session.worker_id, null);
7038
- }
7039
- };
7040
-
7041
- func.utils.alerts = {};
7042
- func.utils.alerts.invoke = async function (SESSION_ID, typeP, paramsP, sourceP, dsSessionP, msgP) {
7043
- try {
7044
- var _session = SESSION_OBJ[SESSION_ID];
7045
- if (ALERT_IS_ACTIVE) return;
7046
- ALERT_IS_ACTIVE = true;
7047
- var title;
7048
- var message = '';
7049
- var alert_type = 'console';
7050
- var alertDisplay;
7051
- var expRet = {};
7052
- var _ds = _session.DS_GLB[dsSessionP];
7053
- var type = '';
7054
- var createLog;
7055
-
7056
- const get_alert_properties = async function (value, fx) {
7057
- var ret = value || '';
7058
-
7059
- if (fx) {
7060
- const exp_ret = await func.expression.get(SESSION_ID, fx, dsSessionP, 'alert');
7061
- ret = exp_ret.result;
7062
- }
7063
-
7064
- return ret;
7065
- };
7066
-
7067
- switch (typeP) {
7068
- case 'alert':
7069
- type = 'User defined alert';
7070
-
7071
- title = await get_alert_properties(paramsP.alertTitle, paramsP.alertTitleFx);
7072
- alert_type = await get_alert_properties(paramsP.alertType, paramsP.alertTypeFx);
7073
- message = await get_alert_properties(paramsP.alertBody, paramsP.alertBodyFx);
7074
- alertDisplay = await get_alert_properties(paramsP.alertDisplay, paramsP.alertDisplayFx);
7075
- createLog = paramsP.createLog;
7076
- break;
7077
-
7078
- case 'call_alert':
7079
- type = 'User defined call alert';
7080
- let prop = await func.utils.TREE_OBJ.get(SESSION_ID, paramsP.prog);
7081
- if (!prop) {
7082
- console.log('events.execute', 'Missing details for alert message object: ' + paramsP.prog, 'W');
7083
- }
7084
- // user defined
7085
-
7086
- let ret = await func.utils.VIEWS_OBJ.get(SESSION_ID, paramsP.prog);
7087
- if (ret?.alertData) {
7088
- title = await get_alert_properties(ret.alertData.alertTitle, ret.alertData.alertTitleFx);
7089
- alert_type = await get_alert_properties(ret.alertData.alertType, ret.alertData.alertTypeFx);
7090
- message = await get_alert_properties(ret.alertData.alertBody, ret.alertData.alertBodyFx);
7091
- alertDisplay = await get_alert_properties(ret.alertData.alertDisplay, ret.alertData.alertDisplayFx);
7092
- createLog = ret.alertData.createLog;
7093
- }
7094
-
7095
- if (!title) {
7096
- title = prop.menuTitle;
7097
- }
7098
- if (!alert_type) {
7099
- alert_type = 'console';
7100
- }
7101
-
7102
- if (!alertDisplay) {
7103
- alertDisplay = 'modal';
7104
- } //window alert by definition
7105
-
7106
- break;
7107
-
7108
- case 'system_msg': {
7109
- type = 'System alert';
7110
- const sys_alerts_obj = func.utils.get_system_error_msg();
7111
- if (sys_alerts_obj[paramsP]) {
7112
- title = sys_alerts_obj[paramsP].subject;
7113
- alert_type = sys_alerts_obj[paramsP].alert_type;
7114
- alertDisplay = sys_alerts_obj[paramsP].alertDisplay;
7115
-
7116
- expRet = await func.expression.get(SESSION_ID, sys_alerts_obj[paramsP].msg, dsSessionP, 'alert');
7117
- message = func.expression.remove_quotes(expRet.result);
7118
-
7119
- if (msgP) message = msgP;
7120
-
7121
- if (alert_type === 'error') {
7122
- if (_ds) _ds.error = title + ' ' + sourceP;
7123
- func.utils.debug_report(SESSION_ID, sourceP, title + ' ' + sourceP, 'E', '', _ds);
7124
- }
7125
- }
7126
- break;
7127
- }
7128
- default:
7129
- message = msgP;
7130
- break;
7131
- }
7132
- } catch (err) {
7133
- console.error(err);
7134
- ALERT_IS_ACTIVE = false;
7135
- return;
7136
- }
7137
-
7138
- if (glb.IS_WORKER) {
7139
- if (_session.IS_API) {
7140
- if (_ds) {
7141
- _ds.api_rendered_output = message;
7142
- } else {
7143
- console.error(message);
7144
- }
7145
- return;
7146
- }
7147
-
7148
- // if (typeof IS_PROCESS_SERVER !== "undefined") return;
7149
- ALERT_IS_ACTIVE = false;
7150
- return func.utils.post_back_to_client(SESSION_ID, 'alert', _session.worker_id, [SESSION_ID, alert_type, alertDisplay, message, title]);
7151
- }
7152
- // const sys_alerts_obj = func.utils.get_system_error_msg();
7153
- // if (sys_alerts_obj[paramsP]) {
7154
- // var str = paramsP + " " + title + " " + message;
7155
- // if (sys_alerts_obj[paramsP].alert_type === "error") {
7156
- // console.error(str);
7157
- // } else if (sys_alerts_obj[paramsP].alert_type === "warning") {
7158
- // console.warn(str);
7159
- // } else {
7160
- // console.log(str);
7161
- // }
7162
- // } else {
7163
- // console.log(str);
7164
- // }
7165
-
7166
- ALERT_IS_ACTIVE = false;
7167
-
7168
- func.utils.alerts.execute(SESSION_ID, alert_type, alertDisplay, message, title, type);
7169
- if (createLog) {
7170
- func.utils.write_log(SESSION_ID, title, message, alert_type);
7171
- }
7172
- };
7173
- func.utils.alerts.execute = function (SESSION_ID, alert_type, alertDisplay, message, title, type) {
7174
- if (!UI_FRAMEWORK_INSTALLED) {
7175
- ALERT_IS_ACTIVE = false;
7176
- if (alertDisplay !== 'console') {
7177
- return alert(title + '\n \n' + message);
7178
- }
7179
- return console[alert_type === 'error' ? 'error' : 'log'](alert_type, title, message);
7180
- }
7181
-
7182
- switch (alertDisplay) {
7183
- case 'console':
7184
- console[alert_type === 'success' ? 'log' : alert_type === 'warning' ? 'warn' : alert_type](alert_type, title, message);
7185
- ALERT_IS_ACTIVE = false;
7186
- break;
7187
-
7188
- case 'modal':
7189
- func.utils.alerts.popup(title, message, alert_type);
7190
- break;
7191
-
7192
- case 'toast':
7193
- func.utils.alerts.toast(SESSION_ID, title, message, alert_type);
7194
- ALERT_IS_ACTIVE = false;
7195
- break;
7196
-
7197
- case 'browser':
7198
- alert(title + '\n \n' + message);
7199
- ALERT_IS_ACTIVE = false;
7200
- default:
7201
- console.log(alert_type, title, message);
7202
- ALERT_IS_ACTIVE = false;
7203
- }
7204
- };
7205
-
7206
- func.utils.alerts.toast = function (SESSION_ID, title, message, alert_type) {
7207
- if (!UI_FRAMEWORK_PLUGIN.toast) return;
7208
- const toast = new UI_FRAMEWORK_PLUGIN.toast();
7209
- toast.create(alert_type, message, title, func.common.get_url(SESSION_ID, 'dist', `runtime/images/${alert_type}_alert_ico.svg`));
7210
- ALERT_IS_ACTIVE = false;
7211
- };
7212
- func.utils.alerts.popup = function (title, message, alert_type) {
7213
- const popup = new UI_FRAMEWORK_PLUGIN.popup();
7214
-
7215
- var buttons = [
7216
- {
7217
- text: 'Ok',
7218
- role: 'cancel',
7219
- // cssClass: "primary",
7220
- handler: () => {
7221
- ALERT_IS_ACTIVE = false;
7222
- },
7223
- },
7224
- ];
7225
-
7226
- popup.create(_.upperFirst(alert_type), title, message, buttons);
7227
- };
7228
-
7229
- func.utils.get_system_error_msg = function () {
7230
- var m = {};
7231
- m['SYS_MSG_0101'] = {
7232
- alert_type: 'success',
7233
- alertDisplay: 'toast',
7234
- subject: 'Save Success',
7235
- msg: 'Settings successfully saved',
7236
- };
7237
- m['SYS_MSG_0102'] = {
7238
- alert_type: 'error',
7239
- alertDisplay: 'toast',
7240
- subject: 'Save Failed CouchDB',
7241
- msg: 'Data fail save to database',
7242
- };
7243
- m['SYS_MSG_0103'] = {
7244
- alert_type: 'error',
7245
- alertDisplay: 'toast',
7246
- subject: 'Save Failed Table Empty',
7247
- msg: 'Table empty, no fields declared',
7248
- };
7249
- m['SYS_MSG_0104'] = {
7250
- alert_type: 'error',
7251
- alertDisplay: 'toast',
7252
- subject: 'Save Failed Missing Primary Index',
7253
- msg: 'Update failed, table missing Primary index',
7254
- };
7255
- m['SYS_MSG_0105'] = {
7256
- alert_type: 'error',
7257
- alertDisplay: 'toast',
7258
- subject: 'Save Failed Table Missing',
7259
- msg: 'Table repository missing',
7260
- };
7261
- m['SYS_MSG_0106'] = {
7262
- alert_type: 'error',
7263
- alertDisplay: 'toast',
7264
- subject: 'Save Failed Record Not Exist',
7265
- msg: 'Save update failed record not exist',
7266
- };
7267
- m['SYS_MSG_0107'] = {
7268
- alert_type: 'error',
7269
- alertDisplay: 'modal',
7270
- subject: 'Save Failed Unique Key',
7271
- msg: 'Save Failed, record already exist',
7272
- };
7273
- m['SYS_MSG_0108'] = {
7274
- alert_type: 'error',
7275
- alertDisplay: 'modal',
7276
- subject: 'Error reading document',
7277
- msg: 'Save Failed, record not found',
7278
- };
7279
- m['SYS_MSG_0110'] = {
7280
- alert_type: 'warning',
7281
- alertDisplay: 'toast',
7282
- subject: 'Record Changed',
7283
- msg: 'Record changed by other user, reload to get the latest changes',
7284
- };
7285
- m['SYS_MSG_0120'] = {
7286
- alert_type: 'error',
7287
- alertDisplay: 'modal',
7288
- subject: 'Create Mode Denied',
7289
- msg: 'Create mode not allowed for this program',
7290
- };
7291
- m['SYS_MSG_0122'] = {
7292
- alert_type: 'error',
7293
- alertDisplay: 'modal',
7294
- subject: 'Modify Mode Denied',
7295
- msg: 'Modify mode not allowed for this program',
7296
- };
7297
- m['SYS_MSG_0124'] = {
7298
- alert_type: 'error',
7299
- alertDisplay: 'modal',
7300
- subject: 'Delete Mode Denied',
7301
- msg: 'Delete mode not allowed for this program',
7302
- };
7303
- m['SYS_MSG_0126'] = {
7304
- alert_type: 'error',
7305
- alertDisplay: 'modal',
7306
- subject: 'Program Read Only',
7307
- msg: 'Program set to Read Only',
7308
- };
7309
- m['SYS_MSG_0130'] = {
7310
- alert_type: 'error',
7311
- alertDisplay: 'modal',
7312
- subject: 'Error Reduce',
7313
- msg: 'Select Index to Reduce',
7314
- };
7315
- m['SYS_MSG_0201'] = {
7316
- alert_type: 'error',
7317
- alertDisplay: 'toast',
7318
- subject: 'Failed to change GUI Property',
7319
- msg: 'Failed to change GUI element property, GUI element missing',
7320
- };
7321
- m['SYS_MSG_0310'] = {
7322
- alert_type: 'error',
7323
- alertDisplay: 'toast',
7324
- subject: 'Missing Reference Parameters Out',
7325
- msg: 'Parameter out not exist in dataset',
7326
- };
7327
- m['SYS_MSG_0400'] = {
7328
- alert_type: 'error',
7329
- alertDisplay: 'modal',
7330
- subject: 'Delete Widget Folder Denied',
7331
- msg: 'The selected folder contains data, Please clean or move content to another folder',
7332
- };
7333
- m['SYS_MSG_0410'] = {
7334
- alert_type: 'error',
7335
- alertDisplay: 'toast',
7336
- subject: 'Recipient Error',
7337
- msg: 'Check recipient data',
7338
- };
7339
- m['SYS_MSG_0412'] = {
7340
- alert_type: 'error',
7341
- alertDisplay: 'modal',
7342
- subject: 'Recipient Empty',
7343
- msg: 'No recipients entered or selected',
7344
- };
7345
- m['SYS_MSG_0414'] = {
7346
- alert_type: 'error',
7347
- alertDisplay: 'modal',
7348
- subject: 'Data Save Error',
7349
- msg: 'Widget has no content',
7350
- };
7351
- m['SYS_MSG_0416'] = {
7352
- alert_type: 'error',
7353
- alertDisplay: 'modal',
7354
- subject: 'Required Field',
7355
- msg: 'Edit url field is empty',
7356
- };
7357
- m['SYS_MSG_0418'] = {
7358
- alert_type: 'error',
7359
- alertDisplay: 'modal',
7360
- subject: 'Required Field',
7361
- msg: 'Publish url field is empty',
7362
- };
7363
- m['SYS_MSG_0420'] = {
7364
- alert_type: 'error',
7365
- alertDisplay: 'modal',
7366
- subject: 'Connection Error',
7367
- msg: 'Cannot connect to mailbox',
7368
- };
7369
- m['SYS_MSG_0422'] = {
7370
- alert_type: 'success',
7371
- alertDisplay: 'modal',
7372
- subject: 'Connection Ok',
7373
- msg: 'Connection Ok :)',
7374
- };
7375
- m['SYS_MSG_0424'] = {
7376
- alert_type: 'error',
7377
- alertDisplay: 'modal',
7378
- subject: 'Connection Failed',
7379
- msg: 'Connection to POP3 failed',
7380
- };
7381
- m['SYS_MSG_0426'] = {
7382
- alert_type: 'error',
7383
- alertDisplay: 'modal',
7384
- subject: 'Connection Failed',
7385
- msg: 'SMTP Connection error, Test Email was not sent',
7386
- };
7387
- m['SYS_MSG_0430'] = {
7388
- alert_type: 'error',
7389
- alertDisplay: 'toast',
7390
- subject: 'Email Account Error',
7391
- msg: 'No email account found, Right Click Tree -> Settings->Manage Accounts -> Right click for menu options',
7392
- };
7393
- m['SYS_MSG_0440'] = {
7394
- alert_type: 'error',
7395
- alertDisplay: 'modal',
7396
- subject: 'Widget Initiation Error',
7397
- msg: 'Missing information for Link Type or Link Name',
7398
- };
7399
- m['SYS_MSG_0442'] = {
7400
- alert_type: 'error',
7401
- alertDisplay: 'modal',
7402
- subject: 'Error Init Widget',
7403
- msg: 'Missing record Id on Create Mode',
7404
- };
7405
- m['SYS_MSG_0450'] = {
7406
- alert_type: 'error',
7407
- alertDisplay: 'modal',
7408
- subject: 'Validation Failed',
7409
- msg: 'Fix fields highlight in Red',
7410
- };
7411
- m['SYS_MSG_0501'] = {
7412
- alert_type: 'error',
7413
- alertDisplay: 'modal',
7414
- subject: 'Mandatory Alert Save',
7415
- msg: 'Save action failed, Mandatory fields missing',
7416
- };
7417
-
7418
- m['SYS_MSG_0550'] = {
7419
- alert_type: 'error',
7420
- alertDisplay: 'toast',
7421
- subject: 'Illegal input number',
7422
- msg: "@SYS_GLOBAL_OBJ_ACTIVE_FIELD_INFO.nameform +' only allow numbers!'",
7423
- };
7424
- m['SYS_MSG_0610'] = {
7425
- alert_type: 'error',
7426
- alertDisplay: 'toast',
7427
- subject: 'Form Field Conflict',
7428
- msg: 'Field declared more than once for the form',
7429
- };
7430
- m['SYS_MSG_0612'] = {
7431
- alert_type: 'error',
7432
- alertDisplay: 'toast',
7433
- subject: 'Mask Error - Missing Definition',
7434
- msg: 'Missing mask definition',
7435
- };
7436
- m['SYS_MSG_0614'] = {
7437
- alert_type: 'error',
7438
- alertDisplay: 'toast',
7439
- subject: 'Mask Error - Wrong Definition',
7440
- msg: 'Wrong mask definition',
7441
- };
7442
- m['SYS_MSG_0616'] = {
7443
- alert_type: 'error',
7444
- alertDisplay: 'toast',
7445
- subject: 'Mask Error - Size Parser',
7446
- msg: 'Size parser error',
7447
- };
7448
- m['SYS_MSG_0618'] = {
7449
- alert_type: 'error',
7450
- alertDisplay: 'toast',
7451
- subject: 'Mask Error - Illegal Z switch',
7452
- msg: "Illegal 'Z' in string mask",
7453
- };
7454
- m['SYS_MSG_0620'] = {
7455
- alert_type: 'error',
7456
- alertDisplay: 'toast',
7457
- subject: 'Mask Error - Illegal N switch',
7458
- msg: "Illegal 'N' in string mask",
7459
- };
7460
- m['SYS_MSG_0622'] = {
7461
- alert_type: 'error',
7462
- alertDisplay: 'toast',
7463
- subject: 'Mask Error - Illegal + switch',
7464
- msg: "Illegal '+' in string mask",
7465
- };
7466
- m['SYS_MSG_0624'] = {
7467
- alert_type: 'error',
7468
- alertDisplay: 'toast',
7469
- subject: 'Mask Error - Illegal - switch',
7470
- msg: "Illegal '-' in string mask",
7471
- };
7472
- m['SYS_MSG_0626'] = {
7473
- alert_type: 'error',
7474
- alertDisplay: 'toast',
7475
- subject: 'Mask Error - Illegal C switch',
7476
- msg: "Illegal 'C' in string mask",
7477
- };
7478
- m['SYS_MSG_0628'] = {
7479
- alert_type: 'error',
7480
- alertDisplay: 'toast',
7481
- subject: 'Mask Error - Invalid switch',
7482
- msg: 'Invalid switch in string mask',
7483
- };
7484
- m['SYS_MSG_0630'] = {
7485
- alert_type: 'error',
7486
- alertDisplay: 'toast',
7487
- subject: 'Mask Error - Missing DOM Element',
7488
- msg: 'Missing DOM element',
7489
- };
7490
- m['SYS_MSG_0632'] = {
7491
- alert_type: 'error',
7492
- alertDisplay: 'toast',
7493
- subject: 'Mask Error - Too Big',
7494
- msg: 'Size to big, max: 15.5',
7495
- };
7496
- m['SYS_MSG_0700'] = {
7497
- alert_type: 'warning',
7498
- alertDisplay: 'console',
7499
- subject: 'Table Warning - Empty',
7500
- msg: 'Table has no content',
7501
- };
7502
- m['SYS_MSG_0702'] = {
7503
- alert_type: 'error',
7504
- alertDisplay: 'console',
7505
- subject: 'Table Error - No Fields',
7506
- msg: 'Table missing fields content',
7507
- };
7508
- m['SYS_MSG_0704'] = {
7509
- alert_type: 'warning',
7510
- alertDisplay: 'console',
7511
- subject: 'Table Warning - Not In Use',
7512
- msg: 'Table not in use by any object',
7513
- };
7514
- m['SYS_MSG_0706'] = {
7515
- alert_type: 'error',
7516
- alertDisplay: 'console',
7517
- subject: 'Table Error - No Primary Index',
7518
- msg: 'Table must have at least one index',
7519
- };
7520
- m['SYS_MSG_0708'] = {
7521
- alert_type: 'error',
7522
- alertDisplay: 'console',
7523
- subject: 'Table Error - Bad Index Name',
7524
- msg: 'Index name is invalid or cannot contain any of non word characters',
7525
- };
7526
- m['SYS_MSG_0710'] = {
7527
- alert_type: 'error',
7528
- alertDisplay: 'console',
7529
- subject: 'Table Error - Empty Index',
7530
- msg: 'Index has no keys',
7531
- };
7532
- m['SYS_MSG_0712'] = {
7533
- alert_type: 'error',
7534
- alertDisplay: 'console',
7535
- subject: 'Table Error - Key Not Exist',
7536
- msg: 'Key not exist in the table fields repository',
7537
- };
7538
- m['SYS_MSG_0714'] = {
7539
- alert_type: 'error',
7540
- alertDisplay: 'console',
7541
- subject: 'Table Error - Duplicate Fields',
7542
- msg: 'Duplicate fields in the table fields repository',
7543
- };
7544
- m['SYS_MSG_0716'] = {
7545
- alert_type: 'error',
7546
- alertDisplay: 'console',
7547
- subject: 'Table Error - Bad Field Name',
7548
- msg: 'Field name is invalid or cannot contain any of non word characters',
7549
- };
7550
- m['SYS_MSG_0718'] = {
7551
- alert_type: 'error',
7552
- alertDisplay: 'console',
7553
- subject: 'Table Error - Integrity Broken',
7554
- msg: 'Field broken from its properties, edit the field and save',
7555
- };
7556
- m['SYS_MSG_0720'] = {
7557
- alert_type: 'error',
7558
- alertDisplay: 'console',
7559
- subject: 'Table Error - Model Not Exist',
7560
- msg: 'Model assigned to the field not exist',
7561
- };
7562
- m['SYS_MSG_0722'] = {
7563
- alert_type: 'warning',
7564
- alertDisplay: 'console',
7565
- subject: 'Object Warning - Not In Use',
7566
- msg: 'Object not in use or not call by any object',
7567
- };
7568
- m['SYS_MSG_0724'] = {
7569
- alert_type: 'error',
7570
- alertDisplay: 'console',
7571
- subject: 'Object Error - Table Not Exist',
7572
- msg: 'Table assigned in object datasource not exist',
7573
- };
7574
- m['SYS_MSG_0726'] = {
7575
- alert_type: 'error',
7576
- alertDisplay: 'console',
7577
- subject: 'Object Error - Index Keys Mismatch',
7578
- msg: 'Table index has different structure',
7579
- };
7580
- m['SYS_MSG_0728'] = {
7581
- alert_type: 'error',
7582
- alertDisplay: 'console',
7583
- subject: 'Object Error - Index Key From Empty',
7584
- msg: 'Index key From must have a value',
7585
- };
7586
- m['SYS_MSG_0730'] = {
7587
- alert_type: 'error',
7588
- alertDisplay: 'console',
7589
- subject: 'Object Error - Index Key From Reference',
7590
- msg: 'Field reference not exist in any dataset or parameters',
7591
- };
7592
- m['SYS_MSG_0732'] = {
7593
- alert_type: 'error',
7594
- alertDisplay: 'console',
7595
- subject: 'Object Error - Index Key To Empty',
7596
- msg: 'Index key To must have a value',
7597
- };
7598
- m['SYS_MSG_0734'] = {
7599
- alert_type: 'error',
7600
- alertDisplay: 'console',
7601
- subject: 'Object Error - Index Key To Reference',
7602
- msg: 'Field reference not exist in any dataset or parameters',
7603
- };
7604
- m['SYS_MSG_0736'] = {
7605
- alert_type: 'error',
7606
- alertDisplay: 'console',
7607
- subject: 'Object Error - Index Locate From Reference',
7608
- msg: 'Field reference not exist in any dataset or parameters',
7609
- };
7610
- m['SYS_MSG_0738'] = {
7611
- alert_type: 'error',
7612
- alertDisplay: 'console',
7613
- subject: 'Object Error - Index Locate To Reference',
7614
- msg: 'Field reference not exist in any dataset or parameters',
7615
- };
7616
- m['SYS_MSG_0740'] = {
7617
- alert_type: 'error',
7618
- alertDisplay: 'console',
7619
- subject: 'Object Error - Index Empty',
7620
- msg: 'Index empty - no keys defined',
7621
- };
7622
- m['SYS_MSG_0742'] = {
7623
- alert_type: 'error',
7624
- alertDisplay: 'console',
7625
- subject: 'Object Error - Index Reference',
7626
- msg: 'Table index reference error',
7627
- };
7628
- m['SYS_MSG_0744'] = {
7629
- alert_type: 'error',
7630
- alertDisplay: 'console',
7631
- subject: 'Object Error - Duplicate Fields',
7632
- msg: 'Duplicate fields in the dataset fields repository',
7633
- };
7634
- m['SYS_MSG_0746'] = {
7635
- alert_type: 'error',
7636
- alertDisplay: 'console',
7637
- subject: 'Object Error - Field reference error',
7638
- msg: 'Field not exist in datasource table fields repository',
7639
- };
7640
- m['SYS_MSG_0748'] = {
7641
- alert_type: 'error',
7642
- alertDisplay: 'console',
7643
- subject: 'Object Error - Mismatch Reference Type',
7644
- msg: 'Mismatch in calling reference type',
7645
- };
7646
- m['SYS_MSG_0750'] = {
7647
- alert_type: 'error',
7648
- alertDisplay: 'console',
7649
- subject: 'Object Error - Reference Broken',
7650
- msg: 'Reference broken calling object not exist',
7651
- };
7652
- m['SYS_MSG_0752'] = {
7653
- alert_type: 'error',
7654
- alertDisplay: 'console',
7655
- subject: 'Object Error - Empty Reference',
7656
- msg: 'Reference empty',
7657
- };
7658
- m['SYS_MSG_0754'] = {
7659
- alert_type: 'error',
7660
- alertDisplay: 'console',
7661
- subject: 'Object Error - Action Not Exist',
7662
- msg: 'Action not exist',
7663
- };
7664
- m['SYS_MSG_0756'] = {
7665
- alert_type: 'error',
7666
- alertDisplay: 'console',
7667
- subject: 'Object Error - Empty Event Reference',
7668
- msg: 'Empty event reference',
7669
- };
7670
- m['SYS_MSG_0758'] = {
7671
- alert_type: 'error',
7672
- alertDisplay: 'console',
7673
- subject: 'Object Error - Bad Field Name',
7674
- msg: 'Field name is invalid or cannot contain any of non word characters',
7675
- };
7676
- m['SYS_MSG_0760'] = {
7677
- alert_type: 'error',
7678
- alertDisplay: 'console',
7679
- subject: 'Object Error - Integrity Broken',
7680
- msg: 'Field broken from its properties, edit the object and save',
7681
- };
7682
- m['SYS_MSG_0762'] = {
7683
- alert_type: 'error',
7684
- alertDisplay: 'console',
7685
- subject: 'Object Error - Model Not Exist',
7686
- msg: 'Model assigned to the field not exist',
7687
- };
7688
- m['SYS_MSG_0764'] = {
7689
- alert_type: 'error',
7690
- alertDisplay: 'console',
7691
- subject: 'Object Error - Empty Dataset',
7692
- msg: 'Dataset empty from fields',
7693
- };
7694
- m['SYS_MSG_0766'] = {
7695
- alert_type: 'error',
7696
- alertDisplay: 'console',
7697
- subject: 'Object Error - Field Type Mismatch',
7698
- msg: 'Field type not match to the underlined table field definition',
7699
- };
7700
- m['SYS_MSG_0768'] = {
7701
- alert_type: 'error',
7702
- alertDisplay: 'console',
7703
- subject: 'Object Error - Field Mask Mismatch',
7704
- msg: 'Field masks not match to the underlined table field definition',
7705
- };
7706
- m['SYS_MSG_0770'] = {
7707
- alert_type: 'error',
7708
- alertDisplay: 'console',
7709
- subject: 'Object Error - Bad Event Name',
7710
- msg: 'Event name is invalid or cannot contain any of non word characters',
7711
- };
7712
- m['SYS_MSG_0772'] = {
7713
- alert_type: 'error',
7714
- alertDisplay: 'console',
7715
- subject: 'Object Error - UI Field Not Exist',
7716
- msg: 'UI Field not exist in the dataset repository',
7717
- };
7718
- m['SYS_MSG_0774'] = {
7719
- alert_type: 'error',
7720
- alertDisplay: 'console',
7721
- subject: 'Object Error - UI Field Reference Broken',
7722
- msg: 'UI Field reference broken',
7723
- };
7724
- m['SYS_MSG_0780'] = {
7725
- alert_type: 'error',
7726
- alertDisplay: 'toast',
7727
- subject: 'UI element error',
7728
- msg: 'UI element not exist',
7729
- };
7730
-
7731
- m['SYS_MSG_1210'] = {
7732
- alert_type: 'error',
7733
- alertDisplay: 'modal',
7734
- subject: 'Program error',
7735
- msg: 'Program not exist',
7736
- };
7737
- m['SYS_MSG_1220'] = {
7738
- alert_type: 'error',
7739
- alertDisplay: 'modal',
7740
- subject: 'Program error',
7741
- msg: 'Non grid output defined',
7742
- };
7743
-
7744
- m['SYS_MSG_1240'] = {
7745
- alert_type: 'error',
7746
- alertDisplay: 'toast',
7747
- subject: 'Debug error',
7748
- msg: '',
7749
- };
7750
- m['SYS_MSG_1250'] = {
7751
- alert_type: 'error',
7752
- alertDisplay: 'toast',
7753
- subject: 'Debug log error',
7754
- msg: '',
7755
- };
7756
- m['SYS_MSG_1260'] = {
7757
- alert_type: 'error',
7758
- alertDisplay: 'toast',
7759
- subject: 'Session Expired',
7760
- msg: 'Renew token session in Studio',
7761
- };
7762
- return m;
7763
- };
7764
-
7765
- func.utils.find_key_in_ViewUITreeObj = function (arr, key, val) {
7766
- return arr.reduce((a, item) => {
7767
- if (a) return a;
7768
- if (item[key] === val) return item;
7769
- if (item.children) return findId(val, item.children);
7770
- }, null);
7771
- };
7772
-
7773
- func.utils.get_plugin_setup = function (SESSION_ID, plugin_name) {
7774
- const report_error = function (descP, warn) {
7775
- func.utils.debug.log(SESSION_ID, plugin_name, {
7776
- module: 'plugin',
7777
- action: 'Init',
7778
- source: 'get_plugin_setup',
7779
- prop: descP,
7780
- details: descP,
7781
- result: null,
7782
- error: warn ? false : true,
7783
- fields: null,
7784
- type: 'plugin',
7785
- });
7786
- };
7787
-
7788
- return new Promise(async (resolve, reject) => {
7789
- try {
7790
- const db = await func.utils.connect_pouchdb(SESSION_ID);
7791
-
7792
- try {
7793
- let ret = await db.get(`cache_plugin_setup_${plugin_name}`);
7794
- return resolve(ret.data);
7795
- } catch (err) {
7796
- // cache not found
7797
- const json = await func.common.db(SESSION_ID, 'get_plugin_setup', {
7798
- plugin_name,
7799
- });
7800
- if (json.code < 0) {
7801
- report_error('Error: ' + json.data, json.error_type === 'W' ? true : false);
7802
- }
7803
- resolve(json);
7804
-
7805
- var doc = {
7806
- _id: `cache_plugin_setup_${plugin_name}`,
7807
- data: json,
7808
- docType: 'cache_plugin',
7809
- };
7810
- db.put(doc);
7811
- }
7812
- } catch (e) {
7813
- console.error(e);
7814
-
7815
- report_error('Error: ' + e.msg, e.error_type === 'W' ? true : false);
7816
- resolve(e.msg);
7817
- }
7818
- });
7819
- };
7820
-
7821
- func.utils.connect_pouchdb = async function (SESSION_ID) {
7822
- const app_id = SESSION_OBJ[SESSION_ID].app_id;
7823
- return new PouchDB('xuda_rt_' + app_id);
7824
- };
7825
-
7826
- // func.utils.validate_pouchdb = async function (SESSION_ID) {
7827
- // const app_id = SESSION_OBJ[SESSION_ID].app_id;
7828
- // const db = new PouchDB("xuda_rt_" + app_id);
7829
- // // db.info()
7830
- // // .then((info) => {
7831
- // // console.log("Database exists", info);
7832
- // // })
7833
- // // .catch((error) => {
7834
- // // if (error.status === 404) {
7835
- // // throw new Error("Database does not exist");
7836
- // // } else {
7837
- // // throw new Error("Error accessing database", error);
7838
- // // }
7839
- // // });
7840
-
7841
- // try {
7842
- // let ret = await db.get(`cache_rt_info`);
7843
- // } catch (error) {
7844
- // throw new Error("new pouch detect");
7845
- // }
7846
- // };
7847
-
7848
- func.utils.call_plugin_api = function (SESSION_ID, plugin_nameP, dataP) {
7849
- var _session = SESSION_OBJ[SESSION_ID];
7850
-
7851
- const report_error = function (descP, warn) {
7852
- func.utils.debug.log(SESSION_ID, plugin_nameP, {
7853
- module: 'plugin',
7854
- action: 'Init',
7855
- source: 'call_plugin_api',
7856
- prop: descP,
7857
- details: descP,
7858
- result: null,
7859
- error: warn ? false : true,
7860
- fields: null,
7861
- type: 'plugin',
7862
- });
7863
- };
7864
- return new Promise(async (resolve) => {
7865
- var data = {
7866
- app_id: APP_OBJ[_session.app_id]._id,
7867
- debug: glb.DEBUG_MODE,
7868
- uid: _session.USR_OBJ._id,
7869
- gtp_token: _session.gtp_token,
7870
- app_token: _session.app_token,
7871
- };
7872
-
7873
- data = _.assignIn(data, dataP);
7874
-
7875
- fetch(`https://xuda.io/ppi/${plugin_nameP}`, {
7876
- method: 'POST',
7877
- headers: {
7878
- Accept: 'application/json',
7879
- 'Content-Type': 'application/json',
7880
- },
7881
- body: JSON.stringify(data),
7882
- })
7883
- .then((response) => {
7884
- if (!response.ok) {
7885
- return response.text().then((text) => {
7886
- throw new Error(text);
7887
- });
7888
- }
7889
- return response.json();
7890
- })
7891
- .then((json) => {
7892
- if (json.code < 0) {
7893
- report_error('Error: ' + json.data, json.error_type === 'W' ? true : false);
7894
- }
7895
- resolve(json.data);
7896
-
7897
- // var doc = {
7898
- // _id: `cache_plugin_${plugin_nameP}`,
7899
- // data: json,
7900
- // docType: "cache_plugin",
7901
- // };
7902
- // db.put(doc);
7903
- })
7904
- .catch((err) => {
7905
- report_error('Error: ' + err.message);
7906
- resolve(err.message);
7907
- });
7908
- // }
7909
- });
7910
- };
7911
-
7912
- func.utils.get_plugin_resource = function (SESSION_ID, plugin_name, plugin_resource) {
7913
- var _session = SESSION_OBJ[SESSION_ID];
7914
-
7915
- const get_path = function (resource) {
7916
- if (_session.worker_type === 'Dev') {
7917
- return `../../plugins/${plugin_name}/${resource}`;
7918
- }
7919
- if (typeof IS_PROCESS_SERVER !== 'undefined') {
7920
- return `${_conf.plugins_drive_path}/${_session.app_id}/node_modules/${plugin_name}/${resource}`;
7921
- } else {
7922
- // return `./node_modules/${plugin_name}/${resource}?app_id=${_session.app_id}`;
7923
- return `https://${_session.domain}/plugins/${plugin_name}/${resource}?app_id=${_session.app_id}`;
7924
- }
7925
- };
7926
-
7927
- return new Promise(async (resolve, reject) => {
7928
- // const db = await func.utils.connect_pouchdb(SESSION_ID);
7929
-
7930
- // try {
7931
- // if (_session.worker_type === "Dev") throw "bypass cache";
7932
-
7933
- // let ret = await db.get(`cache_plugin_${plugin_name}_${plugin_resource}`);
7934
- // return resolve(ret.data);
7935
- // } catch (err) {
7936
- // try {
7937
- // const plugin_resource_res = await import(
7938
- // `${get_path(plugin_resource)}`
7939
- // );
7940
- // resolve(plugin_resource_res);
7941
-
7942
- // // var doc = {
7943
- // // _id: `cache_plugin_${plugin_name}_${plugin_resource}`,
7944
- // // data: JSON.stringify(plugin_resource_res),
7945
- // // docType: "cache_plugin",
7946
- // // };
7947
- // // db.put(doc);
7948
- // } catch (err) {
7949
- // console.error(err);
7950
- // }
7951
- // }
7952
-
7953
- try {
7954
- const plugin_resource_res = await import(`${get_path(plugin_resource)}`);
7955
- resolve(plugin_resource_res);
7956
- } catch (err) {
7957
- console.error(err);
7958
- reject();
7959
- }
7960
- });
7961
- };
7962
-
7963
- func.utils.remove_cached_objects = async function (SESSION_ID) {
7964
- if (typeof IS_DOCKER !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') return;
7965
- try {
7966
- const db = await func.utils.connect_pouchdb(SESSION_ID);
7967
-
7968
- let opt = {
7969
- $or: [
7970
- {
7971
- docType: 'cache_objects',
7972
- },
7973
- {
7974
- docType: 'cache_plugin',
7975
- },
7976
- {
7977
- docType: 'cache_app',
7978
- },
7979
- ],
7980
- };
7981
-
7982
- const res = await db.find({ selector: opt });
7983
- for await (let val of res.docs) {
7984
- await db.remove(val);
7985
- }
7986
- } catch (err) {
7987
- return;
7988
- }
7989
- };
7990
-
7991
- func.utils.get_plugin_npm_cdn = async function (SESSION_ID, plugin_name, resource) {
7992
- const _session = SESSION_OBJ[SESSION_ID];
7993
-
7994
- const get_path = function (resource) {
7995
- if (_session.worker_type === 'Dev') {
7996
- return `../../plugins/${plugin_name}/${resource}`;
7997
- }
7998
-
7999
- return `https://${_session.domain}/plugins/${plugin_name}/${resource}?app_id=${_session.app_id}`;
8000
- };
8001
-
8002
- return get_path(resource);
8003
- };
8004
-
8005
- func.utils.write_log = async function (SESSION_ID, method = '', msg = '', log_type = 'error', source = 'runtime', details) {
8006
- const _session = SESSION_OBJ[SESSION_ID];
8007
- if (typeof IS_API_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
8008
- return __.rpi.write_log(_session.app_id, log_type, source, msg, details);
8009
- }
8010
-
8011
- await func.common.db(SESSION_ID, 'write_log', {
8012
- msg,
8013
- log_type,
8014
- source,
8015
- details,
8016
- method,
8017
- });
8018
- };
8019
-
8020
- func.utils.get_resource_filename = function (build, filename) {
8021
- if (build) {
8022
- return filename.replace(/(\.\w+)$/, `.${build}$1`);
8023
- }
8024
- return filename;
8025
- };
8026
-
8027
- func.utils.set_SYS_GLOBAL_OBJ_WIDGET_INFO = async function (SESSION_ID, docP) {
8028
- var obj = _.clone(docP);
8029
- obj.date = await func.utils.get_dateTime(SESSION_ID, 'SYS_DATE', docP.date);
8030
- obj.time = await func.utils.get_dateTime(SESSION_ID, 'SYS_TIME', docP.date);
8031
-
8032
- var datasource_changes = {
8033
- [0]: {
8034
- ['data_system']: {
8035
- ['SYS_GLOBAL_OBJ_WIDGET_INFO']: obj,
8036
- },
8037
- },
8038
- };
8039
- await func.datasource.update(SESSION_ID, datasource_changes);
8040
- };
8041
-
8042
- func.utils.get_last_datasource_no = function (SESSION_ID) {
8043
- if (typeof IS_PROCESS_SERVER !== 'undefined') {
8044
- return Object.keys(SESSION_OBJ[SESSION_ID].DS_GLB).at?.(-1);
8045
- } else {
8046
- const filtered = Object.values(SESSION_OBJ[SESSION_ID].DS_GLB).filter((e) => e.tree_obj.menuType !== 'api');
8047
- return filtered?.at?.(-1)?.dsSession;
8048
- }
8049
- };
8050
- func.UI.utils = {};
6027
+ func.UI.utils = {};
8051
6028
 
8052
6029
  func.UI.utils.indicator = {};
8053
6030
  func.UI.utils.indicator.worker = {};