import { Meteor } from 'meteor/meteor'; import React, { useState } from 'react'; import { useTracker } from 'meteor/react-meteor-data'; import _ from 'lodash'; import SimpleTable from "/imports/ui/util/SimpleTable"; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; import Select from '@mui/material/Select'; import MenuItem from '@mui/material/MenuItem'; import {Assets, conditions} from "/imports/api/assets"; import {AssetTypes} from "/imports/api/asset-types"; const cssEditorField = { margin: '0.6rem 0', } const cssGridFieldContainer = { display: 'grid', gridTemplateColumns: "1fr 1fr", columnGap: '1rem', rowGap: '0.4rem', marginBottom: '1.5rem' } const cssFieldContainer = { display: 'flex', flexDirection: 'column', backgroundColor: '#DDD', padding: '0.5rem', border: '1px solid #999', borderRadius: '0.2rem', } const cssButtonContainer = { display: 'flex', gap: '1rem', justifyContent: 'flex-end' } const AssetEditor = ({value, close}) => { const [assetId, setAssetId] = useState(value.assetId || "") const [serial, setSerial] = useState(value.serial || "") const [condition, setCondition] = useState(value.condition || "") const [conditionDetails, setConditionDetails] = useState(value.conditionDetails || "") const [assetTypeId, setAssetTypeId] = useState(value.assetTypeId || "") const assetTypes = AssetTypes.find({}, {sort: {year: -1}}); const applyChanges = () => { close() //TODO Should invert this and only close if there was success on the server. if(value._id) Meteor.call("assets.update", value._id, assetTypeId, assetId, serial, condition, conditionDetails); else Meteor.call("assets.add", assetTypeId, assetId, serial, condition, conditionDetails); } const rejectChanges = () => { close() } return (

Asset Editor

{setAssetTypeId(e.target.value)}} label="Asset Type"> {assetTypes.map((assetType, i) => { return {assetType.name} })} {setAssetId(e.target.value)}}/> {setCondition(e.target.value)}}> {conditions.map((condition, i) => { return {condition} })} {setSerial(e.target.value)}}/> {setConditionDetails(e.target.value)}}/>
) } export default () => { Meteor.subscribe('assetTypes'); Meteor.subscribe('assets'); const {assets} = useTracker(() => { const assets = Assets.find({}).fetch(); const assetTypes = AssetTypes.find({}, {sort: {year: -1}}).fetch(); const assetTypeNameMap = assetTypes.reduce((map, obj) => { map[obj._id] = obj; return map; }, {}) for(let asset of assets) { asset.assetType = assetTypeNameMap[asset.assetTypeId] } return { assets } }); const columns = [ { name: "Asset ID", value: (row) => row.assetId, }, { name: "Serial", value: (row) => row.serial, }, { name: "Condition", value: (row) => row.condition, }, { name: "AssetType", value: (row) => row.assetType.name, }, ] const options = { key: (row) => row._id, editor: (row, close) => {return ()}, add: true, maxHeight: '40rem' } return ( <> ) }