Refactor printer control actions and introduce new restart components
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
- Removed outdated restart functions from ControlPrinter component to streamline code. - Added new RestartPrinter, RestartPrinterFirmware, and RestartMoonraker components for improved modularity and user interaction. - Updated Printer model to integrate new restart components into the action menu, enhancing user experience and maintainability.
This commit is contained in:
parent
8fb8f5e337
commit
1cc77390df
@ -118,30 +118,6 @@ const ControlPrinter = ({ slicerIntegration = false }) => {
|
|||||||
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: () => {
|
startQueue: () => {
|
||||||
if (connected == true) {
|
if (connected == true) {
|
||||||
sendObjectAction(printerId, 'printer', {
|
sendObjectAction(printerId, 'printer', {
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
import { useState, useContext } from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { ApiServerContext } from '../../context/ApiServerContext'
|
||||||
|
import { message } from 'antd'
|
||||||
|
import MessageDialogView from '../../common/MessageDialogView.jsx'
|
||||||
|
|
||||||
|
const RestartMoonraker = ({ onOk, objectData }) => {
|
||||||
|
const [restartLoading, setRestartLoading] = useState(false)
|
||||||
|
const { connected, sendObjectAction } = useContext(ApiServerContext)
|
||||||
|
|
||||||
|
const handleRestart = async () => {
|
||||||
|
if (!connected) {
|
||||||
|
message.error('Not connected to server')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setRestartLoading(true)
|
||||||
|
try {
|
||||||
|
sendObjectAction(objectData._id, 'printer', {
|
||||||
|
type: 'restartMoonraker'
|
||||||
|
})
|
||||||
|
message.success('Moonraker restart initiated')
|
||||||
|
onOk()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error restarting Moonraker:', error)
|
||||||
|
} finally {
|
||||||
|
setRestartLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MessageDialogView
|
||||||
|
title='Are you sure you want to restart Moonraker?'
|
||||||
|
description={`Restarting Moonraker on ${objectData?.name || objectData?._id} will restart the Moonraker service. The printer will be temporarily unavailable.`}
|
||||||
|
onOk={handleRestart}
|
||||||
|
okText='Restart Moonraker'
|
||||||
|
okLoading={restartLoading}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
RestartMoonraker.propTypes = {
|
||||||
|
onOk: PropTypes.func.isRequired,
|
||||||
|
objectData: PropTypes.object
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RestartMoonraker
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
import { useState, useContext } from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { ApiServerContext } from '../../context/ApiServerContext'
|
||||||
|
import { message } from 'antd'
|
||||||
|
import MessageDialogView from '../../common/MessageDialogView.jsx'
|
||||||
|
|
||||||
|
const RestartPrinter = ({ onOk, objectData }) => {
|
||||||
|
const [restartLoading, setRestartLoading] = useState(false)
|
||||||
|
const { connected, sendObjectAction } = useContext(ApiServerContext)
|
||||||
|
|
||||||
|
const handleRestart = async () => {
|
||||||
|
if (!connected) {
|
||||||
|
message.error('Not connected to server')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setRestartLoading(true)
|
||||||
|
try {
|
||||||
|
sendObjectAction(objectData._id, 'printer', {
|
||||||
|
type: 'restartPrinter'
|
||||||
|
})
|
||||||
|
message.success('Printer restart initiated')
|
||||||
|
onOk()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error restarting printer:', error)
|
||||||
|
} finally {
|
||||||
|
setRestartLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MessageDialogView
|
||||||
|
title='Are you sure you want to restart this printer?'
|
||||||
|
description={`Restarting printer ${objectData?.name || objectData?._id} will reboot the printer. Any active print jobs may be interrupted.`}
|
||||||
|
onOk={handleRestart}
|
||||||
|
okText='Restart'
|
||||||
|
okLoading={restartLoading}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
RestartPrinter.propTypes = {
|
||||||
|
onOk: PropTypes.func.isRequired,
|
||||||
|
objectData: PropTypes.object
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RestartPrinter
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
import { useState, useContext } from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { ApiServerContext } from '../../context/ApiServerContext'
|
||||||
|
import { message } from 'antd'
|
||||||
|
import MessageDialogView from '../../common/MessageDialogView.jsx'
|
||||||
|
|
||||||
|
const RestartPrinterFirmware = ({ onOk, objectData }) => {
|
||||||
|
const [restartLoading, setRestartLoading] = useState(false)
|
||||||
|
const { connected, sendObjectAction } = useContext(ApiServerContext)
|
||||||
|
|
||||||
|
const handleRestart = async () => {
|
||||||
|
if (!connected) {
|
||||||
|
message.error('Not connected to server')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setRestartLoading(true)
|
||||||
|
try {
|
||||||
|
sendObjectAction(objectData._id, 'printer', {
|
||||||
|
type: 'restartPrinterFirmware'
|
||||||
|
})
|
||||||
|
message.success('Printer firmware restart initiated')
|
||||||
|
onOk()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error restarting printer firmware:', error)
|
||||||
|
} finally {
|
||||||
|
setRestartLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MessageDialogView
|
||||||
|
title='Are you sure you want to restart the printer firmware?'
|
||||||
|
description={`Restarting firmware on ${objectData?.name || objectData?._id} will restart the printer's firmware. Any active print jobs may be interrupted.`}
|
||||||
|
onOk={handleRestart}
|
||||||
|
okText='Restart Firmware'
|
||||||
|
okLoading={restartLoading}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
RestartPrinterFirmware.propTypes = {
|
||||||
|
onOk: PropTypes.func.isRequired,
|
||||||
|
objectData: PropTypes.object
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RestartPrinterFirmware
|
||||||
@ -4,13 +4,27 @@ const PrinterInfo = lazy(
|
|||||||
() => import('../../components/Dashboard/Production/Printers/PrinterInfo')
|
() => import('../../components/Dashboard/Production/Printers/PrinterInfo')
|
||||||
)
|
)
|
||||||
const NewPrinterProfile = lazy(
|
const NewPrinterProfile = lazy(
|
||||||
() => import('../../components/Dashboard/Production/PrinterProfiles/NewPrinterProfile')
|
() =>
|
||||||
|
import('../../components/Dashboard/Production/PrinterProfiles/NewPrinterProfile')
|
||||||
)
|
)
|
||||||
const LoadFilamentStock = lazy(
|
const LoadFilamentStock = lazy(
|
||||||
() => import('../../components/Dashboard/Inventory/FilamentStocks/LoadFilamentStock')
|
() =>
|
||||||
|
import('../../components/Dashboard/Inventory/FilamentStocks/LoadFilamentStock')
|
||||||
)
|
)
|
||||||
const UnloadFilamentStock = lazy(
|
const UnloadFilamentStock = lazy(
|
||||||
() => import('../../components/Dashboard/Inventory/FilamentStocks/UnloadFilamentStock')
|
() =>
|
||||||
|
import('../../components/Dashboard/Inventory/FilamentStocks/UnloadFilamentStock')
|
||||||
|
)
|
||||||
|
const RestartPrinter = lazy(
|
||||||
|
() => import('../../components/Dashboard/Production/Printers/RestartPrinter')
|
||||||
|
)
|
||||||
|
const RestartPrinterFirmware = lazy(
|
||||||
|
() =>
|
||||||
|
import('../../components/Dashboard/Production/Printers/RestartPrinterFirmware')
|
||||||
|
)
|
||||||
|
const RestartMoonraker = lazy(
|
||||||
|
() =>
|
||||||
|
import('../../components/Dashboard/Production/Printers/RestartMoonraker')
|
||||||
)
|
)
|
||||||
import PrinterIcon from '../../components/Icons/PrinterIcon'
|
import PrinterIcon from '../../components/Icons/PrinterIcon'
|
||||||
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
|
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
|
||||||
@ -89,7 +103,11 @@ export const Printer = {
|
|||||||
label: 'New Printer Profile',
|
label: 'New Printer Profile',
|
||||||
icon: PlusIcon,
|
icon: PlusIcon,
|
||||||
content: (objectData, { onOk } = {}) => {
|
content: (objectData, { onOk } = {}) => {
|
||||||
return createElement(NewPrinterProfile, { defaultValues: { printer: objectData }, onOk, reset: true })
|
return createElement(NewPrinterProfile, {
|
||||||
|
defaultValues: { printer: objectData },
|
||||||
|
onOk,
|
||||||
|
reset: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ type: 'divider' },
|
{ type: 'divider' },
|
||||||
@ -103,34 +121,46 @@ export const Printer = {
|
|||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: 'restart',
|
name: 'restart',
|
||||||
|
type: 'modal',
|
||||||
|
modalWidth: 520,
|
||||||
|
modalCentered: true,
|
||||||
label: 'Restart',
|
label: 'Restart',
|
||||||
icon: ReloadIcon,
|
icon: ReloadIcon,
|
||||||
disabled: (objectData) => {
|
disabled: (objectData) => {
|
||||||
return objectData?.online == false
|
return objectData?.online == false
|
||||||
},
|
},
|
||||||
url: (_id) =>
|
content: (objectData, { onOk } = {}) => {
|
||||||
`/dashboard/production/printers/control?printerId=${_id}&action=restart`
|
return createElement(RestartPrinter, { objectData, onOk })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'restartFirmware',
|
name: 'restartFirmware',
|
||||||
|
type: 'modal',
|
||||||
|
modalWidth: 520,
|
||||||
|
modalCentered: true,
|
||||||
label: 'Restart Firmware',
|
label: 'Restart Firmware',
|
||||||
icon: ReloadIcon,
|
icon: ReloadIcon,
|
||||||
disabled: (objectData) => {
|
disabled: (objectData) => {
|
||||||
return objectData?.online == false
|
return objectData?.online == false
|
||||||
},
|
},
|
||||||
url: (_id) =>
|
content: (objectData, { onOk } = {}) => {
|
||||||
`/dashboard/production/printers/control?printerId=${_id}&action=restartFirmware`
|
return createElement(RestartPrinterFirmware, { objectData, onOk })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{ type: 'divider' },
|
{ type: 'divider' },
|
||||||
{
|
{
|
||||||
name: 'restartMoonraker',
|
name: 'restartMoonraker',
|
||||||
|
type: 'modal',
|
||||||
|
modalWidth: 520,
|
||||||
|
modalCentered: true,
|
||||||
label: 'Restart Moonraker',
|
label: 'Restart Moonraker',
|
||||||
icon: ReloadIcon,
|
icon: ReloadIcon,
|
||||||
disabled: (objectData) => {
|
disabled: (objectData) => {
|
||||||
return objectData?.online == false
|
return objectData?.online == false
|
||||||
},
|
},
|
||||||
url: (_id) =>
|
content: (objectData, { onOk } = {}) => {
|
||||||
`/dashboard/production/printers/control?printerId=${_id}&action=restartMoonraker`
|
return createElement(RestartMoonraker, { objectData, onOk })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -276,13 +306,7 @@ export const Printer = {
|
|||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt'
|
'updatedAt'
|
||||||
],
|
],
|
||||||
sorters: [
|
sorters: ['name', 'state', 'connectedAt', 'createdAt', 'updatedAt'],
|
||||||
'name',
|
|
||||||
'state',
|
|
||||||
'connectedAt',
|
|
||||||
'createdAt',
|
|
||||||
'updatedAt'
|
|
||||||
],
|
|
||||||
group: ['tags'],
|
group: ['tags'],
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user