internal/component => internal/dis/component
This commit is contained in:
parent
9443217441
commit
b5b1ce2340
123 changed files with 76 additions and 76 deletions
50
internal/dis/component/static/src/base/index.css
Normal file
50
internal/dis/component/static/src/base/index.css
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
body {
|
||||
font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||
}
|
||||
|
||||
header,
|
||||
main,
|
||||
footer {
|
||||
margin: 2em;
|
||||
}
|
||||
|
||||
.padding {
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
.overflow {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.overflow table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.overflow table td,
|
||||
.overflow table th{
|
||||
padding: .5em .5em;
|
||||
}
|
||||
|
||||
.overflow table td:not(:last-child),
|
||||
.overflow table th:not(:last-child) {
|
||||
width: 1px;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.overflow table td:last-child,
|
||||
.overflow table th:last-child {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.hspace {
|
||||
display: block;
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
.pure-button-action {
|
||||
background-color: rgb(66, 184, 221) !important;
|
||||
}
|
||||
.pure-button-success {
|
||||
background-color: rgb(28, 184, 65) !important;
|
||||
}
|
||||
4
internal/dis/component/static/src/base/index.ts
Normal file
4
internal/dis/component/static/src/base/index.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import "purecss/build/pure.css"
|
||||
import "purecss/build/grids-responsive.css"
|
||||
|
||||
import "./index.css"
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
.wisski {
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
.wisski h3 {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.wisski a.pure-button {
|
||||
float: right;
|
||||
position: relative;
|
||||
bottom: 1em;
|
||||
}
|
||||
|
||||
.wisski.running {
|
||||
background-color: #9ADA07;
|
||||
}
|
||||
|
||||
.wisski.stopped {
|
||||
background-color: #ff7a7a;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
import "~/src/lib/remote"
|
||||
import "~/src/lib/highlight"
|
||||
|
|
@ -0,0 +1 @@
|
|||
@import url("../ControlIndex/index.css")
|
||||
|
|
@ -0,0 +1 @@
|
|||
import "../ControlIndex/index"
|
||||
22
internal/dis/component/static/src/lib/autolink/index.css
Normal file
22
internal/dis/component/static/src/lib/autolink/index.css
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
.header-link {
|
||||
position: relative;
|
||||
left: 0.5em;
|
||||
opacity: 0;
|
||||
font-size: 0.8em;
|
||||
|
||||
transition: opacity 0.2s ease-in-out 0.1s;
|
||||
-webkit-transition: opacity 0.2s ease-in-out 0.1s;
|
||||
-moz-transition: opacity 0.2s ease-in-out 0.1s;
|
||||
-ms-transition: opacity 0.2s ease-in-out 0.1s;
|
||||
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
h2:hover .header-link,
|
||||
h3:hover .header-link,
|
||||
h4:hover .header-link,
|
||||
h5:hover .header-link,
|
||||
h6:hover .header-link {
|
||||
color: black !important;
|
||||
opacity: 1;
|
||||
}
|
||||
21
internal/dis/component/static/src/lib/autolink/index.ts
Normal file
21
internal/dis/component/static/src/lib/autolink/index.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import "./index.css"
|
||||
|
||||
/** Adapted from http://blog.parkermoore.de/2014/08/01/header-anchor-links-in-vanilla-javascript-for-github-pages-and-jekyll/ */
|
||||
const anchorForId = (id: string) => {
|
||||
const anchor = document.createElement("a")
|
||||
anchor.className = "header-link"
|
||||
anchor.href = "#" + id
|
||||
anchor.innerHTML = "#"
|
||||
return anchor
|
||||
}
|
||||
|
||||
const linkifyAnchors = (level: number) => {
|
||||
const headers = document.getElementsByTagName("h" + level);
|
||||
Array.from(headers).forEach((header) => {
|
||||
if (typeof header.id === "undefined" || header.id === "") return
|
||||
header.appendChild(anchorForId(header.id))
|
||||
})
|
||||
}
|
||||
|
||||
// linkify all the anchors from 1 ... 6
|
||||
(new Array(6)).fill(0).forEach((_, i) => linkifyAnchors(i + 1))
|
||||
51
internal/dis/component/static/src/lib/highlight/index.ts
Normal file
51
internal/dis/component/static/src/lib/highlight/index.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import dayjs from "dayjs"
|
||||
const types: Record<string, (element: HTMLElement) => HTMLElement | string> = {
|
||||
"date": (element) => {
|
||||
return dayjs(element.innerText).format('YYYY-MM-DD HH:mm:ss ([UTC]Z)')
|
||||
},
|
||||
"path": (element) => {
|
||||
const text = element.innerText.split("/");
|
||||
return text[text.length - 1];
|
||||
},
|
||||
"pathbuilder": (element) => {
|
||||
// create a link and get the blob
|
||||
const filename = (element.getAttribute('data-name') ?? 'pathbuilder') + ".xml"
|
||||
const [link, blob] = make_download_link(filename, element.innerText, "application/xml")
|
||||
|
||||
link.className = "pure-button"
|
||||
const title = filename + ' (' + blob.size + ' Bytes)';
|
||||
link.append(title)
|
||||
return link
|
||||
}
|
||||
}
|
||||
|
||||
const make_download_link = (filename: string, content: string, type: string): [HTMLAnchorElement, Blob] => {
|
||||
const blob = new Blob(
|
||||
[content],
|
||||
{
|
||||
type: type ?? "text/plain"
|
||||
}
|
||||
);
|
||||
|
||||
const link = document.createElement("a")
|
||||
link.target = "_blank"
|
||||
link.download = filename
|
||||
link.href = URL.createObjectURL(blob)
|
||||
|
||||
return [link, blob]
|
||||
}
|
||||
|
||||
Object.keys(types).forEach(key => {
|
||||
const f = types[key];
|
||||
const elements = document.querySelectorAll("code." + key) as NodeListOf<HTMLElement>
|
||||
elements.forEach(element => {
|
||||
const newElement = f(element)
|
||||
if (typeof newElement === 'string') {
|
||||
element.innerHTML = ""
|
||||
element.appendChild(document.createTextNode(newElement))
|
||||
return
|
||||
}
|
||||
|
||||
element.parentNode!.replaceChild(newElement, element)
|
||||
})
|
||||
})
|
||||
42
internal/dis/component/static/src/lib/remote/index.css
Normal file
42
internal/dis/component/static/src/lib/remote/index.css
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
.modal-terminal {
|
||||
width: 66vw;
|
||||
height: 66vh;
|
||||
|
||||
position: fixed;
|
||||
left: 17vw;
|
||||
top: 17vh;
|
||||
|
||||
background-color: white;
|
||||
|
||||
background-clip: padding-box;
|
||||
-webkit-background-clip: padding-box;
|
||||
|
||||
border-left: 17vw solid rgba(0, 0, 0, 0.8);
|
||||
border-right: 17vw solid rgba(0, 0, 0, 0.8);
|
||||
margin-left: -17vw;
|
||||
margin-right: -17vw;
|
||||
|
||||
border-top: 17vh solid rgba(0, 0, 0, 0.8);
|
||||
border-bottom: 17vh solid rgba(0, 0, 0, 0.8);
|
||||
margin-top: -17vh;
|
||||
margin-bottom: -17vh;
|
||||
|
||||
overflow: auto;
|
||||
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal-terminal button {
|
||||
position: fixed;
|
||||
top: 17vh;
|
||||
right: 17vw;
|
||||
|
||||
z-index: 1001;
|
||||
}
|
||||
|
||||
.modal-terminal pre,
|
||||
.modal-terminal button
|
||||
{
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
125
internal/dis/component/static/src/lib/remote/index.ts
Normal file
125
internal/dis/component/static/src/lib/remote/index.ts
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
import "./index.css"
|
||||
import connectSocket from './socket';
|
||||
|
||||
type Println = ((line: string, flush?: boolean) => void) & {
|
||||
paintedFrames: number;
|
||||
missedFrames: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* makeTextBuffer returns a println() function that efficiently writes text into target, and keeps at most size elements in the traceback.
|
||||
* scrollContainer is used to scroll on every painted update.
|
||||
*/
|
||||
function makeTextBuffer(target: HTMLElement, scrollContainer: HTMLElement, size: number): Println {
|
||||
let lastAnimationFrame: number | null = null; // last scheduled animation frame
|
||||
|
||||
const buffer: Array<string> = []; // the internal buffer of lines
|
||||
const paint = () => {
|
||||
println.paintedFrames++
|
||||
target.innerText = buffer.join("\n")
|
||||
scrollContainer.scrollTop = scrollContainer.scrollHeight
|
||||
lastAnimationFrame = null
|
||||
}
|
||||
|
||||
const println = (line: string, flush?: boolean) => {
|
||||
// add the line
|
||||
buffer.push(line)
|
||||
if (size !== 0 && buffer.length > size) {
|
||||
buffer.splice(0, buffer.length - size)
|
||||
}
|
||||
|
||||
// and update the browser in the next animation frame
|
||||
if (lastAnimationFrame !== null) {
|
||||
println.missedFrames++
|
||||
window.cancelAnimationFrame(lastAnimationFrame)
|
||||
}
|
||||
|
||||
// force a repaint!
|
||||
if(flush) return paint();
|
||||
|
||||
// schedule an animation frame
|
||||
lastAnimationFrame = window.requestAnimationFrame(paint);
|
||||
}
|
||||
println.paintedFrames = 0;
|
||||
println.missedFrames = 0;
|
||||
|
||||
return println;
|
||||
}
|
||||
|
||||
const elements = document.getElementsByClassName('remote-action')
|
||||
Array.from(elements).forEach((element) => {
|
||||
const action = element.getAttribute('data-action') as string;
|
||||
const reload = element.hasAttribute('data-force-reload');
|
||||
const param = element.getAttribute('data-param') as string | undefined;
|
||||
const bufferSize = (function () {
|
||||
const number = parseInt(element.getAttribute('data-buffer') ?? "", 10) ?? 0;
|
||||
return (isFinite(number) && number > 0) ? number : 0;
|
||||
})()
|
||||
|
||||
element.addEventListener('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
// create a modal dialog and append it to the body
|
||||
const modal = document.createElement("div")
|
||||
modal.className = "modal-terminal"
|
||||
document.body.append(modal)
|
||||
|
||||
// create a <pre> to write stuff into
|
||||
const target = document.createElement("pre")
|
||||
const println = makeTextBuffer(target, modal, bufferSize)
|
||||
modal.append(target)
|
||||
|
||||
|
||||
// create a button to eventually close everything
|
||||
const button = document.createElement("button")
|
||||
button.className = "pure-button pure-button-success"
|
||||
button.append(reload ? "Close & Reload" : "Close")
|
||||
button.addEventListener('click', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (reload) {
|
||||
button.setAttribute('disabled', 'disabled');
|
||||
target.innerHTML = 'Reloading page ...'
|
||||
location.reload()
|
||||
return;
|
||||
}
|
||||
|
||||
modal.parentNode?.removeChild(modal);
|
||||
})
|
||||
|
||||
const onbeforeunload = window.onbeforeunload;
|
||||
window.onbeforeunload = () => "A remote session is in progress. Are you sure you want to leave?";
|
||||
|
||||
// when closing, add a button to the modal!
|
||||
let didClose = false
|
||||
const close = function () {
|
||||
if (didClose) return
|
||||
didClose = true
|
||||
|
||||
window.onbeforeunload = onbeforeunload;
|
||||
modal.append(button)
|
||||
// DEBUG: print terminal stats!
|
||||
// const quota = (println.paintedFrames / (println.missedFrames + println.paintedFrames)) * 100
|
||||
// println(`Terminal: painted=${println.paintedFrames} missed=${println.missedFrames} (${quota}%)`, true)
|
||||
}
|
||||
|
||||
println("Connecting ...", true)
|
||||
|
||||
// connect to the socket and send the action
|
||||
connectSocket((socket) => {
|
||||
println("Connected", true)
|
||||
socket.send(action);
|
||||
if (typeof param === 'string') {
|
||||
socket.send(param);
|
||||
}
|
||||
}, (data) => {
|
||||
println(data);
|
||||
}).then(() => {
|
||||
println("Connection closed.", true)
|
||||
close();
|
||||
}).catch(() => {
|
||||
println("Connection errored.", true)
|
||||
close();
|
||||
});
|
||||
});
|
||||
})
|
||||
11
internal/dis/component/static/src/lib/remote/socket.ts
Normal file
11
internal/dis/component/static/src/lib/remote/socket.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
export default function connectSocket(onOpen: (socket: WebSocket) => void, onData: (data: any) => void): Promise<CloseEvent> {
|
||||
return new Promise((rs, rj) => {
|
||||
const socket = new WebSocket(location.href.replace('http', 'ws'));
|
||||
|
||||
socket.onclose = rs;
|
||||
socket.onerror = rj;
|
||||
|
||||
socket.onmessage = (ev) => onData(ev.data)
|
||||
socket.onopen = () => onOpen(socket);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue