kopia lustrzana https://github.com/OpenDroneMap/WebODM
Added share to dronedb button
rodzic
5d71c09460
commit
6ad0bc9f7c
|
@ -248,8 +248,6 @@ class CheckUrlTaskView(TaskView):
|
|||
combined_id = "{}_{}".format(project_pk, pk)
|
||||
data = get_current_plugin().get_global_data_store().get_json(combined_id, default = None)
|
||||
|
||||
logger.info(data)
|
||||
|
||||
if data == None or 'ddbWebUrl' not in data:
|
||||
return Response({'ddbWebUrl': None}, status=status.HTTP_200_OK)
|
||||
else:
|
||||
|
|
|
@ -28,7 +28,7 @@ class Plugin(PluginBase):
|
|||
return ["build/ImportView.css", "build/TaskView.css"]
|
||||
|
||||
def build_jsx_components(self):
|
||||
return ["ImportView.jsx", "TaskView.jsx"]
|
||||
return ["ImportView.jsx", "TaskView.jsx", "ShareButton.jsx"]
|
||||
|
||||
def api_mount_points(self):
|
||||
return [
|
||||
|
|
|
@ -0,0 +1,184 @@
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Storage from 'webodm/classes/Storage';
|
||||
import ErrorMessage from 'webodm/components/ErrorMessage';
|
||||
import $ from 'jquery';
|
||||
|
||||
const ICON_CLASS_MAPPER = [
|
||||
// Idle
|
||||
'fas fa-cloud fa-fw',
|
||||
// Running
|
||||
'fa fa-circle-notch fa-spin fa-fw',
|
||||
// Error
|
||||
'fa fa-exclamation-triangle',
|
||||
// Done
|
||||
'fas fa-external-link-alt'
|
||||
];
|
||||
|
||||
const BUTTON_TEXT_MAPPER = [
|
||||
// Idle
|
||||
'Share to DroneDB',
|
||||
// Running
|
||||
'Sharing...',
|
||||
// Error
|
||||
'Error',
|
||||
// Done
|
||||
'View on DroneDB'
|
||||
];
|
||||
|
||||
export default class ShareButton extends React.Component{
|
||||
static defaultProps = {
|
||||
task: null,
|
||||
token: ""
|
||||
};
|
||||
|
||||
static propTypes = {
|
||||
task: PropTypes.object.isRequired,
|
||||
token: PropTypes.string.isRequired // OAM Token
|
||||
};
|
||||
|
||||
constructor(props){
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
taskInfo: null,
|
||||
error: ''
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
componentDidMount(){
|
||||
this.updateTaskInfo(false);
|
||||
}
|
||||
|
||||
updateTaskInfo = (showErrors) => {
|
||||
const { task } = this.props;
|
||||
return $.ajax({
|
||||
type: 'GET',
|
||||
url: `/api/plugins/dronedb/task/${task.id}/status`,
|
||||
contentType: 'application/json'
|
||||
}).done(taskInfo => {
|
||||
// Allow a user to specify a better name for the sensor
|
||||
// and remember it.
|
||||
let sensor = Storage.getItem("oam_sensor_pref_" + taskInfo.sensor);
|
||||
if (sensor) taskInfo.sensor = sensor;
|
||||
|
||||
// Allow a user to change the default provider name
|
||||
let provider = Storage.getItem("oam_provider_pref");
|
||||
if (provider) taskInfo.provider = provider;
|
||||
|
||||
this.setState({taskInfo, loading: false});
|
||||
if (taskInfo.error && showErrors) this.setState({error: taskInfo.error});
|
||||
}).fail(error => {
|
||||
this.setState({error: error.statusText, loading: false});
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount(){
|
||||
if (this.monitorTimeout) clearTimeout(this.monitorTimeout);
|
||||
}
|
||||
|
||||
handleClick = () => {
|
||||
const { taskInfo } = this.state;
|
||||
if (!taskInfo.shared){
|
||||
this.shareDialog.show();
|
||||
}else if (taskInfo.oam_upload_id){
|
||||
window.open(`https://map.openaerialmap.org/#/upload/status/${encodeURIComponent(taskInfo.oam_upload_id)}`, '_blank');
|
||||
}
|
||||
}
|
||||
|
||||
shareToDdb = (formData) => {
|
||||
const { task } = this.props;
|
||||
|
||||
const oamParams = {
|
||||
token: this.props.token,
|
||||
sensor: formData.sensor,
|
||||
acquisition_start: formData.startDate,
|
||||
acquisition_end: formData.endDate,
|
||||
title: formData.title,
|
||||
provider: formData.provider,
|
||||
tags: formData.tags
|
||||
};
|
||||
|
||||
return $.ajax({
|
||||
url: `/api/plugins/dronedb/task/${task.id}/share`,
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
oamParams: oamParams
|
||||
}),
|
||||
dataType: 'json',
|
||||
type: 'POST'
|
||||
}).done(taskInfo => {
|
||||
// Allow a user to associate the sensor name coming from the EXIF tags
|
||||
// to one that perhaps is more human readable.
|
||||
Storage.setItem("oam_sensor_pref_" + taskInfo.sensor, formData.sensor);
|
||||
Storage.setItem("oam_provider_pref", formData.provider);
|
||||
|
||||
this.setState({taskInfo});
|
||||
this.monitorProgress();
|
||||
});
|
||||
}
|
||||
|
||||
monitorProgress = () => {
|
||||
if (this.state.taskInfo.sharing){
|
||||
// Monitor progress
|
||||
this.monitorTimeout = setTimeout(() => {
|
||||
this.updateTaskInfo(true).always(this.monitorProgress);
|
||||
}, 5000);
|
||||
}
|
||||
}*/
|
||||
|
||||
handleClick = e => {
|
||||
console.log("Clicked");
|
||||
}
|
||||
|
||||
|
||||
render(){
|
||||
const { taskInfo, error } = this.state;
|
||||
|
||||
const getButtonIcon = () => {
|
||||
|
||||
if (taskInfo == null) return "fa fa-circle-notch fa-spin fa-fw";
|
||||
if (taskInfo.error) return "fa fa-exclamation-triangle";
|
||||
|
||||
return ICON_CLASS_MAPPER[taskInfo.status];
|
||||
};
|
||||
|
||||
const getButtonLabel = () => {
|
||||
|
||||
if (taskInfo == null) return "Share on DroneDB";
|
||||
if (taskInfo.error) return "DroneDB plugin error";
|
||||
|
||||
return BUTTON_TEXT_MAPPER[taskInfo.status];
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="share-button">
|
||||
<button className="btn btn-primary btn-sm" onClick={this.handleClick} disabled={taskInfo == null || taskInfo.error}>
|
||||
<i className={getButtonIcon()}></i>
|
||||
{getButtonLabel()}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
|
||||
/*
|
||||
const result = [
|
||||
<ErrorMessage bind={[this, "error"]} />,
|
||||
<button
|
||||
onClick={this.handleClick}
|
||||
disabled={loading || taskInfo.sharing || error}
|
||||
className="btn btn-sm btn-primary">
|
||||
{[<i className={getButtonIcon()}></i>, getButtonLabel()]}
|
||||
</button>];
|
||||
|
||||
if (taskInfo.sensor !== undefined){
|
||||
result.unshift(<ShareDialog
|
||||
ref={(domNode) => { this.shareDialog = domNode; }}
|
||||
task={this.props.task}
|
||||
taskInfo={taskInfo}
|
||||
saveAction={this.shareToOAM}
|
||||
/>);
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
|
@ -29,3 +29,12 @@ PluginsAPI.Dashboard.addTaskActionButton(
|
|||
return reactElement;
|
||||
}
|
||||
);
|
||||
|
||||
PluginsAPI.Dashboard.addTaskActionButton(['dronedb/build/ShareButton.js'],function(args, ShareButton){
|
||||
var task = args.task;
|
||||
|
||||
if (task.available_assets !== null && task.available_assets.length > 0){
|
||||
return React.createElement(ShareButton, {task: task, token: "${token}"});
|
||||
}
|
||||
}
|
||||
);
|
Ładowanie…
Reference in New Issue