diff --git a/src/common/settings.js b/src/common/settings.js index afa5c80d..5fd345e8 100644 --- a/src/common/settings.js +++ b/src/common/settings.js @@ -5,7 +5,10 @@ const version = 1; var upgradeV0toV1 = function(config_v0) { return { - url: [config_v0.url], + teams: [{ + name: 'Primary team', + url: config_v0.url + }], version: 1 }; }; diff --git a/src/index.js b/src/index.js index a0593b83..c6660c82 100644 --- a/src/index.js +++ b/src/index.js @@ -19,8 +19,8 @@ try { config = settings.upgrade(config); settings.writeFileSync(configFile, config); } - if (config.url[0]) { - webView.setAttribute('src', config.url[0]); + if (config.teams[0]) { + webView.setAttribute('src', config.teams[0].url); } else { throw 'URL is not configured'; diff --git a/src/settings.html b/src/settings.html index 1d222b8f..fa84cb4d 100644 --- a/src/settings.html +++ b/src/settings.html @@ -4,35 +4,13 @@ Settings + + -

Settings

-

URL: - -

- - - - +
+ \ No newline at end of file diff --git a/src/settings.jsx b/src/settings.jsx new file mode 100644 index 00000000..7c67a5b6 --- /dev/null +++ b/src/settings.jsx @@ -0,0 +1,120 @@ +'use strict'; + +const remote = require('electron').remote; +const settings = require('./common/settings'); + +var SettingsPage = React.createClass({ + getInitialState: function() { + return { + teams: [] + }; + }, + componentDidMount: function() { + var config = settings.readFileSync(this.props.configFile); + this.setState({teams: config.teams}) + }, + handleTeamsChange: function(teams) { + this.setState({teams: teams}); + }, + handleOK: function() { + var config = { + teams: this.state.teams, + version: 1 + }; + settings.writeFileSync(this.props.configFile, config); + window.location = './index.html'; + }, + handleCancel: function() { + window.location = './index.html'; + }, + render: function() { + return ( +
+ + + +
+ ); + } +}); + +var TeamList = React.createClass({ + handleTeamChange: function(index, team){ + var teams = this.props.teams; + teams[index] = team; + this.props.onTeamsChange(teams); + }, + handleNewTeamAdd: function(team){ + var teams = this.props.teams; + teams.push(team); + this.props.onTeamsChange(teams); + }, + render: function() { + var thisObj = this; + var teamNodes = this.props.teams.map(function(team, i){ + var handleTeamChange = function(team){ + thisObj.handleTeamChange(i, team); + }; + return ( +
  • + ); + }); + return ( +
    +
      + {teamNodes} +
    1. +
    +
    + ); + } +}); + +var TeamItem = React.createClass({ + handleNameChange: function(e){ + this.props.onTeamChange({name: e.target.value, url: this.props.url}); + }, + handleURLChange: function(e){ + this.props.onTeamChange({name: this.props.name, url: e.target.value}); + }, + render: function() { + return ( +
    + + +
    + ); + } +}); + +var NewTeamItem = React.createClass({ + getInitialState: function(){ + return {name: '', url: ''}; + }, + handleNewTeamAdd: function(){ + this.props.onNewTeamAdd({name: this.state.name, url: this.state.url}); + this.setState(this.getInitialState()); + }, + handleNameChange: function(e){ + this.setState({name: e.target.value}); + }, + handleURLChange: function(e){ + this.setState({url: e.target.value}); + }, + render: function() { + return ( +
    + + + +
    + ); + } +}); + +var configFile = remote.getGlobal('config-file'); + +ReactDOM.render( + , + document.getElementById('content') +); diff --git a/test/settings_test.js b/test/settings_test.js index b5a72126..c48a804a 100644 --- a/test/settings_test.js +++ b/test/settings_test.js @@ -11,8 +11,8 @@ describe('settings.js', function() { url: 'http://example.com/team' }; config = settings.upgrade(v0_config); - config.url.length.should.equal(1); - config.url[0].should.equal(v0_config.url); + config.teams.length.should.equal(1); + config.teams[0].url.should.equal(v0_config.url); config.version.should.equal(settings.version); }); });