var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var Unibase; (function (Unibase) { let Platform; (function (Platform) { let Automation; (function (Automation) { let Components; (function (Components) { class ExecuteQuery extends Platform.Core.BaseComponent { constructor() { super(...arguments); this.RowIndex = 0; this.RuleProviderId = 0; this.AutomationMode = 0; } jsFiles() { var jsfiles = ["platform/automation/managers/rulemanager.js", "platform/automation/enums/automationmode.js", "platform/automation/components/conditions.js", "platform/automation/components/contactselection.js", "platform/automation/requests/ruleaction.js", "platform/automation/requests/rulecondition.js", "platform/forms/components/formviewer/formviewer.js", "libs/parsley/parsley.min.js", "libs/querybuilder/query-builder.min.js", "libs/querybuilder/query-builder.standalone.min.js", "libs/querybuilder/query-builder.standalone.js", "libs/querybuilder/sql-parser.min.js", "libs/notificationbuilder/notificationbuilder.js", "platform/automation/components/rulebuilder/notificationgroup.js", "platform/automation/managers/notificationgroupmanager.js" ]; return jsfiles; } cssFiles() { return []; } html(id, containerid) { let html = `
`; return html; } load(id, containerid, callback) { return __awaiter(this, void 0, void 0, function* () { var instance = this; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().ActionId = instance.ActionId; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().RuleActionData = instance.RuleActionData; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().RowIndex = instance.RowIndex; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().AutomationMode = instance.AutomationMode; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().RuleProviderId = instance.RuleProviderId; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().ParentActionId = instance.ParentActionId; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().IsAutomationMode = instance.IsAutomationMode; yield Unibase.Platform.Automation.Components.NotificationGroup.Instance().LoadNotificationGroups(); if (instance.AutomationMode == Unibase.Platform.Automation.Enums.AutomationMode.AdvancedMode) { eval('bizgaze_automation_flow_main.getcontainerid("' + containerid + '")'); } $("#btnCloseExecuteQuery").click(function () { $('#' + containerid).modal('hide'); $('#' + containerid).remove(); if (Unibase.Platform.Automation.Components.ExecuteQuery.Instance().AutomationMode == Unibase.Platform.Automation.Enums.AutomationMode.NormalMode) { if (Unibase.Platform.Automation.Components.ExecuteQuery.Instance().AutomationMode) { if (Unibase.Platform.Automation.Components.ExecuteQuery.Instance().IsAutomationMode) { Unibase.Platform.Automation.Components.Rule.Instance().ChangeAction(instance.RowIndex, id); } } } else { eval("bizgaze_automation_flow_main.getpopupclosed()"); } Unibase.Platform.Automation.Components.Conditions.conditionArray = []; }); $("#btnSaveExecuteQuery").click(function () { let appcontrolid = "frmUnibase_ExecuteQuery"; let result = Unibase.Platform.Forms.Components.FormViewer.Instance().requiredFieldValidation(appcontrolid); if (result == false) { MessageHelper.Instance().showError("Mandatory fields are missing", "Validate_ExecuteQueryAction"); return false; } else { Unibase.Platform.Automation.Components.ExecuteQuery.Instance().SaveExecuteQuery(id, containerid); } }); $("#ddl_QueryType").val(1); if (instance.ParentActionId != 0) { Unibase.Platform.Automation.Components.ContactSelection.Instance().getResultActions(instance.ParentActionId); yield Unibase.Platform.Automation.Components.ExecuteQuery.Instance().GetRuleActionInfo(Number(instance.ParentActionId)); $('#ddl_NotificationGrp').prop("disabled", true); $('#creategrp_btn').addClass('d-none'); } $('#creategrp_btn').click(function () { Unibase.Platform.Automation.Components.NotificationGroup.Instance().init(0, null, true); }); if (id != "") { setTimeout(function () { Unibase.Platform.Automation.Components.ExecuteQuery.Instance().EditExecuteQuery(id); }, 10); } let rpid = instance.RuleProviderId; if (rpid != 0) { Unibase.Platform.Automation.Components.ContactSelection.Instance().loadQueryBuilder(rpid, null); Unibase.Platform.Automation.Managers.RuleManager.Instance().getTokens(instance.RuleProviderId).then(function (response) { var Data = new Array(); for (let i = 0; i <= response.length - 1; i++) { var result = response[i]; Data.push(result); } Unibase.Platform.Automation.Components.ExecuteQuery.Instance().loadSummernote(Data); }); } if (instance.RuleActionData.length != 0) { Unibase.Platform.Automation.Components.ExecuteQuery.Instance().LoadExecuteQueryData(instance.RuleActionData); } }); } GetRuleActionInfo(parentactionid) { return __awaiter(this, void 0, void 0, function* () { yield Unibase.Platform.Automation.Managers.RuleManager.Instance().getRuleAction(parentactionid).then(function (response) { if (response != null) { var html = ''; $('#ddl_NotificationGrp').html('').html(html); } }); }); } ToggleExecuteQueryConditions() { $('#ActionConditionsDiv').toggleClass("hidden"); if ($('.conditionicon').hasClass('fa-angle-down')) { $('.conditionicon').removeClass('fa-angle-down').addClass('fa-angle-up'); Unibase.Platform.Automation.Components.ContactSelection.Instance().loadQueryBuilder(Unibase.Platform.Automation.Components.ExecuteQuery.Instance().RuleProviderId, null); } else { $('.conditionicon').removeClass('fa-angle-up').addClass('fa-angle-down'); } } Toggleadvancedoptions() { if ($('.arrowicon').hasClass('fa-angle-down')) { $('.arrowicon').removeClass('fa-angle-down').addClass('fa-angle-up'); } else { $('.arrowicon').removeClass('fa-angle-up').addClass('fa-angle-down'); } $('.Advanced_options').toggleClass("hidden"); } EditExecuteQuery(id) { let actionid = Number(id); $("#Spn_ExecuteQuery").text("Edit Execute Query"); Unibase.Platform.Automation.Managers.RuleManager.Instance().getRuleAction(actionid).then(function (response) { $("#txtExecuteQuery_RuleActionName").val(response.RuleActionName); $('#ddl_NotificationGrp option[value=' + response.NotificationGroupId + ']').prop('selected', true); if (!Unibase.Platform.Automation.Components.ExecuteQuery.Instance().IsAutomationMode) { Unibase.Platform.Automation.Components.ExecuteQuery.Instance().RuleId = response.RuleId; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().RuleEventId = response.RuleEventId; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().EventGroupId = response.EventGroupId; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().ActionId = response.ActionId; Unibase.Platform.Automation.Components.ExecuteQuery.Instance().ParentActionId = response.ParentActionId; } $("#ddl_QueryType").val(response.String4); $("#ddl_QueryType").attr("disabled", "disabled"); $('#message_result').val(Number(response.BString5)); if (response.ResultActionId != null) { $('#ddl_ResultAction').val(response.ResultActionId); } if (response.ExecuteStatusId != Number(Unibase.Platform.Automation.Enums.ExecuteActionStatus.Approved)) $("#chkAutoApprovedExecuteQuery").prop("checked", false); else $("#chkAutoApprovedExecuteQuery").prop("checked", true); if (response.BString2 == "1") { $("#chkIsAsync").prop("checked", true); } else { $("#chkIsAsync").prop("checked", false); } $('.summernote__Query').summernote("code", response.BString1); Unibase.Platform.Automation.Components.ContactSelection.Instance().loadQueryBuilder(response.RuleProviderId, response.SqlWhere); $("#btn_ActionConditions").addClass("hidden"); if (response.SqlWhere != null && response.SqlWhere != "") { $('.conditionicon').removeClass('fa-angle-down').addClass('fa-angle-up'); $("#ActionConditionsDiv").removeClass("hidden"); } eval('_floatingLabelHelper.init();'); }); } LoadExecuteQueryData(Data) { for (var i = 0; i < Data.length; i++) { $("#txtExecuteQuery_RuleActionName").val(Data[i].RuleActionName); $("#txtExecuteQuery_ApiParameter").val(Data[i].BString1); if (!Data[i].AutoApproved) $("#chkAutoApprovedExecuteQuery").prop("checked", false); else $("#chkAutoApprovedExecuteQuery").prop("checked", true); if (Data[i].BString2 == "1") { $("#chkIsAsync").prop("checked", true); } else { $("#chkIsAsync").prop("checked", false); } $('.summernote__Query').summernote("code", Data[i].BString1); if (Data[i].SqlWhere != "" && Data[i].SqlWhere != null) { Unibase.Platform.Automation.Components.ContactSelection.Instance().loadQueryBuilder(Unibase.Platform.Automation.Components.ExecuteQuery.Instance().RuleProviderId, Data[i].SqlWhere); $("#btn_ActionConditions").addClass("hidden"); $('.conditionicon').removeClass('fa-angle-down').addClass('fa-angle-up'); $("#ActionConditionsDiv").removeClass("hidden"); } eval('_floatingLabelHelper.init();'); } } SaveExecuteQuery(ExecuteQueryid, containerid) { let ruleactionid = Number(ExecuteQueryid); var contents = $('.summernote__Query').summernote('code'); var plainText = $("" + contents + "
").text(); let queryelmnt = $("#builder"); let model = new Unibase.Platform.Automation.Requests.RuleAction(); model.RuleActionId = ruleactionid; model.RuleActionName = $("#txtExecuteQuery_RuleActionName").val().toString(); model.BString1 = plainText; model.String4 = Number($("#ddl_QueryType option:selected").val()); model.BString5 = $('#message_result option:selected').val().toString(); model.ActionId = Unibase.Platform.Automation.Components.ExecuteQuery.Instance().ActionId; model.RuleId = 0; model.Users = ""; model.NotificationGroupId = $('#ddl_NotificationGrp').val() == undefined ? 0 : Number($('#ddl_NotificationGrp').val()); if (model.NotificationGroupId == 0) { MessageHelper.Instance().showError("Please Select Notification Group", "Validate_ExecuteQueryAction"); return; } let query = queryelmnt.queryBuilder('getSQL', false, true); if (query != null) { model.SqlWhere = queryelmnt.queryBuilder('getSQL', false, true).sql.replace(/\n/g, " ").replace(/LIKE/g, "ILIKE"); ; model.SqlWhereJson = JSON.stringify(queryelmnt.queryBuilder('getSQL', false, true)); } else { model.SqlWhere = ""; model.SqlWhereJson = ""; } model.ResultActionId = Number($("#ddl_ResultAction option:selected").val()); if (model.ResultActionId != 0) { model.ResultActionName = $("#ddl_ResultAction option:selected").text(); } else { model.ResultActionName = ""; } if ($('#chkIsAsync').is(':checked')) { model.BString2 = "1"; } else { model.BString2 = "0"; } model.DelayTime = 0; model.ParentActionId = Unibase.Platform.Automation.Components.ExecuteQuery.Instance().ParentActionId; model.AutoApproved = $('#chkAutoApprovedExecuteQuery').is(':checked'); model.RowIndex = Unibase.Platform.Automation.Components.ExecuteQuery.Instance().RowIndex; if (Unibase.Platform.Automation.Components.ExecuteQuery.Instance().IsAutomationMode) { if (Unibase.Platform.Automation.Components.ExecuteQuery.Instance().AutomationMode == Unibase.Platform.Automation.Enums.AutomationMode.NormalMode) { Unibase.Platform.Automation.Components.Rule.Instance().RuleActionsArray(model); $('#' + containerid).modal('hide'); $('#' + containerid).remove(); Unibase.Platform.Automation.Components.Conditions.conditionArray = []; } else { model.RuleId = eval("bizgaze_automation_flow_main.getruleid()"); Automation.Managers.RuleManager.Instance().saveRuleAction(model).then(function (response) { if (response.status == Unibase.Data.Status.Error) { MessageHelper.Instance().showError(response.message, "Validate_ExecuteQueryAction"); } else { MessageHelper.Instance().showSuccess(response.message, "Validate_ExecuteQueryAction"); $('#' + containerid).modal('hide'); $('#' + containerid).remove(); Unibase.Platform.Automation.Components.Conditions.conditionArray = []; var actionname = response.result.RuleActionName; eval("bizgaze_automation_flow_main.saveExecuteQueryblock('" + response.result.RuleActionId + "','" + actionname + "')"); } }); } } else { model.RuleId = Unibase.Platform.Automation.Components.ExecuteQuery.Instance().RuleId; model.EventGroupId = Unibase.Platform.Automation.Components.ExecuteQuery.Instance().EventGroupId; model.RuleEventId = Unibase.Platform.Automation.Components.ExecuteQuery.Instance().RuleEventId; model.ActionId = Unibase.Platform.Automation.Components.ExecuteQuery.Instance().ActionId; model.ParentActionId = Unibase.Platform.Automation.Components.ExecuteQuery.Instance().ParentActionId; Automation.Managers.RuleManager.Instance().saveRuleAction(model).then(function (response) { if (response.status == Unibase.Data.Status.Error) { MessageHelper.Instance().showError(response.message, "Validate_ExecuteQueryAction"); } else { MessageHelper.Instance().showSuccess(response.message, "Validate_ExecuteQueryAction"); $('#' + containerid).modal('hide'); $('#' + containerid).remove(); Unibase.Platform.Automation.Components.Conditions.conditionArray = []; } }); } } loadSummernote(Data) { $(".summernote__Query").summernote({ height: 100, minHeight: null, maxHeight: null, placeholder: "Query", disableDragAndDrop: true, codemirror: { mode: 'text/html', lineNumbers: true }, toolbar: [ ['font', ['bold', 'italic', 'underline']], ['color', ['color']], ['view', ['fullscreen', 'codeview', 'help']], ], hint: { match: /\B[@!](\w*)$/, search: function (keyword, callback) { callback($.grep(Data, function (i) { var user = i; return user.indexOf(keyword) === 0; })); }, content: function (i) { var user = i; return $('@' + user + '')[0]; } } }); } static Instance() { if (this.instance === undefined) { this.instance = new ExecuteQuery(); } return this.instance; } } Components.ExecuteQuery = ExecuteQuery; })(Components = Automation.Components || (Automation.Components = {})); })(Automation = Platform.Automation || (Platform.Automation = {})); })(Platform = Unibase.Platform || (Unibase.Platform = {})); })(Unibase || (Unibase = {}));