UNPKG

@xuda.io/runtime-bundle

Version:

The Xuda Runtime Bundle refers to a collection of scripts and libraries packaged together to provide the necessary runtime environment for executing plugins or components in the Xuda platform.

725 lines (674 loc) • 20 kB
const log_error = function ( SESSION_ID, action, descP, detailsP, warning, prog_id ) { func.utils.debug.log(SESSION_ID, log_nodeId, { module: "event", action, source: "", prop: descP, details: detailsP, result: null, error: !warning, warning: warning, fields: null, type: "event", prog_id, }); }; const get_ui_ids = function (SESSION_ID, event_prop) { if (event_prop.selector === "@_THIS") event_prop.selector = elementP; // var ui_ids = []; if (event_prop.selector_type == "tree_id") { let $elm = func.UI.utils.find_in_element_data( "xuData", $(SESSION_OBJ[SESSION_ID].root_element), "ui_id", event_prop.selector ); return [ { ui_id: event_prop.selector, tagName: $elm?.data()?.xuData?.node.tagName, //$elm[0]?.tagName?.toLowerCase(), }, ]; } return _.map( $(SESSION_OBJ[SESSION_ID].root_element).find(event_prop.selector), function (val, key) { return { ui_id: $(val)?.data()?.xuData?.ui_id, tagName: $(val)?.data()?.xuData?.node.tagName, //$(val)[0]?.tagName?.toLowerCase(), }; } ); }; const get_ui_id = async function (SESSION_ID, dsSession, event_prop, rowP) { if (event_prop.selector === "@_THIS") event_prop.selector = elementP; return await func.expression.get( SESSION_ID, event_prop.selector, dsSession, "ui_id", rowP ); }; const set_info_value = async function ( SESSION_ID, value, source, event_prop, resolve ) { var _session = SESSION_OBJ[SESSION_ID]; if (!event_prop.field_return_value) { log_error(SESSION_ID, source, " Field cannot be empty"); return; } var fieldId = event_prop.field_return_value.substr(1); if (event_prop.field_return_value.substr(0, 1) !== "@") { log_error(SESSION_ID, source, fieldId + " Field not valid"); return; } var fieldsChanged_arr = []; var rows_changed_arr = []; var returned_ds; const update_ds = async function (dsP, rowIdP) { if (!dsP || !_session.DS_GLB[dsP]) return; var _ds = _session.DS_GLB[dsP]; try { const row_idx = func.common.find_ROWID_idx(_ds, rowIdP); if (_ds.data_feed?.rows?.[row_idx]?.[fieldId]) _ds.data_feed.rows[row_idx][fieldId] = value; } catch (err) { console.error(err); } if (!fieldsChanged_arr.includes(fieldId)) fieldsChanged_arr.push(fieldId); if (!rows_changed_arr.includes(rowIdP)) rows_changed_arr.push(rowIdP); returned_ds = dsP; const _view_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, _ds.prog_id); var field_row_id = func.common.find_item_by_key( _view_obj.progFields, "field_id", fieldId )?.id; func.utils.debug.watch( SESSION_ID, _ds.prog_id + "%" + field_row_id, "view_field", "Source: " + source, value ); }; const ret = await func.datasource.get_value( SESSION_ID, fieldId, dsSession, _session.DS_GLB[dsSession].currentRecordId ); await update_ds(ret.dsSessionP, ret.currentRecordId); if (returned_ds) { var obj = { sessionChanged: returned_ds, viewType_target: _session.DS_GLB[returned_ds].viewType, rows_changed: rows_changed_arr, fieldsChanged: fieldsChanged_arr, }; await func.datasource.update(SESSION_ID, obj); resolve(); } }; const element_not_found = function ( SESSION_ID, dsP, jobNoP, alter_attr, ui_id ) { var _session = SESSION_OBJ[SESSION_ID]; if (_.isEmpty(SCREEN_BLOCKER_OBJ)) { // still busy not require alert if (_session.DS_GLB[dsP]) { log_error( SESSION_ID, "UI element not found", alter_attr + " > " + ui_id, null, _session.DS_GLB[dsP].prog_id ); } } if (jobNoP) { func.events.delete_job(SESSION_ID, jobNoP); } }; // export const create_ui_element = async function ( // SESSION_ID, // jobNoP, // refIdP, // elementP, // dsSession // ) { // var event_prop = refIdP; // var _session = SESSION_OBJ[SESSION_ID]; // var debug_info = _.cloneDeep(event_prop); // if (event_prop.append_to_selector === "@_THIS") // event_prop.append_to_selector = elementP; // var append_to_ui_id_info = await func.expression.get( // SESSION_ID, // event_prop.append_to_selector, // dsSession, // "UI_exp", // rowP // ); // var append_to_selector = append_to_ui_id_info.result; // debug_info.append_to_selector = append_to_selector; // debug_info.append_to_ui_id_info = append_to_ui_id_info; // const ui_ids = get_ui_ids(SESSION_ID, event_prop); // if (!ui_ids.length) { // return log_error( // SESSION_ID, // "create_ui_element", // "UI Element empty", // event_prop.selectornull, // _session.DS_GLB[dsSession].prog_id // ); // } // const create_element = function (val) { // return new Promise((resolve) => { // if (!val.ui_id) { // resolve(); // return; // } // func.UI.utils.get_ui_info_tree_scope_sync( // SESSION_ID, // dsSession, // val.ui_id, // event_prop.append_to_ui_type, // async function (res) { // if (!res) { // return log_error( // SESSION_ID, // "create_ui_element", // "Target UI element not found", // val.ui_id, // null, // _session.DS_GLB[dsSession].prog_id // ); // } // var render_node_obj = async function () { // if (!event_prop?.attributes) return; // var ui_id_info = await func.expression.get( // SESSION_ID, // val.ui_id, // dsSession, // "UI_exp", // rowP // ); // var obj = { // id: // new Date().valueOf().toString() + // "_" + // Math.random().toString().replace(".", ""), // data: { label: ui_id_info.result, type: "virtual" }, // props: { fieldType: "string" }, // }; // if ( // event_prop.attributes["xu-bind"] || // event_prop.attributes["xu-exp:xu-bind"] // ) { // let xuModel = // (await func.expression.get( // SESSION_ID, // event_prop.attributes.ExpXuModel, // dsSession, // "UI_exp", // rowP // ).result) || event_prop.attributes["xu-bind"]; // if (xuModel) { // const _view_obj = await func.utils.VIEWS_OBJ.get( // SESSION_ID, // _ds.prog_id // ); // let res = func.common.find_item_by_key( // _view_obj.progFields, // "field_id", // xuModel // ); // if (!res) { // _view_obj.progFields[obj.id] = obj; // event_prop.attributes["xu-bind"] = obj.id; // } // } // } // let _node = { // attributes: event_prop.attributes, // id: event_prop.ui_id, // tagName: event_prop.tag_name, // type: "element", // }; // let _key = res.$elm.data().xuData.node.children.length; // let _$div = func.UI.screen.create_container( // SESSION_ID, // null, // _node, // res.$elm, // res.$elm.data().xuData.paramsP, // {}, // jobNoP, // _key, // {}, // _node.attributes, // null, // null, // event_prop.tag_name, // null, // "" // ); // let ret = await func.UI.screen.set_attributes_new( // SESSION_ID, // null, // null, //$root_container, // _node, // res.$elm, // res.$elm.data().xuData.paramsP, // {}, // jobNoP, // _key, // {}, // _$div, // true // ); // return obj; // }; // await render_node_obj(); // resolve(); // func.utils.debug.watch( // SESSION_ID, // calling_trigger_prop?.id, // "create_ui_element", // debug_info, // "Append to: " + append_to_selector, // expCond // ); // }, // $div, // null // ); // }); // }; // await Promise.all(ui_ids.map(create_element)); // if (jobNoP) func.events.delete_job(SESSION_ID, jobNoP); // }; // export const alter_ui_element = async function ( // SESSION_ID, // jobNoP, // refIdP, // elementP, // dsSession, // rowP // ) { // var event_prop = refIdP; // var _session = SESSION_OBJ[SESSION_ID]; // var ui_id_info = await get_ui_id(SESSION_ID, dsSession, event_prop, rowP); // event_prop.selector = ui_id_info.result; // const ui_ids = get_ui_ids(SESSION_ID, event_prop); // if (!ui_ids.length) { // return log_error( // SESSION_ID, // "alter_ui_element", // "UI Element empty", // event_prop.selector, // null, // _session.DS_GLB[dsSession].prog_id // ); // } // const alter_element = function (val) { // return new Promise((resolve) => { // if (!val.ui_id) { // resolve(); // return; // } // func.UI.utils.get_ui_info_tree_scope_sync( // SESSION_ID, // dsSession, // val.ui_id, // val.tagName, // async function (res) { // var _session = SESSION_OBJ[SESSION_ID]; // if (!res) { // return element_not_found( // SESSION_ID, // dsSession, // jobNoP, // event_prop.alter_attr, // event_prop.selector // ); // } // if ( // func.UI.utils.get_ui_id_count( // SESSION_ID, // res.ds, // event_prop.selector // ) > 1 // ) { // return log_error( // SESSION_ID, // "alter_ui_element", // " UI element must be unique per program ", // event_prop.selector, // null, // _session.DS_GLB[dsSession].prog_id // ); // } // if (_.isEmpty(event_prop.attributes)) { // return log_error( // SESSION_ID, // "alter_ui_element", // " UI element property missing", // null, // _session.DS_GLB[dsSession].prog_id // ); // } // let _xuData = res.$elm.data().xuData; // let ret = await func.UI.screen.set_attributes_new( // SESSION_ID, // null, // _xuData.$root_container, // { // tagName: res.$elm?.data()?.xuData?.node.tagName, //res.$elm[0].tagName.toLowerCase(), // attributes: event_prop.attributes, // type: "element", // }, // _xuData.$container, // _xuData.paramsP, // _xuData.parent_infoP, // jobNoP, // _xuData.keyP, // _xuData.parent_nodeP, // res.$elm // ); // resolve(); // func.utils.debug.watch( // SESSION_ID, // calling_trigger_prop?.id, // "alter_ui_element", // calling_trigger_prop, // " > " + // debug_info.ui_id + // " > " + // event_prop.alter_attr + // " > " + // value, // expCond // ); // }, // $div, // null // ); // }); // }; // await Promise.all(ui_ids.map(alter_element)); // if (jobNoP) func.events.delete_job(SESSION_ID, jobNoP); // }; // export const info_ui_element = async function ( // SESSION_ID, // jobNoP, // event_prop, // elementP, // dsSession, // rowP // ) { // var _session = SESSION_OBJ[SESSION_ID]; // var debug_info = _.cloneDeep(event_prop); // var ui_id_info = await get_ui_id(SESSION_ID, dsSession, event_prop, rowP); // event_prop.selector = ui_id_info.result; // debug_info = {}; // debug_info.ui_id = ui_id_info.result; // debug_info.ui_id_info = ui_id_info; // var value = ""; // if (!event_prop.attribute) { // return log_error( // SESSION_ID, // "info_ui_element", // "UI attribute is empty", // event_prop.selector, // null, // _session.DS_GLB[dsSession].prog_id // ); // } // const ui_ids = get_ui_ids(SESSION_ID, event_prop); // if (!ui_ids.length) { // return log_error( // SESSION_ID, // "info_ui_element", // "UI Element empty", // event_prop.selector, // null, // _session.DS_GLB[dsSession].prog_id // ); // } // const info_element = function (val) { // return new Promise((resolve) => { // if (!val.ui_id) { // resolve(); // return; // } // func.UI.utils.get_ui_info_tree_scope_sync( // SESSION_ID, // dsSession, // val.ui_id, // event_prop.ui_type, // function (res) { // if (!res) { // return; // } // var _session = SESSION_OBJ[SESSION_ID]; // if ( // func.UI.utils.get_ui_id_count(SESSION_ID, res.ds, val.ui_id) > 1 // ) { // return log_error( // SESSION_ID, // "info_ui_element", // " UI element must be unique per program ", // val.ui_id, // null, // _session.DS_GLB[dsSession].prog_id // ); // } // let value = // res.$elm.data().xuData?.debug_info?.attribute_stat?.[ // event_prop.attribute.toLowerCase() // ]; // debug_info[event_prop.attribute.toLowerCase()] = { // value: value, // }; // set_info_value( // SESSION_ID, // value, // "info_ui_element", // event_prop, // resolve // ); // func.utils.debug.watch( // SESSION_ID, // calling_trigger_prop?.id, // "info_ui_element", // debug_info, // debug_info.selector + " > " + event_prop.attribute + " > " + value, // expCond // ); // }, // null, // null // ); // }); // }; // await Promise.all(ui_ids.map(info_element)); // // if (callbackP) callbackP(); // if (jobNoP) func.events.delete_job(SESSION_ID, jobNoP); // return; // func.utils.debug.watch( // SESSION_ID, // nodeIdP + "%" + event_id + "%" + eventIdP, // "info_ui_element", // debug_info, // debug_info.ui_id + " > " + event_prop.alter_attr + " > " + value, // expCond // ); // set_info_value(value, "info_ui_element", event_prop); // }; // export const remove_ui_element = async function ( // SESSION_ID, // jobNoP, // event_prop, // elementP, // dsSession, // rowP // ) { // const ui_ids = get_ui_ids(SESSION_ID, event_prop); // var _session = SESSION_OBJ[SESSION_ID]; // if (!ui_ids.length) { // return log_error( // SESSION_ID, // "remove_ui_element", // "UI Element empty", // event_prop.selector, // null, // _session.DS_GLB[dsSession].prog_id // ); // } // const remove_element = function (val) { // return new Promise((resolve) => { // if (!val.ui_id) { // resolve(); // return; // } // func.UI.utils.get_ui_info_tree_scope_sync( // SESSION_ID, // dsSession, // val.ui_id, // event_prop.ui_type, // async function (res) { // var _session = SESSION_OBJ[SESSION_ID]; // if (!res) { // return element_not_found( // SESSION_ID, // dsSession, // jobNoP, // "", // val.ui_id // ); // } // if ( // func.UI.utils.get_ui_id_count(SESSION_ID, res.ds, val.ui_id) > 1 // ) { // return log_error( // SESSION_ID, // "remove_ui_element", // " UI element must be unique per program ", // null, // _session.DS_GLB[dsSession].prog_id // ); // } // let tagName = res.$elm.data().xuData.node.tagName; // let $parent_elm; // // delete node from the parent node // if (res.$elm.data().xuPanelData) { // $parent_elm = func.UI.utils.find_in_element_data( // "xuData", // $(SESSION_OBJ[SESSION_ID].root_element), // "ui_id", // res.$elm.data().xuPanelData.parent_element_ui_id // ); // } else { // $parent_elm = func.UI.utils.find_in_element_data( // "xuData", // $(SESSION_OBJ[SESSION_ID].root_element), // "ui_id", // res.$elm.data().xuData.parent_element_ui_id // ); // } // let index = res.$elm.data().xuData.key; // $parent_elm.data().xuData.node.children.splice(index, 1); // res.$elm.remove(); // resolve(); // }, // null, // null // ); // }); // }; // await Promise.all(ui_ids.map(remove_element)); // if (jobNoP) func.events.delete_job(SESSION_ID, jobNoP); // }; // export const empty_ui_element = async function ( // SESSION_ID, // jobNoP, // event_prop, // elementP, // dsSession, // rowP // ) { // const ui_ids = get_ui_ids(SESSION_ID, event_prop); // var _session = SESSION_OBJ[SESSION_ID]; // if (!ui_ids.length) { // return log_error( // SESSION_ID, // "empty_ui_element", // "UI Element empty", // event_prop.selector, // null, // _session.DS_GLB[dsSession].prog_id // ); // } // const empty_element = function (val) { // return new Promise((resolve) => { // if (!val.ui_id) { // resolve(); // return; // } // func.UI.utils.get_ui_info_tree_scope_sync( // SESSION_ID, // dsSession, // val.ui_id, // "", // async function (res) { // var _session = SESSION_OBJ[SESSION_ID]; // if (!res) { // return element_not_found( // SESSION_ID, // dsSession, // jobNoP, // "", // val.ui_id // ); // } // if ( // func.UI.utils.get_ui_id_count(SESSION_ID, res.ds, val.ui_id) > 1 // ) { // return log_error( // SESSION_ID, // "empty_ui_element", // " UI element must be unique per program", // null, // _session.DS_GLB[dsSession].prog_id // ); // } // res.$elm.data().xuData.node.children = []; // res.$elm.empty(); // resolve(); // }, // null, // null // ); // }); // }; // await Promise.all(ui_ids.map(empty_element)); // // if (callbackP) callbackP(); // if (jobNoP) func.events.delete_job(SESSION_ID, jobNoP); // };