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

Restructure MediaPlayer

- encoding evaluation taken out to MediaContainer
This commit is contained in:
Tim Daubenschütz 2016-03-10 14:33:54 +01:00
parent e0401de1a3
commit 4fdab505e7
2 changed files with 61 additions and 85 deletions

View File

@ -3,6 +3,7 @@
import React from 'react'; import React from 'react';
import Button from 'react-bootstrap/lib/Button'; import Button from 'react-bootstrap/lib/Button';
import ProgressBar from 'react-bootstrap/lib/ProgressBar';
import MediaPlayer from './../ascribe_media/media_player'; import MediaPlayer from './../ascribe_media/media_player';
@ -13,6 +14,8 @@ import S3DownloadButton from '../ascribe_buttons/s3_download_button';
import CollapsibleButton from './../ascribe_collapsible/collapsible_button'; import CollapsibleButton from './../ascribe_collapsible/collapsible_button';
import AscribeSpinner from '../ascribe_spinner';
import AclProxy from '../acl_proxy'; import AclProxy from '../acl_proxy';
import AppConstants from '../../constants/application_constants'; import AppConstants from '../../constants/application_constants';
@ -45,7 +48,7 @@ let MediaContainer = React.createClass({
const { content: { digital_work: digitalWork }, refreshObject } = this.props; const { content: { digital_work: digitalWork }, refreshObject } = this.props;
const { timerId } = this.state; const { timerId } = this.state;
if (digitalWork && this.isDigitalWorkEncoding() && !timerId) { if (digitalWork && (this.isVideoEncoding() || this.isImageEncoding()) && !timerId) {
this.setState({ timerId: window.setInterval(refreshObject, AppConstants.encodeUpdateThreshold) }); this.setState({ timerId: window.setInterval(refreshObject, AppConstants.encodeUpdateThreshold) });
} }
}, },
@ -53,7 +56,7 @@ let MediaContainer = React.createClass({
componentWillUpdate() { componentWillUpdate() {
const { timerId } = this.state; const { timerId } = this.state;
if (!this.isDigitalWorkEncoding() && timerId) { if (!(this.isVideoEncoding() || this.isImageEncoding()) && timerId) {
window.clearInterval(timerId); window.clearInterval(timerId);
} }
}, },
@ -62,36 +65,50 @@ let MediaContainer = React.createClass({
window.clearInterval(this.state.timerId); window.clearInterval(this.state.timerId);
}, },
/* isVideoEncoding() {
* A digital work is encoding if: const { content: { digital_work: digitalWork } } = this.props;
* return digitalWork.mime === 'video' && digitalWork.isEncoding === 'number' && digitalWork.isEncoding !== 100;
* - it's either a video that has `isEncoding` < 100 },
* - of a .tif|.tiff file that has not yet been converted
* to a .jpeg thumbnail
*/
isDigitalWorkEncoding() {
const {
content: {
digital_work: digitalWork,
thumbnail
} } = this.props;
return ( isImageEncoding() {
( const { content: { thumbnail, digital_work: digitalWork } } = this.props;
digitalWork.mime === 'video' && const thumbnailFileExtension = this.getFileExtensionFromUrl(thumbnail.thumbnail_sizes['600x600']);
typeof digitalWork.isEncoding === 'number' &&
digitalWork.isEncoding !== 100 return digitalWork.mime === 'image' && (thumbnailFileExtension === 'tif' || thumbnailFileExtension === 'tiff');
) },
||
( getEncodingMessage() {
digitalWork.mime === 'image' && if (this.isVideoEncoding()) {
(this.getFileExtensionFromUrl(thumbnail.url) === 'tif' || this.getFileExtensionFromUrl(thumbnail.url) === 'tiff') const { digital_work: digitalWork } = this.props;
)
); return (
<div className="ascribe-detail-header ascribe-media-player">
<p>
<em>We successfully received your video and it is now being encoded.
<br />You can leave this page and check back on the status later.</em>
</p>
<ProgressBar now={digitalWork.isEncoding}
label="%(percent)s%"
className="ascribe-progress-bar" />
</div>
);
} else if (this.isImageEncoding()) {
return (
<div className="ascribe-media-player encoding-image">
<AscribeSpinner color='dark-blue' size='lg' />
<em className="text-center">
{getLangText('We successfully received your image and it is now being encoded.')}
<br />
{getLangText('We will be refreshing this page as soon as encoding has finished.')}
<br />
{getLangText('(You may close this page)')}
</em>
</div>
);
}
}, },
getFileExtensionFromUrl(url) { getFileExtensionFromUrl(url) {
// We want to show the file's extension as a label of the download button. // We want to show the file's extension as a label of the download button.
// We can however not only use `extractFileExtensionFromString` on the url for that // We can however not only use `extractFileExtensionFromString` on the url for that
// as files might be saved on S3 without a file extension which leads // as files might be saved on S3 without a file extension which leads
@ -105,19 +122,17 @@ let MediaContainer = React.createClass({
render() { render() {
const { content, currentUser } = this.props; const { content, currentUser } = this.props;
const mimetype = content.digital_work.mime;
// Pieces and editions are joined to the user by a foreign key in the database, so // Pieces and editions are joined to the user by a foreign key in the database, so
// the information in content will be updated if a user updates their username. // the information in content will be updated if a user updates their username.
// We also force uniqueness of usernames, so this check is safe to dtermine if the // We also force uniqueness of usernames, so this check is safe to dtermine if the
// content was registered by the current user. // content was registered by the current user.
const didUserRegisterContent = currentUser && (currentUser.username === content.user_registered); const didUserRegisterContent = currentUser && (currentUser.username === content.user_registered);
const thumbnail = content.thumbnail.thumbnail_sizes && content.thumbnail.thumbnail_sizes['600x600'] ? content.thumbnail.thumbnail_sizes['600x600']
: content.thumbnail.url_safe;
let thumbnail = content.thumbnail.thumbnail_sizes && content.thumbnail.thumbnail_sizes['600x600'] ?
content.thumbnail.thumbnail_sizes['600x600'] : content.thumbnail.url_safe;
let mimetype = content.digital_work.mime;
let embed = null; let embed = null;
let extraData = null; let extraData = null;
let isEmbedDisabled = mimetype === 'video' && content.digital_work.isEncoding !== undefined && content.digital_work.isEncoding !== 100;
if (content.digital_work.encoding_urls) { if (content.digital_work.encoding_urls) {
extraData = content.digital_work.encoding_urls.map(e => { return { url: e.url, type: e.label }; }); extraData = content.digital_work.encoding_urls.map(e => { return { url: e.url, type: e.label }; });
@ -132,7 +147,7 @@ let MediaContainer = React.createClass({
<Button <Button
bsSize="xsmall" bsSize="xsmall"
className="ascribe-margin-1px" className="ascribe-margin-1px"
disabled={isEmbedDisabled}> disabled={this.isVideoEncoding()}>
{getLangText('Embed')} {getLangText('Embed')}
</Button> </Button>
} }
@ -149,10 +164,9 @@ let MediaContainer = React.createClass({
<MediaPlayer <MediaPlayer
mimetype={mimetype} mimetype={mimetype}
thumbnail={thumbnail} thumbnail={thumbnail}
thumbnailFileExtension={this.getFileExtensionFromUrl(thumbnail)}
url={content.digital_work.url} url={content.digital_work.url}
extraData={extraData} extraData={extraData}
encodingStatus={content.digital_work.isEncoding} /> encodingMessage={this.getEncodingMessage()} />
<p className="text-center hidden-print"> <p className="text-center hidden-print">
<span className="ascribe-social-button-list"> <span className="ascribe-social-button-list">
<FacebookShareButton /> <FacebookShareButton />

View File

@ -4,14 +4,10 @@ import React from 'react';
import Q from 'q'; import Q from 'q';
import Panel from 'react-bootstrap/lib/Panel'; import Panel from 'react-bootstrap/lib/Panel';
import ProgressBar from 'react-bootstrap/lib/ProgressBar';
import AscribeSpinner from '../ascribe_spinner';
import AppConstants from '../../constants/application_constants'; import AppConstants from '../../constants/application_constants';
import { escapeHTML } from '../../utils/general_utils'; import { escapeHTML } from '../../utils/general_utils';
import { getLangText } from '../../utils/lang_utils';
import { InjectInHeadUtils } from '../../utils/inject_utils'; import { InjectInHeadUtils } from '../../utils/inject_utils';
/** /**
@ -135,8 +131,7 @@ let Video = React.createClass({
propTypes: { propTypes: {
thumbnail: React.PropTypes.string.isRequired, thumbnail: React.PropTypes.string.isRequired,
url: React.PropTypes.string.isRequired, url: React.PropTypes.string.isRequired,
extraData: React.PropTypes.array.isRequired, extraData: React.PropTypes.array.isRequired
encodingStatus: React.PropTypes.number
}, },
getInitialState() { getInitialState() {
@ -204,61 +199,28 @@ let MediaPlayer = React.createClass({
propTypes: { propTypes: {
mimetype: React.PropTypes.oneOf(['image', 'video', 'audio', 'pdf', 'other']).isRequired, mimetype: React.PropTypes.oneOf(['image', 'video', 'audio', 'pdf', 'other']).isRequired,
thumbnail: React.PropTypes.string.isRequired, thumbnail: React.PropTypes.string.isRequired,
thumbnailFileExtension: React.PropTypes.string,
url: React.PropTypes.string.isRequired, url: React.PropTypes.string.isRequired,
extraData: React.PropTypes.array, extraData: React.PropTypes.array,
encodingStatus: React.PropTypes.number, encodingMessage: React.PropTypes.node
},
isVideoEncoding() {
const { mimetype, encodingStatus } = this.props;
return mimetype === 'video' && encodingStatus !== undefined && encodingStatus !== 100;
},
isImageEncoding() {
const { mimetype, thumbnailFileExtension } = this.props;
return mimetype === 'image' && (thumbnailFileExtension === 'tif' || thumbnailFileExtension === 'tiff');
}, },
render() { render() {
const { mimetype, const {
thumbnail, mimetype,
url, thumbnail,
extraData, url,
encodingStatus } = this.props; extraData,
encodingMessage
} = this.props;
if (this.isVideoEncoding()) { if (encodingMessage) {
return ( return encodingMessage;
<div className="ascribe-detail-header ascribe-media-player">
<p>
<em>We successfully received your video and it is now being encoded.
<br />You can leave this page and check back on the status later.</em>
</p>
<ProgressBar now={encodingStatus}
label="%(percent)s%"
className="ascribe-progress-bar" />
</div>
);
} else if (this.isImageEncoding()) {
return (
<div className="ascribe-media-player encoding-image">
<AscribeSpinner color='dark-blue' size='lg' />
<em className="text-center">
{getLangText('We successfully received your image and it is now being encoded.')}
<br />
{getLangText('We will be refreshing this page as soon as encoding has finished.')}
<br />
{getLangText('(You may close this page)')}
</em>
</div>
);
} else { } else {
let Component = resourceMap[mimetype] || Other; let Component = resourceMap[mimetype] || Other;
let componentProps = { let componentProps = {
thumbnail, thumbnail,
url, url,
extraData, extraData,
encodingStatus
}; };
// Since the launch of the portfolio whitelabel submission, // Since the launch of the portfolio whitelabel submission,