add new control panel simple 01 (prototype)

dev-fastapi
Иван Маслов 2 years ago
parent 4bd862c911
commit f3d3bcce98

@ -0,0 +1,73 @@
from pyOpenRPA.Tools import CrossOS
import os
import sys
import time
import json
from pyOpenRPA import Orchestrator
from datetime import date
from pyOpenRPA.Orchestrator.Server import app
import threading
from fastapi import Depends, Body
from fastapi.responses import PlainTextResponse
from fastapi.responses import FileResponse
time.sleep(1.5) # Определить очередность в панели управления
from fastapi.staticfiles import StaticFiles
# путь к папке, в которой расположена панель управления (используется для формирования других путей)
cp_path_str = CrossOS.PathJoinList(CrossOS.PathSplitList(__file__)[:-1])
#AGENT SETTINGS
agent_hostname_str = ""
agent_username_str = ""
# ROBOT SETTINGS
robot_logs_path_str = f"{cp_path_str}"
gSettings = Orchestrator.GSettingsGet()
# календарь
robot_key_str = "SIMPLE_01"
# Подключить папку
#app.mount(f"/{robot_key_str}/calendar", StaticFiles(directory=os.path.join(os.path.abspath(cpPathStr), "calendar")), name=f"{robot_key_str}_calendar")
# пути для ...
htmlPath = os.path.join(cp_path_str, "index.html")
scriptPath = os.path.join(cp_path_str, f"scripts.js")
# вывод папки логов
def check_folder(folder):
files = os.listdir(folder)
return files[::-1]
app.mount(f"/{robot_key_str}/logs", StaticFiles(directory=robot_logs_path_str), name=f"{robot_key_str}-logs")
@app.get(path=f"/{robot_key_str}/scripts.js",tags=[f"{robot_key_str}"])
def get_file2():
return FileResponse(os.path.abspath(scriptPath))
# сторонние файлы
infoPath = os.path.join(cp_path_str, "how_to.docx")
@app.get(path=f"/{robot_key_str}/how_to.docx",tags=[f"{robot_key_str}"])
def get_file():
return FileResponse(os.path.abspath(infoPath))
#проверка процесса
def process_is_started():
return Orchestrator.ProcessIsStarted(inProcessNameWOExeStr = robot_key_str)
# функции для запуска процессов
buildPathStr = CrossOS.PathJoinList(CrossOS.PathSplitList(__file__)[:-3]+["builds"])
startHandPathStr = os.path.join(buildPathStr, "startHand.cmd")
def startHand():
Orchestrator.AgentOSCMD(inHostNameStr=agent_hostname_str, inUserStr=agent_username_str, inCMDStr=startHandPathStr, inRunAsyncBool=True, inSendOutputToOrchestratorLogsBool=False, inCaptureBool=False)
@app.get(path=f"/{robot_key_str}/startHand",tags=[f"{robot_key_str}"])
def start_app():
startHand()
# инициализация панели
lCPManager = Orchestrator.Managers.ControlPanel(inControlPanelNameStr=robot_key_str,
inRefreshHTMLJinja2TemplatePathStr=htmlPath, inJinja2TemplateRefreshBool = True)
contextDict = {"config": sys.modules[__name__]}
lCPManager.Jinja2DataUpdateDictSet(inJinja2DataUpdateDict=contextDict)

@ -0,0 +1,56 @@
<div class="card" style="width:100%;" id="{{config.robot_key_str}}-card">
<div class="content">
<h1 class="ui center aligned icon header">SIMPLE_01: ПРОСТОЙ РОБОТ</h1>
<div class="ui message">
<div class="header">Применение:</div>
<p>Текст панели управления.</p>
<div class="header">Сотрудник:</div>
<p>{{UserInfoDict['UserNameUpperStr']}}</p>
</div>
<div class="ui segment" id="{{config.robot_key_str}}-segment">
<div class="ui two column very relaxed grid">
<div class="column">
<h3 class="ui center aligned icon header">СОСТОЯНИЕ</h3>
{% if config.process_is_started() %}
<h2 class="ui center aligned icon header green">
<i class="circular play icon"></i>
Включен
</h2>
<script>start_block(1);</script>
{% else %}
<h2 class="ui center aligned icon header red">
<i class="circular stop icon"></i>
Выключен
</h2>
<script>start_block(1);</script>
{% endif %}
</div>
<div class="column">
<h3 class="ui center aligned icon header">ДЕЙСТВИЯ</h3>
<p class="ui center aligned"><button class="ui right labeled icon button" id="{{config.robot_key_str}}-log-btn" onclick="{{config.robot_key_str}}_logs()"><i class="right file alternate icon"></i> Скачать лог </button></p>
<p class="ui center aligned"><button class="ui right labeled icon button" id="{{config.robot_key_str}}-info-btn" onclick="{{config.robot_key_str}}_info()"><i class="right info icon"></i> Скачать инструкцию </button></p>
<p class="ui center aligned"><button class="ui right labeled icon button"><i class="right book icon"></i> Скачать документацию </button></p>
<p class="ui center aligned"><button class="ui right labeled icon button green"><i class="right book icon"></i> Запустить </button></p>
<p class="ui center aligned"><button class="ui right labeled icon button red"><i class="right book icon"></i> Остановить </button></p>
</div>
</div>
<div class="ui vertical divider">
</div>
</div>
</div>
</div>
<script src="/{{config.robot_key_str}}/scripts.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// JS CODE GOES HERE
});
</script>

@ -59,7 +59,7 @@ else:
# Restore DUMP # Restore DUMP
Orchestrator.OrchestratorSessionRestore(inGSettings=gSettings) Orchestrator.OrchestratorSessionRestore(inGSettings=gSettings)
# Autoinit control panels starts with CP_ # Autoinit control panels starts with CP_
lPyModules = Orchestrator.OrchestratorPySearchInit(inGlobPatternStr="Demo\\*\\config.py", inAsyncInitBool=True) lPyModules = Orchestrator.OrchestratorPySearchInit(inGlobPatternStr="Demo\\*\\config.py", inAsyncInitBool=True, inPackageLevelInt=1)
lPyModules2 = Orchestrator.OrchestratorPySearchInit(inGlobPatternStr="..\\..\\KPI_Effect\\packages\\*_control_panel\\config.py", inAsyncInitBool=True, inPackageLevelInt=1) lPyModules2 = Orchestrator.OrchestratorPySearchInit(inGlobPatternStr="..\\..\\KPI_Effect\\packages\\*_control_panel\\config.py", inAsyncInitBool=True, inPackageLevelInt=1)
# Call the orchestrator def # Call the orchestrator def

Loading…
Cancel
Save