mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
f550d847c4
Based on pull request #2712 by fhfuih commit 7d3815e51dbf682ecc1ed3544a15e51b79d5d12d Author: Laurent Cozic <laurent@cozic.net> Date: Sat Apr 4 18:26:01 2020 +0100 Fix issues commit dad1d2c4d4eb37fdd23096a3344cf4f14498e335 Merge:16cf0a3058
0a1ba511ea
Author: Laurent Cozic <laurent@cozic.net> Date: Sat Apr 4 18:09:46 2020 +0100 Merge branch 'master' of https://github.com/fhfuih/joplin into fhfuih-master commit0a1ba511ea
Merge:6207b42044
bdd760f343
Author: fhfuih <fhfuih@outlook.com> Date: Sat Mar 14 20:30:27 2020 -0400 Merge branch 'master' into master commit6207b42044
Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:13:28 2020 -0400 Decryption Retry All RN frontend commit6f46d1985f
Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:10:55 2020 -0400 Decryption Retry All backend & desktop commit4c3d37b311
Author: fhfuih <sam.zyhuang@outlook.com> Date: Fri Mar 13 13:21:21 2020 -0400 Revert "Add "retry all" option to synchronisation page" This reverts commit15daaa16fd
. commitcffc919791
Author: fhfuih <sam.zyhuang@outlook.com> Date: Fri Mar 13 13:19:51 2020 -0400 Revert "Refactor "retry all" renderer to avoid hacks" This reverts commit51ba6ea655
. commit51ba6ea655
Author: fhfuih <sam.zyhuang@outlook.com> Date: Tue Mar 10 18:27:22 2020 -0400 Refactor "retry all" renderer to avoid hacks commit57d71712e1
Merge:15daaa16fd
b367955e56
Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:42:02 2020 -0400 Merge branch 'master' of https://github.com/fhfuih/joplin commit15daaa16fd
Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:36:09 2020 -0400 Add "retry all" option to synchronisation page
160 lines
3.9 KiB
JavaScript
160 lines
3.9 KiB
JavaScript
const React = require('react');
|
|
const { connect } = require('react-redux');
|
|
const Setting = require('lib/models/Setting.js');
|
|
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');
|
|
const fs = require('fs-extra');
|
|
|
|
class StatusScreenComponent extends React.Component {
|
|
constructor() {
|
|
super();
|
|
this.state = {
|
|
report: [],
|
|
};
|
|
}
|
|
|
|
UNSAFE_componentWillMount() {
|
|
this.resfreshScreen();
|
|
}
|
|
|
|
async resfreshScreen() {
|
|
const service = new ReportService();
|
|
const report = await service.status(Setting.value('sync.target'));
|
|
this.setState({ report: report });
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
render() {
|
|
const theme = themeStyle(this.props.theme);
|
|
const style = this.props.style;
|
|
|
|
const headerStyle = Object.assign({}, theme.headerStyle, { width: style.width });
|
|
const retryStyle = Object.assign({}, theme.urlStyle, { marginLeft: 5 });
|
|
const retryAllStyle = Object.assign({}, theme.urlStyle, { marginTop: 5, display: 'inline-block' });
|
|
|
|
const containerPadding = 10;
|
|
|
|
const containerStyle = Object.assign({}, theme.containerStyle, {
|
|
padding: containerPadding,
|
|
height: style.height - theme.headerHeight - containerPadding * 2,
|
|
});
|
|
|
|
function renderSectionTitleHtml(key, title) {
|
|
return (
|
|
<h2 key={`section_${key}`} style={theme.h2Style}>
|
|
{title}
|
|
</h2>
|
|
);
|
|
}
|
|
|
|
function renderSectionRetryAllHtml(key, retryAllHandler) {
|
|
return (
|
|
<a key={`retry_all_${key}`} href="#" onClick={retryAllHandler} style={retryAllStyle}>
|
|
{_('Retry All')}
|
|
</a>
|
|
);
|
|
}
|
|
|
|
const renderSectionHtml = (key, section) => {
|
|
const itemsHtml = [];
|
|
|
|
itemsHtml.push(renderSectionTitleHtml(section.title, section.title));
|
|
|
|
for (const n in section.body) {
|
|
if (!section.body.hasOwnProperty(n)) continue;
|
|
const item = section.body[n];
|
|
let text = '';
|
|
|
|
let retryLink = null;
|
|
if (typeof item === 'object') {
|
|
if (item.canRetry) {
|
|
const onClick = async () => {
|
|
await item.retryHandler();
|
|
this.resfreshScreen();
|
|
};
|
|
|
|
retryLink = (
|
|
<a href="#" onClick={onClick} style={retryStyle}>
|
|
{_('Retry')}
|
|
</a>
|
|
);
|
|
}
|
|
text = item.text;
|
|
} else {
|
|
text = item;
|
|
}
|
|
|
|
if (!text) text = '\xa0';
|
|
|
|
itemsHtml.push(
|
|
<div style={theme.textStyle} key={`item_${n}`}>
|
|
<span>{text}</span>
|
|
{retryLink}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (section.canRetryAll) {
|
|
itemsHtml.push(renderSectionRetryAllHtml(section.title, section.retryAllHandler));
|
|
}
|
|
|
|
return <div key={key}>{itemsHtml}</div>;
|
|
};
|
|
|
|
function renderBodyHtml(report) {
|
|
const sectionsHtml = [];
|
|
|
|
for (let i = 0; i < report.length; i++) {
|
|
const section = report[i];
|
|
if (!section.body.length) continue;
|
|
sectionsHtml.push(renderSectionHtml(i, section));
|
|
}
|
|
|
|
return <div>{sectionsHtml}</div>;
|
|
}
|
|
|
|
const body = renderBodyHtml(this.state.report);
|
|
|
|
return (
|
|
<div style={style}>
|
|
<Header style={headerStyle} />
|
|
<div style={containerStyle}>
|
|
<a style={theme.textStyle} onClick={() => this.exportDebugReportClick()} href="#">
|
|
Export debug report
|
|
</a>
|
|
{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 };
|