Files
PiDoBot/templates/index.html

406 lines
6.0 KiB
HTML

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PiDoBot Dashboard</title>
<link rel="stylesheet" href="/static/gridstack.min.css" />
<link rel="stylesheet" href="/static/xterm.css" />
<style>
body{
font-family:Arial,Helvetica,sans-serif;
background:#0f1116;
color:#e6e6e6;
margin:0;
}
header{
padding:10px 20px;
background:#1a1d25;
border-bottom:1px solid #2a2f3a;
display:flex;
align-items:center;
gap:20px;
}
select,input,button{
background:#1c212b;
color:white;
border:1px solid #333;
padding:6px;
border-radius:6px;
}
button{
cursor:pointer;
}
#dashboard{
padding:10px;
}
.panel{
background:#161a22;
border:1px solid #2c313d;
border-radius:10px;
padding:10px;
height:100%;
display:flex;
flex-direction:column;
}
.panel-title{
font-weight:bold;
margin-bottom:6px;
}
#nodes{
display:flex;
flex-wrap:wrap;
gap:10px;
}
.node{
background:#1d2230;
border:1px solid #2f3647;
border-radius:8px;
padding:10px;
min-width:140px;
cursor:pointer;
}
.node small{
display:block;
opacity:0.7;
}
#chat-log{
flex:1;
overflow:auto;
font-size:14px;
}
.message-user{
color:#8fd3ff;
margin-bottom:6px;
}
.message-ai{
color:#b6ffb2;
margin-bottom:10px;
}
#chat-input-row{
display:flex;
gap:6px;
margin-top:6px;
}
#chat-input{
flex:1;
}
#system-log{
flex:1;
overflow:auto;
font-size:13px;
font-family:monospace;
}
.log-entry{
margin-bottom:3px;
}
#terminal{
flex:1;
}
.grid-stack-item-content{
height:100%;
}
</style>
</head>
<body>
<header>
<label>Provider</label>
<select id="ai-provider">
<option value="google">Google</option>
<option value="openai">OpenAI</option>
<option value="ollama">Ollama</option>
</select>
<label>Model</label>
<select id="ai-model">
<option>gemini-2.5-flash</option>
<option>gpt-4o</option>
<option>llama3</option>
</select>
<label>Ollama URL</label>
<input id="ollama-url" placeholder="http://127.0.0.1:11434/v1" style="width:260px">
<button onclick="saveAISettings()">Save</button>
<button onclick="addNode()">Add Node</button>
<button onclick="refreshNodes()">Refresh</button>
</header>
<div id="dashboard" class="grid-stack"></div>
<script src="/static/gridstack-all.js"></script>
<script src="/static/xterm.js"></script>
<script src="/static/xterm-addon-fit.js"></script>
<script>
let grid
let term
let fitAddon
let terminalSocket
let chatSocket
function initGrid(){
grid = GridStack.init({
float:true,
cellHeight:120,
margin:8
})
createPanels()
}
function createPanels(){
addWidget("nodesPanel",0,0,4,2,`<div class="panel">
<div class="panel-title">Nodes</div>
<div id="nodes"></div>
</div>`)
addWidget("terminalPanel",0,2,4,3,`<div class="panel">
<div class="panel-title">Terminal</div>
<div id="terminal"></div>
</div>`)
addWidget("chatPanel",4,0,4,3,`<div class="panel">
<div class="panel-title">AI Chat</div>
<div id="chat-log"></div>
<div id="chat-input-row">
<input id="chat-input" placeholder="Ask the AI...">
<button onclick="sendChat()">Send</button>
</div>
</div>`)
addWidget("logPanel",4,3,4,2,`<div class="panel">
<div class="panel-title">System Log</div>
<div id="system-log"></div>
</div>`)
setTimeout(initTerminal,200)
connectChat()
loadNodes()
}
function addWidget(id,x,y,w,h,content){
grid.addWidget({
id:id,
x:x,
y:y,
w:w,
h:h,
content:content
})
}
function initTerminal(){
term = new Terminal({
fontSize:14,
theme:{background:"#161a22"}
})
fitAddon = new FitAddon.FitAddon()
term.loadAddon(fitAddon)
term.open(document.getElementById("terminal"))
fitAddon.fit()
terminalSocket = new WebSocket(`ws://${location.host}/ws/terminal`)
terminalSocket.onmessage = e=>term.write(e.data)
term.onData(data=>{
terminalSocket.send(data)
})
}
function connectChat(){
chatSocket = new WebSocket(`ws://${location.host}/ws/chat`)
chatSocket.onmessage = e=>{
addChat("ai",e.data)
log("AI: "+e.data)
}
}
function sendChat(){
let input=document.getElementById("chat-input")
let msg=input.value.trim()
if(!msg) return
addChat("user",msg)
chatSocket.send(msg)
input.value=""
}
function addChat(type,text){
let log=document.getElementById("chat-log")
let div=document.createElement("div")
if(type=="user"){
div.className="message-user"
div.innerText="You: "+text
}
else{
div.className="message-ai"
div.innerText="AI: "+text
}
log.appendChild(div)
log.scrollTop=log.scrollHeight
}
function log(text){
let el=document.getElementById("system-log")
let div=document.createElement("div")
div.className="log-entry"
let time=new Date().toLocaleTimeString()
div.innerText=`[${time}] ${text}`
el.appendChild(div)
el.scrollTop=el.scrollHeight
}
async function loadNodes(){
let res = await fetch("/nodes")
let nodes = await res.json()
renderNodes(nodes)
}
function renderNodes(nodes){
let container=document.getElementById("nodes")
container.innerHTML=""
nodes.forEach(n=>{
let div=document.createElement("div")
div.className="node"
div.innerHTML=`
<b>${n.name}</b>
<small>${n.ip}</small>
<small>${n.os || "unknown"}</small>
<small>${n.arch || ""}</small>
`
div.onclick=()=>editNode(n)
container.appendChild(div)
})
}
function refreshNodes(){
loadNodes()
log("Nodes refreshed")
}
function addNode(){
let name=prompt("Node Name")
let ip=prompt("IP Address")
let user=prompt("User")
fetch("/nodes",{
method:"POST",
headers:{"Content-Type":"application/json"},
body:JSON.stringify({name,ip,user})
}).then(()=>{
log("Node added: "+name)
loadNodes()
})
}
function editNode(node){
let name=prompt("Name",node.name)
let ip=prompt("IP",node.ip)
let user=prompt("User",node.user)
fetch(`/nodes/${node.id}`,{
method:"PUT",
headers:{"Content-Type":"application/json"},
body:JSON.stringify({name,ip,user})
}).then(()=>{
log("Node updated: "+name)
loadNodes()
})
}
function saveAISettings(){
let provider=document.getElementById("ai-provider").value
let model=document.getElementById("ai-model").value
let ollama=document.getElementById("ollama-url").value
fetch("/ai/settings",{
method:"POST",
headers:{"Content-Type":"application/json"},
body:JSON.stringify({provider,model,ollama})
})
log("AI settings saved")
}
setInterval(()=>{
refreshNodes()
},60000)
window.onload=initGrid
</script>
</body>
</html>