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