OpenDroneMap-WebODM/app/static/app/js/components/TaskList.jsx

85 wiersze
1.9 KiB
React
Czysty Zwykły widok Historia

2016-10-25 14:47:49 +00:00
import React from 'react';
import '../css/TaskList.scss';
2016-10-27 16:26:15 +00:00
import TaskListItem from './TaskListItem';
2016-10-25 14:47:49 +00:00
class TaskList extends React.Component {
constructor(){
super();
2016-10-26 21:35:31 +00:00
this.state = {
2016-10-27 16:26:15 +00:00
tasks: [],
error: "",
loading: true
2016-10-26 21:35:31 +00:00
};
2016-10-27 16:26:15 +00:00
this.refresh = this.refresh.bind(this);
this.retry = this.retry.bind(this);
this.deleteTask = this.deleteTask.bind(this);
2016-10-25 14:47:49 +00:00
}
componentDidMount(){
2016-10-26 21:35:31 +00:00
this.loadTaskList();
2016-10-25 14:47:49 +00:00
}
refresh(){
2016-10-26 21:35:31 +00:00
this.loadTaskList();
}
retry(){
this.setState({error: "", loading: true});
this.refresh();
}
2016-10-26 21:35:31 +00:00
loadTaskList(){
this.taskListRequest =
$.getJSON(this.props.source, json => {
2016-10-27 16:26:15 +00:00
this.setState({
tasks: json
});
})
.fail((jqXHR, textStatus, errorThrown) => {
this.setState({
error: `Could not load task list: ${textStatus}`,
2016-10-27 16:26:15 +00:00
});
})
.always(() => {
this.setState({
loading: false
})
});
2016-10-26 21:35:31 +00:00
}
componentWillUnmount(){
this.taskListRequest.abort();
2016-10-25 14:47:49 +00:00
}
deleteTask(id){
this.setState({
tasks: this.state.tasks.filter(t => t.id !== id)
});
}
2016-10-25 14:47:49 +00:00
render() {
2016-10-27 20:40:22 +00:00
let message = "";
if (this.state.loading){
message = (<span>Loading... <i className="fa fa-refresh fa-spin fa-fw"></i></span>);
}else if (this.state.error){
message = (<span>Error: {this.state.error}. <a href="javascript:void(0);" onClick={this.retry}>Try again</a></span>);
2016-10-27 20:40:22 +00:00
}else if (this.state.tasks.length === 0){
message = (<span>This project has no tasks. Create one by uploading some images!</span>);
}
2016-10-25 14:47:49 +00:00
return (
<div className="task-list">
2016-10-27 20:40:22 +00:00
{message}
2016-10-27 16:26:15 +00:00
{this.state.tasks.map(task => (
<TaskListItem data={task} key={task.id} refreshInterval={3000} onDelete={this.deleteTask} />
2016-10-27 16:26:15 +00:00
))}
2016-10-25 14:47:49 +00:00
</div>
);
}
}
export default TaskList;