2022-09-07 08:58:00 -07:00
|
|
|
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 {Sites} from "/imports/api/sites";
|
|
|
|
|
|
|
|
|
|
const cssEditorField = {
|
|
|
|
|
margin: '0.6rem 0',
|
|
|
|
|
}
|
|
|
|
|
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 SiteEditor = ({value, close}) => {
|
|
|
|
|
const [name, setName] = useState(value.name || "")
|
2023-06-16 11:52:48 -07:00
|
|
|
const [externalId, setExternalId] = useState(value.externalId || "")
|
2022-09-07 08:58:00 -07:00
|
|
|
|
2025-09-25 09:31:02 -07:00
|
|
|
const applyChanges = async () => {
|
2022-09-07 08:58:00 -07:00
|
|
|
close()
|
|
|
|
|
//TODO Should invert this and only close if there was success on the server.
|
|
|
|
|
if(value._id)
|
2025-09-25 09:31:02 -07:00
|
|
|
await Meteor.callAsync("sites.update", value._id, name, externalId);
|
2022-09-07 08:58:00 -07:00
|
|
|
else
|
2025-09-25 09:31:02 -07:00
|
|
|
await Meteor.callAsync("sites.add", name, externalId);
|
2022-09-07 08:58:00 -07:00
|
|
|
}
|
|
|
|
|
const rejectChanges = () => {
|
|
|
|
|
close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div style={cssFieldContainer}>
|
|
|
|
|
<h1>Site Editor</h1>
|
|
|
|
|
<TextField style={cssEditorField} variant="standard" label="Name" value={name} onChange={(e) => {setName(e.target.value)}}/>
|
2023-06-16 11:52:48 -07:00
|
|
|
<TextField style={cssEditorField} variant="standard" label="External ID" value={externalId} onChange={(e) => {setExternalId(e.target.value)}}/>
|
2022-09-07 08:58:00 -07:00
|
|
|
<div style={cssButtonContainer}>
|
|
|
|
|
<Button variant="contained" className="button accept-button" onClick={applyChanges}>Accept</Button>
|
|
|
|
|
<Button variant="outlined" className="button reject-button" onClick={rejectChanges}>Reject</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default () => {
|
|
|
|
|
Meteor.subscribe('sites');
|
|
|
|
|
|
2025-09-25 09:31:02 -07:00
|
|
|
const {sites} = useTracker(async () => {
|
|
|
|
|
const sites = await Sites.find({}).fetchAsync();
|
2022-09-07 08:58:00 -07:00
|
|
|
return {
|
|
|
|
|
sites
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
|
{
|
|
|
|
|
name: "Name",
|
|
|
|
|
value: (row) => row.name,
|
|
|
|
|
},
|
2023-06-16 11:52:48 -07:00
|
|
|
{
|
|
|
|
|
name: "External ID",
|
|
|
|
|
value: (row) => row.externalId,
|
|
|
|
|
},
|
2022-09-07 08:58:00 -07:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
|
key: (row) => row._id,
|
|
|
|
|
editor: (row, close) => {return (<SiteEditor value={row} close={close}/>)},
|
|
|
|
|
add: true,
|
|
|
|
|
maxHeight: '40rem',
|
|
|
|
|
keyHandler: (e, selected) => {
|
|
|
|
|
if(selected && selected._id && e.key === "Delete") {
|
|
|
|
|
Meteor.call("sites.remove", selected._id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<SimpleTable rows={sites} columns={columns} options={options}/>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|