1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ElectronClient/gui/StatusScreen.jsx

160 lines
3.9 KiB
React
Raw Normal View History

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('lib/theme');
2017-12-05 20:56:39 +02:00
const { _ } = require('lib/locale.js');
const { ReportService } = require('lib/services/report.js');
const fs = require('fs-extra');
2017-12-05 20:56:39 +02:00
class StatusScreenComponent extends React.Component {
constructor() {
super();
this.state = {
report: [],
};
}
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'));
this.setState({ report: report });
2017-12-05 20:56:39 +02:00
}
async exportDebugReportClick() {
2019-09-19 23:51:18 +02:00
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 = Object.assign({}, theme.headerStyle, { width: style.width });
const retryStyle = Object.assign({}, theme.urlStyle, { marginLeft: 5 });
Desktop: Resolves #2688: Add "Retry All" option to synchronisation page 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 commit 0a1ba511ea4cb04a20a1334dbc45a9ad6ad15300 Merge: 6207b42044 bdd760f343 Author: fhfuih <fhfuih@outlook.com> Date: Sat Mar 14 20:30:27 2020 -0400 Merge branch 'master' into master commit 6207b42044127b49fdd879217fc080fa11fb686b Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:13:28 2020 -0400 Decryption Retry All RN frontend commit 6f46d1985f580ce4b1428c0a2ce16800b696ce1d Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:10:55 2020 -0400 Decryption Retry All backend & desktop commit 4c3d37b311991dcbb76e984c299d5c5517bd2437 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 commit 15daaa16fdb961003af78d54a083a3a35c79d7b3. commit cffc919791f86dd980bf326c913c4931c3261eca 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 commit 51ba6ea65521c8bfa953d90f8078684d8293122b. commit 51ba6ea65521c8bfa953d90f8078684d8293122b Author: fhfuih <sam.zyhuang@outlook.com> Date: Tue Mar 10 18:27:22 2020 -0400 Refactor "retry all" renderer to avoid hacks commit 57d71712e1718d9bdb18bc2b5fdaea94211a01e8 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 commit 15daaa16fdb961003af78d54a083a3a35c79d7b3 Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:36:09 2020 -0400 Add "retry all" option to synchronisation page
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;
const containerStyle = Object.assign({}, theme.containerStyle, {
2017-12-05 20:56:39 +02:00
padding: containerPadding,
height: style.height - theme.headerHeight - containerPadding * 2,
});
2017-12-05 20:56:39 +02:00
function renderSectionTitleHtml(key, title) {
return (
2019-09-19 23:51:18 +02:00
<h2 key={`section_${key}`} style={theme.h2Style}>
{title}
</h2>
);
2017-12-05 20:56:39 +02:00
}
Desktop: Resolves #2688: Add "Retry All" option to synchronisation page 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 commit 0a1ba511ea4cb04a20a1334dbc45a9ad6ad15300 Merge: 6207b42044 bdd760f343 Author: fhfuih <fhfuih@outlook.com> Date: Sat Mar 14 20:30:27 2020 -0400 Merge branch 'master' into master commit 6207b42044127b49fdd879217fc080fa11fb686b Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:13:28 2020 -0400 Decryption Retry All RN frontend commit 6f46d1985f580ce4b1428c0a2ce16800b696ce1d Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:10:55 2020 -0400 Decryption Retry All backend & desktop commit 4c3d37b311991dcbb76e984c299d5c5517bd2437 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 commit 15daaa16fdb961003af78d54a083a3a35c79d7b3. commit cffc919791f86dd980bf326c913c4931c3261eca 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 commit 51ba6ea65521c8bfa953d90f8078684d8293122b. commit 51ba6ea65521c8bfa953d90f8078684d8293122b Author: fhfuih <sam.zyhuang@outlook.com> Date: Tue Mar 10 18:27:22 2020 -0400 Refactor "retry all" renderer to avoid hacks commit 57d71712e1718d9bdb18bc2b5fdaea94211a01e8 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 commit 15daaa16fdb961003af78d54a083a3a35c79d7b3 Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:36:09 2020 -0400 Add "retry all" option to synchronisation page
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>
);
}
const renderSectionHtml = (key, section) => {
const itemsHtml = [];
2017-12-05 20:56:39 +02:00
itemsHtml.push(renderSectionTitleHtml(section.title, section.title));
for (const n in section.body) {
2017-12-05 20:56:39 +02:00
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;
}
2017-01-29 20:29:34 +02:00
if (!text) text = '\xa0';
itemsHtml.push(
2019-09-19 23:51:18 +02:00
<div style={theme.textStyle} key={`item_${n}`}>
<span>{text}</span>
{retryLink}
</div>
);
2017-12-05 20:56:39 +02:00
}
Desktop: Resolves #2688: Add "Retry All" option to synchronisation page 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 commit 0a1ba511ea4cb04a20a1334dbc45a9ad6ad15300 Merge: 6207b42044 bdd760f343 Author: fhfuih <fhfuih@outlook.com> Date: Sat Mar 14 20:30:27 2020 -0400 Merge branch 'master' into master commit 6207b42044127b49fdd879217fc080fa11fb686b Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:13:28 2020 -0400 Decryption Retry All RN frontend commit 6f46d1985f580ce4b1428c0a2ce16800b696ce1d Author: fhfuih <sam.zyhuang@outlook.com> Date: Sat Mar 14 20:10:55 2020 -0400 Decryption Retry All backend & desktop commit 4c3d37b311991dcbb76e984c299d5c5517bd2437 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 commit 15daaa16fdb961003af78d54a083a3a35c79d7b3. commit cffc919791f86dd980bf326c913c4931c3261eca 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 commit 51ba6ea65521c8bfa953d90f8078684d8293122b. commit 51ba6ea65521c8bfa953d90f8078684d8293122b Author: fhfuih <sam.zyhuang@outlook.com> Date: Tue Mar 10 18:27:22 2020 -0400 Refactor "retry all" renderer to avoid hacks commit 57d71712e1718d9bdb18bc2b5fdaea94211a01e8 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 commit 15daaa16fdb961003af78d54a083a3a35c79d7b3 Author: fhfuih <sam.zyhuang@outlook.com> Date: Mon Mar 9 20:36:09 2020 -0400 Add "retry all" option to synchronisation page
2020-04-04 19:30:13 +02:00
if (section.canRetryAll) {
itemsHtml.push(renderSectionRetryAllHtml(section.title, section.retryAllHandler));
}
return <div key={key}>{itemsHtml}</div>;
};
2017-12-05 20:56:39 +02:00
function renderBodyHtml(report) {
const sectionsHtml = [];
2017-12-05 20:56:39 +02:00
for (let i = 0; i < report.length; i++) {
const section = report[i];
2017-12-05 20:56:39 +02:00
if (!section.body.length) continue;
sectionsHtml.push(renderSectionHtml(i, section));
}
return <div>{sectionsHtml}</div>;
2017-12-05 20:56:39 +02:00
}
const body = renderBodyHtml(this.state.report);
2017-12-05 20:56:39 +02:00
return (
<div style={style}>
<Header style={headerStyle} />
<div style={containerStyle}>
<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 => {
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);
module.exports = { StatusScreen };