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

Merge remote-tracking branch 'origin/AD-435-hash-locally-for-when-a-artist-do' into AD-435-hash-locally-for-when-a-artist-do

This commit is contained in:
diminator 2015-07-28 09:50:29 +02:00
commit 60ad72aabb
4 changed files with 38 additions and 16 deletions

View File

@ -174,7 +174,7 @@ let FileUploader = React.createClass({
}
}}
multiple={false}
localHashing={false} />
enableLocalHashing={true} />
);
}
});

View File

@ -30,7 +30,7 @@ let FileDragAndDrop = React.createClass({
areAssetsDownloadable: React.PropTypes.bool,
areAssetsEditable: React.PropTypes.bool,
localHashing: React.PropTypes.bool,
enableLocalHashing: React.PropTypes.bool,
// triggers a FileDragAndDrop-global spinner
hashingProgress: React.PropTypes.number,
@ -82,6 +82,10 @@ let FileDragAndDrop = React.createClass({
event.stopPropagation();
let files;
if(this.props.dropzoneInactive) {
return;
}
// handle Drag and Drop
if(event.dataTransfer && event.dataTransfer.files.length > 0) {
files = event.dataTransfer.files;
@ -157,7 +161,7 @@ let FileDragAndDrop = React.createClass({
<p>{getLangText('Computing hash(es)... This may take a few minutes.')}</p>
<p>
<span>{Math.ceil(this.props.hashingProgress)}%</span>
<span onClick={this.props.handleCancelHashing}> {getLangText('Cancel hashing')}</span>
<a onClick={this.props.handleCancelHashing}> {getLangText('Cancel hashing')}</a>
</p>
<ProgressBar completed={this.props.hashingProgress} color="#48DACB"/>
</div>
@ -177,7 +181,7 @@ let FileDragAndDrop = React.createClass({
multipleFiles={this.props.multiple}
hasFiles={hasFiles}
onClick={this.handleOnClick}
localHashing={this.props.localHashing}/>
enableLocalHashing={this.props.enableLocalHashing}/>
<FileDragAndDropPreviewIterator
files={this.props.filesToUpload}
handleDeleteFile={this.handleDeleteFile}

View File

@ -3,8 +3,6 @@
import React from 'react';
import Router from 'react-router';
import ButtonLink from 'react-router-bootstrap/lib/ButtonLink';
import { getLangText } from '../../utils/lang_utils';
let Link = Router.Link;
@ -14,7 +12,7 @@ let FileDragAndDropDialog = React.createClass({
hasFiles: React.PropTypes.bool,
multipleFiles: React.PropTypes.bool,
onClick: React.PropTypes.func,
localHashing: React.PropTypes.bool
enableLocalHashing: React.PropTypes.bool
},
mixins: [Router.State],
@ -25,7 +23,7 @@ let FileDragAndDropDialog = React.createClass({
if(this.props.hasFiles) {
return null;
} else {
if(!queryParams.method) {
if(this.props.enableLocalHashing && !queryParams.method) {
let queryParamsHash = Object.assign({}, queryParams);
queryParamsHash.method = 'hash';

View File

@ -1,6 +1,7 @@
'use strict';
import React from 'react/addons';
import Router from 'react-router';
import Raven from 'raven-js';
import Q from 'q';
@ -106,9 +107,14 @@ var ReactS3FineUploader = React.createClass({
// the file in the browser using md5 and then uploading the resulting text document instead
// of the actual file.
// This boolean essentially enables that behavior
localHashing: React.PropTypes.bool
enableLocalHashing: React.PropTypes.bool,
// automatically injected by React-Router
query: React.PropTypes.object
},
mixins: [Router.State],
getDefaultProps() {
return {
autoUpload: true,
@ -167,10 +173,10 @@ var ReactS3FineUploader = React.createClass({
};
},
// since the csrf header is defined in this component's props,
// everytime the csrf cookie is changed we'll need to reinitalize
// fineuploader and update the actual csrf token
componentWillUpdate() {
// since the csrf header is defined in this component's props,
// everytime the csrf cookie is changed we'll need to reinitalize
// fineuploader and update the actual csrf token
let potentiallyNewCSRFToken = getCookie(AppConstants.csrftoken);
if(this.state.csrfToken !== potentiallyNewCSRFToken) {
this.setState({
@ -511,8 +517,11 @@ var ReactS3FineUploader = React.createClass({
// As mentioned already in the propTypes declaration, in some instances we need to calculate the
// md5 hash of a file locally and just upload a txt file containing that hash.
// This if statement essentially takes care of that solution.
if(this.props.localHashing) {
//
// In the view this only happens when the user is allowed to do local hashing as well
// as when the correct query parameter is present in the url ('hash' and not 'upload')
let queryParams = this.getQuery();
if(this.props.enableLocalHashing && queryParams && queryParams.method === 'hash') {
let convertedFilePromises = [];
let overallFileSize = 0;
@ -686,6 +695,17 @@ var ReactS3FineUploader = React.createClass({
this.setState(newState);
},
isDropzoneInactive() {
let filesToDisplay = this.state.filesToUpload.filter((file) => file.status !== 'deleted' && file.status !== 'canceled' && file.size !== -1);
let queryParams = this.getQuery();
if((this.props.enableLocalHashing && !queryParams.method) || !this.props.areAssetsEditable || !this.props.multiple && filesToDisplay.length > 0) {
return true;
} else {
return false;
}
},
render() {
return (
@ -702,9 +722,9 @@ var ReactS3FineUploader = React.createClass({
multiple={this.props.multiple}
areAssetsDownloadable={this.props.areAssetsDownloadable}
areAssetsEditable={this.props.areAssetsEditable}
dropzoneInactive={!this.props.areAssetsEditable || !this.props.multiple && this.state.filesToUpload.filter((file) => file.status !== 'deleted' && file.status !== 'canceled' && file.size !== -1).length > 0}
dropzoneInactive={this.isDropzoneInactive()}
hashingProgress={this.state.hashingProgress}
localHashing={this.props.localHashing} />
enableLocalHashing={this.props.enableLocalHashing} />
</div>
);
}