Add printer control actions for firmware and queue management
This commit is contained in:
parent
594c9a99ce
commit
3c9071be33
@ -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}
|
||||
@ -195,33 +230,33 @@ const ControlPrinter = () => {
|
||||
loading={objectFormState.loading}
|
||||
ref={actionHandlerRef}
|
||||
>
|
||||
<ObjectForm
|
||||
id={printerId}
|
||||
type='printer'
|
||||
ref={objectFormRef}
|
||||
onStateChange={(state) => {
|
||||
console.log('Got edit form state change', state)
|
||||
setEditFormState((prev) => ({ ...prev, ...state }))
|
||||
}}
|
||||
>
|
||||
{({
|
||||
loading: printerObjectLoading,
|
||||
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)
|
||||
}
|
||||
>
|
||||
<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}
|
||||
type='printer'
|
||||
ref={objectFormRef}
|
||||
onStateChange={(state) => {
|
||||
console.log('Got edit form state change', state)
|
||||
setEditFormState((prev) => ({ ...prev, ...state }))
|
||||
}}
|
||||
>
|
||||
{({
|
||||
loading: printerObjectLoading,
|
||||
objectData: printerObjectData
|
||||
}) => {
|
||||
return (
|
||||
<ObjectInfo
|
||||
loading={printerObjectLoading}
|
||||
column={sideBarVisible ? 1 : undefined}
|
||||
@ -236,155 +271,158 @@ const ControlPrinter = () => {
|
||||
'moonraker.protocol': false,
|
||||
'moonraker.host': false,
|
||||
tags: false,
|
||||
firmware: false
|
||||
firmware: false,
|
||||
alerts: false
|
||||
}}
|
||||
objectData={printerObjectData}
|
||||
type='printer'
|
||||
/>
|
||||
</InfoCollapse>
|
||||
<InfoCollapse
|
||||
title={'Job'}
|
||||
icon={<JobIcon />}
|
||||
collapseKey='job'
|
||||
active={collapseState.job}
|
||||
onToggle={(expanded) =>
|
||||
updateCollapseState('job', expanded)
|
||||
}
|
||||
>
|
||||
{printerObjectData?.currentJob?._id ? (
|
||||
<ObjectForm
|
||||
id={printerObjectData.currentJob._id}
|
||||
type='job'
|
||||
onStateChange={() => {}}
|
||||
>
|
||||
{({
|
||||
loading: jobObjectLoading,
|
||||
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%'
|
||||
)
|
||||
}}
|
||||
</ObjectForm>
|
||||
</InfoCollapse>
|
||||
<InfoCollapse
|
||||
title={'Job'}
|
||||
icon={<JobIcon />}
|
||||
collapseKey='job'
|
||||
active={collapseState.job}
|
||||
onToggle={(expanded) =>
|
||||
updateCollapseState('job', expanded)
|
||||
}
|
||||
>
|
||||
{objectFormState.objectData?.currentJob?._id ? (
|
||||
<ObjectForm
|
||||
id={objectFormState.objectData.currentJob._id}
|
||||
type='job'
|
||||
onStateChange={() => {}}
|
||||
>
|
||||
{sideBarItems}
|
||||
</Splitter.Panel>
|
||||
) : null}
|
||||
</Splitter>
|
||||
{isMobile ? (
|
||||
<>
|
||||
<Divider />
|
||||
{sideBarItems}
|
||||
</>
|
||||
) : null}
|
||||
{({
|
||||
loading: jobObjectLoading,
|
||||
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)
|
||||
}
|
||||
>
|
||||
{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>
|
||||
)
|
||||
}}
|
||||
</ObjectForm>
|
||||
</Splitter.Panel>
|
||||
{sideBarVisible && !isMobile ? (
|
||||
<Splitter.Panel
|
||||
style={{ minWidth: '325px' }}
|
||||
defaultSize='20%'
|
||||
max='35%'
|
||||
>
|
||||
{sideBarItems}
|
||||
</Splitter.Panel>
|
||||
) : null}
|
||||
</Splitter>
|
||||
{isMobile ? (
|
||||
<>
|
||||
<Divider />
|
||||
{sideBarItems}
|
||||
</>
|
||||
) : null}
|
||||
</Flex>
|
||||
</ActionHandler>
|
||||
<InfoCollapse
|
||||
title='Notes'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user