2019-07-29 15:43:53 +02:00
|
|
|
const React = require('react');
|
2019-07-29 15:58:33 +02:00
|
|
|
|
2020-06-10 23:08:59 +02:00
|
|
|
const { View, Text, Button, FlatList } = require('react-native');
|
2020-11-07 17:59:37 +02:00
|
|
|
const Setting = require('@joplin/lib/models/Setting').default;
|
2018-03-09 22:59:12 +02:00
|
|
|
const { connect } = require('react-redux');
|
2020-11-05 18:58:23 +02:00
|
|
|
const { ScreenHeader } = require('../screen-header.js');
|
2021-01-22 19:41:11 +02:00
|
|
|
const ReportService = require('@joplin/lib/services/ReportService').default;
|
2020-11-07 17:59:37 +02:00
|
|
|
const { _ } = require('@joplin/lib/locale');
|
2020-11-05 18:58:23 +02:00
|
|
|
const { BaseScreenComponent } = require('../base-screen.js');
|
|
|
|
const { themeStyle } = require('../global-style.js');
|
2017-07-10 21:16:59 +02:00
|
|
|
|
2017-07-14 20:49:14 +02:00
|
|
|
class StatusScreenComponent extends BaseScreenComponent {
|
2019-09-13 00:16:42 +02:00
|
|
|
static navigationOptions() {
|
2017-07-10 21:16:59 +02:00
|
|
|
return { header: null };
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
2017-07-13 20:09:47 +02:00
|
|
|
report: [],
|
2017-07-10 21:16:59 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-30 18:38:19 +02:00
|
|
|
UNSAFE_componentWillMount() {
|
2017-07-10 21:16:59 +02:00
|
|
|
this.resfreshScreen();
|
|
|
|
}
|
|
|
|
|
2017-07-13 00:32:08 +02:00
|
|
|
async resfreshScreen() {
|
2020-03-14 01:46:14 +02:00
|
|
|
const service = new ReportService();
|
|
|
|
const report = await service.status(Setting.value('sync.target'));
|
2017-07-13 20:09:47 +02:00
|
|
|
this.setState({ report: report });
|
2017-07-13 00:32:08 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 23:08:59 +02:00
|
|
|
styles() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2020-06-10 23:08:59 +02:00
|
|
|
return {
|
|
|
|
body: {
|
|
|
|
flex: 1,
|
|
|
|
margin: theme.margin,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-07-13 00:32:08 +02:00
|
|
|
render() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2017-08-01 19:59:01 +02:00
|
|
|
|
2020-05-21 10:14:33 +02:00
|
|
|
const renderBody = report => {
|
2020-03-14 01:46:14 +02:00
|
|
|
const baseStyle = {
|
2017-07-13 20:09:47 +02:00
|
|
|
paddingLeft: 6,
|
|
|
|
paddingRight: 6,
|
2017-08-01 20:59:10 +02:00
|
|
|
paddingTop: 2,
|
|
|
|
paddingBottom: 2,
|
2017-07-13 20:09:47 +02:00
|
|
|
flex: 0,
|
2017-08-01 19:59:01 +02:00
|
|
|
color: theme.color,
|
|
|
|
fontSize: theme.fontSize,
|
2017-07-13 20:09:47 +02:00
|
|
|
};
|
2017-08-01 20:59:10 +02:00
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const lines = [];
|
2017-08-01 20:59:10 +02:00
|
|
|
|
2017-07-13 20:09:47 +02:00
|
|
|
for (let i = 0; i < report.length; i++) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const section = report[i];
|
2017-07-13 20:09:47 +02:00
|
|
|
|
|
|
|
let style = Object.assign({}, baseStyle);
|
2018-03-09 22:59:12 +02:00
|
|
|
style.fontWeight = 'bold';
|
2017-07-13 20:09:47 +02:00
|
|
|
if (i > 0) style.paddingTop = 20;
|
2019-09-19 23:51:18 +02:00
|
|
|
lines.push({ key: `section_${i}`, isSection: true, text: section.title });
|
2020-04-04 19:30:13 +02:00
|
|
|
if (section.canRetryAll) {
|
|
|
|
lines.push({ key: `retry_all_${i}`, text: '', retryAllHandler: section.retryAllHandler });
|
|
|
|
}
|
2017-07-13 20:09:47 +02:00
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
for (const n in section.body) {
|
2017-07-13 20:09:47 +02:00
|
|
|
if (!section.body.hasOwnProperty(n)) continue;
|
|
|
|
style = Object.assign({}, baseStyle);
|
2019-06-08 00:11:08 +02:00
|
|
|
const item = section.body[n];
|
|
|
|
|
|
|
|
let text = '';
|
|
|
|
|
|
|
|
let retryHandler = null;
|
|
|
|
if (typeof item === 'object') {
|
|
|
|
if (item.canRetry) {
|
|
|
|
retryHandler = async () => {
|
|
|
|
await item.retryHandler();
|
|
|
|
this.resfreshScreen();
|
2019-07-29 15:43:53 +02:00
|
|
|
};
|
2019-06-08 00:11:08 +02:00
|
|
|
}
|
|
|
|
text = item.text;
|
|
|
|
} else {
|
|
|
|
text = item;
|
|
|
|
}
|
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
lines.push({ key: `item_${i}_${n}`, text: text, retryHandler: retryHandler });
|
2017-07-13 20:09:47 +02:00
|
|
|
}
|
2017-08-01 20:59:10 +02:00
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
lines.push({ key: `divider2_${i}`, isDivider: true });
|
2017-07-13 20:09:47 +02:00
|
|
|
}
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
return (
|
|
|
|
<FlatList
|
|
|
|
data={lines}
|
|
|
|
renderItem={({ item }) => {
|
2020-03-14 01:46:14 +02:00
|
|
|
const style = Object.assign({}, baseStyle);
|
2019-06-08 00:11:08 +02:00
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
if (item.isSection === true) {
|
|
|
|
style.fontWeight = 'bold';
|
|
|
|
style.marginBottom = 5;
|
|
|
|
}
|
2019-06-08 00:11:08 +02:00
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
style.flex = 1;
|
2019-06-08 00:11:08 +02:00
|
|
|
|
2020-04-04 19:30:13 +02:00
|
|
|
const retryAllButton = item.retryAllHandler ? (
|
|
|
|
<View style={{ flex: 0 }}>
|
|
|
|
<Button title={_('Retry All')} onPress={item.retryAllHandler} />
|
|
|
|
</View>
|
|
|
|
) : null;
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
const retryButton = item.retryHandler ? (
|
|
|
|
<View style={{ flex: 0 }}>
|
|
|
|
<Button title={_('Retry')} onPress={item.retryHandler} />
|
2019-06-08 00:11:08 +02:00
|
|
|
</View>
|
2019-07-29 15:43:53 +02:00
|
|
|
) : null;
|
|
|
|
|
|
|
|
if (item.isDivider) {
|
|
|
|
return <View style={{ borderBottomWidth: 1, borderBottomColor: theme.dividerColor, marginTop: 20, marginBottom: 20 }} />;
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<View style={{ flex: 1, flexDirection: 'row' }}>
|
|
|
|
<Text style={style}>{item.text}</Text>
|
2020-04-04 19:30:13 +02:00
|
|
|
{retryAllButton}
|
2019-07-29 15:43:53 +02:00
|
|
|
{retryButton}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2017-07-13 20:09:47 +02:00
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const body = renderBody(this.state.report);
|
2017-07-10 21:16:59 +02:00
|
|
|
|
|
|
|
return (
|
2020-09-15 15:01:07 +02:00
|
|
|
<View style={this.rootStyle(this.props.themeId).root}>
|
2019-07-29 15:43:53 +02:00
|
|
|
<ScreenHeader title={_('Status')} />
|
2020-06-10 23:08:59 +02:00
|
|
|
<View style={this.styles().body}>{body}</View>
|
2019-07-29 15:43:53 +02:00
|
|
|
<Button title={_('Refresh')} onPress={() => this.resfreshScreen()} />
|
2017-07-10 21:16:59 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-21 10:14:33 +02:00
|
|
|
const StatusScreen = connect(state => {
|
2019-07-29 15:43:53 +02:00
|
|
|
return {
|
2020-09-15 15:01:07 +02:00
|
|
|
themeId: state.settings.theme,
|
2019-07-29 15:43:53 +02:00
|
|
|
};
|
|
|
|
})(StatusScreenComponent);
|
2017-07-10 21:16:59 +02:00
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = { StatusScreen };
|