ohif-viewer/src/components/Header/Header.js

123 lines
3.1 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
2019-01-08 10:48:57 +01:00
import PropTypes from 'prop-types';
import { Link, withRouter } from 'react-router-dom';
import { Dropdown } from 'react-viewerbase';
2019-05-30 20:41:15 +02:00
import { withTranslation } from 'react-i18next';
2019-06-05 22:09:54 +02:00
import i18n from 'ohif-i18n';
2019-01-08 10:48:57 +01:00
import './Header.css';
import OHIFLogo from '../OHIFLogo/OHIFLogo.js';
import ConnectedUserPreferencesModal from '../../connectedComponents/ConnectedUserPreferencesModal.js';
2019-01-08 10:48:57 +01:00
class Header extends Component {
static propTypes = {
home: PropTypes.bool.isRequired,
location: PropTypes.object.isRequired,
openUserPreferencesModal: PropTypes.func,
2019-06-05 22:09:54 +02:00
children: PropTypes.node,
t: PropTypes.func.isRequired,
};
static defaultProps = {
home: true,
2019-05-29 14:39:54 +02:00
children: OHIFLogo(),
};
constructor(props) {
super(props);
this.state = {
2019-05-29 14:39:54 +02:00
userPreferencesOpen: false,
};
2019-06-03 23:02:01 +02:00
this.loadOptions();
}
loadOptions() {
2019-06-05 22:09:54 +02:00
const { t } = this.props;
this.options = [
{
2019-06-04 17:34:57 +02:00
title: t('preferences'),
icon: 'fa fa-user',
2019-05-29 14:39:54 +02:00
onClick: this.props.openUserPreferencesModal,
},
{
2019-06-04 17:34:57 +02:00
title: t('about'),
icon: 'fa fa-info',
2019-05-29 14:39:54 +02:00
link: 'http://ohif.org',
},
];
}
2019-06-03 23:02:01 +02:00
changeLanguage(language) {
2019-06-04 17:34:57 +02:00
i18n.init({
2019-06-04 23:16:07 +02:00
fallbackLng: language.substring(0, 2),
2019-06-05 22:09:54 +02:00
lng: language,
2019-06-04 17:34:57 +02:00
});
2019-06-03 23:02:01 +02:00
this.loadOptions();
}
render() {
2019-06-05 22:09:54 +02:00
const { t } = this.props;
return (
<div className={`entry-header ${this.props.home ? 'header-big' : ''}`}>
<div className="header-left-box">
{this.props.location && this.props.location.studyLink && (
<Link
to={this.props.location.studyLink}
className="header-btn header-viewerLink"
>
2019-06-04 17:34:57 +02:00
{t('back_to_viewer')}
</Link>
)}
{this.props.children}
{!this.props.home && (
<Link
className="header-btn header-studyListLinkSection"
to={{
pathname: '/',
2019-05-29 14:39:54 +02:00
state: { studyLink: this.props.location.pathname },
}}
>
2019-06-04 17:34:57 +02:00
{t('study_list')}
</Link>
)}
</div>
2019-01-08 10:48:57 +01:00
<div className="header-menu">
2019-06-04 17:34:57 +02:00
<span className="research-use">{t('research_use')}</span>
2019-06-03 23:02:01 +02:00
<button
className="research-use"
onClick={() => this.changeLanguage('en-US')}
>
2019-06-04 17:34:57 +02:00
EN-US
</button>
<button
className="research-use"
onClick={() => this.changeLanguage('en-UK')}
>
EN-UK
</button>
<button
className="research-use"
onClick={() => this.changeLanguage('es-AR')}
>
ES-AR
2019-06-03 23:02:01 +02:00
</button>
<button
className="research-use"
2019-06-04 00:56:59 +02:00
onClick={() => this.changeLanguage('es-MX')}
2019-06-03 23:02:01 +02:00
>
2019-06-04 17:34:57 +02:00
ES-MX
2019-06-03 23:02:01 +02:00
</button>
2019-06-05 22:09:54 +02:00
<Dropdown title={t('options')} list={this.options} align="right" />
<ConnectedUserPreferencesModal />
</div>
</div>
);
}
}
2019-01-08 10:48:57 +01:00
2019-05-30 20:41:15 +02:00
export default withTranslation('Header')(withRouter(Header));