Show story data next to backlog

This commit is contained in:
Tom Willemse 2013-07-13 19:57:22 +02:00
parent 4b910d426f
commit bdd07b68ca

View file

@ -90,35 +90,34 @@ var StoryTaskForm = React.createClass({
var StoryData = React.createClass({ var StoryData = React.createClass({
handleTaskSubmit: React.autoBind(function (task) { handleTaskSubmit: React.autoBind(function (task) {
task.storyId = this.props.data.id; task.storyId = this.state.data.id;
$.post("/stories/tasks/new", task); $.post("/stories/tasks/new", task);
}), }),
getInitialState: function() {
return {data: null};
},
setData: function(data) {
this.setState({data: data});
},
render: function() { render: function() {
var taskTable = null; if (this.state.data) {
if (this.props.data.tasks)
taskTable = <StoryTaskTable tasks={this.props.data.tasks} />;
if (this.props.data) {
return (<div> return (<div>
Assignee: {this.props.data.assignee} <h1>{this.state.data.title}</h1>
<pre>{this.props.data.content}</pre> Assignee: {this.state.data.assignee}
{taskTable} <div class="well">
<StoryTaskForm onTaskSubmit={this.handleTaskSubmit} /> {this.state.data.content}
</div>
<StoryTaskTable tasks={this.state.data.tasks || []} />
<StoryTaskForm onTaskSubmit={this.handleTaskSubmit} />
</div>); </div>);
} }
return null; return <div></div>;
} }
}); });
var StoryRow = React.createClass({ var StoryRow = React.createClass({
render: function() { render: function() {
var sdata = null;
if (this.state.content)
sdata = <StoryData data={this.state.content} />;
return ( return (
<tr> <tr>
<td class="span1"> <td class="span1">
@ -137,8 +136,6 @@ var StoryRow = React.createClass({
{this.props.story.necessity} to {this.props.story.necessity} to
{this.props.story.title} {this.props.story.title}
</a> </a>
<br />
{sdata}
</td> </td>
</tr> </tr>
); );
@ -148,15 +145,7 @@ var StoryRow = React.createClass({
content: null}; content: null};
}, },
handleClick: React.autoBind(function(event) { handleClick: React.autoBind(function(event) {
if (!!this.state.content) { this.props.onTitleClicked(this.props.story.id);
this.setState({content: null});
return;
}
$.get('/stories/' + this.props.story.id)
.done(function (data, textStatus, jqXHR) {
this.setState({content: data});
}.bind(this), 'json');
}), }),
changeState: React.autoBind(function(event) { changeState: React.autoBind(function(event) {
$.post("/stories/state", {'id': this.props.story.id}) $.post("/stories/state", {'id': this.props.story.id})
@ -185,9 +174,13 @@ var StoryTable = React.createClass({
handleMoved: React.autoBind(function(direction) { handleMoved: React.autoBind(function(direction) {
this.props.onStoryMoved(direction); this.props.onStoryMoved(direction);
}), }),
handleSelected: React.autoBind(function(storyId) {
this.props.onStorySelected(storyId);
}),
render: function() { render: function() {
var storyNodes = this.props.data.map(function (story) { var storyNodes = this.props.data.map(function (story) {
return <StoryRow story={story} onMoved={this.handleMoved} />; return <StoryRow story={story} onMoved={this.handleMoved}
onTitleClicked={this.handleSelected} />;
}.bind(this)); }.bind(this));
return ( return (
<table class="table table-striped"> <table class="table table-striped">
@ -274,11 +267,24 @@ var StoryPage = React.createClass({
alert("error: " + errorThrown); alert("error: " + errorThrown);
}.bind(this)); }.bind(this));
}), }),
handleStorySelected: React.autoBind(function (storyId) {
$.get('/stories/' + storyId)
.done(function (data, textStatus, jqXHR) {
this.refs.data.setData(data);
}.bind(this), 'json');
}),
render: function() { render: function() {
return ( return (
<div> <div class="row">
<StoryTable data={this.state.data} onStoryMoved={this.handleStoryMoved} /> <div class="span6">
<StoryForm onStorySubmit={this.handleStorySubmit} /> <StoryTable data={this.state.data}
onStoryMoved={this.handleStoryMoved}
onStorySelected={this.handleStorySelected} />
<StoryForm onStorySubmit={this.handleStorySubmit} />
</div>
<div class="span6">
<StoryData ref="data" />
</div>
</div> </div>
); );
} }