<commit_before>/*
Copyright 2016 First People's Cultural Council

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React, {Component, PropTypes} from 'react';
import classNames from 'classnames';
import selectn from 'selectn';

import DOMPurify from 'dompurify';

import ConfGlobal from 'conf/local.json';

import Paper from 'material-ui/lib/paper';

import Preview from 'views/components/Editor/Preview';
import MediaPanel from 'views/pages/explore/dialect/learn/base/media-panel';

import {Introduction} from '../list-view';

import RaisedButton from 'material-ui/lib/raised-button';
import Tabs from 'material-ui/lib/tabs/tabs';
import Tab from 'material-ui/lib/tabs/tab';

import ActionLaunch from 'material-ui/lib/svg-icons/action/launch';

const defaultInnerStyle = {padding: '15px', margin: '15px 0', minHeight: '420px', overflowX: 'auto'};
const defaultCoverStyle = {padding: '15px', margin: '15px 0'};

class MediaThumbnail extends Component {
    render() {
        const photoMediaPanel = <MediaPanel minimal={true} label="" type="FVPicture" items={this.props.photos} />;
        const videoMediaPanel = <MediaPanel minimal={true} label="" type="FVVideo" items={this.props.videos} />;

        if (this.props.photos.length > 0 && this.props.videos.length > 0) {
            return  <Tabs style={{marginTop: '15px'}}> 
                        <Tab label="Photo(s)">{photoMediaPanel}</Tab> 
                        <Tab label="Video(s)">{videoMediaPanel}</Tab> 
                    </Tabs>;
        } else if (this.props.photos.length > 0) {
            return photoMediaPanel; 
        } else if (this.props.videos.length > 0) {
            return videoMediaPanel;
        }

        return null;
    }
}

class Cover extends Component {
    render() {

        const DEFAULT_LANGUAGE = this.props.defaultLanguage;

        const dominant_language_title_translation = (selectn('properties.fvbook:title_literal_translation', this.props.entry) || []).filter(function(translation) {
            return translation.language == DEFAULT_LANGUAGE;
        });

        return  <div className="row">

                    <div className="col-xs-12">

                        <div className={classNames('col-xs-12', 'col-md-3', {'hidden': this.props.videos.length == 0 && this.props.photos.length == 0})}>
                            <MediaThumbnail videos={this.props.videos} photos={this.props.photos} />
                        </div>

                        <div className="col-xs-12 col-md-9">
                             <header style={{marginBottom: '10px'}}>
                                <h1 dangerouslySetInnerHTML={{__html: DOMPurify.sanitize( selectn('title', this.props.entry) )}}></h1>
                                <h2 style={{fontSize: '1.3em'}} dangerouslySetInnerHTML={{__html: DOMPurify.sanitize( selectn('[0].translation', dominant_language_title_translation) )}}></h2>
                                <subheader>{(selectn('contextParameters.book.authors', this.props.entry) || []).map(function(author, i) {
                                    return <span className={classNames('label', 'label-default')} key={i}>{selectn('dc:title', author)}</span>;
                                })}
                                </subheader>
                            </header>

                            <div>
                                <Introduction item={this.props.entry} defaultLanguage={this.props.defaultLanguage} style={{height: '16vh', padding: '5px'}} />
                                {this.props.audios}
                            </div>
                        </div>
                    </div>

                    <div className="col-xs-12">
                        <div className={classNames('col-xs-12', 'text-right')}>
                            {(this.props.openBookAction && this.props.pageCount > 0) ? <RaisedButton style={{marginRight: '10px'}} primary={true} label="Open Book" onTouchTap={this.props.openBookAction} icon={<ActionLaunch />} /> : ''}  
                        </div>
                    </div>

                </div>;
    }
}

class Page extends Component {

  render() {

    const DEFAULT_LANGUAGE = this.props.defaultLanguage;

    return  <div>

                <div className="row">

                    <div className={classNames('col-xs-12', 'col-md-3', {'hidden': this.props.videos.length == 0 && this.props.photos.length == 0})} style={{marginBottom: '10px', textAlign: 'center'}}>
                        <MediaThumbnail videos={this.props.videos} photos={this.props.photos} />
                    </div>

                    <div className="col-xs-12 col-md-9">
                        <div className={classNames('col-xs-6')}>
                            <div dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(selectn('properties.dc:title', this.props.entry))}}></div> 
                        </div>
                        <div className={classNames('col-xs-6')} style={{borderLeft: '1px solid #e1e1e1'}}>
                            {(selectn('properties.fvbookentry:dominant_language_text', this.props.entry) || []).map(function(translation, i) {
                                if (translation.language == DEFAULT_LANGUAGE) {
                                    return <div key={i} dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(translation.translation)}}></div>;
                                }
                            })}
                        </div>
                        <div className={classNames('col-xs-12')} style={{marginTop: '15px'}}>
                            {(selectn('properties.fv:literal_translation', this.props.entry)  || []).map(function(translation, i) {
                                if (translation.language == DEFAULT_LANGUAGE) {
                                    return <span key={i}><strong>Literal Translation</strong>: <span dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(translation.translation)}}></span></span>;
                                }
                            })}
                        </div>
                    </div>
                </div>

                <div className="row">
                    <div className={classNames('col-xs-12', 'text-right')}><commit_msg>Add audio to book page.<commit_after>/*
Copyright 2016 First People's Cultural Council

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React, {Component, PropTypes} from 'react';
import classNames from 'classnames';
import selectn from 'selectn';

import DOMPurify from 'dompurify';

import ConfGlobal from 'conf/local.json';

import Paper from 'material-ui/lib/paper';

import Preview from 'views/components/Editor/Preview';
import MediaPanel from 'views/pages/explore/dialect/learn/base/media-panel';

import {Introduction} from '../list-view';

import RaisedButton from 'material-ui/lib/raised-button';
import Tabs from 'material-ui/lib/tabs/tabs';
import Tab from 'material-ui/lib/tabs/tab';

import ActionLaunch from 'material-ui/lib/svg-icons/action/launch';

const defaultInnerStyle = {padding: '15px', margin: '15px 0', minHeight: '420px', overflowX: 'auto'};
const defaultCoverStyle = {padding: '15px', margin: '15px 0'};

class MediaThumbnail extends Component {
    render() {
        const photoMediaPanel = <MediaPanel minimal={true} label="" type="FVPicture" items={this.props.photos} />;
        const videoMediaPanel = <MediaPanel minimal={true} label="" type="FVVideo" items={this.props.videos} />;

        if (this.props.photos.length > 0 && this.props.videos.length > 0) {
            return  <Tabs style={{marginTop: '15px'}}> 
                        <Tab label="Photo(s)">{photoMediaPanel}</Tab> 
                        <Tab label="Video(s)">{videoMediaPanel}</Tab> 
                    </Tabs>;
        } else if (this.props.photos.length > 0) {
            return photoMediaPanel; 
        } else if (this.props.videos.length > 0) {
            return videoMediaPanel;
        }

        return null;
    }
}

class Cover extends Component {
    render() {

        const DEFAULT_LANGUAGE = this.props.defaultLanguage;

        const dominant_language_title_translation = (selectn('properties.fvbook:title_literal_translation', this.props.entry) || []).filter(function(translation) {
            return translation.language == DEFAULT_LANGUAGE;
        });

        return  <div className="row">

                    <div className="col-xs-12">

                        <div className={classNames('col-xs-12', 'col-md-3', {'hidden': this.props.videos.length == 0 && this.props.photos.length == 0})}>
                            <MediaThumbnail videos={this.props.videos} photos={this.props.photos} />
                        </div>

                        <div className="col-xs-12 col-md-9">
                             <header style={{marginBottom: '10px'}}>
                                <h1 dangerouslySetInnerHTML={{__html: DOMPurify.sanitize( selectn('title', this.props.entry) )}}></h1>
                                <h2 style={{fontSize: '1.3em'}} dangerouslySetInnerHTML={{__html: DOMPurify.sanitize( selectn('[0].translation', dominant_language_title_translation) )}}></h2>
                                <subheader>{(selectn('contextParameters.book.authors', this.props.entry) || []).map(function(author, i) {
                                    return <span className={classNames('label', 'label-default')} key={i}>{selectn('dc:title', author)}</span>;
                                })}
                                </subheader>
                            </header>

                            <div>
                                <Introduction item={this.props.entry} defaultLanguage={this.props.defaultLanguage} style={{height: '16vh', padding: '5px'}} />
                                {this.props.audios}
                            </div>
                        </div>
                    </div>

                    <div className="col-xs-12">
                        <div className={classNames('col-xs-12', 'text-right')}>
                            {(this.props.openBookAction && this.props.pageCount > 0) ? <RaisedButton style={{marginRight: '10px'}} primary={true} label="Open Book" onTouchTap={this.props.openBookAction} icon={<ActionLaunch />} /> : ''}  
                        </div>
                    </div>

                </div>;
    }
}

class Page extends Component {

  render() {

    const DEFAULT_LANGUAGE = this.props.defaultLanguage;

    // Audio
    let audios = [];

    (selectn('contextParameters.book.related_audio', this.props.entry) || []).map(function(audio, key) {
      audios.push(<Preview minimal={true} key={selectn('uid', audio)} expandedValue={audio} type="FVAudio" />);
    })

    return  <div>

                <div className="row">

                    <div className={classNames('col-xs-12', 'col-md-3', {'hidden': this.props.videos.length == 0 && this.props.photos.length == 0})} style={{marginBottom: '10px', textAlign: 'center'}}>
                        <MediaThumbnail videos={this.props.videos} photos={this.props.photos} />
                    </div>

                    <div className="col-xs-12 col-md-9">
                        <div className={classNames('col-xs-6')}>
                            <div dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(selectn('properties.dc:title', this.props.entry))}}></div> 
                            {audios}
                        </div>
                        <div className={classNames('col-xs-6')} style={{borderLeft: '1px solid #e1e1e1'}}>
                            {(selectn('properties.fvbookentry:dominant_language_text', this.props.entry) || []).map(function(translation, i) {
                                if (translation.language == DEFAULT_LANGUAGE) {
                                    return <div key={i} dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(translation.translation)}}></div>;
                                }
                            })}
                        </div>
                        <div className={classNames('col-xs-12')} style={{marginTop: '15px'}}>
                            {(selectn('properties.fv:literal_translation', this.props.entry)  || []).map(function(translation, i) {
                                if (translation.language == DEFAULT_LANGUAGE) {
                                    return <span key={i}><strong>Literal Translation</strong>: <span dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(translation.translation)}}></span></span>;
                                }
                            })}
                        </div>
                    </div>
                </div>

                <div className="row">
                    <div className={classNames('col-xs-12', 'text-right')}>
{'fraction_non_alphanumeric': 0.137002256679042, 'fraction_numerical': 0.011356191308145884, 'mean_word_length': 1.9904222899434045, 'pattern_counts': {'":': 0, '<': 128, '<?xml version=': 0, '>': 138, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5567069', 'n_tokens_mistral': 3862, 'n_tokens_neox': 3602, 'n_words': 783}