1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 01:25:17 +01:00

add download functionality to s3 fine uploader

This commit is contained in:
Tim Daubenschütz 2015-06-30 16:15:50 +02:00
parent 9ce6c45690
commit e6ac475ad5
5 changed files with 34 additions and 41 deletions

View File

@ -40,8 +40,11 @@ let FileDragAndDropPreview = React.createClass({
}
},
// implement a handle cancel action here that triggers fineuploaders cancel method
// to delete files that are currently uploading
handleDownloadFile() {
if(this.props.file.s3Url) {
open(this.props.file.s3Url);
}
},
render() {
let previewElement;
@ -53,14 +56,16 @@ let FileDragAndDropPreview = React.createClass({
progress={this.props.file.progress}
url={this.props.file.url}
toggleUploadProcess={this.toggleUploadProcess}
areAssetsDownloadable={this.props.areAssetsDownloadable}/>);
areAssetsDownloadable={this.props.areAssetsDownloadable}
downloadFile={this.handleDownloadFile}/>);
} else {
previewElement = (<FileDragAndDropPreviewOther
onClick={this.handleDeleteFile}
progress={this.props.file.progress}
type={this.props.file.type.split('/')[1]}
toggleUploadProcess={this.toggleUploadProcess}
areAssetsDownloadable={this.props.areAssetsDownloadable}/>);
areAssetsDownloadable={this.props.areAssetsDownloadable}
downloadFile={this.handleDownloadFile}/>);
}
return (

View File

@ -31,10 +31,6 @@ let FileDragAndDropPreviewImage = React.createClass({
this.props.toggleUploadProcess();
},
downloadFile() {
console.log('implement this');
},
render() {
let imageStyle = {
backgroundImage: 'url("' + this.props.url + '")',

View File

@ -11,7 +11,7 @@ let FileDragAndDropPreviewOther = React.createClass({
progress: React.PropTypes.number,
areAssetsDownloadable: React.PropTypes.bool,
toggleUploadProcess: React.PropTypes.func,
downloadFile: React.PropTypes.func,
downloadFile: React.PropTypes.func
},
getInitialState() {
@ -31,10 +31,6 @@ let FileDragAndDropPreviewOther = React.createClass({
this.props.toggleUploadProcess();
},
downloadFile() {
console.log('implement this');
},
render() {
let actionSymbol;

View File

@ -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) {
let newState = React.addons.update(this.state, {
filesToUpload: { [id]: {
@ -364,18 +345,37 @@ var ReactS3FineUploader = React.createClass({
let newState = React.addons.update(this.state, {filesToUpload: {$set: updatedFilesToUpload}});
this.setState(newState);
} 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);
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) {
// 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!).
// Since you can only delete a file by its id, we have to implement this method ourselves
//
//
// So, if an id is not present, we delete the file manually
// To check which files are already uploaded from previous sessions we check their status.
// If they are, it is "online"
@ -390,12 +390,8 @@ var ReactS3FineUploader = React.createClass({
let fileToDelete = this.state.filesToUpload[fileId];
S3Fetcher
.deleteFile(fileToDelete.s3Key, fileToDelete.s3Bucket)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
.then(() => this.onDeleteComplete(fileToDelete.id, null, false))
.catch(() => this.onDeleteComplete(fileToDelete.id, null, true));
}
},

View File

@ -100,4 +100,4 @@ function _mergeOptions(obj1, obj2){
}
}
return obj3;
}
}