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

109 wiersze
2.6 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';
2017-09-06 15:47:04 +00:00
import PropTypes from 'prop-types';
import $ from 'jquery';
2020-12-16 16:35:54 +00:00
import { _, interpolate } from '../classes/gettext';
2016-10-25 14:47:49 +00:00
class TaskList extends React.Component {
2017-09-06 15:47:04 +00:00
static propTypes = {
history: PropTypes.object.isRequired,
source: PropTypes.string.isRequired, // URL where to load task list
onDelete: PropTypes.func,
2021-08-04 20:20:51 +00:00
onTaskMoved: PropTypes.func,
hasPermission: PropTypes.func.isRequired
2017-09-06 15:47:04 +00:00
}
constructor(props){
super(props);
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({
2020-12-16 16:35:54 +00:00
error: interpolate(_("Could not load task list: %(error)s"), { error: 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)
});
if (this.props.onDelete) this.props.onDelete(id);
}
2021-08-04 20:20:51 +00:00
moveTask = (task) => {
this.refresh();
if (this.props.onTaskMoved) this.props.onTaskMoved(task);
}
2016-10-25 14:47:49 +00:00
render() {
2016-10-27 20:40:22 +00:00
let message = "";
if (this.state.loading){
2020-12-16 16:35:54 +00:00
message = (<span>{_("Loading...")} <i className="fa fa-sync fa-spin fa-fw"></i></span>);
2016-10-27 20:40:22 +00:00
}else if (this.state.error){
2020-12-16 16:35:54 +00:00
message = (<span>{interpolate(_("Error: %(error)s"), {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){
2021-08-04 20:20:51 +00:00
message = (<span></span>);
2016-10-27 20:40:22 +00:00
}
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}
onMove={this.moveTask}
hasPermission={this.props.hasPermission}
history={this.props.history} />
2016-10-27 16:26:15 +00:00
))}
2016-10-25 14:47:49 +00:00
</div>
);
}
}
export default TaskList;