186 lines
4.1 KiB
JavaScript
186 lines
4.1 KiB
JavaScript
import JobIcon from '../../components/Icons/JobIcon'
|
|
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
|
|
import CheckIcon from '../../components/Icons/CheckIcon'
|
|
import dayjs from 'dayjs'
|
|
|
|
export const Job = {
|
|
name: 'job',
|
|
label: 'Job',
|
|
labelPlural: 'Jobs',
|
|
url: '/dashboard/production/jobs',
|
|
prefix: 'JOB',
|
|
icon: JobIcon,
|
|
actions: [
|
|
{
|
|
name: 'info',
|
|
label: 'Info',
|
|
default: true,
|
|
row: true,
|
|
icon: InfoCircleIcon,
|
|
url: (_id) => `/dashboard/production/jobs/info?jobId=${_id}`
|
|
},
|
|
{
|
|
name: 'deploy',
|
|
label: 'Deploy',
|
|
default: true,
|
|
row: true,
|
|
icon: CheckIcon,
|
|
url: (_id) =>
|
|
`/dashboard/production/jobs/info?jobId=${_id}&action=deploy`,
|
|
disabled: (objectData) => {
|
|
return objectData?.state?.type != 'draft'
|
|
}
|
|
},
|
|
],
|
|
columns: ['_reference', 'quantity', 'state', 'gcodeFile', 'createdAt'],
|
|
filters: ['state', '_id', 'gcodeFile', 'quantity'],
|
|
sorters: ['createdAt', 'state', 'quantity', 'gcodeFile'],
|
|
properties: [
|
|
{
|
|
name: '_id',
|
|
label: 'ID',
|
|
type: 'id',
|
|
columnFixed: 'left',
|
|
objectType: 'job',
|
|
showCopy: true,
|
|
columnWidth: 140
|
|
},
|
|
{
|
|
name: 'createdAt',
|
|
label: 'Created At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 175
|
|
},
|
|
{
|
|
name: '_reference',
|
|
label: 'Reference',
|
|
type: 'reference',
|
|
columnFixed: 'left',
|
|
objectType: 'job',
|
|
showCopy: true,
|
|
readOnly: true,
|
|
columnWidth: 180
|
|
},
|
|
{
|
|
name: 'state',
|
|
label: 'State',
|
|
type: 'state',
|
|
objectType: 'job',
|
|
showStatus: true,
|
|
showProgress: true,
|
|
showId: false,
|
|
showQuantity: false,
|
|
columnWidth: 250,
|
|
readOnly: true
|
|
},
|
|
{
|
|
name: 'updatedAt',
|
|
label: 'Updated At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 175
|
|
},
|
|
{
|
|
name: 'quantity',
|
|
label: 'Quantity',
|
|
type: 'number',
|
|
columnFixed: 'left',
|
|
columnWidth: 125,
|
|
required: true
|
|
},
|
|
{
|
|
name: 'startedAt',
|
|
label: 'Started At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 175
|
|
},
|
|
{
|
|
name: 'printers',
|
|
label: 'Printers',
|
|
type: 'objectList',
|
|
objectType: 'printer',
|
|
required: true,
|
|
columnWidth: 200
|
|
},
|
|
{
|
|
name: 'finishedAt',
|
|
label: 'Finished At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 175
|
|
},
|
|
{
|
|
name: 'gcodeFile',
|
|
label: 'GCode File',
|
|
type: 'object',
|
|
columnWidth: 200,
|
|
objectType: 'gcodeFile',
|
|
required: true,
|
|
showHyperlink: true
|
|
},
|
|
{
|
|
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(' ')
|
|
}
|
|
}
|
|
],
|
|
stats: [
|
|
{
|
|
name: 'draft.count',
|
|
label: 'Draft',
|
|
type: 'number',
|
|
color: 'default'
|
|
},
|
|
{
|
|
name: 'queued.count',
|
|
label: 'Queued',
|
|
type: 'number',
|
|
color: 'warning'
|
|
},
|
|
{
|
|
name: 'printing.count',
|
|
label: 'Printing',
|
|
type: 'number',
|
|
color: 'processing'
|
|
},
|
|
{
|
|
name: 'failed.count',
|
|
label: 'Failed',
|
|
type: 'number',
|
|
combine: ['failed.count', 'cancelled.count'],
|
|
color: 'error'
|
|
},
|
|
{
|
|
name: 'complete.count',
|
|
label: 'Complete',
|
|
type: 'number',
|
|
color: 'success'
|
|
}
|
|
]
|
|
}
|