var mGlobal={} mGlobal.pyOpenRPA = {} window.onload=function() { //document.cookie = "SessionGUIDStr=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; //Render existing data //mGlobal.Monitor.fControlPanelRefresh_TechnicalRender() } $(document).ready(function() { document.cookie = "SessionGUIDStr=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; console.log("Cookie is deleted") // fix main menu to page on passing $('.main.menu').visibility({ type: 'fixed' }); $('.overlay').visibility({ type: 'fixed', offset: 80 }); // lazy load images $('.image').visibility({ type: 'image', transition: 'vertical flip in', duration: 500 }); // show dropdown on hover $('.main.menu .ui.dropdown').dropdown({ on: 'hover' }); function clone(obj) { var copy; // Handle the 3 simple types, and null or undefined if (null == obj || "object" != typeof obj) return obj; // Handle Date if (obj instanceof Date) { copy = new Date(); copy.setTime(obj.getTime()); return copy; } // Handle Array if (obj instanceof Array) { copy = []; for (var i = 0, len = obj.length; i < len; i++) { copy[i] = clone(obj[i]); } return copy; } // Handle Object if (obj instanceof Object) { copy = {}; for (var attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]); } return copy; } throw new Error("Unable to copy obj! Its type isn't supported."); } //For data storage key mGlobal["DataStorage"] = {} // Clear the session cookie String.prototype.replaceAll = function(search, replace){ return this.split(search).join(replace); } mGlobal.GeneralGenerateHTMLCodeHandlebars=function(inInnerTemplateSelector,inData) { lHTMLTemplate=$(inInnerTemplateSelector)[0].innerHTML //console.log(lHTMLTemplate) //Компиляция var template = Handlebars.compile(lHTMLTemplate); //Вставка данных var lHTMLResult = template(inData); return lHTMLResult } mGlobal.GeneralGenerateHTMLCode=function(inTemplateHTMLSelector,inItemDictionary,inKeywordPrefix="::",inKeywordPostfix="::") { ///Получить заготовку lTemplateHTMLCode=$(inTemplateHTMLSelector)[0].outerHTML ///Определить ключь экранирования специальных ключевых слов ///Выполнить циклические замены, если там есть пожходящие ключи lResultHTMLCode=lTemplateHTMLCode for(var lKey in inItemDictionary) { lHTMLKey=inKeywordPrefix+lKey+inKeywordPostfix; lResultHTMLCode=lResultHTMLCode.replaceAll(lHTMLKey,inItemDictionary[lKey]) } ///Вернуть результат return lResultHTMLCode } ////////////////////////// /////Info JS module ////////////////////////// mGlobal.Info={}; mGlobal.Info.TableActivityLogScheduleListRefresh=function() { } ////////////////////////// /////Controller JS module ////////////////////////// mGlobal.Controller={}; mGlobal.Controller.CMDRunText=function(inCMDText) { ///Подготовить конфигурацию lData = [ {"Type":"CMDStart", "Command": inCMDText} ] ///Обнулить таблицу $.ajax({ type: "POST", url: 'Utils/Processor', data: JSON.stringify(lData), success: function(lData,l2,l3){}, dataType: "text" }); } mGlobal.Controller.CMDRun=function() { ///Обнулить таблицу lCMDCode=$(".openrpa-controller-cmd-run-input")[0].value ///Подготовить конфигурацию lData = [ { "Def":"OSCMD", // def link or def alias (look gSettings["Processor"]["AliasDefDict"]) "ArgList":[], // Args list "ArgDict":{"inCMDStr":lCMDCode,"inRunAsyncBool":false}, // Args dictionary "ArgGSettings": null, // Name of GSettings attribute: str (ArgDict) or index (for ArgList) "ArgLogger": "inLogger" // Name of GSettings attribute: str (ArgDict) or index (for ArgList) } ] $.ajax({ type: "POST", url: '/pyOpenRPA/ActivityListExecute', data: JSON.stringify(lData), success: function(lData,l2,l3) { var lResponseJSON=JSON.parse(lData) ///Отправить запрос на формирование таблицы //lHTMLCode=console.log("CMDRun result: "+lResponseJSON[0].result) }, dataType: "text" }); } mGlobal.Controller.CMDRunGUILogout=function() { ///Обнулить таблицу lCMDCode="for /f \"skip=1 tokens=2\" %s in ('query user %USERNAME%') do (tscon \\dest:console)" //lCMDCode = lCMDCode.replace(/\\n/g, "\\n") // .replace(/\\'/g, "\\'") // .replace(/\\"/g, '\\"') // .replace(/\\&/g, "\\&") // .replace(/\\r/g, "\\r") // .replace(/\\t/g, "\\t") // .replace(/\\b/g, "\\b") // .replace(/\\f/g, "\\f") // .replace('"', "\\\""); ///Подготовить конфигурацию lData = [ {"Type":"CMDStart", "Command": lCMDCode } ] $.ajax({ type: "POST", url: 'Utils/Processor', data: JSON.stringify(lData), success: function(lData,l2,l3) { var lResponseJSON=JSON.parse(lData) ///Отправить запрос на формирование таблицы //lHTMLCode=console.log("CMDRun result: "+lResponseJSON[0].result) }, dataType: "text" }); } ///Restart PC mGlobal.Controller.PCRestart = function () { mGlobal.Controller.CMDRunText("shutdown -r") } ///Orchestrator save session mGlobal.Controller.OrchestratorSessionSave=function() { ///Подготовить конфигурацию lData = [ {"Type":"OrchestratorSessionSave"} ] $.ajax({ type: "POST", url: 'Utils/Processor', data: JSON.stringify(lData), success: function(lData,l2,l3) { var lResponseJSON=JSON.parse(lData) }, dataType: "text" }); } ///Перезагрузить Orchestrator mGlobal.Controller.OrchestratorRestart=function() { ///Подготовить конфигурацию lData = [ {"Type":"OrchestratorRestart"} ] $.ajax({ type: "POST", url: 'Utils/Processor', data: JSON.stringify(lData), success: function(lData,l2,l3) { var lResponseJSON=JSON.parse(lData) }, dataType: "text" }); } mGlobal.Controller.OrchestratorGITPullRestart = function() { mGlobal.Controller.OrchestratorSessionSave() //Save current RDP list session mGlobal.Controller.CMDRunText("timeout 3 & taskkill /f /im OpenRPA_Orchestrator.exe & timeout 2 & cd "+mGlobal.WorkingDirectoryPathStr+" & git reset --hard & git pull & pyOpenRPA.Orchestrator_x64_administrator_startup.cmd"); } ////////////////////////// /////Monitor JS module ////////////////////////// mGlobal.Monitor={}; mGlobal.Monitor.ScreenshotModal={}; mGlobal.Monitor.GenerateUniqueID=function(inPrefix="tempUID=") { return inPrefix+Math.round(Math.random()*1000)+"-"+Math.round(Math.random()*10000)+"-"+Math.round(Math.random()*1000) } //inHostURI: http://localhost:8081 mGlobal.Monitor.ScreenshotModal.Show=function(inHostURI=" ") { $('.ui.modal.daemon-screenshot').modal({'onHide':function (inElement) {mGlobal.Monitor.ScreenshotModal.Close();} }).modal('show'); //Функция обновления картинки lScreenshotUpdate=function() { lScreenshotSrc=inHostURI+"/GetScreenshot?"+mGlobal.Monitor.GenerateUniqueID() $(".daemon-screenshot img").attr('src', lScreenshotSrc); } mGlobal.Monitor.ScreenshotModal.timerId=setInterval(lScreenshotUpdate,1500) } mGlobal.Monitor.ScreenshotModal.Close=function() { clearInterval(mGlobal.Monitor.ScreenshotModal.timerId); } ///Monitor mGlobal.Monitor.DaemonList={} mGlobal.Monitor.DaemonList.fRefreshTable=function() { ///Загрузка данных $.ajax({ type: "GET", url: 'Monitor/JSONDaemonListGet', data: '', success: function(lData,l2,l3) { var lResponseJSON=JSON.parse(lData) ///Сформировать HTML код новой таблицы lHTMLCode=mGlobal.GeneralGenerateHTMLCodeHandlebars(".openrpa-hidden-monitor-table-general",lResponseJSON) ///Очистить дерево //mGlobal.ElementTree.fClear(); ///Прогрузить новую таблицу $(".openrpa-monitor").html(lHTMLCode) }, dataType: "text" }); } //////////////////////////////// ///////Control panel /////////////////////////////// ///Refresh control panel function sleep(ms) { ms += new Date().getTime(); while (new Date() < ms){} } function uuidv4() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } mGlobal.SessionGUIDStr = uuidv4() // Generate uuid4 of the session //console.log(uuidv4()); mGlobal.RobotRDPActive = {} mGlobal.Monitor.fControlPanelRefresh_TechnicalRender = function() { lResponseJSON = mGlobal.Monitor.mDatasetLast if (lResponseJSON!= null) { /// New version of control panels for (var lKeyStr in lResponseJSON){ if (lKeyStr != "RenderRobotList") { /// Check if not "RenderRobotList" lCPDict = lResponseJSON[lKeyStr] /// Render HTML if ("HTMLStr" in lCPDict) { } } } /// v1.2.0 Backward compatibility - support old control panels if ("RenderRobotList" in lResponseJSON) { ///Escape onclick /// RenderRobotList lResponseJSON["RenderRobotList"].forEach( function(lItem){ if ('FooterButtonX2List' in lItem) { /// FooterButtonX2List lItem["FooterButtonX2List"].forEach( function(lItem2){ if ('OnClick' in lItem) { lOnClickEscaped = lItem["OnClick"]; lOnClickEscaped = lOnClickEscaped.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); lItem["OnClick"] = lOnClickEscaped; } } ); /// FooterButtonX1List lItem["FooterButtonX1List"].forEach( function(lItem2){ if ('OnClick' in lItem) { lOnClickEscaped = lItem["OnClick"]; lOnClickEscaped = lOnClickEscaped.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); lItem["OnClick"] = lOnClickEscaped; } } ); } } ); ////////////////////////////////////////////////////////// ///Сформировать HTML код новой таблицы - контрольная панель lHTMLCode+=mGlobal.GeneralGenerateHTMLCodeHandlebars(".openrpa-hidden-control-panel",lResponseJSON) //Присвоить ответ в mGlobal.Monitor.mResponseList mGlobal.Monitor.mResponseList = lResponseJSON ///Set result in mGlobal.DataStorage lResponseJSON["RenderRobotList"].forEach( function(lItem){ if ('DataStorageKey' in lItem) { mGlobal["DataStorage"][lItem['DataStorageKey']]=lItem } } ) ///Прогрузить новую таблицу $(".openrpa-control-panel").html(lHTMLCode) //////////////////////////////////////////////////// /// !RDP List ! Сформировать HTML код новой таблицы - список RDP lHTMLCode=mGlobal.GeneralGenerateHTMLCodeHandlebars(".openrpa-hidden-robotrdpactive-control-panel",lResponseJSON) //Присвоить ответ в mGlobal.RobotRDPActive.mResponseList mGlobal.RobotRDPActive.mResponseList = lResponseJSON ///Прогрузить новую таблицу $(".openrpa-robotrdpactive-control-panel").html(lHTMLCode) ///Очистить дерево //mGlobal.ElementTree.fClear(); //////////////////////////////////////////////////// /// !UserAgent List ! Сформировать HTML код новой таблицы - список RDP lHTMLCode=mGlobal.GeneralGenerateHTMLCodeHandlebars(".pyOpenRPA-Agent-ListTemplate",lResponseJSON) //Присвоить ответ в mGlobal.RobotRDPActive.mResponseList mGlobal.RobotRDPActive.mResponseList = lResponseJSON ///Прогрузить новую таблицу $(".pyOpenRPA-Agent-List").html(lHTMLCode) ///Очистить дерево //mGlobal.ElementTree.fClear(); } } } ///v 1.2.0 pyOpenRPA /// Execute ActivityItem mGlobal.pyOpenRPA.ActivityItemExecute=function(inActivityItem) { ///EXAMPLE // { // "Def":"OSCMD", // def link or def alias (look gSettings["Processor"]["AliasDefDict"]) // "ArgList":[], // Args list // "ArgDict":{"inCMDStr":lCMDCode,"inRunAsyncBool":false}, // Args dictionary // "ArgGSettings": null, // Name of GSettings attribute: str (ArgDict) or index (for ArgList) // "ArgLogger": "inLogger" // Name of GSettings attribute: str (ArgDict) or index (for ArgList) // } ///Подготовить конфигурацию lData = [inActivityItem] $.ajax({ type: "POST", url: '/pyOpenRPA/ActivityListExecute', data: JSON.stringify(lData), success: function(lData,l2,l3) { var lResponseJSON=JSON.parse(lData) console.log(lResponseJSON) }, dataType: "text" }); } /// Execute ActivityList mGlobal.pyOpenRPA.ActivityListExecute=function(inActivityList) { ///EXAMPLE // [{ // "Def":"OSCMD", // def link or def alias (look gSettings["Processor"]["AliasDefDict"]) // "ArgList":[], // Args list // "ArgDict":{"inCMDStr":lCMDCode,"inRunAsyncBool":false}, // Args dictionary // "ArgGSettings": null, // Name of GSettings attribute: str (ArgDict) or index (for ArgList) // "ArgLogger": "inLogger" // Name of GSettings attribute: str (ArgDict) or index (for ArgList) // }] ///Подготовить конфигурацию lData = inActivityList $.ajax({ type: "POST", url: '/pyOpenRPA/ActivityListExecute', data: JSON.stringify(lData), success: function(lData,l2,l3) { var lResponseJSON=JSON.parse(lData) console.log(lResponseJSON) }, dataType: "text" }); } /// Add ActivityList in processor queue mGlobal.pyOpenRPA.ProcessorQueueAdd=function(inActivityList) { ///EXAMPLE // [{ // "Def":"OSCMD", // def link or def alias (look gSettings["Processor"]["AliasDefDict"]) // "ArgList":[], // Args list // "ArgDict":{"inCMDStr":lCMDCode,"inRunAsyncBool":false}, // Args dictionary // "ArgGSettings": null, // Name of GSettings attribute: str (ArgDict) or index (for ArgList) // "ArgLogger": "inLogger" // Name of GSettings attribute: str (ArgDict) or index (for ArgList) // }] ///Подготовить конфигурацию lData = inActivityList $.ajax({ type: "POST", url: '/pyOpenRPA/ProcessorQueueAdd', data: JSON.stringify(lData), success: function(lData,l2,l3) { var lResponseJSON=JSON.parse(lData) console.log(lResponseJSON) }, dataType: "text" }); } /// v1.2.0 pyOpenRPA ServerJSInit mGlobal.pyOpenRPA.ServerJSInitDef=function() { try { $.ajax({ type: "GET", headers: {}, url: 'pyOpenRPA/ServerJSInit', data: mGlobal.pyOpenRPA.ServerDataHashStr, async: false, success: function(lJSText) { try { eval(lJSText) } catch(error) { console.log(error) } }, dataType: "text", error: function(jqXHR, textStatus, errorThrown ) { console.log(textStatus) } }); } catch(error) { console.log(error) } } /// v1.2.0 pyOpenRPA ServerData mGlobal.pyOpenRPA.ServerDataDict = null mGlobal.pyOpenRPA.ServerDataHashStr = "" mGlobal.pyOpenRPA.ServerDataRefreshDef_TechnicalRender = function() { lResponseJSON = mGlobal.pyOpenRPA.ServerDataDict if (lResponseJSON!= null) { /// New version of control panels lHTMLCode = '