// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import LoadingScreen from '../loading_screen.jsx'; import * as Utils from '../../utils/utils.jsx'; import AdminStore from '../../stores/admin_store.jsx'; import UserStore from '../../stores/user_store.jsx'; import Client from 'client/web_client.jsx'; import * as AsyncClient from '../../utils/async_client.jsx'; import {FormattedMessage, FormattedDate, FormattedTime} from 'react-intl'; import React from 'react'; import ReactDOM from 'react-dom'; export default class ComplianceReports extends React.Component { constructor(props) { super(props); this.onComplianceReportsListenerChange = this.onComplianceReportsListenerChange.bind(this); this.reload = this.reload.bind(this); this.runReport = this.runReport.bind(this); this.getDateTime = this.getDateTime.bind(this); this.state = { enabled: AdminStore.getConfig().ComplianceSettings.Enable, reports: AdminStore.getComplianceReports(), serverError: null }; } componentDidMount() { AdminStore.addComplianceReportsChangeListener(this.onComplianceReportsListenerChange); if (global.window.mm_license.IsLicensed !== 'true' || !this.state.enabled) { return; } AsyncClient.getComplianceReports(); } componentWillUnmount() { AdminStore.removeComplianceReportsChangeListener(this.onComplianceReportsListenerChange); } onComplianceReportsListenerChange() { this.setState({ reports: AdminStore.getComplianceReports() }); } reload() { AdminStore.saveComplianceReports(null); this.setState({ reports: null, serverError: null }); AsyncClient.getComplianceReports(); } runReport(e) { e.preventDefault(); $('#run-button').button('loading'); var job = {}; job.desc = ReactDOM.findDOMNode(this.refs.desc).value; job.emails = ReactDOM.findDOMNode(this.refs.emails).value; job.keywords = ReactDOM.findDOMNode(this.refs.keywords).value; job.start_at = Date.parse(ReactDOM.findDOMNode(this.refs.from).value); job.end_at = Date.parse(ReactDOM.findDOMNode(this.refs.to).value); Client.saveComplianceReports( job, () => { ReactDOM.findDOMNode(this.refs.emails).value = ''; ReactDOM.findDOMNode(this.refs.keywords).value = ''; ReactDOM.findDOMNode(this.refs.desc).value = ''; ReactDOM.findDOMNode(this.refs.from).value = ''; ReactDOM.findDOMNode(this.refs.to).value = ''; this.reload(); $('#run-button').button('reset'); }, (err) => { this.setState({serverError: err.message}); $('#run-button').button('reset'); } ); } getDateTime(millis) { const date = new Date(millis); return ( {' - '} ); } render() { var content = null; if (global.window.mm_license.IsLicensed !== 'true' || !this.state.enabled) { return
; } if (this.state.reports === null) { content = ; } else { var list = []; for (var i = 0; i < this.state.reports.length; i++) { const report = this.state.reports[i]; var params = ''; if (report.type === 'adhoc') { params = ( {' '}{this.getDateTime(report.start_at)}
{' '}{this.getDateTime(report.end_at)}
{' '}{report.emails}
{' '}{report.keywords}
); } var download = ''; if (report.status === 'finished') { download = ( ); } var status = report.status; if (report.status === 'finished') { status = ( {report.status} ); } if (report.status === 'failed') { status = ( {report.status} ); } var user = report.user_id; var profile = UserStore.getProfile(report.user_id); if (profile) { user = profile.email; } list[i] = ( {download} {this.getDateTime(report.create_at)} {status} {report.count} {report.type} {report.desc} {user} {params} ); } content = (
{list}
); } let serverError = ''; if (this.state.serverError) { serverError = (
); } return (

{serverError}
{content}
); } }