2018-08-30 14:25:33 +00:00
|
|
|
import React, { Component, Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-10-25 06:52:03 +00:00
|
|
|
import { Trans, withNamespaces } from 'react-i18next';
|
2018-08-30 14:25:33 +00:00
|
|
|
|
|
|
|
import Statistics from './Statistics';
|
|
|
|
import Counters from './Counters';
|
|
|
|
import Clients from './Clients';
|
|
|
|
import QueriedDomains from './QueriedDomains';
|
|
|
|
import BlockedDomains from './BlockedDomains';
|
|
|
|
|
|
|
|
import PageTitle from '../ui/PageTitle';
|
|
|
|
import Loading from '../ui/Loading';
|
2018-10-12 16:52:19 +00:00
|
|
|
import './Dashboard.css';
|
2018-08-30 14:25:33 +00:00
|
|
|
|
|
|
|
class Dashboard extends Component {
|
|
|
|
componentDidMount() {
|
2018-09-17 14:44:32 +00:00
|
|
|
this.getAllStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllStats = () => {
|
2018-08-30 14:25:33 +00:00
|
|
|
this.props.getStats();
|
|
|
|
this.props.getStatsHistory();
|
|
|
|
this.props.getTopStats();
|
2018-09-26 14:12:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getToggleFilteringButton = () => {
|
2019-01-16 11:51:17 +00:00
|
|
|
const { protectionEnabled, processingProtection } = this.props.dashboard;
|
2018-11-09 06:51:28 +00:00
|
|
|
const buttonText = protectionEnabled ? 'disable_protection' : 'enable_protection';
|
2018-10-11 07:57:36 +00:00
|
|
|
const buttonClass = protectionEnabled ? 'btn-gray' : 'btn-success';
|
2018-09-26 14:12:31 +00:00
|
|
|
|
|
|
|
return (
|
2019-01-16 11:51:17 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={`btn btn-sm mr-2 ${buttonClass}`}
|
|
|
|
onClick={() => this.props.toggleProtection(protectionEnabled)}
|
|
|
|
disabled={processingProtection}
|
|
|
|
>
|
2018-11-09 06:51:28 +00:00
|
|
|
<Trans>{buttonText}</Trans>
|
2018-09-26 14:12:31 +00:00
|
|
|
</button>
|
|
|
|
);
|
2018-09-19 15:58:55 +00:00
|
|
|
}
|
2018-08-30 14:25:33 +00:00
|
|
|
|
|
|
|
render() {
|
2018-10-25 06:52:03 +00:00
|
|
|
const { dashboard, t } = this.props;
|
2018-08-30 14:25:33 +00:00
|
|
|
const dashboardProcessing =
|
|
|
|
dashboard.processing ||
|
|
|
|
dashboard.processingStats ||
|
|
|
|
dashboard.processingStatsHistory ||
|
|
|
|
dashboard.processingTopStats;
|
|
|
|
|
2018-11-09 06:51:28 +00:00
|
|
|
const refreshFullButton = <button type="button" className="btn btn-outline-primary btn-sm" onClick={() => this.getAllStats()}><Trans>refresh_statics</Trans></button>;
|
2018-09-17 14:44:32 +00:00
|
|
|
const refreshButton = <button type="button" className="btn btn-outline-primary btn-sm card-refresh" onClick={() => this.getAllStats()} />;
|
2018-08-30 14:25:33 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2018-11-09 06:51:28 +00:00
|
|
|
<PageTitle title={ t('dashboard') }>
|
2018-08-30 14:25:33 +00:00
|
|
|
<div className="page-title__actions">
|
2018-09-26 14:12:31 +00:00
|
|
|
{this.getToggleFilteringButton()}
|
2018-08-30 14:25:33 +00:00
|
|
|
{refreshFullButton}
|
|
|
|
</div>
|
|
|
|
</PageTitle>
|
|
|
|
{dashboardProcessing && <Loading />}
|
|
|
|
{!dashboardProcessing &&
|
|
|
|
<div className="row row-cards">
|
|
|
|
{dashboard.statsHistory &&
|
|
|
|
<div className="col-lg-12">
|
|
|
|
<Statistics
|
|
|
|
history={dashboard.statsHistory}
|
|
|
|
refreshButton={refreshButton}
|
2018-10-12 13:02:01 +00:00
|
|
|
dnsQueries={dashboard.stats.dns_queries}
|
|
|
|
blockedFiltering={dashboard.stats.blocked_filtering}
|
|
|
|
replacedSafebrowsing={dashboard.stats.replaced_safebrowsing}
|
|
|
|
replacedParental={dashboard.stats.replaced_parental}
|
2018-08-30 14:25:33 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
<div className="col-lg-6">
|
|
|
|
{dashboard.stats &&
|
|
|
|
<Counters
|
|
|
|
refreshButton={refreshButton}
|
|
|
|
dnsQueries={dashboard.stats.dns_queries}
|
|
|
|
blockedFiltering={dashboard.stats.blocked_filtering}
|
|
|
|
replacedSafebrowsing={dashboard.stats.replaced_safebrowsing}
|
|
|
|
replacedParental={dashboard.stats.replaced_parental}
|
|
|
|
replacedSafesearch={dashboard.stats.replaced_safesearch}
|
|
|
|
avgProcessingTime={dashboard.stats.avg_processing_time}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
{dashboard.topStats &&
|
|
|
|
<Fragment>
|
|
|
|
<div className="col-lg-6">
|
|
|
|
<Clients
|
2018-10-12 13:02:01 +00:00
|
|
|
dnsQueries={dashboard.stats.dns_queries}
|
2018-08-30 14:25:33 +00:00
|
|
|
refreshButton={refreshButton}
|
|
|
|
topClients={dashboard.topStats.top_clients}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-lg-6">
|
|
|
|
<QueriedDomains
|
2018-10-12 13:02:01 +00:00
|
|
|
dnsQueries={dashboard.stats.dns_queries}
|
2018-08-30 14:25:33 +00:00
|
|
|
refreshButton={refreshButton}
|
|
|
|
topQueriedDomains={dashboard.topStats.top_queried_domains}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-lg-6">
|
|
|
|
<BlockedDomains
|
|
|
|
refreshButton={refreshButton}
|
|
|
|
topBlockedDomains={dashboard.topStats.top_blocked_domains}
|
2018-10-12 13:02:01 +00:00
|
|
|
blockedFiltering={dashboard.stats.blocked_filtering}
|
|
|
|
replacedSafebrowsing={dashboard.stats.replaced_safebrowsing}
|
|
|
|
replacedParental={dashboard.stats.replaced_parental}
|
2018-08-30 14:25:33 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Dashboard.propTypes = {
|
|
|
|
getStats: PropTypes.func,
|
|
|
|
getStatsHistory: PropTypes.func,
|
|
|
|
getTopStats: PropTypes.func,
|
|
|
|
dashboard: PropTypes.object,
|
|
|
|
isCoreRunning: PropTypes.bool,
|
2018-09-26 14:12:31 +00:00
|
|
|
getFiltering: PropTypes.func,
|
2018-10-11 07:57:36 +00:00
|
|
|
toggleProtection: PropTypes.func,
|
2019-01-16 11:51:17 +00:00
|
|
|
processingProtection: PropTypes.bool,
|
2018-10-25 06:52:03 +00:00
|
|
|
t: PropTypes.func,
|
2018-08-30 14:25:33 +00:00
|
|
|
};
|
|
|
|
|
2018-10-25 06:52:03 +00:00
|
|
|
export default withNamespaces()(Dashboard);
|