Tom Butcher 5ed086cf8b Enhance Sidebar and Object Models with List Action Integration
- Added a 'list' action to various object models, including AppPassword, AuditLog, Client, and more, to standardize access to list views across the application.
- Updated the ObjectModels.js to include a new label for the 'list' action, improving clarity in the permission matrix.
- Refactored Sidebar.js to incorporate user profile permissions for sidebar item visibility, enhancing user experience based on access rights.
- Introduced utility functions for normalizing paths and filtering sidebar items based on user permissions, streamlining sidebar management.
- Improved the overall structure and readability of the Sidebar and ObjectModels components.
2026-08-20 20:14:57 +01:00

203 lines
4.1 KiB
JavaScript

import { createElement, lazy } from 'react'
const SubJobInfo = lazy(
() => import('../../components/Dashboard/Production/SubJobs/SubJobInfo')
)
import SubJobIcon from '../../components/Icons/SubJobIcon'
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
import XMarkIcon from '../../components/Icons/XMarkIcon'
import dayjs from 'dayjs'
import ListIcon from '../../components/Icons/ListIcon'
export const SubJob = {
name: 'subJob',
label: 'Sub Job',
labelPlural: 'Sub Jobs',
url: '/dashboard/production/subjobs',
prefix: 'SJB',
icon: SubJobIcon,
actions: [
{
name: 'list',
type: 'page',
pageName: 'list',
label: 'List',
icon: ListIcon
},
{
name: 'info',
type: 'page',
pageName: 'info',
label: 'Info',
default: true,
row: true,
icon: InfoCircleIcon
},
{
name: 'cancel',
type: 'page',
pageName: 'info',
label: 'Cancel Sub Job',
row: true,
icon: XMarkIcon,
disabled: (objectData) => {
return objectData?.state?.type !== 'queued'
}
}
],
pages: [
{
name: 'info',
content: () => createElement(SubJobInfo)
}
],
columns: [
'_reference',
'printer',
'job',
'state',
'startedAt',
'finishedAt',
'createdAt',
'updatedAt'
],
filters: [
'_id',
'job',
'printer',
'_reference',
'state',
'createdAt',
'updatedAt',
'startedAt',
'finishedAt'
],
sorters: [
'createdAt',
'state',
'updatedAt',
'startedAt',
'finishedAt',
'job',
'printer'
],
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: 'updatedAt',
label: 'Updated At',
type: 'dateTime',
readOnly: true,
columnWidth: 175
},
{
name: 'state',
label: 'State',
type: 'state',
objectType: 'subJob',
showStatus: true,
showProgress: true,
showId: false,
showQuantity: false,
columnWidth: 260,
readOnly: true
},
{
name: 'startedAt',
label: 'Started At',
type: 'dateTime',
readOnly: true,
columnWidth: 175
},
{
name: 'moonrakerJobId',
label: 'Moonraker Job ID',
type: 'miscId',
columnWidth: 140,
showCopy: true
},
{
name: 'finishedAt',
label: 'Finished At',
type: 'dateTime',
readOnly: true,
columnWidth: 175
},
{
name: 'job',
label: 'Job',
type: 'object',
objectType: 'job',
showHyperlink: true,
columnWidth: 200
},
{
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(' ')
}
}
]
}