zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import React, { Component, Fragment } from "react";
import PropTypes from 'prop-types';
 
import ResizeModes from 'webodm/classes/ResizeModes';
import { Modal, Button } from "react-bootstrap";
import SelectUrlDialog from "./components/SelectUrlDialog";
import ErrorDialog from "./components/ErrorDialog";
import ConfigureNewTaskDialog from "./components/ConfigureNewTaskDialog";
 
import "./ImportView.scss";
 
export default class TaskView extends Component {
    
     static propTypes = {
        projectId: PropTypes.number.isRequired,
        apiURL: PropTypes.string.isRequired,
        onNewTaskAdded: PropTypes.func.isRequired,
      }
    
    state = {
        error: "",
        ddbRes: null,
        isDialogOpen: false
    };
    
    onHideDialog = () => this.setState({ ddbRes: null, taskId: null, isDialogOpen: false });
    onSelectDdbRes = res => {
        console.log("Result", res);
        this.setState({ ddbRes: res, isDialogOpen: false });
    }
    
    
    onSaveTask = taskInfo => {
        // Create task
        const formData = {
            name: taskInfo.name,
            options: taskInfo.options,
            processing_node:  taskInfo.selectedNode.id,
            auto_processing_node: taskInfo.selectedNode.key == "auto",
            partial: true
        };
 
        if (taskInfo.resizeMode === ResizeModes.YES) {
            formData.resize_to = taskInfo.resizeSize;
        }
 
        $.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',
                        data: JSON.stringify({ddb_url: this.state.ddbRes.url}),
                        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();
    };
 
    handleClick = () => {
        this.setState({ isDialogOpen: true });
    }
 
    render() {
        const {
            error,
            ddbRes,
            isDialogOpen
        } = this.state;
        return (
            <Fragment>
                {error ? <ErrorDialog errorMessage={error} /> : ""}                
                <Button
                    bsStyle={"default"}
                    bsSize={"small"}
                    className={"platform-btn"}
                    onClick={this.handleClick}>
                        <i className={"ddb-icon fa-fw"} />
                        DroneDB Import
                </Button>
                <SelectUrlDialog
                          show={isDialogOpen}                          
                          onHide={this.onHideDialog}
                          onSubmit={this.onSelectDdbRes}
                          apiURL={this.props.apiURL}
                        />        
                {ddbRes ?                             
                    <ConfigureNewTaskDialog
                        show={ddbRes !== null}
                        ddbRes={ddbRes}                    
                        onHide={this.onHideDialog}
                        onSaveTask={this.onSaveTask}
                    /> : ""}
                
            </Fragment>        
                    
        );
    }
}