1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

finalized delete functionality

This commit is contained in:
Tim Daubenschütz 2015-06-30 17:57:20 +02:00
parent bb73416a8c
commit 929c694ad7
5 changed files with 21 additions and 6 deletions

View File

@ -133,7 +133,7 @@ let FileDragAndDrop = React.createClass({
render: function () { render: function () {
// has files only is true if there are files that do not have the status deleted or canceled // has files only is true if there are files that do not have the status deleted or canceled
let hasFiles = this.props.filesToUpload.filter((file) => file.status !== 'deleted' && file.status !== 'canceled').length > 0; let hasFiles = this.props.filesToUpload.filter((file) => file.status !== 'deleted' && file.status !== 'canceled' && file.size !== -1).length > 0;
let className = hasFiles ? 'has-files ' : ''; let className = hasFiles ? 'has-files ' : '';
className += this.props.dropzoneInactive ? 'inactive-dropzone' : 'active-dropzone'; className += this.props.dropzoneInactive ? 'inactive-dropzone' : 'active-dropzone';
className += this.props.className ? ' ' + this.props.className : ''; className += this.props.className ? ' ' + this.props.className : '';

View File

@ -19,7 +19,7 @@ let FileDragAndDropPreviewIterator = React.createClass({
return ( return (
<div> <div>
{this.props.files.map((file, i) => { {this.props.files.map((file, i) => {
if(file.status !== 'deleted' && file.status !== 'canceled') { if(file.status !== 'deleted' && file.status !== 'canceled' && file.size !== -1) {
return ( return (
<FileDragAndDropPreview <FileDragAndDropPreview
key={i} key={i}

View File

@ -345,6 +345,7 @@ 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 {
// server has to respond with 204
//let notification = new GlobalNotificationModel('Could not load attached files (Further data)', 'danger', 10000); //let notification = new GlobalNotificationModel('Could not load attached files (Further data)', 'danger', 10000);
//GlobalNotificationActions.appendGlobalNotification(notification); //GlobalNotificationActions.appendGlobalNotification(notification);
// //
@ -388,6 +389,8 @@ var ReactS3FineUploader = React.createClass({
// promise // promise
} else { } else {
let fileToDelete = this.state.filesToUpload[fileId]; let fileToDelete = this.state.filesToUpload[fileId];
fileToDelete.status = 'deleted';
console.log(this.state.uploader.getUploads());
S3Fetcher S3Fetcher
.deleteFile(fileToDelete.s3Key, fileToDelete.s3Bucket) .deleteFile(fileToDelete.s3Key, fileToDelete.s3Bucket)
.then(() => this.onDeleteComplete(fileToDelete.id, null, false)) .then(() => this.onDeleteComplete(fileToDelete.id, null, false))
@ -417,7 +420,7 @@ var ReactS3FineUploader = React.createClass({
}, },
handleUploadFile(files) { handleUploadFile(files) {
console.log(this.state.files);
// If multiple set and user already uploaded its work, // If multiple set and user already uploaded its work,
// cancel upload // cancel upload
if(!this.props.multiple && this.state.filesToUpload.filter((file) => file.status !== 'deleted' && file.status !== 'canceled').length > 0) { if(!this.props.multiple && this.state.filesToUpload.filter((file) => file.status !== 'deleted' && file.status !== 'canceled').length > 0) {
@ -512,7 +515,7 @@ var ReactS3FineUploader = React.createClass({
handleResumeFile={this.handleResumeFile} handleResumeFile={this.handleResumeFile}
multiple={this.props.multiple} multiple={this.props.multiple}
areAssetsDownloadable={this.props.areAssetsDownloadable} areAssetsDownloadable={this.props.areAssetsDownloadable}
dropzoneInactive={!this.props.multiple && this.state.filesToUpload.filter((file) => file.status !== 'deleted' && file.status !== 'canceled').length > 0} /> dropzoneInactive={!this.props.multiple && this.state.filesToUpload.filter((file) => file.status !== 'deleted' && file.status !== 'canceled' && file.size !== -1).length > 0} />
</div> </div>
); );
} }

View File

@ -27,6 +27,17 @@ class Requests {
return response.text(); return response.text();
} }
customJSONparse(responseText) {
// If the responses' body does not contain any data,
// fetch will resolve responseText to the string 'None'.
// If this is the case, we can not try to parse it as JSON.
if(responseText !== 'None') {
return JSON.parse(responseText);
} else {
return {};
}
}
handleFatalError(err) { handleFatalError(err) {
this.fatalErrorHandler(err); this.fatalErrorHandler(err);
throw new ServerError(err); throw new ServerError(err);
@ -36,6 +47,7 @@ class Requests {
if (!json.success) { if (!json.success) {
let error = new APIError(); let error = new APIError();
error.json = json; error.json = json;
console.error(new Error('The \'success\' property is missing in the server\'s response.'));
throw error; throw error;
} }
return json; return json;
@ -83,7 +95,7 @@ class Requests {
merged.method = verb; merged.method = verb;
return fetch(url, merged) return fetch(url, merged)
.then(this.unpackResponse) .then(this.unpackResponse)
.then(JSON.parse) .then(this.customJSONparse)
.catch(this.handleFatalError.bind(this)) .catch(this.handleFatalError.bind(this))
.then(this.handleAPIError); .then(this.handleAPIError);
} }

View File

@ -244,5 +244,5 @@ body {
} }
.ascribe-button-list button { .ascribe-button-list button {
margin-right: 1em; margin-right: 1px;
} }