2017-04-29 02:42:32 +08:00
|
|
|
import React, { Component } from 'react';
|
2017-09-08 02:18:14 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-09-29 22:03:08 +08:00
|
|
|
import { defineMessages, injectIntl, intlShape } from 'react-intl';
|
2017-06-07 20:28:41 +08:00
|
|
|
import Dropzone from 'react-dropzone';
|
2017-05-04 00:36:16 +08:00
|
|
|
import update from 'immutability-helper';
|
2017-06-07 20:28:41 +08:00
|
|
|
import cx from 'classnames';
|
2017-11-22 22:47:27 +08:00
|
|
|
import _ from 'lodash';
|
2018-07-12 06:03:56 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2017-06-07 20:28:41 +08:00
|
|
|
|
2017-11-28 20:29:11 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2017-05-04 04:51:17 +08:00
|
|
|
import ModalFullscreen from '/imports/ui/components/modal/fullscreen/component';
|
2018-07-18 07:49:14 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/modal/service';
|
2017-04-29 02:42:32 +08:00
|
|
|
import Icon from '/imports/ui/components/icon/component';
|
|
|
|
import ButtonBase from '/imports/ui/components/button/base/component';
|
2017-05-04 00:36:16 +08:00
|
|
|
import Checkbox from '/imports/ui/components/checkbox/component';
|
2018-01-08 14:17:18 +08:00
|
|
|
import { styles } from './styles.scss';
|
2017-04-29 02:42:32 +08:00
|
|
|
|
2017-09-08 02:18:14 +08:00
|
|
|
const propTypes = {
|
2017-09-30 04:32:31 +08:00
|
|
|
intl: intlShape.isRequired,
|
2017-09-08 02:18:14 +08:00
|
|
|
defaultFileName: PropTypes.string.isRequired,
|
|
|
|
fileSizeMin: PropTypes.number.isRequired,
|
|
|
|
fileSizeMax: PropTypes.number.isRequired,
|
|
|
|
handleSave: PropTypes.func.isRequired,
|
|
|
|
fileValidMimeTypes: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
|
|
presentations: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
filename: PropTypes.string.isRequired,
|
|
|
|
isCurrent: PropTypes.bool.isRequired,
|
|
|
|
conversion: PropTypes.object,
|
|
|
|
upload: PropTypes.object,
|
|
|
|
})).isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
};
|
|
|
|
|
2017-04-29 02:42:32 +08:00
|
|
|
const intlMessages = defineMessages({
|
2017-12-05 00:10:37 +08:00
|
|
|
current: {
|
|
|
|
id: 'app.presentationUploder.currentBadge',
|
|
|
|
},
|
2017-04-29 02:42:32 +08:00
|
|
|
title: {
|
|
|
|
id: 'app.presentationUploder.title',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'title of the modal',
|
2017-04-29 02:42:32 +08:00
|
|
|
},
|
|
|
|
message: {
|
|
|
|
id: 'app.presentationUploder.message',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'message warning the types of files accepted',
|
2017-04-29 02:42:32 +08:00
|
|
|
},
|
|
|
|
confirmLabel: {
|
|
|
|
id: 'app.presentationUploder.confirmLabel',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'used in the button that start the upload of the new presentation',
|
2017-04-29 02:42:32 +08:00
|
|
|
},
|
|
|
|
confirmDesc: {
|
|
|
|
id: 'app.presentationUploder.confirmDesc',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'description of the confirm',
|
2017-04-29 02:42:32 +08:00
|
|
|
},
|
|
|
|
dismissLabel: {
|
|
|
|
id: 'app.presentationUploder.dismissLabel',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'used in the button that close modal',
|
2017-04-29 02:42:32 +08:00
|
|
|
},
|
|
|
|
dismissDesc: {
|
|
|
|
id: 'app.presentationUploder.dismissDesc',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'description of the dismiss',
|
2017-04-29 02:42:32 +08:00
|
|
|
},
|
|
|
|
dropzoneLabel: {
|
|
|
|
id: 'app.presentationUploder.dropzoneLabel',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'message warning where drop files for upload',
|
2017-04-29 02:42:32 +08:00
|
|
|
},
|
|
|
|
browseFilesLabel: {
|
|
|
|
id: 'app.presentationUploder.browseFilesLabel',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'message use on the file browser',
|
2017-04-29 02:42:32 +08:00
|
|
|
},
|
2017-05-06 04:17:38 +08:00
|
|
|
fileToUpload: {
|
|
|
|
id: 'app.presentationUploder.fileToUpload',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'message used in the file selected for upload',
|
2017-05-06 04:17:38 +08:00
|
|
|
},
|
2017-11-28 01:44:45 +08:00
|
|
|
genericError: {
|
|
|
|
id: 'app.presentationUploder.genericError',
|
|
|
|
description: 'generic error while uploading/converting',
|
|
|
|
},
|
2017-09-08 02:18:14 +08:00
|
|
|
uploadProcess: {
|
|
|
|
id: 'app.presentationUploder.upload.progress',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'message that indicates the percentage of the upload',
|
2017-09-08 02:18:14 +08:00
|
|
|
},
|
|
|
|
413: {
|
|
|
|
id: 'app.presentationUploder.upload.413',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'error that file exceed the size limit',
|
2017-05-06 04:17:38 +08:00
|
|
|
},
|
|
|
|
conversionProcessingSlides: {
|
|
|
|
id: 'app.presentationUploder.conversion.conversionProcessingSlides',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'indicates how many slides were converted',
|
2017-05-06 04:17:38 +08:00
|
|
|
},
|
|
|
|
genericConversionStatus: {
|
|
|
|
id: 'app.presentationUploder.conversion.genericConversionStatus',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'indicates that file is being converted',
|
2017-05-06 04:17:38 +08:00
|
|
|
},
|
2017-11-28 01:44:45 +08:00
|
|
|
TIMEOUT: {
|
|
|
|
id: 'app.presentationUploder.conversion.timeout',
|
|
|
|
},
|
2017-05-06 04:17:38 +08:00
|
|
|
GENERATING_THUMBNAIL: {
|
|
|
|
id: 'app.presentationUploder.conversion.generatingThumbnail',
|
2017-11-28 01:44:45 +08:00
|
|
|
description: 'indicatess that it is generating thumbnails',
|
2017-05-06 04:17:38 +08:00
|
|
|
},
|
2017-09-27 03:45:33 +08:00
|
|
|
GENERATING_SVGIMAGES: {
|
|
|
|
id: 'app.presentationUploder.conversion.generatingSvg',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'warns that it is generating svg images',
|
2017-09-27 03:45:33 +08:00
|
|
|
},
|
2017-05-06 04:17:38 +08:00
|
|
|
GENERATED_SLIDE: {
|
|
|
|
id: 'app.presentationUploder.conversion.generatedSlides',
|
2017-11-02 00:13:18 +08:00
|
|
|
description: 'warns that were slides generated',
|
2017-05-06 04:17:38 +08:00
|
|
|
},
|
2017-11-28 20:26:00 +08:00
|
|
|
PAGE_COUNT_EXCEEDED: {
|
|
|
|
id: 'app.presentationUploder.conversion.pageCountExceeded',
|
|
|
|
description: 'warns the user that the conversion failed because of the page count',
|
|
|
|
},
|
2017-04-29 02:42:32 +08:00
|
|
|
});
|
|
|
|
|
2017-05-06 04:17:38 +08:00
|
|
|
class PresentationUploader extends Component {
|
2017-04-29 02:42:32 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2017-11-28 01:44:45 +08:00
|
|
|
const currentPres = props.presentations.find(p => p.isCurrent);
|
|
|
|
|
2017-04-29 02:42:32 +08:00
|
|
|
this.state = {
|
|
|
|
presentations: props.presentations,
|
2017-11-28 01:44:45 +08:00
|
|
|
oldCurrentId: currentPres ? currentPres.id : -1,
|
2017-05-06 04:17:38 +08:00
|
|
|
preventClosing: false,
|
|
|
|
disableActions: false,
|
2017-04-29 02:42:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
this.handleConfirm = this.handleConfirm.bind(this);
|
|
|
|
this.handleDismiss = this.handleDismiss.bind(this);
|
|
|
|
this.handleFiledrop = this.handleFiledrop.bind(this);
|
|
|
|
this.handleCurrentChange = this.handleCurrentChange.bind(this);
|
|
|
|
this.handleRemove = this.handleRemove.bind(this);
|
2017-09-27 03:45:33 +08:00
|
|
|
|
|
|
|
this.updateFileKey = this.updateFileKey.bind(this);
|
|
|
|
this.deepMergeUpdateFileKey = this.deepMergeUpdateFileKey.bind(this);
|
2017-04-29 02:42:32 +08:00
|
|
|
}
|
|
|
|
|
2017-09-27 03:45:33 +08:00
|
|
|
updateFileKey(id, key, value, operation = '$set') {
|
|
|
|
this.setState(({ presentations }) => {
|
2017-11-22 22:47:27 +08:00
|
|
|
const fileIndex = presentations.findIndex(f => f.id === id);
|
2017-09-27 03:45:33 +08:00
|
|
|
|
|
|
|
return fileIndex === -1 ? false : {
|
|
|
|
presentations: update(presentations, {
|
2017-11-22 22:47:27 +08:00
|
|
|
[fileIndex]: {
|
|
|
|
$apply: file =>
|
|
|
|
update(file, {
|
|
|
|
[key]: {
|
|
|
|
[operation]: value,
|
|
|
|
},
|
|
|
|
}),
|
2017-09-27 03:45:33 +08:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deepMergeUpdateFileKey(id, key, value) {
|
|
|
|
const applyValue = toUpdate => update(toUpdate, { $merge: value });
|
|
|
|
this.updateFileKey(id, key, applyValue, '$apply');
|
|
|
|
}
|
|
|
|
|
2017-12-04 21:15:11 +08:00
|
|
|
isDefault(presentation) {
|
|
|
|
const { defaultFileName } = this.props;
|
|
|
|
return presentation.filename === defaultFileName
|
|
|
|
&& !presentation.id.includes(defaultFileName);
|
|
|
|
}
|
|
|
|
|
2017-04-29 02:42:32 +08:00
|
|
|
handleConfirm() {
|
2018-07-18 07:49:14 +08:00
|
|
|
const { mountModal } = this.props;
|
2017-11-28 01:44:45 +08:00
|
|
|
const presentationsToSave = this.state.presentations
|
|
|
|
.filter(p => !p.upload.error && !p.conversion.error);
|
2017-05-04 00:36:16 +08:00
|
|
|
|
2017-05-06 04:17:38 +08:00
|
|
|
this.setState({
|
|
|
|
disableActions: true,
|
|
|
|
preventClosing: true,
|
2017-11-28 01:44:45 +08:00
|
|
|
presentations: presentationsToSave,
|
2017-05-06 04:17:38 +08:00
|
|
|
});
|
2017-05-04 00:36:16 +08:00
|
|
|
|
2017-11-28 01:44:45 +08:00
|
|
|
return this.props.handleSave(presentationsToSave)
|
2017-09-30 01:44:18 +08:00
|
|
|
.then(() => {
|
2017-11-28 20:26:00 +08:00
|
|
|
const hasError = this.state.presentations.some(p => p.upload.error || p.conversion.error);
|
2017-11-28 01:44:45 +08:00
|
|
|
if (!hasError) {
|
|
|
|
this.setState({
|
|
|
|
disableActions: false,
|
|
|
|
preventClosing: false,
|
|
|
|
});
|
|
|
|
|
2018-07-18 07:49:14 +08:00
|
|
|
return mountModal(null);
|
2017-11-28 01:44:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// if theres error we dont want to close the modal
|
2017-09-30 01:44:18 +08:00
|
|
|
this.setState({
|
|
|
|
disableActions: false,
|
2017-11-28 01:44:45 +08:00
|
|
|
preventClosing: true,
|
|
|
|
}, () => {
|
|
|
|
// if the selected current has error we revert back to the old one
|
2017-11-28 20:26:00 +08:00
|
|
|
const newCurrent = this.state.presentations.find(p => p.isCurrent);
|
2017-11-28 01:44:45 +08:00
|
|
|
if (newCurrent.upload.error || newCurrent.conversion.error) {
|
2017-11-28 20:26:00 +08:00
|
|
|
this.handleCurrentChange(this.state.oldCurrentId);
|
2017-11-28 01:44:45 +08:00
|
|
|
}
|
2017-09-30 01:44:18 +08:00
|
|
|
});
|
|
|
|
})
|
2017-09-27 03:45:33 +08:00
|
|
|
.catch((error) => {
|
2017-11-28 20:29:11 +08:00
|
|
|
notify(this.props.intl.formatMessage(intlMessages.genericError), 'error');
|
|
|
|
|
2018-07-12 06:03:56 +08:00
|
|
|
logger.error(error);
|
2017-11-28 01:44:45 +08:00
|
|
|
|
2017-09-27 03:45:33 +08:00
|
|
|
this.setState({
|
|
|
|
disableActions: false,
|
|
|
|
preventClosing: true,
|
|
|
|
});
|
|
|
|
});
|
2017-04-29 02:42:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleDismiss() {
|
2018-07-18 07:49:14 +08:00
|
|
|
const { mountModal } = this.props;
|
|
|
|
|
2017-06-07 20:28:41 +08:00
|
|
|
return new Promise((resolve) => {
|
2018-07-18 07:49:14 +08:00
|
|
|
mountModal(null);
|
|
|
|
|
2017-05-06 04:17:38 +08:00
|
|
|
this.setState({
|
|
|
|
preventClosing: false,
|
|
|
|
disableActions: false,
|
|
|
|
}, resolve);
|
|
|
|
});
|
2017-04-29 02:42:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleFiledrop(files) {
|
2017-11-22 22:47:27 +08:00
|
|
|
const presentationsToUpload = files.map((file) => {
|
|
|
|
const id = _.uniqueId(file.name);
|
|
|
|
|
|
|
|
return {
|
|
|
|
file,
|
|
|
|
id,
|
|
|
|
filename: file.name,
|
|
|
|
isCurrent: false,
|
|
|
|
conversion: { done: false, error: false },
|
|
|
|
upload: { done: false, error: false, progress: 0 },
|
|
|
|
onProgress: (event) => {
|
|
|
|
if (!event.lengthComputable) {
|
|
|
|
this.deepMergeUpdateFileKey(id, 'upload', {
|
|
|
|
progress: 100,
|
|
|
|
done: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.deepMergeUpdateFileKey(id, 'upload', {
|
|
|
|
progress: (event.loaded / event.total) * 100,
|
|
|
|
done: event.loaded === event.total,
|
2017-09-23 04:45:31 +08:00
|
|
|
});
|
2017-11-22 22:47:27 +08:00
|
|
|
},
|
2017-11-28 01:44:45 +08:00
|
|
|
onConversion: (conversion) => {
|
|
|
|
this.deepMergeUpdateFileKey(id, 'conversion', conversion);
|
|
|
|
},
|
|
|
|
onUpload: (upload) => {
|
|
|
|
this.deepMergeUpdateFileKey(id, 'upload', upload);
|
|
|
|
},
|
|
|
|
onDone: (newId) => {
|
|
|
|
this.updateFileKey(id, 'id', newId);
|
2017-11-22 22:47:27 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
2017-04-29 02:42:32 +08:00
|
|
|
|
|
|
|
this.setState(({ presentations }) => ({
|
2017-09-08 02:18:14 +08:00
|
|
|
presentations: presentations.concat(presentationsToUpload),
|
2018-07-19 02:47:40 +08:00
|
|
|
}), () => {
|
|
|
|
// after the state is set (files have been dropped),
|
|
|
|
// make the first of the new presentations current
|
|
|
|
if (presentationsToUpload && presentationsToUpload.length) {
|
|
|
|
this.handleCurrentChange(presentationsToUpload[0].id);
|
|
|
|
}
|
|
|
|
});
|
2017-04-29 02:42:32 +08:00
|
|
|
}
|
|
|
|
|
2017-11-28 01:44:45 +08:00
|
|
|
handleCurrentChange(id) {
|
2017-09-27 03:45:33 +08:00
|
|
|
const { presentations, disableActions } = this.state;
|
|
|
|
if (disableActions) return;
|
|
|
|
|
2017-04-29 02:42:32 +08:00
|
|
|
const currentIndex = presentations.findIndex(p => p.isCurrent);
|
2017-11-28 01:44:45 +08:00
|
|
|
const newCurrentIndex = presentations.findIndex(p => p.id === id);
|
2017-04-29 02:42:32 +08:00
|
|
|
|
2017-06-07 20:28:41 +08:00
|
|
|
const commands = {};
|
2017-09-26 04:49:54 +08:00
|
|
|
|
|
|
|
// we can end up without a current presentation
|
|
|
|
if (currentIndex !== -1) {
|
|
|
|
commands[currentIndex] = {
|
2017-11-28 01:44:45 +08:00
|
|
|
$apply: (presentation) => {
|
|
|
|
const p = presentation;
|
2017-09-26 04:49:54 +08:00
|
|
|
p.isCurrent = false;
|
|
|
|
return p;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-29 02:42:32 +08:00
|
|
|
commands[newCurrentIndex] = {
|
2017-11-28 01:44:45 +08:00
|
|
|
$apply: (presentation) => {
|
|
|
|
const p = presentation;
|
2017-04-29 02:42:32 +08:00
|
|
|
p.isCurrent = true;
|
|
|
|
return p;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-06-07 20:28:41 +08:00
|
|
|
const presentationsUpdated = update(presentations, commands);
|
2017-04-29 02:42:32 +08:00
|
|
|
|
|
|
|
this.setState({
|
|
|
|
presentations: presentationsUpdated,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRemove(item) {
|
2017-09-27 03:45:33 +08:00
|
|
|
const { presentations, disableActions } = this.state;
|
|
|
|
if (disableActions) return;
|
|
|
|
|
2017-04-29 02:42:32 +08:00
|
|
|
const toRemoveIndex = presentations.indexOf(item);
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
presentations: update(presentations, {
|
|
|
|
$splice: [[toRemoveIndex, 1]],
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderPresentationList() {
|
2017-06-07 20:28:41 +08:00
|
|
|
const { presentations } = this.state;
|
2017-04-29 02:42:32 +08:00
|
|
|
|
2017-06-07 20:28:41 +08:00
|
|
|
const presentationsSorted = presentations
|
2017-12-04 21:15:11 +08:00
|
|
|
.sort((a, b) => {
|
|
|
|
// Sort by ID first so files with the same name have the same order
|
|
|
|
if (a.id > b.id) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (a.id < b.id) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
})
|
|
|
|
.sort((a, b) => this.isDefault(b));
|
2017-04-29 02:42:32 +08:00
|
|
|
|
|
|
|
return (
|
2017-05-04 00:36:16 +08:00
|
|
|
<div className={styles.fileList}>
|
|
|
|
<table className={styles.table}>
|
|
|
|
<tbody>
|
2017-06-07 20:28:41 +08:00
|
|
|
{ presentationsSorted.map(item => this.renderPresentationItem(item))}
|
2017-05-04 00:36:16 +08:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2017-04-29 02:42:32 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-06 04:17:38 +08:00
|
|
|
renderPresentationItemStatus(item) {
|
2017-06-07 20:28:41 +08:00
|
|
|
const { intl } = this.props;
|
2017-05-06 04:17:38 +08:00
|
|
|
|
2017-09-08 02:18:14 +08:00
|
|
|
if (!item.upload.done && item.upload.progress === 0) {
|
|
|
|
return intl.formatMessage(intlMessages.fileToUpload);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!item.upload.done && !item.upload.error) {
|
|
|
|
return intl.formatMessage(intlMessages.uploadProcess, {
|
2018-06-14 03:35:07 +08:00
|
|
|
0: Math.floor(item.upload.progress).toString(),
|
2017-09-08 02:18:14 +08:00
|
|
|
});
|
|
|
|
}
|
2017-05-06 04:17:38 +08:00
|
|
|
|
2017-09-08 02:18:14 +08:00
|
|
|
if (item.upload.done && item.upload.error) {
|
2017-11-28 01:44:45 +08:00
|
|
|
const errorMessage = intlMessages[item.upload.status] || intlMessages.genericError;
|
2017-09-08 02:18:14 +08:00
|
|
|
return intl.formatMessage(errorMessage);
|
|
|
|
}
|
|
|
|
|
2017-11-28 20:26:00 +08:00
|
|
|
if (item.conversion.done && item.conversion.error) {
|
2017-11-28 01:44:45 +08:00
|
|
|
const errorMessage = intlMessages[item.conversion.status] || intlMessages.genericError;
|
2017-05-06 04:17:38 +08:00
|
|
|
return intl.formatMessage(errorMessage);
|
|
|
|
}
|
|
|
|
|
2017-09-08 02:18:14 +08:00
|
|
|
if (!item.conversion.done && !item.conversion.error) {
|
|
|
|
if (item.conversion.pagesCompleted < item.conversion.numPages) {
|
2017-05-06 04:17:38 +08:00
|
|
|
return intl.formatMessage(intlMessages.conversionProcessingSlides, {
|
2018-06-14 03:35:07 +08:00
|
|
|
0: item.conversion.pagesCompleted,
|
|
|
|
1: item.conversion.numPages,
|
2017-05-06 04:17:38 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversionStatusMessage =
|
|
|
|
intlMessages[item.conversion.status] || intlMessages.genericConversionStatus;
|
|
|
|
return intl.formatMessage(conversionStatusMessage);
|
|
|
|
}
|
|
|
|
|
2017-09-08 02:18:14 +08:00
|
|
|
return null;
|
2017-05-06 04:17:38 +08:00
|
|
|
}
|
|
|
|
|
2017-04-29 02:42:32 +08:00
|
|
|
renderPresentationItem(item) {
|
2017-12-05 00:10:37 +08:00
|
|
|
const { disableActions, oldCurrentId } = this.state;
|
2017-05-04 00:36:16 +08:00
|
|
|
|
2017-12-05 00:10:37 +08:00
|
|
|
const isActualCurrent = item.id === oldCurrentId;
|
2017-11-28 20:26:00 +08:00
|
|
|
const isUploading = !item.upload.done && item.upload.progress > 0;
|
|
|
|
const isConverting = !item.conversion.done && item.upload.done;
|
|
|
|
const hasError = item.conversion.error || item.upload.error;
|
|
|
|
const isProcessing = (isUploading || isConverting) && !hasError;
|
|
|
|
|
|
|
|
const itemClassName = {
|
|
|
|
[styles.tableItemNew]: item.id.indexOf(item.filename) !== -1,
|
|
|
|
[styles.tableItemUploading]: isUploading,
|
|
|
|
[styles.tableItemConverting]: isConverting,
|
|
|
|
[styles.tableItemError]: hasError,
|
|
|
|
[styles.tableItemAnimated]: isProcessing,
|
|
|
|
};
|
2017-04-29 02:42:32 +08:00
|
|
|
|
2017-12-04 21:15:11 +08:00
|
|
|
const hideRemove = this.isDefault(item);
|
2017-05-04 04:51:17 +08:00
|
|
|
|
2017-04-29 02:42:32 +08:00
|
|
|
return (
|
|
|
|
<tr
|
2017-05-04 00:36:16 +08:00
|
|
|
key={item.id}
|
2017-04-29 02:42:32 +08:00
|
|
|
className={cx(itemClassName)}
|
|
|
|
>
|
|
|
|
<td className={styles.tableItemIcon}>
|
2017-11-22 22:47:27 +08:00
|
|
|
<Icon iconName="file" />
|
2017-04-29 02:42:32 +08:00
|
|
|
</td>
|
2017-12-05 00:10:37 +08:00
|
|
|
{
|
|
|
|
isActualCurrent ?
|
|
|
|
<th className={styles.tableItemCurrent}>
|
|
|
|
<span className={styles.currentLabel}>
|
|
|
|
{this.props.intl.formatMessage(intlMessages.current)}
|
|
|
|
</span>
|
|
|
|
</th>
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
<th className={styles.tableItemName} colSpan={!isActualCurrent ? 2 : 0}>
|
2017-04-29 02:42:32 +08:00
|
|
|
<span>{item.filename}</span>
|
|
|
|
</th>
|
2017-11-28 20:26:00 +08:00
|
|
|
<td className={styles.tableItemStatus} colSpan={hasError ? 2 : 0}>
|
2017-05-06 04:17:38 +08:00
|
|
|
{this.renderPresentationItemStatus(item)}
|
2017-04-29 02:42:32 +08:00
|
|
|
</td>
|
2017-11-28 20:26:00 +08:00
|
|
|
{ hasError ? null : (
|
|
|
|
<td className={styles.tableItemActions}>
|
2017-11-28 01:44:45 +08:00
|
|
|
<Checkbox
|
|
|
|
disabled={disableActions}
|
|
|
|
ariaLabel="Set as current presentation"
|
|
|
|
className={styles.itemAction}
|
|
|
|
checked={item.isCurrent}
|
|
|
|
onChange={() => this.handleCurrentChange(item.id)}
|
|
|
|
/>
|
2017-11-28 20:26:00 +08:00
|
|
|
{ hideRemove ? null : (
|
|
|
|
<ButtonBase
|
|
|
|
disabled={disableActions}
|
|
|
|
className={cx(styles.itemAction, styles.itemActionRemove)}
|
|
|
|
label="Remove presentation"
|
|
|
|
onClick={() => this.handleRemove(item)}
|
|
|
|
>
|
|
|
|
<Icon iconName="delete" />
|
|
|
|
</ButtonBase>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
)}
|
2017-04-29 02:42:32 +08:00
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDropzone() {
|
2017-05-04 00:36:16 +08:00
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
fileSizeMin,
|
|
|
|
fileSizeMax,
|
|
|
|
fileValidMimeTypes,
|
|
|
|
} = this.props;
|
2017-04-29 02:42:32 +08:00
|
|
|
|
2017-05-06 04:17:38 +08:00
|
|
|
const { disableActions } = this.state;
|
|
|
|
|
2017-09-29 20:50:20 +08:00
|
|
|
if (disableActions) return null;
|
2017-05-04 04:51:17 +08:00
|
|
|
|
2017-04-29 02:42:32 +08:00
|
|
|
return (
|
|
|
|
<Dropzone
|
2017-09-08 02:18:14 +08:00
|
|
|
multiple
|
2017-04-29 02:42:32 +08:00
|
|
|
className={styles.dropzone}
|
|
|
|
activeClassName={styles.dropzoneActive}
|
|
|
|
rejectClassName={styles.dropzoneReject}
|
2017-05-04 00:36:16 +08:00
|
|
|
accept={fileValidMimeTypes.join()}
|
|
|
|
minSize={fileSizeMin}
|
|
|
|
maxSize={fileSizeMax}
|
2017-06-07 20:28:41 +08:00
|
|
|
disablePreview
|
2017-04-29 02:42:32 +08:00
|
|
|
onDrop={this.handleFiledrop}
|
|
|
|
>
|
2017-11-22 22:47:27 +08:00
|
|
|
<Icon className={styles.dropzoneIcon} iconName="upload" />
|
2017-04-29 02:42:32 +08:00
|
|
|
<p className={styles.dropzoneMessage}>
|
|
|
|
{intl.formatMessage(intlMessages.dropzoneLabel)}
|
|
|
|
<span className={styles.dropzoneLink}>
|
|
|
|
{intl.formatMessage(intlMessages.browseFilesLabel)}
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
</Dropzone>
|
|
|
|
);
|
|
|
|
}
|
2017-06-07 20:28:41 +08:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { intl } = this.props;
|
|
|
|
const { preventClosing, disableActions } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ModalFullscreen
|
|
|
|
title={intl.formatMessage(intlMessages.title)}
|
|
|
|
preventClosing={preventClosing}
|
|
|
|
confirm={{
|
|
|
|
callback: this.handleConfirm,
|
|
|
|
label: intl.formatMessage(intlMessages.confirmLabel),
|
|
|
|
description: intl.formatMessage(intlMessages.confirmDesc),
|
|
|
|
disabled: disableActions,
|
|
|
|
}}
|
|
|
|
dismiss={{
|
|
|
|
callback: this.handleDismiss,
|
|
|
|
label: intl.formatMessage(intlMessages.dismissLabel),
|
|
|
|
description: intl.formatMessage(intlMessages.dismissDesc),
|
|
|
|
disabled: disableActions,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<p>{intl.formatMessage(intlMessages.message)}</p>
|
|
|
|
{this.renderPresentationList()}
|
|
|
|
{this.renderDropzone()}
|
|
|
|
</ModalFullscreen>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-04-29 02:42:32 +08:00
|
|
|
|
2017-09-23 04:45:31 +08:00
|
|
|
PresentationUploader.propTypes = propTypes;
|
|
|
|
PresentationUploader.defaultProps = defaultProps;
|
|
|
|
|
2018-07-18 07:49:14 +08:00
|
|
|
export default withModalMounter(injectIntl(PresentationUploader));
|