summaryrefslogtreecommitdiffstats
path: root/webapp/components/access_history_modal.jsx
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-03-14 08:50:46 -0400
committerChristopher Speller <crspeller@gmail.com>2016-03-16 18:02:55 -0400
commit12896bd23eeba79884245c1c29fdc568cf21a7fa (patch)
tree4e7f83d3e2564b9b89d669e9f7905ff11768b11a /webapp/components/access_history_modal.jsx
parent29fe6a3d13c9c7aa490fffebbe5d1b5fdf1e3090 (diff)
downloadchat-12896bd23eeba79884245c1c29fdc568cf21a7fa.tar.gz
chat-12896bd23eeba79884245c1c29fdc568cf21a7fa.tar.bz2
chat-12896bd23eeba79884245c1c29fdc568cf21a7fa.zip
Converting to Webpack. Stage 1.
Diffstat (limited to 'webapp/components/access_history_modal.jsx')
-rw-r--r--webapp/components/access_history_modal.jsx113
1 files changed, 113 insertions, 0 deletions
diff --git a/webapp/components/access_history_modal.jsx b/webapp/components/access_history_modal.jsx
new file mode 100644
index 000000000..94a10c97f
--- /dev/null
+++ b/webapp/components/access_history_modal.jsx
@@ -0,0 +1,113 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import $ from 'jquery';
+import ReactDOM from 'react-dom';
+import {Modal} from 'react-bootstrap';
+import LoadingScreen from './loading_screen.jsx';
+import AuditTable from './audit_table.jsx';
+
+import UserStore from 'stores/user_store.jsx';
+
+import * as AsyncClient from 'utils/async_client.jsx';
+import * as Utils from 'utils/utils.jsx';
+
+import {intlShape, injectIntl, FormattedMessage} from 'react-intl';
+
+import React from 'react';
+
+class AccessHistoryModal extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.onAuditChange = this.onAuditChange.bind(this);
+ this.onShow = this.onShow.bind(this);
+ this.onHide = this.onHide.bind(this);
+
+ const state = this.getStateFromStoresForAudits();
+ state.moreInfo = [];
+
+ this.state = state;
+ }
+ getStateFromStoresForAudits() {
+ return {
+ audits: UserStore.getAudits()
+ };
+ }
+ onShow() {
+ AsyncClient.getAudits();
+
+ if ($(window).width() > 768) {
+ $(ReactDOM.findDOMNode(this.refs.modalBody)).css('max-height', $(window).height() - 200);
+ } else {
+ $(ReactDOM.findDOMNode(this.refs.modalBody)).css('max-height', $(window).height() - 150);
+ }
+ }
+ onHide() {
+ this.setState({moreInfo: []});
+ this.props.onHide();
+ }
+ componentDidMount() {
+ UserStore.addAuditsChangeListener(this.onAuditChange);
+
+ if (this.props.show) {
+ this.onShow();
+ }
+ }
+ componentDidUpdate(prevProps) {
+ if (this.props.show && !prevProps.show) {
+ this.onShow();
+ }
+ }
+ componentWillUnmount() {
+ UserStore.removeAuditsChangeListener(this.onAuditChange);
+ }
+ onAuditChange() {
+ var newState = this.getStateFromStoresForAudits();
+ if (!Utils.areObjectsEqual(newState.audits, this.state.audits)) {
+ this.setState(newState);
+ }
+ }
+ render() {
+ var content;
+ if (this.state.audits.loading) {
+ content = (<LoadingScreen/>);
+ } else {
+ content = (
+ <AuditTable
+ audits={this.state.audits}
+ showIp={true}
+ showSession={true}
+ />
+ );
+ }
+
+ return (
+ <Modal
+ show={this.props.show}
+ onHide={this.onHide}
+ bsSize='large'
+ >
+ <Modal.Header closeButton={true}>
+ <Modal.Title>
+ <FormattedMessage
+ id='access_history.title'
+ defaultMessage='Access History'
+ />
+ </Modal.Title>
+ </Modal.Header>
+ <Modal.Body ref='modalBody'>
+ {content}
+ </Modal.Body>
+ </Modal>
+ );
+ }
+}
+
+AccessHistoryModal.propTypes = {
+ intl: intlShape.isRequired,
+ show: React.PropTypes.bool.isRequired,
+ onHide: React.PropTypes.func.isRequired
+};
+
+export default injectIntl(AccessHistoryModal);