2017-12-05 20:56:39 +02:00
|
|
|
const React = require('react');
|
|
|
|
const { connect } = require('react-redux');
|
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: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-12-13 03:16:34 +02:00
|
|
|
UNSAFE_componentWillMount() {
|
2017-12-05 20:56:39 +02:00
|
|
|
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() {
|
2019-09-19 23:51:18 +02:00
|
|
|
const filename = `syncReport-${new Date().getTime()}.csv`;
|
2017-12-07 23:18:18 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2018-11-08 00:37:13 +02:00
|
|
|
const headerStyle = Object.assign({}, theme.headerStyle, { width: style.width });
|
2019-07-29 14:13:23 +02:00
|
|
|
const retryStyle = Object.assign({}, theme.urlStyle, { marginLeft: 5 });
|
2020-04-04 19:30:13 +02:00
|
|
|
const retryAllStyle = Object.assign({}, theme.urlStyle, { marginTop: 5, display: 'inline-block' });
|
2017-12-05 20:56:39 +02:00
|
|
|
|
|
|
|
const containerPadding = 10;
|
|
|
|
|
2018-11-08 00:37:13 +02:00
|
|
|
const containerStyle = Object.assign({}, theme.containerStyle, {
|
2017-12-05 20:56:39 +02:00
|
|
|
padding: containerPadding,
|
|
|
|
height: style.height - theme.headerHeight - containerPadding * 2,
|
2018-11-08 00:37:13 +02:00
|
|
|
});
|
2017-12-05 20:56:39 +02:00
|
|
|
|
|
|
|
function renderSectionTitleHtml(key, title) {
|
2019-07-29 14:13:23 +02:00
|
|
|
return (
|
2019-09-19 23:51:18 +02:00
|
|
|
<h2 key={`section_${key}`} style={theme.h2Style}>
|
2019-07-29 14:13:23 +02:00
|
|
|
{title}
|
|
|
|
</h2>
|
|
|
|
);
|
2017-12-05 20:56:39 +02:00
|
|
|
}
|
|
|
|
|
2020-04-04 19:30:13 +02:00
|
|
|
function renderSectionRetryAllHtml(key, retryAllHandler) {
|
|
|
|
return (
|
|
|
|
<a key={`retry_all_${key}`} href="#" onClick={retryAllHandler} style={retryAllStyle}>
|
|
|
|
{_('Retry All')}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-08 00:11:08 +02:00
|
|
|
const renderSectionHtml = (key, section) => {
|
2020-03-14 01:46:14 +02:00
|
|
|
const itemsHtml = [];
|
2017-12-05 20:56:39 +02:00
|
|
|
|
|
|
|
itemsHtml.push(renderSectionTitleHtml(section.title, section.title));
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
for (const n in section.body) {
|
2017-12-05 20:56:39 +02:00
|
|
|
if (!section.body.hasOwnProperty(n)) continue;
|
2020-03-14 01:46:14 +02:00
|
|
|
const item = section.body[n];
|
2019-06-08 00:11:08 +02:00
|
|
|
let text = '';
|
|
|
|
|
|
|
|
let retryLink = null;
|
|
|
|
if (typeof item === 'object') {
|
|
|
|
if (item.canRetry) {
|
|
|
|
const onClick = async () => {
|
|
|
|
await item.retryHandler();
|
|
|
|
this.resfreshScreen();
|
2019-07-29 14:13:23 +02:00
|
|
|
};
|
2019-06-08 00:11:08 +02:00
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
retryLink = (
|
|
|
|
<a href="#" onClick={onClick} style={retryStyle}>
|
|
|
|
{_('Retry')}
|
|
|
|
</a>
|
|
|
|
);
|
2019-06-08 00:11:08 +02:00
|
|
|
}
|
|
|
|
text = item.text;
|
|
|
|
} else {
|
|
|
|
text = item;
|
|
|
|
}
|
|
|
|
|
2017-01-29 20:29:34 +02:00
|
|
|
if (!text) text = '\xa0';
|
2019-06-08 00:11:08 +02:00
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
itemsHtml.push(
|
2019-09-19 23:51:18 +02:00
|
|
|
<div style={theme.textStyle} key={`item_${n}`}>
|
2019-07-29 14:13:23 +02:00
|
|
|
<span>{text}</span>
|
|
|
|
{retryLink}
|
|
|
|
</div>
|
|
|
|
);
|
2017-12-05 20:56:39 +02:00
|
|
|
}
|
|
|
|
|
2020-04-04 19:30:13 +02:00
|
|
|
if (section.canRetryAll) {
|
|
|
|
itemsHtml.push(renderSectionRetryAllHtml(section.title, section.retryAllHandler));
|
|
|
|
}
|
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
return <div key={key}>{itemsHtml}</div>;
|
|
|
|
};
|
2017-12-05 20:56:39 +02:00
|
|
|
|
2017-12-05 21:21:01 +02:00
|
|
|
function renderBodyHtml(report) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const sectionsHtml = [];
|
2017-12-05 20:56:39 +02:00
|
|
|
|
|
|
|
for (let i = 0; i < report.length; i++) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const section = report[i];
|
2017-12-05 20:56:39 +02:00
|
|
|
if (!section.body.length) continue;
|
|
|
|
sectionsHtml.push(renderSectionHtml(i, section));
|
|
|
|
}
|
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
return <div>{sectionsHtml}</div>;
|
2017-12-05 20:56:39 +02:00
|
|
|
}
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const body = renderBodyHtml(this.state.report);
|
2019-07-29 14:13:23 +02:00
|
|
|
|
2017-12-05 20:56:39 +02:00
|
|
|
return (
|
|
|
|
<div style={style}>
|
|
|
|
<Header style={headerStyle} />
|
|
|
|
<div style={containerStyle}>
|
2019-07-29 14:13:23 +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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-21 10:14:33 +02:00
|
|
|
const mapStateToProps = state => {
|
2017-12-05 20:56:39 +02:00
|
|
|
return {
|
|
|
|
theme: state.settings.theme,
|
|
|
|
settings: state.settings,
|
|
|
|
locale: state.settings.locale,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const StatusScreen = connect(mapStateToProps)(StatusScreenComponent);
|
|
|
|
|
2018-11-08 00:37:13 +02:00
|
|
|
module.exports = { StatusScreen };
|