2017-07-07 19:19:24 +02:00
|
|
|
import React, { Component } from 'react';
|
2017-08-01 19:59:01 +02:00
|
|
|
import { ListView, View, Text, Button, StyleSheet } from 'react-native';
|
2017-07-07 19:19:24 +02:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { Log } from 'lib/log.js'
|
|
|
|
import { reg } from 'lib/registry.js'
|
|
|
|
import { ScreenHeader } from 'lib/components/screen-header.js';
|
|
|
|
import { time } from 'lib/time-utils'
|
2017-08-01 19:59:01 +02:00
|
|
|
import { themeStyle } from 'lib/components/global-style.js';
|
2017-07-10 01:20:38 +02:00
|
|
|
import { Logger } from 'lib/logger.js';
|
2017-07-14 20:49:14 +02:00
|
|
|
import { BaseScreenComponent } from 'lib/components/base-screen.js';
|
2017-07-24 23:58:14 +02:00
|
|
|
import { _ } from 'lib/locale.js';
|
2017-07-07 19:19:24 +02:00
|
|
|
|
2017-07-14 20:49:14 +02:00
|
|
|
class LogScreenComponent extends BaseScreenComponent {
|
2017-07-07 19:19:24 +02:00
|
|
|
|
|
|
|
static navigationOptions(options) {
|
|
|
|
return { header: null };
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
const ds = new ListView.DataSource({
|
|
|
|
rowHasChanged: (r1, r2) => { return r1 !== r2; }
|
|
|
|
});
|
|
|
|
this.state = {
|
|
|
|
dataSource: ds,
|
|
|
|
};
|
2017-08-01 19:59:01 +02:00
|
|
|
this.styles_ = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
styles() {
|
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
|
|
|
|
if (this.styles_[this.props.theme]) return this.styles_[this.props.theme];
|
|
|
|
this.styles_ = {};
|
|
|
|
|
|
|
|
let styles = {
|
|
|
|
row: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
paddingLeft: 1,
|
|
|
|
paddingRight: 1,
|
|
|
|
paddingTop:0,
|
|
|
|
paddingBottom:0,
|
|
|
|
},
|
|
|
|
rowText: {
|
|
|
|
fontFamily: 'monospace',
|
|
|
|
fontSize: 10,
|
|
|
|
color: theme.color,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
styles.rowTextError = Object.assign({}, styles.rowText);
|
|
|
|
styles.rowTextError.color = theme.colorError;
|
|
|
|
|
|
|
|
styles.rowTextWarn = Object.assign({}, styles.rowWarn);
|
|
|
|
styles.rowTextWarn.color = theme.colorWarn;
|
|
|
|
|
|
|
|
this.styles_[this.props.theme] = StyleSheet.create(styles);
|
|
|
|
return this.styles_[this.props.theme];
|
2017-07-07 19:19:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
2017-07-08 01:25:10 +02:00
|
|
|
this.resfreshLogEntries();
|
|
|
|
}
|
|
|
|
|
|
|
|
resfreshLogEntries() {
|
2017-07-07 19:19:24 +02:00
|
|
|
reg.logger().lastEntries(1000).then((entries) => {
|
|
|
|
const newDataSource = this.state.dataSource.cloneWithRows(entries);
|
|
|
|
this.setState({ dataSource: newDataSource });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let renderRow = (item) => {
|
2017-08-01 19:59:01 +02:00
|
|
|
let textStyle = this.styles().rowText;
|
|
|
|
if (item.level == Logger.LEVEL_WARN) textStyle = this.styles().rowTextWarn;
|
|
|
|
if (item.level == Logger.LEVEL_ERROR) textStyle = this.styles().rowTextError;
|
|
|
|
|
2017-07-07 19:19:24 +02:00
|
|
|
return (
|
2017-08-01 19:59:01 +02:00
|
|
|
<View style={this.styles().row}>
|
|
|
|
<Text style={textStyle}>{time.formatMsToLocal(item.timestamp, 'MM-DDTHH:mm:ss') + ': ' + item.message}</Text>
|
2017-07-07 19:19:24 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// `enableEmptySections` is to fix this warning: https://github.com/FaridSafi/react-native-gifted-listview/issues/39
|
|
|
|
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={_('Log')}/>
|
2017-07-07 19:19:24 +02:00
|
|
|
<ListView
|
|
|
|
dataSource={this.state.dataSource}
|
|
|
|
renderRow={renderRow}
|
|
|
|
enableEmptySections={true}
|
|
|
|
/>
|
2017-07-27 19:34:43 +02:00
|
|
|
<Button title={_("Refresh")} onPress={() => { this.resfreshLogEntries(); }}/>
|
2017-07-07 19:19:24 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const LogScreen = connect(
|
|
|
|
(state) => {
|
2017-08-01 19:59:01 +02:00
|
|
|
return {
|
|
|
|
theme: state.settings.theme,
|
|
|
|
};
|
2017-07-07 19:19:24 +02:00
|
|
|
}
|
|
|
|
)(LogScreenComponent)
|
|
|
|
|
|
|
|
export { LogScreen };
|