2017-12-05 20:56:39 +02:00
|
|
|
const React = require('react');
|
|
|
|
const { connect } = require('react-redux');
|
|
|
|
const { reg } = require('lib/registry.js');
|
2017-12-14 20:12:14 +02:00
|
|
|
const Setting = require('lib/models/Setting.js');
|
2017-12-05 20:56:39 +02:00
|
|
|
const { bridge } = require('electron').remote.require('./bridge');
|
|
|
|
const { Header } = require('./Header.min.js');
|
|
|
|
const { themeStyle } = require('../theme.js');
|
|
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
const { ReportService } = require('lib/services/report.js');
|
2017-12-07 23:18:18 +02:00
|
|
|
const fs = require('fs-extra');
|
2017-12-05 20:56:39 +02:00
|
|
|
|
|
|
|
class StatusScreenComponent extends React.Component {
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
|
|
|
report: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.resfreshScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
async resfreshScreen() {
|
|
|
|
const service = new ReportService();
|
|
|
|
const report = await service.status(Setting.value('sync.target'));
|
2017-12-05 21:21:01 +02:00
|
|
|
this.setState({ report: report });
|
2017-12-05 20:56:39 +02:00
|
|
|
}
|
|
|
|
|
2017-12-07 23:18:18 +02:00
|
|
|
async exportDebugReportClick() {
|
|
|
|
const filename = 'syncReport-' + (new Date()).getTime() + '.csv';
|
|
|
|
|
|
|
|
const filePath = bridge().showSaveDialog({
|
|
|
|
title: _('Please select where the sync status should be exported to'),
|
|
|
|
defaultPath: filename,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!filePath) return;
|
|
|
|
|
|
|
|
const service = new ReportService();
|
|
|
|
const csv = await service.basicItemList({ format: 'csv' });
|
|
|
|
await fs.writeFileSync(filePath, csv);
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:56:39 +02:00
|
|
|
render() {
|
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
const style = this.props.style;
|
|
|
|
|
|
|
|
const headerStyle = {
|
|
|
|
width: style.width,
|
|
|
|
};
|
|
|
|
|
|
|
|
const containerPadding = 10;
|
|
|
|
|
|
|
|
const containerStyle = {
|
|
|
|
padding: containerPadding,
|
|
|
|
overflowY: 'auto',
|
|
|
|
height: style.height - theme.headerHeight - containerPadding * 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
function renderSectionTitleHtml(key, title) {
|
|
|
|
return <h2 key={'section_' + key} style={theme.h2Style}>{title}</h2>
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderSectionHtml(key, section) {
|
|
|
|
let itemsHtml = [];
|
|
|
|
|
|
|
|
itemsHtml.push(renderSectionTitleHtml(section.title, section.title));
|
|
|
|
|
|
|
|
for (let n in section.body) {
|
|
|
|
if (!section.body.hasOwnProperty(n)) continue;
|
|
|
|
itemsHtml.push(<div style={theme.textStyle} key={'item_' + n}>{section.body[n]}</div>);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div key={key}>
|
|
|
|
{itemsHtml}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-12-05 21:21:01 +02:00
|
|
|
function renderBodyHtml(report) {
|
2017-12-05 20:56:39 +02:00
|
|
|
let output = [];
|
|
|
|
let baseStyle = {
|
|
|
|
paddingLeft: 6,
|
|
|
|
paddingRight: 6,
|
|
|
|
paddingTop: 2,
|
|
|
|
paddingBottom: 2,
|
|
|
|
flex: 0,
|
|
|
|
color: theme.color,
|
|
|
|
fontSize: theme.fontSize,
|
|
|
|
};
|
|
|
|
|
|
|
|
let sectionsHtml = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < report.length; i++) {
|
|
|
|
let section = report[i];
|
|
|
|
if (!section.body.length) continue;
|
|
|
|
sectionsHtml.push(renderSectionHtml(i, section));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{sectionsHtml}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-12-05 21:21:01 +02:00
|
|
|
let body = renderBodyHtml(this.state.report);
|
2017-12-05 20:56:39 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={style}>
|
|
|
|
<Header style={headerStyle} />
|
|
|
|
<div style={containerStyle}>
|
2017-12-07 23:18:18 +02:00
|
|
|
<a style={theme.textStyle} onClick={() => this.exportDebugReportClick()}href="#">Export debug report</a>
|
2017-12-05 20:56:39 +02:00
|
|
|
{body}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
return {
|
|
|
|
theme: state.settings.theme,
|
|
|
|
settings: state.settings,
|
|
|
|
locale: state.settings.locale,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const StatusScreen = connect(mapStateToProps)(StatusScreenComponent);
|
|
|
|
|
|
|
|
module.exports = { StatusScreen };
|