All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
150 lines
3.5 KiB
JavaScript
150 lines
3.5 KiB
JavaScript
import SubJobIcon from '../../components/Icons/SubJobIcon'
|
|
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
|
|
import XMarkIcon from '../../components/Icons/XMarkIcon'
|
|
import dayjs from 'dayjs'
|
|
|
|
export const SubJob = {
|
|
name: 'subJob',
|
|
label: 'Sub Job',
|
|
prefix: 'SJB',
|
|
icon: SubJobIcon,
|
|
actions: [
|
|
{
|
|
name: 'info',
|
|
label: 'Info',
|
|
default: true,
|
|
row: true,
|
|
icon: InfoCircleIcon,
|
|
url: (_id) => `/dashboard/production/subjobs/info?subJobId=${_id}`
|
|
},
|
|
{
|
|
name: 'cancel',
|
|
label: 'Cancel Sub Job',
|
|
row: true,
|
|
icon: XMarkIcon,
|
|
url: (_id) =>
|
|
`/dashboard/production/subjobs/info?subJobId=${_id}&action=cancel`,
|
|
disabled: (objectData) => {
|
|
return objectData?.state?.type !== 'queued'
|
|
}
|
|
}
|
|
],
|
|
columns: ['_reference', 'printer', 'job', 'state', 'createdAt'],
|
|
filters: ['state', '_id', 'job', 'printer'],
|
|
sorters: ['createdAt', 'state'],
|
|
group: ['job'],
|
|
properties: [
|
|
{
|
|
name: '_id',
|
|
label: 'ID',
|
|
type: 'id',
|
|
columnFixed: 'left',
|
|
objectType: 'subJob',
|
|
columnWidth: 140,
|
|
showCopy: true
|
|
},
|
|
{
|
|
name: 'createdAt',
|
|
label: 'Created At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 175
|
|
},
|
|
{
|
|
name: '_reference',
|
|
label: 'Reference',
|
|
type: 'reference',
|
|
columnFixed: 'left',
|
|
objectType: 'subJob',
|
|
showCopy: true,
|
|
readOnly: true,
|
|
columnWidth: 180
|
|
},
|
|
{
|
|
name: 'state',
|
|
label: 'State',
|
|
type: 'state',
|
|
objectType: 'subJob',
|
|
showStatus: true,
|
|
showProgress: true,
|
|
showId: false,
|
|
showQuantity: false,
|
|
columnWidth: 250,
|
|
readOnly: true
|
|
},
|
|
{
|
|
name: 'updatedAt',
|
|
label: 'Updated At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 175
|
|
},
|
|
{
|
|
name: 'moonrakerJobId',
|
|
label: 'Moonraker Job ID',
|
|
type: 'miscId',
|
|
columnWidth: 140,
|
|
showCopy: true
|
|
},
|
|
{
|
|
name: 'startedAt',
|
|
label: 'Started At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 175
|
|
},
|
|
{
|
|
name: 'job',
|
|
label: 'Job',
|
|
type: 'object',
|
|
objectType: 'job',
|
|
showHyperlink: true,
|
|
columnWidth: 200
|
|
},
|
|
{
|
|
name: 'finishedAt',
|
|
label: 'Finished At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 175
|
|
},
|
|
{
|
|
name: 'printer',
|
|
label: 'Printer',
|
|
type: 'object',
|
|
columnFixed: 'left',
|
|
objectType: 'printer',
|
|
showHyperlink: true,
|
|
columnWidth: 200
|
|
},
|
|
{
|
|
name: 'totalTime',
|
|
label: 'Total Time',
|
|
type: 'text',
|
|
columnWidth: 110,
|
|
readOnly: true,
|
|
value: (objectData) => {
|
|
if (!objectData?.startedAt || !objectData?.finishedAt) {
|
|
return '-'
|
|
}
|
|
const totalSeconds = dayjs(objectData?.finishedAt).diff(
|
|
dayjs(objectData?.startedAt),
|
|
'seconds'
|
|
)
|
|
const days = Math.floor(totalSeconds / 86400)
|
|
const hours = Math.floor((totalSeconds % 86400) / 3600)
|
|
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
|
const seconds = totalSeconds % 60
|
|
|
|
const parts = []
|
|
if (days > 0) parts.push(`${days}d`)
|
|
if (hours > 0) parts.push(`${hours}h`)
|
|
if (minutes > 0) parts.push(`${minutes}m`)
|
|
if (seconds > 0 || parts.length === 0) parts.push(`${seconds}s`)
|
|
|
|
return parts.join(' ')
|
|
}
|
|
}
|
|
]
|
|
}
|