fixing errors in export
This commit is contained in:
parent
757b758d98
commit
0f54cb6862
2 changed files with 51 additions and 46 deletions
|
|
@ -172,7 +172,7 @@ export default function ComponentActions(props: Props) {
|
|||
refreshCallback={refreshCallback}
|
||||
canEdit={canEdit}
|
||||
/>
|
||||
{/* <ExportDataSettings
|
||||
<ExportDataSettings
|
||||
device={device}
|
||||
component={component}
|
||||
isDialogOpen={isExportDataOpen}
|
||||
|
|
@ -182,7 +182,7 @@ export default function ComponentActions(props: Props) {
|
|||
isJSON={isJSON}
|
||||
// newMeasurements={newStructure}
|
||||
user={user}
|
||||
/> */}
|
||||
/>
|
||||
</React.Fragment>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,13 +7,16 @@ import {
|
|||
DialogContent,
|
||||
DialogTitle,
|
||||
Divider,
|
||||
Grid,
|
||||
Grid2 as Grid,
|
||||
InputAdornment,
|
||||
TextField,
|
||||
Typography
|
||||
} from "@material-ui/core";
|
||||
import { Theme } from "@material-ui/core/styles/createMuiTheme";
|
||||
import withStyles, { WithStyles } from "@material-ui/core/styles/withStyles";
|
||||
Typography,
|
||||
Theme
|
||||
} from "@mui/material"
|
||||
//import { Theme } from "@material-ui/core/styles/createMuiTheme";
|
||||
//import withStyles, { WithStyles } from "@material-ui/core/styles/withStyles";
|
||||
import { withStyles, WithStyles } from "@mui/styles";
|
||||
|
||||
import DateSelect from "common/time/DateSelect";
|
||||
import { Component, Device, User } from "models";
|
||||
import moment, { Moment } from "moment";
|
||||
|
|
@ -53,7 +56,7 @@ interface State {
|
|||
|
||||
class ExportDataSettings extends React.Component<Props, State> {
|
||||
static contextType = ComponentAPIContext;
|
||||
context!: React.ContextType<typeof ComponentAPIContext>;
|
||||
declare context: React.ContextType<typeof ComponentAPIContext>;
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = this.defaultSettings(props);
|
||||
|
|
@ -90,12 +93,15 @@ class ExportDataSettings extends React.Component<Props, State> {
|
|||
};
|
||||
|
||||
submit = () => {
|
||||
console.log("submit export request")
|
||||
const { device, component, newMeasurements, user } = this.props;
|
||||
const { startDate, endDate } = this.state;
|
||||
const { sampleMeasurements, listUnitMeasurements } = this.context;
|
||||
|
||||
this.setState({ isLoading: true });
|
||||
if (newMeasurements) {
|
||||
console.log("Device")
|
||||
console.log(device)
|
||||
// if (newMeasurements) {
|
||||
listUnitMeasurements(
|
||||
device.id(),
|
||||
component.key(),
|
||||
|
|
@ -139,39 +145,39 @@ class ExportDataSettings extends React.Component<Props, State> {
|
|||
this.setState({ isLoading: false });
|
||||
this.close();
|
||||
});
|
||||
} else {
|
||||
sampleMeasurements(device.id(), component.key(), startDate, endDate, 4294967295)
|
||||
.then((response: any) => {
|
||||
this.formatMeasurements(response.data.measurements)
|
||||
.then((data: Array<any>) => {
|
||||
this.setState({
|
||||
isLoading: false
|
||||
});
|
||||
this.exportData(
|
||||
data
|
||||
.map(entry => {
|
||||
let out = entry;
|
||||
out.Timestamp = moment(entry.Timestamp)
|
||||
.local()
|
||||
.format();
|
||||
return out;
|
||||
})
|
||||
.sort(function(a, b) {
|
||||
return a.Timestamp < b.Timestamp ? -1 : 1;
|
||||
})
|
||||
);
|
||||
this.close();
|
||||
})
|
||||
.catch((error: any) => {
|
||||
this.setState({ isLoading: false });
|
||||
this.close();
|
||||
});
|
||||
})
|
||||
.catch((error: any) => {
|
||||
this.setState({ isLoading: false });
|
||||
this.close();
|
||||
});
|
||||
}
|
||||
// } else {
|
||||
// sampleMeasurements(device.id(), component.key(), startDate, endDate, 4294967295)
|
||||
// .then((response: any) => {
|
||||
// this.formatMeasurements(response.data.measurements)
|
||||
// .then((data: Array<any>) => {
|
||||
// this.setState({
|
||||
// isLoading: false
|
||||
// });
|
||||
// this.exportData(
|
||||
// data
|
||||
// .map(entry => {
|
||||
// let out = entry;
|
||||
// out.Timestamp = moment(entry.Timestamp)
|
||||
// .local()
|
||||
// .format();
|
||||
// return out;
|
||||
// })
|
||||
// .sort(function(a, b) {
|
||||
// return a.Timestamp < b.Timestamp ? -1 : 1;
|
||||
// })
|
||||
// );
|
||||
// this.close();
|
||||
// })
|
||||
// .catch((error: any) => {
|
||||
// this.setState({ isLoading: false });
|
||||
// this.close();
|
||||
// });
|
||||
// })
|
||||
// .catch((error: any) => {
|
||||
// this.setState({ isLoading: false });
|
||||
// this.close();
|
||||
// });
|
||||
// }
|
||||
};
|
||||
|
||||
// formatExportedMeasurements(measurements: Array<pond.ExportedMeasurement>): Promise<Array<any>> {
|
||||
|
|
@ -326,7 +332,6 @@ class ExportDataSettings extends React.Component<Props, State> {
|
|||
<Grid
|
||||
container
|
||||
direction="column"
|
||||
justify="center"
|
||||
alignItems="center"
|
||||
className={classes.loadingContent}>
|
||||
<CircularProgress color="secondary" />
|
||||
|
|
@ -343,7 +348,7 @@ class ExportDataSettings extends React.Component<Props, State> {
|
|||
|
||||
return (
|
||||
<Grid container direction="row" spacing={2}>
|
||||
<Grid item xs={12}>
|
||||
<Grid size={12}>
|
||||
<TextField
|
||||
id="exportDataFilename"
|
||||
label="Filename"
|
||||
|
|
@ -361,7 +366,7 @@ class ExportDataSettings extends React.Component<Props, State> {
|
|||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Grid size={12}>
|
||||
<DateSelect
|
||||
startDate={startDate}
|
||||
endDate={endDate}
|
||||
|
|
@ -369,7 +374,7 @@ class ExportDataSettings extends React.Component<Props, State> {
|
|||
label="Extract data from"
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Grid size={12}>
|
||||
<Typography variant="body2" color="textSecondary">
|
||||
Note: This process might take a while (depends on how much data is requested)
|
||||
</Typography>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue