1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +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} multiple={false}
localHashing={false} /> enableLocalHashing={true} />
); );
} }
}); });

View File

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

View File

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

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
import React from 'react/addons'; import React from 'react/addons';
import Router from 'react-router';
import Raven from 'raven-js'; import Raven from 'raven-js';
import Q from 'q'; 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 // the file in the browser using md5 and then uploading the resulting text document instead
// of the actual file. // of the actual file.
// This boolean essentially enables that behavior // 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() { getDefaultProps() {
return { return {
autoUpload: true, autoUpload: true,
@ -167,10 +173,10 @@ var ReactS3FineUploader = React.createClass({
}; };
}, },
componentWillUpdate() {
// since the csrf header is defined in this component's props, // since the csrf header is defined in this component's props,
// everytime the csrf cookie is changed we'll need to reinitalize // everytime the csrf cookie is changed we'll need to reinitalize
// fineuploader and update the actual csrf token // fineuploader and update the actual csrf token
componentWillUpdate() {
let potentiallyNewCSRFToken = getCookie(AppConstants.csrftoken); let potentiallyNewCSRFToken = getCookie(AppConstants.csrftoken);
if(this.state.csrfToken !== potentiallyNewCSRFToken) { if(this.state.csrfToken !== potentiallyNewCSRFToken) {
this.setState({ 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 // 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. // 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 convertedFilePromises = [];
let overallFileSize = 0; let overallFileSize = 0;
@ -686,6 +695,17 @@ var ReactS3FineUploader = React.createClass({
this.setState(newState); 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() { render() {
return ( return (
@ -702,9 +722,9 @@ var ReactS3FineUploader = React.createClass({
multiple={this.props.multiple} multiple={this.props.multiple}
areAssetsDownloadable={this.props.areAssetsDownloadable} areAssetsDownloadable={this.props.areAssetsDownloadable}
areAssetsEditable={this.props.areAssetsEditable} 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} hashingProgress={this.state.hashingProgress}
localHashing={this.props.localHashing} /> enableLocalHashing={this.props.enableLocalHashing} />
</div> </div>
); );
} }