206 lines
4.6 KiB
JavaScript
206 lines
4.6 KiB
JavaScript
import ProductIcon from '../../components/Icons/ProductIcon'
|
|
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
|
|
import ReloadIcon from '../../components/Icons/ReloadIcon'
|
|
import EditIcon from '../../components/Icons/EditIcon'
|
|
import CheckIcon from '../../components/Icons/CheckIcon'
|
|
import XMarkIcon from '../../components/Icons/XMarkIcon'
|
|
|
|
export const Product = {
|
|
name: 'product',
|
|
label: 'Product',
|
|
prefix: 'PRD',
|
|
icon: ProductIcon,
|
|
actions: [
|
|
{
|
|
name: 'info',
|
|
label: 'Info',
|
|
default: true,
|
|
row: true,
|
|
icon: InfoCircleIcon,
|
|
url: (_id) => `/dashboard/management/products/info?productId=${_id}`
|
|
},
|
|
{
|
|
name: 'reload',
|
|
label: 'Reload',
|
|
icon: ReloadIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/products/info?productId=${_id}&action=reload`
|
|
},
|
|
{
|
|
name: 'edit',
|
|
label: 'Edit',
|
|
row: true,
|
|
icon: EditIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/products/info?productId=${_id}&action=edit`,
|
|
visible: (objectData) => {
|
|
return !(objectData?._isEditing && objectData?._isEditing == true)
|
|
}
|
|
},
|
|
{
|
|
name: 'finishEdit',
|
|
label: 'Save Edits',
|
|
icon: CheckIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/products/info?productId=${_id}&action=finishEdit`,
|
|
visible: (objectData) => {
|
|
return objectData?._isEditing && objectData?._isEditing == true
|
|
}
|
|
},
|
|
{
|
|
name: 'cancelEdit',
|
|
label: 'Cancel Edits',
|
|
icon: XMarkIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/products/info?productId=${_id}&action=cancelEdit`,
|
|
visible: (objectData) => {
|
|
console.log(objectData?._isEditing)
|
|
return objectData?._isEditing && objectData?._isEditing == true
|
|
}
|
|
}
|
|
],
|
|
columns: [
|
|
'_id',
|
|
'name',
|
|
'tags',
|
|
'vendor',
|
|
'vendor._id',
|
|
'price',
|
|
'createdAt',
|
|
'updatedAt'
|
|
],
|
|
filters: ['_id', 'name', 'type', 'color', 'cost', 'vendor', 'vendor._id'],
|
|
sorters: ['name', 'createdAt', 'type', 'vendor', 'cost', 'updatedAt'],
|
|
properties: [
|
|
{
|
|
name: '_id',
|
|
label: 'ID',
|
|
type: 'id',
|
|
objectType: 'product',
|
|
showCopy: true,
|
|
readOnly: true
|
|
},
|
|
{
|
|
name: 'createdAt',
|
|
label: 'Created At',
|
|
type: 'dateTime',
|
|
readOnly: true
|
|
},
|
|
{
|
|
name: 'name',
|
|
label: 'Name',
|
|
required: true,
|
|
type: 'text'
|
|
},
|
|
{
|
|
name: 'updatedAt',
|
|
label: 'Updated At',
|
|
type: 'dateTime',
|
|
readOnly: true
|
|
},
|
|
{
|
|
name: 'vendor',
|
|
label: 'Vendor',
|
|
required: true,
|
|
type: 'object',
|
|
objectType: 'vendor'
|
|
},
|
|
{
|
|
name: 'vendor._id',
|
|
label: 'Vendor ID',
|
|
readOnly: true,
|
|
type: 'id',
|
|
showHyperlink: true,
|
|
objectType: 'vendor'
|
|
},
|
|
{
|
|
name: 'version',
|
|
label: 'Version',
|
|
required: false,
|
|
type: 'text'
|
|
},
|
|
{
|
|
name: 'tags',
|
|
label: 'Tags',
|
|
required: false,
|
|
type: 'tags'
|
|
},
|
|
{
|
|
name: 'priceMode',
|
|
label: 'Price Mode',
|
|
required: true,
|
|
type: 'priceMode'
|
|
},
|
|
{
|
|
name: 'margin',
|
|
label: 'Margin',
|
|
required: true,
|
|
type: 'number',
|
|
disabled: (objectData) => {
|
|
return objectData.priceMode == 'amount'
|
|
},
|
|
suffix: '%',
|
|
min: 0,
|
|
max: 100,
|
|
step: 0.01
|
|
},
|
|
{
|
|
name: 'amount',
|
|
label: 'Amount',
|
|
disabled: (objectData) => {
|
|
return objectData.priceMode == 'margin'
|
|
},
|
|
type: 'number',
|
|
required: true,
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.1
|
|
},
|
|
{
|
|
name: 'parts',
|
|
label: 'Parts',
|
|
type: 'objectChildren',
|
|
objectType: 'part',
|
|
properties: [
|
|
{
|
|
name: 'part',
|
|
label: 'Part',
|
|
type: 'object',
|
|
objectType: 'part',
|
|
required: true
|
|
},
|
|
{
|
|
name: 'part._id',
|
|
label: 'Part ID',
|
|
type: 'id',
|
|
objectType: 'part',
|
|
showHyperlink: true,
|
|
value: (objectData) => {
|
|
return objectData?.part?._id
|
|
}
|
|
},
|
|
{
|
|
name: 'quantity',
|
|
label: 'Quantity',
|
|
type: 'number',
|
|
required: true
|
|
}
|
|
],
|
|
rollups: [
|
|
{
|
|
name: 'totalQuantity',
|
|
label: 'Total',
|
|
type: 'number',
|
|
property: 'quantity',
|
|
value: (objectData) => {
|
|
return objectData?.parts?.reduce(
|
|
(acc, part) => acc + part.quantity,
|
|
0
|
|
)
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|