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 { useLocation } from 'react-router-dom'
import { Space, Flex, Card, Splitter, Divider } from 'antd' import { Space, Flex, Card, Splitter, Divider } from 'antd'
import loglevel from 'loglevel' import loglevel from 'loglevel'
@ -26,6 +26,7 @@ import FilamentStockIcon from '../../../Icons/FilamentStockIcon.jsx'
import MissingPlaceholder from '../../common/MissingPlaceholder.jsx' import MissingPlaceholder from '../../common/MissingPlaceholder.jsx'
import { useMediaQuery } from 'react-responsive' import { useMediaQuery } from 'react-responsive'
import AlertsDisplay from '../../common/AlertsDisplay.jsx' import AlertsDisplay from '../../common/AlertsDisplay.jsx'
import { ApiServerContext } from '../../context/ApiServerContext.jsx'
const log = loglevel.getLogger('ControlPrinter') const log = loglevel.getLogger('ControlPrinter')
log.setLevel(config.logLevel) log.setLevel(config.logLevel)
@ -49,6 +50,7 @@ const ControlPrinter = () => {
} }
) )
const { connected, sendObjectAction } = useContext(ApiServerContext)
const [sideBarVisible, setSideBarVisible] = useState( const [sideBarVisible, setSideBarVisible] = useState(
collapseState.temperature || collapseState.temperature ||
collapseState.position || collapseState.position ||
@ -88,6 +90,38 @@ const ControlPrinter = () => {
finishEdit: () => { finishEdit: () => {
objectFormRef?.current.handleUpdate() objectFormRef?.current.handleUpdate()
return true 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} id={printerId}
disabled={objectFormState.loading} disabled={objectFormState.loading}
visibleActions={{ edit: false }} visibleActions={{ edit: false }}
objectData={objectFormState.objectData}
/> />
<ViewButton <ViewButton
disabled={objectFormState.loading} disabled={objectFormState.loading}
@ -195,33 +230,33 @@ const ControlPrinter = () => {
loading={objectFormState.loading} loading={objectFormState.loading}
ref={actionHandlerRef} ref={actionHandlerRef}
> >
<ObjectForm <Flex vertical>
id={printerId} <Splitter className={'farmcontrol-splitter'}>
type='printer' <Splitter.Panel>
ref={objectFormRef} <Flex vertical gap={'large'}>
onStateChange={(state) => { <InfoCollapse
console.log('Got edit form state change', state) title={'Printer'}
setEditFormState((prev) => ({ ...prev, ...state })) icon={<PrinterIcon />}
}} collapseKey='printer'
> active={collapseState.printer}
{({ onToggle={(expanded) =>
loading: printerObjectLoading, updateCollapseState('printer', expanded)
objectData: printerObjectData }
}) => { >
return ( <ObjectForm
<Flex vertical> id={printerId}
<Splitter className={'farmcontrol-splitter'}> type='printer'
<Splitter.Panel> ref={objectFormRef}
<Flex vertical gap={'large'}> onStateChange={(state) => {
<InfoCollapse console.log('Got edit form state change', state)
title={'Printer'} setEditFormState((prev) => ({ ...prev, ...state }))
icon={<PrinterIcon />} }}
collapseKey='printer' >
active={collapseState.printer} {({
onToggle={(expanded) => loading: printerObjectLoading,
updateCollapseState('printer', expanded) objectData: printerObjectData
} }) => {
> return (
<ObjectInfo <ObjectInfo
loading={printerObjectLoading} loading={printerObjectLoading}
column={sideBarVisible ? 1 : undefined} column={sideBarVisible ? 1 : undefined}
@ -236,155 +271,158 @@ const ControlPrinter = () => {
'moonraker.protocol': false, 'moonraker.protocol': false,
'moonraker.host': false, 'moonraker.host': false,
tags: false, tags: false,
firmware: false firmware: false,
alerts: false
}} }}
objectData={printerObjectData} objectData={printerObjectData}
type='printer' type='printer'
/> />
</InfoCollapse> )
<InfoCollapse }}
title={'Job'} </ObjectForm>
icon={<JobIcon />} </InfoCollapse>
collapseKey='job' <InfoCollapse
active={collapseState.job} title={'Job'}
onToggle={(expanded) => icon={<JobIcon />}
updateCollapseState('job', expanded) collapseKey='job'
} active={collapseState.job}
> onToggle={(expanded) =>
{printerObjectData?.currentJob?._id ? ( updateCollapseState('job', expanded)
<ObjectForm }
id={printerObjectData.currentJob._id} >
type='job' {objectFormState.objectData?.currentJob?._id ? (
onStateChange={() => {}} <ObjectForm
> id={objectFormState.objectData.currentJob._id}
{({ type='job'
loading: jobObjectLoading, onStateChange={() => {}}
objectData: jobObjectData
}) => {
return (
<ObjectInfo
loading={jobObjectLoading}
column={sideBarVisible ? 1 : undefined}
visibleProperties={{
printers: false,
createdAt: false
}}
objectData={jobObjectData}
type='job'
/>
)
}}
</ObjectForm>
) : (
<MissingPlaceholder
message={'No job.'}
hasBackground={false}
/>
)}
</InfoCollapse>
<InfoCollapse
title={'Sub Job'}
icon={<SubJobIcon />}
collapseKey='subJob'
active={collapseState.subJob}
onToggle={(expanded) =>
updateCollapseState('subJob', expanded)
}
>
{printerObjectData?.currentSubJob?._id ? (
<ObjectForm
id={printerObjectData.currentSubJob._id}
type='subjob'
onStateChange={() => {}}
>
{({
loading: subJobObjectLoading,
objectData: subJobObjectData
}) => {
return (
<ObjectInfo
loading={subJobObjectLoading}
column={sideBarVisible ? 1 : undefined}
visibleProperties={{
printers: false,
createdAt: false
}}
objectData={subJobObjectData}
type='subJob'
/>
)
}}
</ObjectForm>
) : (
<MissingPlaceholder
message={'No sub job.'}
hasBackground={false}
/>
)}
</InfoCollapse>
<InfoCollapse
title={'Filament Stock'}
icon={<FilamentStockIcon />}
collapseKey='filamentStock'
active={collapseState.filamentStock}
onToggle={(expanded) =>
updateCollapseState('filamentStock', expanded)
}
>
{printerObjectData?.currentFilamentStock?._id ? (
<ObjectForm
id={printerObjectData.currentFilamentStock._id}
type='filamentStock'
onStateChange={() => {}}
>
{({
loading: filamentStockObjectLoading,
objectData: filamentStockObjectData
}) => {
return (
<ObjectInfo
loading={filamentStockObjectLoading}
column={sideBarVisible ? 1 : undefined}
showHyperlink={true}
visibleProperties={{
updatedAt: false,
createdAt: false
}}
objectData={filamentStockObjectData}
type='filamentStock'
/>
)
}}
</ObjectForm>
) : (
<MissingPlaceholder
message={'No filament stock.'}
hasBackground={false}
/>
)}
</InfoCollapse>
</Flex>
</Splitter.Panel>
{sideBarVisible && !isMobile ? (
<Splitter.Panel
style={{ minWidth: '325px' }}
defaultSize='20%'
max='35%'
> >
{sideBarItems} {({
</Splitter.Panel> loading: jobObjectLoading,
) : null} objectData: jobObjectData
</Splitter> }) => {
{isMobile ? ( return (
<> <ObjectInfo
<Divider /> loading={jobObjectLoading}
{sideBarItems} column={sideBarVisible ? 1 : undefined}
</> visibleProperties={{
) : null} printers: false,
createdAt: false
}}
objectData={jobObjectData}
type='job'
/>
)
}}
</ObjectForm>
) : (
<MissingPlaceholder
message={'No job.'}
hasBackground={false}
/>
)}
</InfoCollapse>
<InfoCollapse
title={'Sub Job'}
icon={<SubJobIcon />}
collapseKey='subJob'
active={collapseState.subJob}
onToggle={(expanded) =>
updateCollapseState('subJob', expanded)
}
>
{objectFormState.objectData?.currentSubJob?._id ? (
<ObjectForm
id={objectFormState.objectData.currentSubJob._id}
type='subjob'
onStateChange={() => {}}
>
{({
loading: subJobObjectLoading,
objectData: subJobObjectData
}) => {
return (
<ObjectInfo
loading={subJobObjectLoading}
column={sideBarVisible ? 1 : undefined}
visibleProperties={{
printers: false,
createdAt: false
}}
objectData={subJobObjectData}
type='subJob'
/>
)
}}
</ObjectForm>
) : (
<MissingPlaceholder
message={'No sub job.'}
hasBackground={false}
/>
)}
</InfoCollapse>
<InfoCollapse
title={'Filament Stock'}
icon={<FilamentStockIcon />}
collapseKey='filamentStock'
active={collapseState.filamentStock}
onToggle={(expanded) =>
updateCollapseState('filamentStock', expanded)
}
>
{objectFormState.objectData?.currentFilamentStock?._id ? (
<ObjectForm
id={
objectFormState.objectData.currentFilamentStock._id
}
type='filamentStock'
onStateChange={() => {}}
>
{({
loading: filamentStockObjectLoading,
objectData: filamentStockObjectData
}) => {
return (
<ObjectInfo
loading={filamentStockObjectLoading}
column={sideBarVisible ? 1 : undefined}
showHyperlink={true}
visibleProperties={{
updatedAt: false,
createdAt: false
}}
objectData={filamentStockObjectData}
type='filamentStock'
/>
)
}}
</ObjectForm>
) : (
<MissingPlaceholder
message={'No filament stock.'}
hasBackground={false}
/>
)}
</InfoCollapse>
</Flex> </Flex>
) </Splitter.Panel>
}} {sideBarVisible && !isMobile ? (
</ObjectForm> <Splitter.Panel
style={{ minWidth: '325px' }}
defaultSize='20%'
max='35%'
>
{sideBarItems}
</Splitter.Panel>
) : null}
</Splitter>
{isMobile ? (
<>
<Divider />
{sideBarItems}
</>
) : null}
</Flex>
</ActionHandler> </ActionHandler>
<InfoCollapse <InfoCollapse
title='Notes' title='Notes'