From e64adb796ea45aa1b899952cb3650a7b9b6c2278 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 9 Aug 2022 07:21:40 +0000 Subject: [PATCH] Begin display page --- webclient/src/App.js | 5 +++ webclient/src/Display.js | 87 ++++++++++++++++++++++++++++++++++++++++ webclient/src/light.css | 23 ++++++++++- 3 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 webclient/src/Display.js diff --git a/webclient/src/App.js b/webclient/src/App.js index 035471c..8455f79 100644 --- a/webclient/src/App.js +++ b/webclient/src/App.js @@ -29,6 +29,7 @@ import { NotFound, PleaseLogin } from './Misc.js'; import { Debug } from './Debug.js'; import { Garden } from './Garden.js'; import { Footer } from './Footer.js'; +import { LCARS1Display } from './Display.js'; const APP_VERSION = 3; // TODO: automate this @@ -124,6 +125,10 @@ function App() { + + + +
diff --git a/webclient/src/Display.js b/webclient/src/Display.js new file mode 100644 index 0000000..471cbc4 --- /dev/null +++ b/webclient/src/Display.js @@ -0,0 +1,87 @@ +import React, { useRef, useState, useEffect } from 'react'; +import { useParams } from 'react-router-dom'; +import moment from 'moment-timezone'; +import { Button, Container, Header } from 'semantic-ui-react'; +import { requester } from './utils.js'; +import { TrotecUsage } from './Usage.js'; + +const deviceNames = { + 'trotec': {title: 'Trotec', device: 'TROTECS300'}, +}; + +export function LCARS1Display(props) { + const { token } = props; + const [fullElement, setFullElement] = useState(false); + const ref = useRef(null); + + const goFullScreen = () => { + if ('wakeLock' in navigator) { + navigator.wakeLock.request('screen'); + } + + ref.current.requestFullscreen({ navigationUI: 'hide' }).then(() => { + setFullElement(true); + }); + }; + + return ( + +
+ + {!fullElement && +

+ +

+ } + +
+ +
+ +
+
+
+ ); +}; + +export function DisplayUsage(props) { + const { token, name } = props; + const title = deviceNames[name].title; + const device = deviceNames[name].device; + const [usage, setUsage] = useState(false); + + const getUsage = () => { + requester('/stats/usage_data/?device='+device, 'GET', token) + .then(res => { + setUsage(res); + }) + .catch(err => { + console.log(err); + setUsage(false); + }); + }; + + useEffect(() => { + getUsage(); + const interval = setInterval(getUsage, 60000); + return () => clearInterval(interval); + }, []); + + const showUsage = usage && usage.track.username === usage.username; + + return ( + <> + {showUsage ? + + : + <> +
Trotec Usage
+ +

+ Waiting for job +

+ + } + + ); +}; diff --git a/webclient/src/light.css b/webclient/src/light.css index 930c613..c04016e 100644 --- a/webclient/src/light.css +++ b/webclient/src/light.css @@ -167,23 +167,42 @@ body { border: 2px solid black; } +.display { + display: flex; + justify-content: space-between; + height: 100vh; + background-color: black; + color: white; + font-size: 1em; +} + +.display-usage { + border: 1px solid white; + padding: 0.5em; + align-self: flex-end; + width: 240px; + height: 383px; +} + .usage { height: 100vh; background-color: black; color: white; padding: 0.5em; font-size: 2.5em; - cursor: none; } +.display .ui.header, .usage .ui.header { color: white; + margin-top: 0.5em; margin-bottom: 0em; } +.display .stat, .usage .stat { font-size: 2em; - margin-bottom: 0.5em; + margin-bottom: 0; } .nowrap-stat {