Fix some error cases when the number of teams is zero

* There is no config.json
* config.teams.length === 0
This commit is contained in:
Yuya Ochiai
2016-01-14 23:27:37 +09:00
parent 267d0e3ded
commit 54f7eb3657
3 changed files with 18 additions and 2 deletions

View File

@@ -210,6 +210,9 @@ try {
} catch (e) {
window.location = 'settings.html';
}
if (config.teams.length === 0) {
window.location = 'settings.html';
}
var contextMenu = require('./menus/context');
var menu = contextMenu.createDefault();

View File

@@ -14,7 +14,12 @@ const Glyphicon = ReactBootstrap.Glyphicon;
var SettingsPage = React.createClass({
getInitialState: function() {
var config = settings.readFileSync(this.props.configFile);
var config;
try {
config = settings.readFileSync(this.props.configFile);
} catch (e) {
config = settings.loadDefault();
}
return {
teams: config.teams,
hideMenuBar: config.hideMenuBar
@@ -76,7 +81,7 @@ var SettingsPage = React.createClass({
<Col md={ 12 }>
<Button id="btnCancel" onClick={ this.handleCancel }>Cancel</Button>
{ ' ' }
<Button id="btnSave" bsStyle="primary" onClick={ this.handleSave }>Save</Button>
<Button id="btnSave" bsStyle="primary" onClick={ this.handleSave } disabled={ this.state.teams.length === 0 }>Save</Button>
</Col>
</Row>
</Grid>

View File

@@ -38,5 +38,13 @@ module.exports = {
}
var data = JSON.stringify(config, null, ' ');
fs.writeFileSync(configFile, data, 'utf8');
},
loadDefault: function() {
return {
teams: [],
hideMenuBar: false,
version: version
};
}
};