mirror of
https://github.com/ascribe/onion.git
synced 2025-02-14 21:10:27 +01:00
add editable acl to react s3 fineuploader
This commit is contained in:
parent
2bf7d2cbb3
commit
b5a5481285
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
*This should be a living document. So if you have any ideas for refactoring stuff, then feel free to add them to this document*
|
*This should be a living document. So if you have any ideas for refactoring stuff, then feel free to add them to this document*
|
||||||
|
|
||||||
- Get rid of all Mixins.
|
- Get rid of all Mixins. (making good progress there :))
|
||||||
- Make all standalone components independent from things like global utilities (GeneralUtils is maybe used in table for example)
|
- Make all standalone components independent from things like global utilities (GeneralUtils is maybe used in table for example)
|
||||||
- Check if all polyfills are appropriately initialized and available: Compare to this
|
- Check if all polyfills are appropriately initialized and available: Compare to this
|
||||||
- Extract all standalone components to their own folder structure and write application independent tests (+ figure out how to do that in a productive way) (fetch lib especially)
|
- Extract all standalone components to their own folder structure and write application independent tests (+ figure out how to do that in a productive way) (fetch lib especially)
|
||||||
@ -11,3 +11,8 @@
|
|||||||
queryParams of the piece_list_store should all be reflected in the url and not a single component each should manipulate the URL bar (refactor pagination, use actions and state)
|
queryParams of the piece_list_store should all be reflected in the url and not a single component each should manipulate the URL bar (refactor pagination, use actions and state)
|
||||||
- Refactor string-templating for api_urls
|
- Refactor string-templating for api_urls
|
||||||
- Use classNames plugin instead of if-conditional-classes
|
- Use classNames plugin instead of if-conditional-classes
|
||||||
|
|
||||||
|
## React-S3-Fineuploader
|
||||||
|
- implementation should enable to define all important methods outside
|
||||||
|
- and: maybe create a utility class for all methods to avoid code duplication
|
||||||
|
- filesToUpload CRUD methods are dirty
|
||||||
|
@ -4,8 +4,6 @@ import React from 'react';
|
|||||||
import FileDragAndDropPreviewIterator from './file_drag_and_drop_preview_iterator';
|
import FileDragAndDropPreviewIterator from './file_drag_and_drop_preview_iterator';
|
||||||
|
|
||||||
|
|
||||||
let ReactTestUtils = React.addons.TestUtils;
|
|
||||||
|
|
||||||
// Taken from: https://github.com/fedosejev/react-file-drag-and-drop
|
// Taken from: https://github.com/fedosejev/react-file-drag-and-drop
|
||||||
let FileDragAndDrop = React.createClass({
|
let FileDragAndDrop = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
@ -25,7 +23,8 @@ let FileDragAndDrop = React.createClass({
|
|||||||
handleResumeFile: React.PropTypes.func,
|
handleResumeFile: React.PropTypes.func,
|
||||||
multiple: React.PropTypes.bool,
|
multiple: React.PropTypes.bool,
|
||||||
dropzoneInactive: React.PropTypes.bool,
|
dropzoneInactive: React.PropTypes.bool,
|
||||||
areAssetsDownloadable: React.PropTypes.bool
|
areAssetsDownloadable: React.PropTypes.bool,
|
||||||
|
areAssetsEditable: React.PropTypes.bool
|
||||||
},
|
},
|
||||||
|
|
||||||
handleDragStart(event) {
|
handleDragStart(event) {
|
||||||
@ -156,7 +155,8 @@ let FileDragAndDrop = React.createClass({
|
|||||||
handleCancelFile={this.handleCancelFile}
|
handleCancelFile={this.handleCancelFile}
|
||||||
handlePauseFile={this.handlePauseFile}
|
handlePauseFile={this.handlePauseFile}
|
||||||
handleResumeFile={this.handleResumeFile}
|
handleResumeFile={this.handleResumeFile}
|
||||||
areAssetsDownloadable={this.props.areAssetsDownloadable}/>
|
areAssetsDownloadable={this.props.areAssetsDownloadable}
|
||||||
|
areAssetsEditable={this.props.areAssetsEditable}/>
|
||||||
<input
|
<input
|
||||||
multiple={this.props.multiple}
|
multiple={this.props.multiple}
|
||||||
ref="fileinput"
|
ref="fileinput"
|
||||||
|
@ -17,7 +17,8 @@ let FileDragAndDropPreview = React.createClass({
|
|||||||
handleCancelFile: React.PropTypes.func,
|
handleCancelFile: React.PropTypes.func,
|
||||||
handlePauseFile: React.PropTypes.func,
|
handlePauseFile: React.PropTypes.func,
|
||||||
handleResumeFile: React.PropTypes.func,
|
handleResumeFile: React.PropTypes.func,
|
||||||
areAssetsDownloadable: React.PropTypes.bool
|
areAssetsDownloadable: React.PropTypes.bool,
|
||||||
|
areAssetsEditable: React.PropTypes.bool
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleUploadProcess() {
|
toggleUploadProcess() {
|
||||||
@ -48,6 +49,7 @@ let FileDragAndDropPreview = React.createClass({
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let previewElement;
|
let previewElement;
|
||||||
|
let removeBtn;
|
||||||
|
|
||||||
// Decide whether an image or a placeholder picture should be displayed
|
// Decide whether an image or a placeholder picture should be displayed
|
||||||
if(this.props.file.type.split('/')[0] === 'image') {
|
if(this.props.file.type.split('/')[0] === 'image') {
|
||||||
@ -68,12 +70,16 @@ let FileDragAndDropPreview = React.createClass({
|
|||||||
downloadUrl={this.props.file.s3UrlSafe}/>);
|
downloadUrl={this.props.file.s3UrlSafe}/>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.props.areAssetsEditable) {
|
||||||
|
removeBtn = (<div className="delete-file">
|
||||||
|
<span className="glyphicon glyphicon-remove text-center" aria-hidden="true" title="Remove file" onClick={this.handleDeleteFile}/>
|
||||||
|
</div>);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="file-drag-and-drop-position">
|
className="file-drag-and-drop-position">
|
||||||
<div className="delete-file">
|
{removeBtn}
|
||||||
<span className="glyphicon glyphicon-remove text-center" aria-hidden="true" title="Remove file" onClick={this.handleDeleteFile}/>
|
|
||||||
</div>
|
|
||||||
{previewElement}
|
{previewElement}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -11,7 +11,8 @@ let FileDragAndDropPreviewIterator = React.createClass({
|
|||||||
handleCancelFile: React.PropTypes.func,
|
handleCancelFile: React.PropTypes.func,
|
||||||
handlePauseFile: React.PropTypes.func,
|
handlePauseFile: React.PropTypes.func,
|
||||||
handleResumeFile: React.PropTypes.func,
|
handleResumeFile: React.PropTypes.func,
|
||||||
areAssetsDownloadable: React.PropTypes.bool
|
areAssetsDownloadable: React.PropTypes.bool,
|
||||||
|
areAssetsEditable: React.PropTypes.bool
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -28,7 +29,8 @@ let FileDragAndDropPreviewIterator = React.createClass({
|
|||||||
handleCancelFile={this.props.handleCancelFile}
|
handleCancelFile={this.props.handleCancelFile}
|
||||||
handlePauseFile={this.props.handlePauseFile}
|
handlePauseFile={this.props.handlePauseFile}
|
||||||
handleResumeFile={this.props.handleResumeFile}
|
handleResumeFile={this.props.handleResumeFile}
|
||||||
areAssetsDownloadable={this.props.areAssetsDownloadable}/>
|
areAssetsDownloadable={this.props.areAssetsDownloadable}
|
||||||
|
areAssetsEditable={this.props.areAssetsEditable}/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -85,7 +85,8 @@ var ReactS3FineUploader = React.createClass({
|
|||||||
}),
|
}),
|
||||||
setIsUploadReady: React.PropTypes.func,
|
setIsUploadReady: React.PropTypes.func,
|
||||||
isReadyForFormSubmission: React.PropTypes.func,
|
isReadyForFormSubmission: React.PropTypes.func,
|
||||||
areAssetsDownloadable: React.PropTypes.bool
|
areAssetsDownloadable: React.PropTypes.bool,
|
||||||
|
areAssetsEditable: React.PropTypes.bool
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultProps() {
|
getDefaultProps() {
|
||||||
@ -278,6 +279,10 @@ var ReactS3FineUploader = React.createClass({
|
|||||||
.then((res) =>{
|
.then((res) =>{
|
||||||
if(res.otherdata) {
|
if(res.otherdata) {
|
||||||
file.s3Url = res.otherdata.url_safe;
|
file.s3Url = res.otherdata.url_safe;
|
||||||
|
file.s3UrlSafe = res.otherdata.url_safe;
|
||||||
|
} else if(res.digitalwork) {
|
||||||
|
file.s3Url = res.digitalwork.url_safe;
|
||||||
|
file.s3UrlSafe = res.digitalwork.url_safe;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Could not find a url to download.');
|
throw new Error('Could not find a url to download.');
|
||||||
}
|
}
|
||||||
@ -519,7 +524,8 @@ 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' && file.size !== -1).length > 0} />
|
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} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,8 @@ let Edition = React.createClass({
|
|||||||
this.setState(state);
|
this.setState(state);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let thumbnail = this.props.edition.thumbnail;
|
let thumbnail = this.props.edition.thumbnail;
|
||||||
let mimetype = this.props.edition.digital_work.mime;
|
let mimetype = this.props.edition.digital_work.mime;
|
||||||
@ -474,6 +476,7 @@ let EditionFurtherDetails = React.createClass({
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let editable = this.props.edition.acl.indexOf('edit') > -1;
|
let editable = this.props.edition.acl.indexOf('edit') > -1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
<Col md={12} className="ascribe-edition-personal-note">
|
<Col md={12} className="ascribe-edition-personal-note">
|
||||||
@ -512,11 +515,17 @@ let FileUploader = React.createClass({
|
|||||||
edition: React.PropTypes.object,
|
edition: React.PropTypes.object,
|
||||||
setIsUploadReady: React.PropTypes.func,
|
setIsUploadReady: React.PropTypes.func,
|
||||||
submitKey: React.PropTypes.func,
|
submitKey: React.PropTypes.func,
|
||||||
isReadyForFormSubmission: React.PropTypes.func
|
isReadyForFormSubmission: React.PropTypes.func,
|
||||||
|
editable: React.PropTypes.bool
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.props.editable && this.props.edition.other_data === null){
|
// Essentially there a three cases important to the fileuploader
|
||||||
|
//
|
||||||
|
// 1. there is no other_data => do not show the fileuploader at all
|
||||||
|
// 2. there is other_data, but user has no edit rights => show fileuploader but without action buttons
|
||||||
|
// 3. both other_data and editable are defined or true => show fileuploade with all action buttons
|
||||||
|
if (!this.props.editable && !this.props.edition.other_data){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
@ -549,7 +558,8 @@ let FileUploader = React.createClass({
|
|||||||
'pk': this.props.edition.other_data ? this.props.edition.other_data.id : null
|
'pk': this.props.edition.other_data ? this.props.edition.other_data.id : null
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
areAssetsDownloadable={true}/>
|
areAssetsDownloadable={true}
|
||||||
|
areAssetsEditable={this.props.editable}/>
|
||||||
</Property>
|
</Property>
|
||||||
<hr />
|
<hr />
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -212,7 +212,8 @@ let FileUploader = React.createClass({
|
|||||||
}}
|
}}
|
||||||
setIsUploadReady={this.props.setIsUploadReady}
|
setIsUploadReady={this.props.setIsUploadReady}
|
||||||
isReadyForFormSubmission={this.props.isReadyForFormSubmission}
|
isReadyForFormSubmission={this.props.isReadyForFormSubmission}
|
||||||
areAssetsDownloadable={false}/>
|
areAssetsDownloadable={false}
|
||||||
|
areAssetsEditable={true}/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user