mirror of
https://github.com/ascribe/onion.git
synced 2025-02-14 21:10:27 +01:00
add download functionality to s3 fine uploader
This commit is contained in:
parent
9ce6c45690
commit
e6ac475ad5
@ -40,8 +40,11 @@ let FileDragAndDropPreview = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// implement a handle cancel action here that triggers fineuploaders cancel method
|
handleDownloadFile() {
|
||||||
// to delete files that are currently uploading
|
if(this.props.file.s3Url) {
|
||||||
|
open(this.props.file.s3Url);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let previewElement;
|
let previewElement;
|
||||||
@ -53,14 +56,16 @@ let FileDragAndDropPreview = React.createClass({
|
|||||||
progress={this.props.file.progress}
|
progress={this.props.file.progress}
|
||||||
url={this.props.file.url}
|
url={this.props.file.url}
|
||||||
toggleUploadProcess={this.toggleUploadProcess}
|
toggleUploadProcess={this.toggleUploadProcess}
|
||||||
areAssetsDownloadable={this.props.areAssetsDownloadable}/>);
|
areAssetsDownloadable={this.props.areAssetsDownloadable}
|
||||||
|
downloadFile={this.handleDownloadFile}/>);
|
||||||
} else {
|
} else {
|
||||||
previewElement = (<FileDragAndDropPreviewOther
|
previewElement = (<FileDragAndDropPreviewOther
|
||||||
onClick={this.handleDeleteFile}
|
onClick={this.handleDeleteFile}
|
||||||
progress={this.props.file.progress}
|
progress={this.props.file.progress}
|
||||||
type={this.props.file.type.split('/')[1]}
|
type={this.props.file.type.split('/')[1]}
|
||||||
toggleUploadProcess={this.toggleUploadProcess}
|
toggleUploadProcess={this.toggleUploadProcess}
|
||||||
areAssetsDownloadable={this.props.areAssetsDownloadable}/>);
|
areAssetsDownloadable={this.props.areAssetsDownloadable}
|
||||||
|
downloadFile={this.handleDownloadFile}/>);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -31,10 +31,6 @@ let FileDragAndDropPreviewImage = React.createClass({
|
|||||||
this.props.toggleUploadProcess();
|
this.props.toggleUploadProcess();
|
||||||
},
|
},
|
||||||
|
|
||||||
downloadFile() {
|
|
||||||
console.log('implement this');
|
|
||||||
},
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let imageStyle = {
|
let imageStyle = {
|
||||||
backgroundImage: 'url("' + this.props.url + '")',
|
backgroundImage: 'url("' + this.props.url + '")',
|
||||||
|
@ -11,7 +11,7 @@ let FileDragAndDropPreviewOther = React.createClass({
|
|||||||
progress: React.PropTypes.number,
|
progress: React.PropTypes.number,
|
||||||
areAssetsDownloadable: React.PropTypes.bool,
|
areAssetsDownloadable: React.PropTypes.bool,
|
||||||
toggleUploadProcess: React.PropTypes.func,
|
toggleUploadProcess: React.PropTypes.func,
|
||||||
downloadFile: React.PropTypes.func,
|
downloadFile: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
@ -31,10 +31,6 @@ let FileDragAndDropPreviewOther = React.createClass({
|
|||||||
this.props.toggleUploadProcess();
|
this.props.toggleUploadProcess();
|
||||||
},
|
},
|
||||||
|
|
||||||
downloadFile() {
|
|
||||||
console.log('implement this');
|
|
||||||
},
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
let actionSymbol;
|
let actionSymbol;
|
||||||
|
@ -314,25 +314,6 @@ var ReactS3FineUploader = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onDeleteComplete(id, xhr, isError) {
|
|
||||||
if(isError) {
|
|
||||||
let notification = new GlobalNotificationModel('Couldn\'t delete file', 'danger', 10000);
|
|
||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
||||||
} else {
|
|
||||||
this.removeFileWithIdFromFilesToUpload(id);
|
|
||||||
|
|
||||||
let notification = new GlobalNotificationModel('File deleted', 'success', 5000);
|
|
||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.props.isReadyForFormSubmission && this.props.isReadyForFormSubmission(this.state.filesToUpload)) {
|
|
||||||
// if so, set uploadstatus to true
|
|
||||||
this.props.setIsUploadReady(true);
|
|
||||||
} else {
|
|
||||||
this.props.setIsUploadReady(false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
onProgress(id, name, uploadedBytes, totalBytes) {
|
onProgress(id, name, uploadedBytes, totalBytes) {
|
||||||
let newState = React.addons.update(this.state, {
|
let newState = React.addons.update(this.state, {
|
||||||
filesToUpload: { [id]: {
|
filesToUpload: { [id]: {
|
||||||
@ -364,13 +345,32 @@ var ReactS3FineUploader = React.createClass({
|
|||||||
let newState = React.addons.update(this.state, {filesToUpload: {$set: updatedFilesToUpload}});
|
let newState = React.addons.update(this.state, {filesToUpload: {$set: updatedFilesToUpload}});
|
||||||
this.setState(newState);
|
this.setState(newState);
|
||||||
} else {
|
} else {
|
||||||
let notification = new GlobalNotificationModel('Could not load attached files (Further data)', 'success', 5000);
|
let notification = new GlobalNotificationModel('Could not load attached files (Further data)', 'danger', 10000);
|
||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
|
|
||||||
throw new Error('The session request failed', response);
|
throw new Error('The session request failed', response);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onDeleteComplete(id, xhr, isError) {
|
||||||
|
if(isError) {
|
||||||
|
let notification = new GlobalNotificationModel('Couldn\'t delete file', 'danger', 10000);
|
||||||
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
|
} else {
|
||||||
|
this.removeFileWithIdFromFilesToUpload(id);
|
||||||
|
|
||||||
|
let notification = new GlobalNotificationModel('File deleted', 'success', 5000);
|
||||||
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.props.isReadyForFormSubmission && this.props.isReadyForFormSubmission(this.state.filesToUpload)) {
|
||||||
|
// if so, set uploadstatus to true
|
||||||
|
this.props.setIsUploadReady(true);
|
||||||
|
} else {
|
||||||
|
this.props.setIsUploadReady(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
handleDeleteFile(fileId) {
|
handleDeleteFile(fileId) {
|
||||||
// In some instances (when the file was already uploaded and is just displayed to the user)
|
// In some instances (when the file was already uploaded and is just displayed to the user)
|
||||||
// fineuploader does not register an id on the file (we do, don't be confused by this!).
|
// fineuploader does not register an id on the file (we do, don't be confused by this!).
|
||||||
@ -390,12 +390,8 @@ var ReactS3FineUploader = React.createClass({
|
|||||||
let fileToDelete = this.state.filesToUpload[fileId];
|
let fileToDelete = this.state.filesToUpload[fileId];
|
||||||
S3Fetcher
|
S3Fetcher
|
||||||
.deleteFile(fileToDelete.s3Key, fileToDelete.s3Bucket)
|
.deleteFile(fileToDelete.s3Key, fileToDelete.s3Bucket)
|
||||||
.then((res) => {
|
.then(() => this.onDeleteComplete(fileToDelete.id, null, false))
|
||||||
console.log(res);
|
.catch(() => this.onDeleteComplete(fileToDelete.id, null, true));
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user