Add printer control actions for firmware and queue management

This commit is contained in:
Tom Butcher 2025-11-17 18:49:00 +00:00
parent 594c9a99ce
commit 3c9071be33

View File

@ -1,4 +1,4 @@
import { useState, useRef, useEffect } from 'react'
import { useState, useRef, useEffect, useContext } from 'react'
import { useLocation } from 'react-router-dom'
import { Space, Flex, Card, Splitter, Divider } from 'antd'
import loglevel from 'loglevel'
@ -26,6 +26,7 @@ import FilamentStockIcon from '../../../Icons/FilamentStockIcon.jsx'
import MissingPlaceholder from '../../common/MissingPlaceholder.jsx'
import { useMediaQuery } from 'react-responsive'
import AlertsDisplay from '../../common/AlertsDisplay.jsx'
import { ApiServerContext } from '../../context/ApiServerContext.jsx'
const log = loglevel.getLogger('ControlPrinter')
log.setLevel(config.logLevel)
@ -49,6 +50,7 @@ const ControlPrinter = () => {
}
)
const { connected, sendObjectAction } = useContext(ApiServerContext)
const [sideBarVisible, setSideBarVisible] = useState(
collapseState.temperature ||
collapseState.position ||
@ -88,6 +90,38 @@ const ControlPrinter = () => {
finishEdit: () => {
objectFormRef?.current.handleUpdate()
return true
},
restartFirmware: () => {
if (connected == true) {
sendObjectAction(printerId, 'printer', {
type: 'restartPrinterFirmware'
})
}
return true
},
restartMoonraker: () => {
if (connected == true) {
sendObjectAction(printerId, 'printer', {
type: 'restartMoonraker'
})
}
return true
},
restart: () => {
if (connected == true) {
sendObjectAction(printerId, 'printer', {
type: 'restartPrinter'
})
}
return true
},
startQueue: () => {
if (connected == true) {
sendObjectAction(printerId, 'printer', {
type: 'startQueue'
})
}
return true
}
}
@ -128,6 +162,7 @@ const ControlPrinter = () => {
id={printerId}
disabled={objectFormState.loading}
visibleActions={{ edit: false }}
objectData={objectFormState.objectData}
/>
<ViewButton
disabled={objectFormState.loading}
@ -194,6 +229,19 @@ const ControlPrinter = () => {
actions={actions}
loading={objectFormState.loading}
ref={actionHandlerRef}
>
<Flex vertical>
<Splitter className={'farmcontrol-splitter'}>
<Splitter.Panel>
<Flex vertical gap={'large'}>
<InfoCollapse
title={'Printer'}
icon={<PrinterIcon />}
collapseKey='printer'
active={collapseState.printer}
onToggle={(expanded) =>
updateCollapseState('printer', expanded)
}
>
<ObjectForm
id={printerId}
@ -209,19 +257,6 @@ const ControlPrinter = () => {
objectData: printerObjectData
}) => {
return (
<Flex vertical>
<Splitter className={'farmcontrol-splitter'}>
<Splitter.Panel>
<Flex vertical gap={'large'}>
<InfoCollapse
title={'Printer'}
icon={<PrinterIcon />}
collapseKey='printer'
active={collapseState.printer}
onToggle={(expanded) =>
updateCollapseState('printer', expanded)
}
>
<ObjectInfo
loading={printerObjectLoading}
column={sideBarVisible ? 1 : undefined}
@ -236,11 +271,15 @@ const ControlPrinter = () => {
'moonraker.protocol': false,
'moonraker.host': false,
tags: false,
firmware: false
firmware: false,
alerts: false
}}
objectData={printerObjectData}
type='printer'
/>
)
}}
</ObjectForm>
</InfoCollapse>
<InfoCollapse
title={'Job'}
@ -251,9 +290,9 @@ const ControlPrinter = () => {
updateCollapseState('job', expanded)
}
>
{printerObjectData?.currentJob?._id ? (
{objectFormState.objectData?.currentJob?._id ? (
<ObjectForm
id={printerObjectData.currentJob._id}
id={objectFormState.objectData.currentJob._id}
type='job'
onStateChange={() => {}}
>
@ -291,9 +330,9 @@ const ControlPrinter = () => {
updateCollapseState('subJob', expanded)
}
>
{printerObjectData?.currentSubJob?._id ? (
{objectFormState.objectData?.currentSubJob?._id ? (
<ObjectForm
id={printerObjectData.currentSubJob._id}
id={objectFormState.objectData.currentSubJob._id}
type='subjob'
onStateChange={() => {}}
>
@ -331,9 +370,11 @@ const ControlPrinter = () => {
updateCollapseState('filamentStock', expanded)
}
>
{printerObjectData?.currentFilamentStock?._id ? (
{objectFormState.objectData?.currentFilamentStock?._id ? (
<ObjectForm
id={printerObjectData.currentFilamentStock._id}
id={
objectFormState.objectData.currentFilamentStock._id
}
type='filamentStock'
onStateChange={() => {}}
>
@ -382,9 +423,6 @@ const ControlPrinter = () => {
</>
) : null}
</Flex>
)
}}
</ObjectForm>
</ActionHandler>
<InfoCollapse
title='Notes'