From d153d661db7d4349d69824d318aa9ad571970606 Mon Sep 17 00:00:00 2001
From: JoramWilander <jwawilander@gmail.com>
Date: Tue, 2 Feb 2016 16:49:27 -0500
Subject: Add basic server audit tab to system console for EE

---
 web/react/components/admin_console/audits.jsx | 94 +++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 web/react/components/admin_console/audits.jsx

(limited to 'web/react/components/admin_console/audits.jsx')

diff --git a/web/react/components/admin_console/audits.jsx b/web/react/components/admin_console/audits.jsx
new file mode 100644
index 000000000..866539b3d
--- /dev/null
+++ b/web/react/components/admin_console/audits.jsx
@@ -0,0 +1,94 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import LoadingScreen from '../loading_screen.jsx';
+import AuditTable from '../audit_table.jsx';
+
+import AdminStore from '../../stores/admin_store.jsx';
+
+import * as AsyncClient from '../../utils/async_client.jsx';
+
+import {FormattedMessage} from 'mm-intl';
+
+export default class Audits extends React.Component {
+    constructor(props) {
+        super(props);
+
+        this.onAuditListenerChange = this.onAuditListenerChange.bind(this);
+        this.reload = this.reload.bind(this);
+
+        this.state = {
+            audits: AdminStore.getAudits()
+        };
+    }
+
+    componentDidMount() {
+        AdminStore.addAuditChangeListener(this.onAuditListenerChange);
+        AsyncClient.getServerAudits();
+    }
+
+    componentWillUnmount() {
+        AdminStore.removeAuditChangeListener(this.onAuditListenerChange);
+    }
+
+    onAuditListenerChange() {
+        this.setState({
+            audits: AdminStore.getAudits()
+        });
+    }
+
+    reload() {
+        AdminStore.saveAudits(null);
+        this.setState({
+            audits: null
+        });
+
+        AsyncClient.getServerAudits();
+    }
+
+    render() {
+        var content = null;
+
+        if (global.window.mm_license.IsLicensed !== 'true') {
+            return <div/>;
+        }
+
+        if (this.state.audits === null) {
+            content = <LoadingScreen />;
+        } else {
+            content = (
+                <div style={{margin: '10px'}}>
+                <AuditTable
+                    audits={this.state.audits}
+                    oneLine={true}
+                    showUserId={true}
+                />
+                </div>
+            );
+        }
+
+        return (
+            <div className='panel'>
+                <h3>
+                    <FormattedMessage
+                        id='admin.audits.title'
+                        defaultMessage='Server Audits'
+                    />
+                </h3>
+                <button
+                    type='submit'
+                    className='btn btn-primary'
+                    onClick={this.reload}
+                >
+                    <FormattedMessage
+                        id='admin.audits.reload'
+                        defaultMessage='Reload'
+                    />
+                </button>
+                <div className='log__panel'>
+                    {content}
+                </div>
+            </div>
+        );
+    }
+}
-- 
cgit v1.2.3-1-g7c22

