2017-11-03 02:09:34 +02:00
|
|
|
const React = require('react'); const Component = React.Component;
|
|
|
|
const { ListView, StyleSheet, View, Text, Button, FlatList } = require('react-native');
|
|
|
|
const { Setting } = require('lib/models/setting.js');
|
|
|
|
const { connect } = require('react-redux');
|
|
|
|
const { Log } = require('lib/log.js');
|
|
|
|
const { reg } = require('lib/registry.js');
|
|
|
|
const { ScreenHeader } = require('lib/components/screen-header.js');
|
|
|
|
const { time } = require('lib/time-utils');
|
|
|
|
const { Logger } = require('lib/logger.js');
|
|
|
|
const { BaseItem } = require('lib/models/base-item.js');
|
|
|
|
const { Database } = require('lib/database.js');
|
|
|
|
const { Folder } = require('lib/models/folder.js');
|
|
|
|
const { ReportService } = require('lib/services/report.js');
|
|
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
const { BaseScreenComponent } = require('lib/components/base-screen.js');
|
|
|
|
const { globalStyle, themeStyle } = require('lib/components/global-style.js');
|
2017-07-22 00:42:24 +02:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
body: {
|
|
|
|
flex: 1,
|
|
|
|
margin: globalStyle.margin,
|
|
|
|
},
|
|
|
|
});
|
2017-07-10 21:16:59 +02:00
|
|
|
|
2017-07-14 20:49:14 +02:00
|
|
|
class StatusScreenComponent extends BaseScreenComponent {
|
2017-07-10 21:16:59 +02:00
|
|
|
|
|
|
|
static navigationOptions(options) {
|
|
|
|
return { header: null };
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
2017-07-13 20:09:47 +02:00
|
|
|
report: [],
|
2017-07-10 21:16:59 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.resfreshScreen();
|
|
|
|
}
|
|
|
|
|
2017-07-13 00:32:08 +02:00
|
|
|
async resfreshScreen() {
|
2017-07-13 20:09:47 +02:00
|
|
|
let service = new ReportService();
|
2017-07-24 20:58:11 +02:00
|
|
|
let 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
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-08-01 19:59:01 +02:00
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
|
2017-07-13 20:09:47 +02:00
|
|
|
function renderBody(report) {
|
|
|
|
let output = [];
|
|
|
|
let baseStyle = {
|
|
|
|
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
|
|
|
|
|
|
|
let lines = [];
|
|
|
|
|
2017-07-13 20:09:47 +02:00
|
|
|
for (let i = 0; i < report.length; i++) {
|
|
|
|
let section = report[i];
|
|
|
|
|
|
|
|
let style = Object.assign({}, baseStyle);
|
|
|
|
style.fontWeight = 'bold';
|
|
|
|
if (i > 0) style.paddingTop = 20;
|
2017-08-01 20:59:10 +02:00
|
|
|
lines.push({ key: 'section_' + i, isSection: true, text: section.title });
|
2017-07-13 20:09:47 +02:00
|
|
|
|
|
|
|
for (let n in section.body) {
|
|
|
|
if (!section.body.hasOwnProperty(n)) continue;
|
|
|
|
style = Object.assign({}, baseStyle);
|
2017-08-01 20:59:10 +02:00
|
|
|
lines.push({ key: 'item_' + i + '_' + n, text: section.body[n] });
|
2017-07-13 20:09:47 +02:00
|
|
|
}
|
2017-08-01 20:59:10 +02:00
|
|
|
|
|
|
|
lines.push({ key: 'divider2_' + i, isDivider: true });
|
2017-07-13 20:09:47 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 20:59:10 +02:00
|
|
|
return (<FlatList
|
|
|
|
data={lines}
|
|
|
|
renderItem={({item}) => {
|
|
|
|
let style = Object.assign({}, baseStyle);
|
|
|
|
if (item.isSection === true) {
|
|
|
|
style.fontWeight = 'bold';
|
|
|
|
style.marginBottom = 5;
|
|
|
|
}
|
|
|
|
if (item.isDivider) {
|
|
|
|
return (<View style={{borderBottomWidth: 1, borderBottomColor: 'white', marginTop: 20, marginBottom: 20}}/>);
|
|
|
|
} else {
|
|
|
|
return (<Text style={style}>{item.text}</Text>);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>);
|
2017-07-13 20:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let body = renderBody(this.state.report);
|
2017-07-10 21:16:59 +02:00
|
|
|
|
|
|
|
return (
|
2017-08-01 19:59:01 +02:00
|
|
|
<View style={this.rootStyle(this.props.theme).root}>
|
2017-07-24 23:58:14 +02:00
|
|
|
<ScreenHeader title={_('Status')}/>
|
2017-07-22 00:42:24 +02:00
|
|
|
<View style={styles.body}>
|
2017-07-13 20:09:47 +02:00
|
|
|
{ body }
|
|
|
|
</View>
|
2017-07-27 19:34:43 +02:00
|
|
|
<Button title={_("Refresh")} onPress={() => this.resfreshScreen()}/>
|
2017-07-10 21:16:59 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const StatusScreen = connect(
|
|
|
|
(state) => {
|
2017-08-01 19:59:01 +02:00
|
|
|
return {
|
|
|
|
theme: state.settings.theme,
|
|
|
|
};
|
2017-07-10 21:16:59 +02:00
|
|
|
}
|
|
|
|
)(StatusScreenComponent)
|
|
|
|
|
2017-11-03 02:13:17 +02:00
|
|
|
module.exports = { StatusScreen };
|