Merge branch 'staging_environment' into libracart
This commit is contained in:
commit
e5300b19f4
3 changed files with 211 additions and 57 deletions
|
|
@ -6,7 +6,7 @@ import {
|
|||
DialogActions,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
Grid,
|
||||
Grid2 as Grid,
|
||||
InputAdornment,
|
||||
MenuItem,
|
||||
Slider,
|
||||
|
|
@ -19,7 +19,7 @@ import { DevicePreset } from "models/DevicePreset";
|
|||
import { ObjectTypeString } from "objects/ObjectDescriber";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useSnackbar } from "providers";
|
||||
// import { useDevicePresetAPI } from "providers/pond/devicePresetAPI";
|
||||
import { useDevicePresetAPI } from "providers/pond/devicePresetAPI";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { getTemperatureUnit } from "utils";
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ export default function DevicePresetCard(props: Props) {
|
|||
removeCallback,
|
||||
updateCallback
|
||||
} = props;
|
||||
// const devicePresetAPI = useDevicePresetAPI();
|
||||
const devicePresetAPI = useDevicePresetAPI();
|
||||
const [presetName, setPresetName] = useState("");
|
||||
const [presetType, setPresetType] = useState<pond.PresetType>(1);
|
||||
const [controllerType, setControllerType] = useState<pond.ControllerType>(1);
|
||||
|
|
@ -81,22 +81,22 @@ export default function DevicePresetCard(props: Props) {
|
|||
p.settings.temperature = tempC;
|
||||
p.settings.humidity = hum;
|
||||
|
||||
// devicePresetAPI
|
||||
// .addDevicePreset(p.name, p.settings, objectKey, typestring)
|
||||
// .then(resp => {
|
||||
// //get the temp key from the preset
|
||||
// let temp = p.key;
|
||||
// //update the key in the preset with the key that came back from the add
|
||||
// p.key = resp.data.key;
|
||||
// //use the callback function passing in the preset and the temp key
|
||||
// if (addCallback) {
|
||||
// addCallback(p, temp);
|
||||
// }
|
||||
// openSnack("New preset saved");
|
||||
// })
|
||||
// .catch(err => {
|
||||
// openSnack("Failed to save new preset");
|
||||
// });
|
||||
devicePresetAPI
|
||||
.addDevicePreset(p.name, p.settings, objectKey, typestring)
|
||||
.then(resp => {
|
||||
//get the temp key from the preset
|
||||
let temp = p.key;
|
||||
//update the key in the preset with the key that came back from the add
|
||||
p.key = resp.data.key;
|
||||
//use the callback function passing in the preset and the temp key
|
||||
if (addCallback) {
|
||||
addCallback(p, temp);
|
||||
}
|
||||
openSnack("New preset saved");
|
||||
})
|
||||
.catch(err => {
|
||||
openSnack("Failed to save new preset");
|
||||
});
|
||||
};
|
||||
|
||||
const updatePreset = () => {
|
||||
|
|
@ -108,32 +108,32 @@ export default function DevicePresetCard(props: Props) {
|
|||
newPreset.settings.temperature = tempC;
|
||||
newPreset.settings.humidity = hum;
|
||||
|
||||
// devicePresetAPI
|
||||
// .updateDevicePreset(newPreset.key, newPreset.name, newPreset.settings)
|
||||
// .then(resp => {
|
||||
// if (updateCallback) {
|
||||
// updateCallback(oldPreset, newPreset);
|
||||
// }
|
||||
// openSnack("Preset Updated");
|
||||
// })
|
||||
// .catch(err => {
|
||||
// openSnack("There was a problem updating the preset");
|
||||
// });
|
||||
devicePresetAPI
|
||||
.updateDevicePreset(newPreset.key, newPreset.name, newPreset.settings)
|
||||
.then(resp => {
|
||||
if (updateCallback) {
|
||||
updateCallback(oldPreset, newPreset);
|
||||
}
|
||||
openSnack("Preset Updated");
|
||||
})
|
||||
.catch(err => {
|
||||
openSnack("There was a problem updating the preset");
|
||||
});
|
||||
};
|
||||
|
||||
const removePreset = () => {
|
||||
// devicePresetAPI
|
||||
// .removeDevicePreset(preset.key)
|
||||
// .then(resp => {
|
||||
// openSnack("Preset has been deleted");
|
||||
// setOpenDeleteConfirmation(false);
|
||||
// if (removeCallback) {
|
||||
// removeCallback(preset);
|
||||
// }
|
||||
// })
|
||||
// .catch(err => {
|
||||
// openSnack("There was a problem deleting this preset");
|
||||
// });
|
||||
devicePresetAPI
|
||||
.removeDevicePreset(preset.key)
|
||||
.then(resp => {
|
||||
openSnack("Preset has been deleted");
|
||||
setOpenDeleteConfirmation(false);
|
||||
if (removeCallback) {
|
||||
removeCallback(preset);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
openSnack("There was a problem deleting this preset");
|
||||
});
|
||||
};
|
||||
|
||||
const deleteConfirmation = () => {
|
||||
|
|
@ -192,7 +192,7 @@ export default function DevicePresetCard(props: Props) {
|
|||
<Card raised style={{ padding: 10, width: "100%" }}>
|
||||
{deleteConfirmation()}
|
||||
<Grid container direction="row" alignContent="center" alignItems="center">
|
||||
<Grid item xs={12} sm={6}>
|
||||
<Grid size={{xs:12, sm:6}}>
|
||||
<TextField
|
||||
variant="outlined"
|
||||
margin="normal"
|
||||
|
|
@ -203,7 +203,7 @@ export default function DevicePresetCard(props: Props) {
|
|||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<Grid size={{xs:12, sm:6}}>
|
||||
{presetType !== pond.PresetType.PRESET_TYPE_UNKNOWN &&
|
||||
controllerType !== pond.ControllerType.CONTROLLER_TYPE_UNKNOWN && (
|
||||
<Box paddingLeft={2}>
|
||||
|
|
@ -216,7 +216,7 @@ export default function DevicePresetCard(props: Props) {
|
|||
</Box>
|
||||
)}
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<Grid size={6}>
|
||||
{/* type */}
|
||||
<TextField
|
||||
style={{ width: "100%", marginRight: 5 }}
|
||||
|
|
@ -250,7 +250,7 @@ export default function DevicePresetCard(props: Props) {
|
|||
</MenuItem>
|
||||
</TextField>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<Grid size={6}>
|
||||
{/* controller type */}
|
||||
<TextField
|
||||
style={{ width: "100%", marginLeft: 5 }}
|
||||
|
|
@ -281,7 +281,7 @@ export default function DevicePresetCard(props: Props) {
|
|||
</Grid>
|
||||
{/* temp slider */}
|
||||
{isMobile ? (
|
||||
<Grid item xs={12}>
|
||||
<Grid size={12}>
|
||||
<Box
|
||||
display="flex"
|
||||
alignContent="center"
|
||||
|
|
@ -338,10 +338,10 @@ export default function DevicePresetCard(props: Props) {
|
|||
</Grid>
|
||||
) : (
|
||||
<React.Fragment>
|
||||
<Grid item xs={2}>
|
||||
<Grid size={2}>
|
||||
<Typography>Temperature</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={7}>
|
||||
<Grid size={7}>
|
||||
<Box paddingRight={2}>
|
||||
<Slider
|
||||
//orientation="vertical"
|
||||
|
|
@ -362,7 +362,7 @@ export default function DevicePresetCard(props: Props) {
|
|||
/>
|
||||
</Box>
|
||||
</Grid>
|
||||
<Grid item xs={3}>
|
||||
<Grid size={3}>
|
||||
<TextField
|
||||
style={{ width: "100%" }}
|
||||
margin="dense"
|
||||
|
|
@ -395,7 +395,7 @@ export default function DevicePresetCard(props: Props) {
|
|||
)}
|
||||
{/* humidity slider */}
|
||||
{isMobile ? (
|
||||
<Grid item xs={12}>
|
||||
<Grid size={12}>
|
||||
<Box
|
||||
display="flex"
|
||||
alignContent="center"
|
||||
|
|
@ -437,10 +437,10 @@ export default function DevicePresetCard(props: Props) {
|
|||
</Grid>
|
||||
) : (
|
||||
<React.Fragment>
|
||||
<Grid item xs={2}>
|
||||
<Grid size={2}>
|
||||
<Typography>Humidity</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={7}>
|
||||
<Grid size={7}>
|
||||
<Box paddingRight={2}>
|
||||
<Slider
|
||||
//orientation="vertical"
|
||||
|
|
@ -456,7 +456,7 @@ export default function DevicePresetCard(props: Props) {
|
|||
/>
|
||||
</Box>
|
||||
</Grid>
|
||||
<Grid item xs={3}>
|
||||
<Grid size={3}>
|
||||
<TextField
|
||||
style={{ width: "100%" }}
|
||||
margin="dense"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue