OpenDroneMap-WebODM/coreplugins/dronedb/public/ImportView.jsx

116 wiersze
2.8 KiB
React
Czysty Zwykły widok Historia

2022-01-04 17:13:15 +00:00
import React, { Component, Fragment } from "react";
import PropTypes from 'prop-types';
import ResizeModes from 'webodm/classes/ResizeModes';
2022-01-13 17:39:43 +00:00
import { Modal, Button } from "react-bootstrap";
import SelectUrlDialog from "./components/SelectUrlDialog";
2022-01-04 17:13:15 +00:00
import ErrorDialog from "./components/ErrorDialog";
import ConfigureNewTaskDialog from "./components/ConfigureNewTaskDialog";
2022-01-07 18:02:01 +00:00
import "./ImportView.scss";
2022-01-04 17:13:15 +00:00
export default class TaskView extends Component {
2022-01-14 12:20:37 +00:00
2022-01-13 17:39:43 +00:00
static propTypes = {
2022-01-04 17:13:15 +00:00
projectId: PropTypes.number.isRequired,
apiURL: PropTypes.string.isRequired,
onNewTaskAdded: PropTypes.func.isRequired,
2022-01-14 12:20:37 +00:00
}
2022-01-04 17:13:15 +00:00
state = {
error: "",
2022-01-14 18:59:28 +00:00
ddbRes: null,
2022-01-13 17:39:43 +00:00
isDialogOpen: false
2022-01-04 17:13:15 +00:00
};
2022-01-14 18:59:28 +00:00
onHideDialog = () => this.setState({ ddbRes: null, taskId: null, isDialogOpen: false });
onSelectDdbRes = res => {
console.log("Result", res);
this.setState({ ddbRes: res, isDialogOpen: false });
}
2022-01-13 17:39:43 +00:00
2022-01-04 17:13:15 +00:00
onSaveTask = taskInfo => {
// Create task
const formData = {
2022-01-14 18:59:28 +00:00
name: taskInfo.name,
options: taskInfo.options,
processing_node: taskInfo.selectedNode.id,
auto_processing_node: taskInfo.selectedNode.key == "auto",
partial: true
2022-01-04 17:13:15 +00:00
};
2022-01-07 18:02:01 +00:00
if (taskInfo.resizeMode === ResizeModes.YES) {
formData.resize_to = taskInfo.resizeSize;
2022-01-04 17:13:15 +00:00
}
$.ajax({
url: `/api/projects/${this.props.projectId}/tasks/`,
contentType: 'application/json',
data: JSON.stringify(formData),
dataType: 'json',
type: 'POST'
}).done((task) => {
$.ajax({
url: `${this.props.apiURL}/projects/${this.props.projectId}/tasks/${task.id}/import`,
contentType: 'application/json',
2022-01-14 18:59:28 +00:00
data: JSON.stringify({ddb_url: this.state.ddbRes.url}),
2022-01-04 17:13:15 +00:00
dataType: 'json',
type: 'POST'
}).done(() => {
this.onHideDialog();
this.props.onNewTaskAdded();
}).fail(error => {
this.onErrorInDialog("Failed to start importing.");
});
}).fail(() => {
this.onErrorInDialog("Cannot create new task. Please try again later.");
});
}
onErrorInDialog = msg => {
this.setState({ error: msg });
this.onHideDialog();
2022-01-14 18:59:28 +00:00
};
2022-01-13 17:39:43 +00:00
handleClick = () => {
this.setState({ isDialogOpen: true });
}
2022-01-04 17:13:15 +00:00
render() {
const {
error,
2022-01-14 18:59:28 +00:00
ddbRes,
2022-01-13 17:39:43 +00:00
isDialogOpen
2022-01-04 17:13:15 +00:00
} = this.state;
return (
<Fragment>
2022-01-07 18:02:01 +00:00
{error ? <ErrorDialog errorMessage={error} /> : ""}
<Button
bsStyle={"default"}
bsSize={"small"}
className={"platform-btn"}
onClick={this.handleClick}>
2022-01-25 14:58:57 +00:00
<i className={"ddb-icon fa-fw"} />
DroneDB Import
2022-01-07 18:02:01 +00:00
</Button>
2022-01-13 17:39:43 +00:00
<SelectUrlDialog
show={isDialogOpen}
2022-01-04 17:13:15 +00:00
onHide={this.onHideDialog}
2022-01-14 18:59:28 +00:00
onSubmit={this.onSelectDdbRes}
2022-01-14 12:20:37 +00:00
apiURL={this.props.apiURL}
2022-01-14 18:59:28 +00:00
/>
{ddbRes ?
<ConfigureNewTaskDialog
show={ddbRes !== null}
ddbRes={ddbRes}
onHide={this.onHideDialog}
onSaveTask={this.onSaveTask}
/> : ""}
2022-01-13 17:39:43 +00:00
</Fragment>
2022-01-04 17:13:15 +00:00
);
}
}