badguardhome/client/src/components/Settings/index.js

151 lines
5.3 KiB
JavaScript
Raw Normal View History

2018-08-30 14:25:33 +00:00
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
2019-09-04 14:39:35 +00:00
import { withNamespaces } from 'react-i18next';
2019-05-23 11:14:22 +00:00
2019-07-18 11:52:47 +00:00
import Services from './Services';
import StatsConfig from './StatsConfig';
2019-09-04 14:39:35 +00:00
import LogsConfig from './LogsConfig';
2019-09-12 13:19:35 +00:00
import FiltersConfig from './FiltersConfig';
2019-12-04 18:52:38 +00:00
2018-08-30 14:25:33 +00:00
import Checkbox from '../ui/Checkbox';
import Loading from '../ui/Loading';
import PageTitle from '../ui/PageTitle';
import Card from '../ui/Card';
2019-05-23 11:14:22 +00:00
2018-08-30 14:25:33 +00:00
import './Settings.css';
2018-10-25 10:33:44 +00:00
class Settings extends Component {
2018-08-30 14:25:33 +00:00
settings = {
safebrowsing: {
enabled: false,
2018-11-09 06:51:28 +00:00
title: 'use_adguard_browsing_sec',
subtitle: 'use_adguard_browsing_sec_hint',
2018-08-30 14:25:33 +00:00
},
parental: {
enabled: false,
2018-11-09 06:51:28 +00:00
title: 'use_adguard_parental',
subtitle: 'use_adguard_parental_hint',
2018-08-30 14:25:33 +00:00
},
safesearch: {
enabled: false,
2018-11-09 06:51:28 +00:00
title: 'enforce_safe_search',
subtitle: 'enforce_save_search_hint',
2018-08-30 14:25:33 +00:00
},
};
componentDidMount() {
this.props.initSettings(this.settings);
2019-07-18 11:52:47 +00:00
this.props.getBlockedServices();
this.props.getStatsConfig();
2019-09-04 14:39:35 +00:00
this.props.getLogsConfig();
2019-09-12 13:19:35 +00:00
this.props.getFilteringStatus();
2018-08-30 14:25:33 +00:00
}
renderSettings = (settings) => {
2019-09-12 13:19:35 +00:00
const settingsKeys = Object.keys(settings);
if (settingsKeys.length > 0) {
return settingsKeys.map((key) => {
2018-08-30 14:25:33 +00:00
const setting = settings[key];
const { enabled } = setting;
2019-05-22 14:59:57 +00:00
return (
<Checkbox
{...settings[key]}
2019-09-12 13:19:35 +00:00
key={key}
2019-05-22 14:59:57 +00:00
handleChange={() => this.props.toggleSetting(key, enabled)}
/>
);
2018-08-30 14:25:33 +00:00
});
}
2019-09-04 14:39:35 +00:00
return '';
2019-05-22 14:59:57 +00:00
};
2018-08-30 14:25:33 +00:00
render() {
2019-07-18 11:52:47 +00:00
const {
settings,
services,
setBlockedServices,
setStatsConfig,
2019-08-30 15:35:27 +00:00
resetStats,
stats,
2019-09-04 14:39:35 +00:00
queryLogs,
setLogsConfig,
clearLogs,
2019-09-12 13:19:35 +00:00
filtering,
setFiltersConfig,
t,
2019-07-18 11:52:47 +00:00
} = this.props;
2019-09-04 14:39:35 +00:00
const isDataReady =
!settings.processing &&
!services.processing &&
!stats.processingGetConfig &&
!queryLogs.processingGetConfig;
2018-08-30 14:25:33 +00:00
return (
<Fragment>
<PageTitle title={t('general_settings')} />
2019-09-04 14:39:35 +00:00
{!isDataReady && <Loading />}
{isDataReady && (
2018-08-30 14:25:33 +00:00
<div className="content">
<div className="row">
<div className="col-md-12">
<Card bodyType="card-body box-body--settings">
2018-08-30 14:25:33 +00:00
<div className="form">
2019-09-12 13:19:35 +00:00
<FiltersConfig
interval={filtering.interval}
enabled={filtering.enabled}
processing={filtering.processingSetConfig}
setFiltersConfig={setFiltersConfig}
/>
2018-08-30 14:25:33 +00:00
{this.renderSettings(settings.settingsList)}
</div>
</Card>
</div>
2019-09-04 14:39:35 +00:00
<div className="col-md-12">
<LogsConfig
enabled={queryLogs.enabled}
interval={queryLogs.interval}
processing={queryLogs.processingSetConfig}
processingClear={queryLogs.processingClear}
setLogsConfig={setLogsConfig}
clearLogs={clearLogs}
/>
</div>
<div className="col-md-12">
<StatsConfig
interval={stats.interval}
processing={stats.processingSetConfig}
processingReset={stats.processingReset}
setStatsConfig={setStatsConfig}
resetStats={resetStats}
/>
</div>
2019-07-18 11:52:47 +00:00
<div className="col-md-12">
<Services
services={services}
setBlockedServices={setBlockedServices}
/>
</div>
2018-08-30 14:25:33 +00:00
</div>
</div>
2019-05-22 14:59:57 +00:00
)}
2018-08-30 14:25:33 +00:00
</Fragment>
);
}
}
Settings.propTypes = {
2019-08-30 15:35:27 +00:00
initSettings: PropTypes.func.isRequired,
settings: PropTypes.object.isRequired,
toggleSetting: PropTypes.func.isRequired,
getStatsConfig: PropTypes.func.isRequired,
setStatsConfig: PropTypes.func.isRequired,
resetStats: PropTypes.func.isRequired,
2019-09-12 13:19:35 +00:00
setFiltersConfig: PropTypes.func.isRequired,
getFilteringStatus: PropTypes.func.isRequired,
2019-08-30 15:35:27 +00:00
t: PropTypes.func.isRequired,
2018-08-30 14:25:33 +00:00
};
2018-10-25 10:33:44 +00:00
export default withNamespaces()(Settings);