ensl_gathers/lib/react/gather.jsx

767 lines
18 KiB
React
Raw Normal View History

2015-07-28 15:54:29 +00:00
"use strict";
var SelectPlayerButton = React.createClass({
2015-08-11 00:19:04 +00:00
selectPlayer(e) {
2015-07-28 15:54:29 +00:00
e.preventDefault();
2015-07-28 23:32:50 +00:00
socket.emit("gather:select", {
player: parseInt(e.target.value, 10)
})
2015-07-28 15:54:29 +00:00
},
2015-08-11 00:19:04 +00:00
render() {
2015-07-28 23:32:50 +00:00
if (this.props.gatherer.leader) {
return (<button
className="btn btn-xs btn-default"
data-disabled="true">Leader</button>);
2015-08-08 17:13:17 +00:00
} else if (this.props.gatherer.team !== "lobby") {
return (<button
onClick={this.selectPlayer}
value={this.props.gatherer.id}
className="btn btn-xs btn-default"> Reselect
</button>
);
2015-07-28 15:54:29 +00:00
} else {
return (<button
onClick={this.selectPlayer}
2015-07-28 23:32:50 +00:00
value={this.props.gatherer.id}
2015-07-28 15:54:29 +00:00
className="btn btn-xs btn-primary"> Select
</button>
);
}
}
2015-07-28 23:32:50 +00:00
});
2015-07-28 15:54:29 +00:00
2015-08-08 19:14:16 +00:00
var GathererList = React.createClass({
2015-08-11 00:19:04 +00:00
memberList() {
2015-08-08 19:14:16 +00:00
var self = this;
2015-08-11 00:19:04 +00:00
return this.props.gather.gatherers
.filter(gatherer => gatherer.team === self.props.team )
.sort(gatherer => gatherer.leader ? 1 : -1);
2015-07-28 15:54:29 +00:00
},
2015-08-11 00:19:04 +00:00
render() {
var extractGatherer = gatherer => {
2015-07-28 15:54:29 +00:00
var image;
if (gatherer.leader) {
image = (<img src="/images/commander.png"
alt="Commander"
height="20"
width="20" />);
}
return (
<tr key={gatherer.id}>
<td className="col-md-1">{image}</td>
<td className="col-md-11">{gatherer.user.username}</td>
</tr>
);
}
2015-08-08 19:14:16 +00:00
var members = this.memberList().map(extractGatherer);
return (
<table className="table">
<tbody>
{members}
</tbody>
</table>
);
}
});
var GatherTeams = React.createClass({
2015-08-11 00:19:04 +00:00
render() {
2015-07-28 15:54:29 +00:00
return (
2015-09-05 17:22:23 +00:00
<div className="row add-top">
<div className="col-md-6">
<div className="panel panel-default">
<div className="panel-heading">
Aliens
2015-07-28 15:54:29 +00:00
</div>
2015-09-05 17:22:23 +00:00
<GathererList gather={this.props.gather} team="alien" />
2015-07-28 15:54:29 +00:00
</div>
2015-09-05 17:22:23 +00:00
</div>
<div className="col-md-6">
<div className="panel panel-default">
<div className="panel-heading">
Marines
2015-07-28 15:54:29 +00:00
</div>
2015-09-05 17:22:23 +00:00
<GathererList gather={this.props.gather} team="marine" />
2015-07-28 15:54:29 +00:00
</div>
</div>
</div>
);
}
2015-08-08 19:14:16 +00:00
});
2015-07-28 15:54:29 +00:00
2015-07-31 15:54:08 +00:00
var ElectionProgressBar = React.createClass({
2015-08-11 00:19:04 +00:00
componentDidMount() {
2015-07-31 15:54:08 +00:00
var self = this;
2015-08-11 00:19:04 +00:00
this.timer = setInterval(() => {
2015-07-31 15:54:08 +00:00
self.forceUpdate();
}, 900);
},
2015-08-11 00:19:04 +00:00
progress() {
2015-07-31 15:54:08 +00:00
var interval = this.props.gather.election.interval;
var startTime = (new Date(this.props.gather.election.startTime)).getTime();
var msTranspired = Math.floor((new Date()).getTime() - startTime);
return {
num: msTranspired,
den: interval,
barMessage: Math.floor((interval - msTranspired) / 1000) + "s remaining"
2015-07-31 15:54:08 +00:00
}
},
2015-08-11 00:19:04 +00:00
componentWillUnmount() {
2015-07-31 15:54:08 +00:00
clearInterval(this.timer);
},
2015-08-11 00:19:04 +00:00
render() {
2015-07-31 15:54:08 +00:00
return (<ProgressBar progress={this.progress()} />);
}
});
var ProgressBar = React.createClass({
2015-08-11 00:19:04 +00:00
render() {
2015-07-31 15:54:08 +00:00
var style = {
width: Math.round((this.props.progress.num / this.props.progress.den * 100)) + "%"
};
var barMessage = this.props.progress.barMessage || "";
return (
<div className="progress">
2015-09-05 17:22:23 +00:00
<div className="progress-bar progress-bar-striped active"
data-role="progressbar"
data-aria-valuenow={this.props.progress.num}
data-aria-valuemin="0"
data-aria-valuemax={this.props.progress.den}
style={style}>{barMessage}
</div>
</div>
2015-07-31 15:54:08 +00:00
);
}
});
2015-07-28 15:54:29 +00:00
var GatherProgress = React.createClass({
2015-08-11 00:19:04 +00:00
stateDescription() {
2015-07-28 15:54:29 +00:00
switch(this.props.gather.state) {
case "gathering":
return "Waiting for more gatherers.";
case "election":
return "Currently voting for team leaders.";
case "selection":
2015-07-31 16:34:27 +00:00
return "Waiting for leaders to pick teams.";
2015-07-28 15:54:29 +00:00
case "done":
return "Gather completed.";
default:
return "Initialising gather.";
}
},
2015-08-11 00:19:04 +00:00
gatheringProgress() {
2015-07-28 15:54:29 +00:00
var num = this.props.gather.gatherers.length;
var den = 12;
var remaining = den - num;
var message = (remaining === 1) ? "Waiting for last player" : "Waiting for " + remaining + " more players";
return {
num: num,
den: den,
message: message
};
},
2015-08-11 00:19:04 +00:00
electionProgress() {
var num = this.props.gather.gatherers.reduce((acc, gatherer) => {
2015-07-28 15:54:29 +00:00
if (gatherer.leaderVote) acc++;
return acc;
}, 0);
var den = 12;
return {
num: num,
den: den,
message: den - num + " more votes required"
};
},
2015-08-11 00:19:04 +00:00
selectionProgress() {
var num = this.props.gather.gatherers.reduce((acc, gatherer) => {
2015-07-28 15:54:29 +00:00
if (gatherer.team !== "lobby") acc++;
return acc;
}, 0);
var den = 12;
return {
num: num,
den: den,
message: num + " out of " + den + " players assigned"
};
},
2015-08-11 00:19:04 +00:00
render() {
2015-07-31 15:54:08 +00:00
var progress, progressBar;
2015-07-28 15:54:29 +00:00
var gatherState = this.props.gather.state;
if (gatherState === 'gathering' && this.props.gather.gatherers.length) {
progress = this.gatheringProgress();
2015-07-31 15:54:08 +00:00
progressBar = (<ProgressBar progress={progress} />);
2015-07-28 15:54:29 +00:00
} else if (gatherState === 'election') {
progress = this.electionProgress();
2015-07-31 15:54:08 +00:00
progressBar = (<ElectionProgressBar {...this.props} progress={progress} />);
2015-07-28 15:54:29 +00:00
} else if (gatherState === 'selection') {
progress = this.selectionProgress();
2015-07-31 15:54:08 +00:00
progressBar = (<ProgressBar progress={progress} />);
2015-07-28 15:54:29 +00:00
}
2015-07-31 15:54:08 +00:00
if (!progress) return false;
return (
2015-09-05 17:22:23 +00:00
<div className="no-bottom">
2015-07-31 15:54:08 +00:00
<p><strong>{this.stateDescription()}</strong> {progress.message}</p>
{progressBar}
</div>
);
2015-07-28 15:54:29 +00:00
}
});
2015-08-27 11:57:35 +00:00
var TeamSpeakButton = React.createClass({
getDefaultProps() {
let password = "ns2gather";
return {
url: "ts3server://ensl.org/",
password: password,
alien: {
channel: "NS2 Gather/Gather #1/Alien (Team Y)",
password: password
},
marine: {
channel: "NS2 Gather/Gather #1/Marine (Team X)",
password: password
}
};
},
marineUrl() {
2015-08-27 14:00:10 +00:00
return this.teamSpeakUrl(this.props.marine);
2015-08-27 11:57:35 +00:00
},
alienUrl() {
2015-08-27 14:00:10 +00:00
return this.teamSpeakUrl(this.props.alien);
2015-08-27 11:57:35 +00:00
},
teamSpeakUrl(conn) {
let params = `channel=${encodeURIComponent(conn.channel)}&channelpassword=${encodeURIComponent(conn.password)}`;
return (`${this.props.url}?${params}`);
},
render() {
return (
<div className="btn-group dropup">
2015-09-05 17:22:23 +00:00
<button type="button" className="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Teamspeak <span className="caret"></span>
</button>
<ul className="dropdown-menu">
<li><a href={this.props.url}>Join Teamspeak Lobby</a></li>
<li><a href={this.marineUrl()}>Join Marine Teamspeak</a></li>
<li><a href={this.alienUrl()}>Join Alien Teamspeak</a></li>
<li role="separator" className="divider"></li>
<li><a href="#" data-toggle="modal" data-target="#teamspeakmodal">Teamspeak Details</a></li>
</ul>
<div className="modal fade text-left" id="teamspeakmodal">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 className="modal-title">Teamspeak Server Information</h4>
</div>
<div className="modal-body">
<dl className="dl-horizontal">
<dt>Server</dt>
<dd>{this.props.url}</dd>
<dt>Password</dt>
<dd>{this.props.password}</dd>
<dt>Marine Channel</dt>
<dd>{this.props.marine.channel}</dd>
<dt>Alien Channel</dt>
<dd>{this.props.alien.channel}</dd>
2015-08-27 11:57:35 +00:00
</dl>
2015-09-05 17:22:23 +00:00
</div>
</div>
</div>
2015-08-27 11:57:35 +00:00
</div>
</div>
);
}
});
2015-07-28 23:32:50 +00:00
var GatherActions = React.createClass({
2015-08-11 00:19:04 +00:00
joinGather(e) {
2015-07-29 14:35:58 +00:00
e.preventDefault();
socket.emit("gather:join");
},
2015-08-11 00:19:04 +00:00
leaveGather(e) {
2015-07-28 15:54:29 +00:00
e.preventDefault();
2015-07-28 23:32:50 +00:00
socket.emit("gather:leave");
},
2015-08-11 00:19:04 +00:00
confirmTeam(e) {
2015-07-28 23:32:50 +00:00
e.preventDefault();
socket.emit("gather:select:confirm");
2015-07-28 15:54:29 +00:00
},
2015-08-11 00:19:04 +00:00
inviteToGather(e) {
2015-07-28 15:54:29 +00:00
e.preventDefault();
2015-07-29 14:35:58 +00:00
alert("Boop!");
2015-07-28 15:54:29 +00:00
},
2015-08-11 00:19:04 +00:00
render() {
2015-07-28 15:54:29 +00:00
var joinButton;
2015-07-28 23:32:50 +00:00
if (this.props.currentGatherer) {
2015-07-28 15:54:29 +00:00
joinButton = (<li><button
onClick={this.leaveGather}
className="btn btn-danger">Leave Gather</button></li>);
2015-07-29 14:35:58 +00:00
} else if (this.props.gather.state === 'gathering') {
joinButton = (
<button
onClick={this.joinGather}
className="btn btn-success">Join Gather</button>
);
2015-07-28 15:54:29 +00:00
}
2015-07-28 23:32:50 +00:00
var confirmTeam;
if (this.props.currentGatherer &&
2015-08-11 00:19:04 +00:00
this.props.currentGatherer.leader &&
this.props.gather.state === 'selection' &&
this.props.gather.gatherers.every(gatherer => gatherer.team !== 'lobby')) {
2015-07-28 23:32:50 +00:00
if (this.props.currentGatherer.confirm) {
confirmTeam = (
<li>
<button
className="btn btn-default"
data-disabled="true"
>
Confirmed
</button>
</li>
);
} else {
confirmTeam = (
<li>
<button
2015-07-29 10:46:30 +00:00
className="btn btn-success"
2015-07-28 23:32:50 +00:00
onClick={this.confirmTeam}
>
Confirm Team
</button>
</li>
);
}
}
2015-07-28 15:54:29 +00:00
var inviteButton;
if (this.props.gather.state === 'gathering') {
inviteButton = (<li><button
onClick={this.inviteToGather}
className="btn btn-primary">Invite to Gather</button></li>);
}
2015-07-28 23:32:50 +00:00
return (
2015-09-05 17:22:23 +00:00
<div className="gather-actions text-right">
2015-07-29 10:46:30 +00:00
<ul className="list-inline no-bottom">
2015-08-27 11:57:35 +00:00
<TeamSpeakButton />
2015-07-28 23:32:50 +00:00
{confirmTeam}
{inviteButton}
{joinButton}
</ul>
</div>
);
}
});
2015-08-27 14:53:11 +00:00
var VoteButton = React.createClass({
cancelVote(e) {
socket.emit("gather:vote", {
leader: {
candidate: null
}
});
},
vote(e) {
2015-07-29 13:50:39 +00:00
e.preventDefault();
socket.emit("gather:vote", {
2015-08-27 14:53:11 +00:00
leader: {
candidate: parseInt(e.target.value, 10)
2015-07-29 13:50:39 +00:00
}
});
},
2015-08-11 00:19:04 +00:00
2015-08-27 14:53:11 +00:00
render() {
if (this.props.currentGatherer === null) {
return false;
}
if (this.props.currentGatherer.leaderVote === this.props.candidate.id) {
return (
<button
onClick={this.cancelVote}
className="btn btn-xs btn-success">Voted
</button>
);
} else {
return (
<button
onClick={this.vote}
2015-08-28 20:28:50 +00:00
className="btn btn-xs btn-primary"
2015-08-27 14:53:11 +00:00
value={this.props.candidate.id}>Vote
</button>
);
}
}
});
var ServerVoting = React.createClass({
voteHandler(serverId) {
return function (e) {
e.preventDefault();
socket.emit("gather:vote", {
server: {
id: serverId
}
});
}
},
2015-08-11 00:19:04 +00:00
votesForServer(server) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
2015-07-29 13:50:39 +00:00
if (server.id === gatherer.serverVote) acc++;
return acc;
}, 0);
},
2015-08-11 00:19:04 +00:00
render() {
2015-07-29 13:50:39 +00:00
var self = this;
2015-08-27 14:53:11 +00:00
let servers = self.props.servers.map(server => {
let votes = self.votesForServer(server);
2015-07-29 13:50:39 +00:00
if (self.props.currentGatherer.serverVote === server.id) {
2015-08-27 14:53:11 +00:00
return (
2015-08-27 16:59:08 +00:00
<a href="#"
className="list-group-item list-group-item-success"
onClick={ e => e.preventDefault() }
key={server.id}>
2015-08-27 14:53:11 +00:00
<span className="badge">{votes}</span>
{server.name || server.description || server.dns}
2015-08-27 14:53:11 +00:00
</a>
);
2015-07-29 13:50:39 +00:00
} else {
2015-08-27 14:53:11 +00:00
return (
<a href="#" className="list-group-item"
onClick={self.voteHandler(server.id)}
key={server.id}>
<span className="badge">{votes}</span>
{server.description || server.dns}
</a>
);
2015-07-29 13:50:39 +00:00
}
});
2015-08-27 14:53:11 +00:00
2015-08-27 15:11:54 +00:00
let voted = self.props.currentGatherer.serverVote !== null;
2015-08-27 14:53:11 +00:00
2015-07-29 13:50:39 +00:00
return (
<div className="panel panel-default">
<div className="panel-heading">
2015-08-27 15:11:54 +00:00
{voted ? "Server Votes" : "Please Vote for a Server" }
2015-07-29 13:50:39 +00:00
</div>
2015-08-27 14:53:11 +00:00
<div className="list-group gather-voting">
2015-07-29 13:50:39 +00:00
{servers}
2015-08-27 14:53:11 +00:00
</div>
2015-07-29 13:50:39 +00:00
</div>
);
}
})
var MapVoting = React.createClass({
2015-08-27 14:53:11 +00:00
voteHandler(mapId) {
return function (e) {
e.preventDefault();
socket.emit("gather:vote", {
map: {
id: mapId
}
});
}
2015-07-29 13:50:39 +00:00
},
2015-08-11 00:19:04 +00:00
votesForMap(map) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
2015-07-29 13:50:39 +00:00
if (map.id === gatherer.mapVote) acc++;
return acc;
}, 0);
},
2015-08-11 00:19:04 +00:00
render() {
2015-07-29 13:50:39 +00:00
var self = this;
2015-08-27 15:11:54 +00:00
let maps = self.props.maps.map(map => {
2015-08-27 14:53:11 +00:00
let votes = self.votesForMap(map);
2015-07-29 13:50:39 +00:00
if (self.props.currentGatherer.mapVote === map.id) {
2015-08-27 14:53:11 +00:00
return (
<a href="#"
key={map.id}
2015-08-27 16:59:08 +00:00
onClick={ e => e.preventDefault() }
2015-08-27 14:53:11 +00:00
className="list-group-item list-group-item-success">
<span className="badge">{votes}</span>
{map.name}
</a>
);
2015-07-29 13:50:39 +00:00
} else {
2015-08-27 14:53:11 +00:00
return (
<a href="#"
key={map.id}
onClick={self.voteHandler(map.id)}
className="list-group-item">
<span className="badge">{votes}</span>
{map.name}
</a>
);
2015-07-29 13:50:39 +00:00
}
});
2015-08-27 15:11:54 +00:00
let voted = (self.props.currentGatherer.mapVote !== null);
2015-07-29 13:50:39 +00:00
return (
<div className="panel panel-default">
<div className="panel-heading">
2015-08-27 16:54:34 +00:00
{ voted ? "Map Votes" : "Please Vote for a Map" }
2015-07-29 13:50:39 +00:00
</div>
2015-08-27 14:53:11 +00:00
<div className="list-group gather-voting">
2015-07-29 13:50:39 +00:00
{maps}
2015-08-27 14:53:11 +00:00
</div>
2015-07-29 13:50:39 +00:00
</div>
);
}
})
2015-07-28 23:32:50 +00:00
var Gather = React.createClass({
2015-08-11 00:19:04 +00:00
getDefaultProps() {
2015-07-28 23:32:50 +00:00
return {
gather: {
gatherers: []
}
}
},
2015-08-11 00:19:04 +00:00
2015-08-27 16:54:34 +00:00
checkForStateChange: function (data) {
2015-08-27 17:01:11 +00:00
let previousState = this.props.gather.state;
2015-08-27 16:54:34 +00:00
let newState = data.gather.state;
2015-08-27 17:01:11 +00:00
if (newState === previousState) return;
2015-08-27 16:54:34 +00:00
// Callbacks for new states
if (newState === "election"
&& previousState === "gathering"
&& data.currentGatherer) {
2015-08-27 16:54:34 +00:00
soundController.playGatherMusic();
}
},
2015-08-11 00:19:04 +00:00
componentDidMount() {
2015-07-28 23:32:50 +00:00
var self = this;
2015-08-27 16:54:34 +00:00
socket.on("gather:refresh", (data) => {
self.checkForStateChange(data);
self.setProps(data)
});
2015-07-28 23:32:50 +00:00
},
2015-08-11 00:19:04 +00:00
render() {
2015-07-28 23:32:50 +00:00
if (this.props.gather.state === 'done') {
2015-07-29 14:35:58 +00:00
return (<CompletedGather {...this.props} />);
2015-07-28 23:32:50 +00:00
}
2015-07-29 13:50:39 +00:00
var voting;
if (this.props.currentGatherer) {
voting = (
2015-09-05 17:22:23 +00:00
<div className="row add-top">
<div className="col-md-6">
<MapVoting {...this.props} />
</div>
<div className="col-md-6">
<ServerVoting {...this.props} />
2015-07-29 13:50:39 +00:00
</div>
</div>
);
}
2015-07-28 15:54:29 +00:00
var gatherTeams;
if (this.props.gather.state === 'selection') {
gatherTeams = <GatherTeams gather={this.props.gather} />
}
var previousGather;
if (this.props.previousGather) {
previousGather = (<CompletedGather {...this.props} gather={this.props.previousGather} />);
}
2015-07-28 15:54:29 +00:00
return (
<div>
2015-09-05 17:22:23 +00:00
<h2 className="headline">Current Gather</h2>
2015-07-31 15:54:08 +00:00
<GatherProgress {...this.props} />
<Gatherers {...this.props} />
2015-07-28 15:54:29 +00:00
{gatherTeams}
2015-07-29 14:35:58 +00:00
{voting}
2015-07-28 23:32:50 +00:00
<GatherActions {...this.props} />
2015-09-05 17:22:23 +00:00
{previousGather}
</div>
2015-07-28 15:54:29 +00:00
);
}
});
var Gatherers = React.createClass({
2015-08-11 00:19:04 +00:00
joinGather(e) {
2015-07-29 14:35:58 +00:00
e.preventDefault();
socket.emit("gather:join");
},
2015-08-11 00:19:04 +00:00
render() {
2015-07-28 15:54:29 +00:00
var self = this;
2015-08-11 00:19:04 +00:00
var gatherers = this.props.gather.gatherers.map(gatherer => {
2015-08-08 17:13:17 +00:00
if (gatherer.user.country) {
2015-09-05 17:22:23 +00:00
var country = (<img src="images/blank.gif"
2015-08-08 17:13:17 +00:00
className={"flag flag-" + gatherer.user.country.toLowerCase()}
alt={gatherer.user.country} />);
};
2015-07-28 15:54:29 +00:00
2015-09-05 17:22:23 +00:00
var skill = gatherer.user.profile.skill || "Not Available";
2015-08-28 14:17:08 +00:00
var abilities = [];
for (let attr in gatherer.user.profile.abilities) {
if (gatherer.user.profile.abilities[attr]) abilities.push(_.capitalize(attr));
}
2015-08-31 14:55:42 +00:00
2015-09-05 17:22:23 +00:00
var lifeform = (abilities.length) ? abilities.join(", ") : "None Specified";
var hiveStats = [];
if (gatherer.user.hive.skill) hiveStats.push("ELO: " + gatherer.user.hive.skill);
2015-08-31 14:55:42 +00:00
if (gatherer.user.hive.playTime) {
2015-09-05 17:22:23 +00:00
hiveStats.push(Math.floor(gatherer.user.hive.playTime / 3600) + " Hours");
2015-08-31 14:55:42 +00:00
}
2015-09-05 17:22:23 +00:00
var hive = (hiveStats.length) ? hiveStats.join(", ") : "Not Available";
var team = (gatherer.user.team) ? gatherer.user.team.name : "None";
2015-07-28 23:32:50 +00:00
2015-08-05 00:06:09 +00:00
var action;
2015-07-28 15:54:29 +00:00
if (self.props.gather.state === "election") {
2015-08-11 00:19:04 +00:00
var votes = self.props.gather.gatherers.reduce((acc, voter) => {
2015-07-28 15:54:29 +00:00
if (voter.leaderVote === gatherer.id) acc++;
return acc;
}, 0)
action = (
<span>
<small>{votes + " votes"} &nbsp;</small>
<VoteButton currentGatherer={self.props.currentGatherer} candidate={gatherer} />
</span>
);
}
2015-07-28 23:32:50 +00:00
if (self.props.gather.state === 'selection') {
2015-08-08 17:13:17 +00:00
if (self.props.currentGatherer && self.props.currentGatherer.leader) {
action = (
<span>
<SelectPlayerButton gatherer={gatherer} />
</span>
);
} else {
if (gatherer.team !== "lobby") {
action = (<span className="label label-success">{gatherer.team}</span>);
}
}
2015-07-28 23:32:50 +00:00
}
2015-07-28 15:54:29 +00:00
return (
2015-09-05 17:22:23 +00:00
<div className="panel panel-success" key={gatherer.user.id} data-userid={gatherer.user.id}>
<div className="panel-heading">
<h4 className="panel-title">
<a data-toggle="collapse"
href={"#"+gatherer.user.id.toString() + "-collapse"}
aria-expanded="false"
aria-controls={gatherer.user.id.toString() + "-collapse"}>
{country} {gatherer.user.username} <span className="caret"></span>
</a>
<span className="pull-right">
{action}
</span>
</h4>
</div>
<div id={gatherer.user.id.toString() + "-collapse"}
className="panel-collapse collapse out" >
<div className="panel-body">
<dl className="dl-horizontal">
<dt>Lifeforms</dt>
<dd>{lifeform}</dd>
<dt>Skill Level</dt>
<dd>{skill}</dd>
<dt>Team</dt>
<dd>{team}</dd>
<dt>Hive Stats</dt>
<dd>{hive}</dd>
</dl>
</div>
</div>
</div>
2015-07-28 15:54:29 +00:00
);
})
if (this.props.gather.gatherers.length) {
return (
2015-09-05 17:22:23 +00:00
<div class="panel-group" role="tablist" aria-multiselectable="true" id="gatherers-panel">
{gatherers}
2015-07-28 15:54:29 +00:00
</div>
);
} else {
2015-07-29 10:46:30 +00:00
return (
<div className="panel-body text-center join-hero">
2015-07-29 14:35:58 +00:00
<button
onClick={this.joinGather}
className="btn btn-success btn-lg">Start a Gather</button>
2015-07-29 10:46:30 +00:00
</div>
);
2015-07-28 15:54:29 +00:00
}
}
});
2015-07-29 14:35:58 +00:00
var CompletedGather = React.createClass({
2015-08-11 00:19:04 +00:00
countVotes(voteType) {
return this.props.gather.gatherers.reduce((acc, gatherer) => {
2015-08-08 19:14:16 +00:00
if (gatherer[voteType] !== null) acc.push(gatherer[voteType]);
return acc;
}, []);
2015-07-29 14:35:58 +00:00
},
2015-08-11 00:19:04 +00:00
selectedMaps() {
2015-08-08 19:14:16 +00:00
return rankVotes(this.countVotes('mapVote'), this.props.maps).slice(0, 2)
},
2015-08-11 00:19:04 +00:00
selectedServer() {
2015-08-08 19:14:16 +00:00
return rankVotes(this.countVotes('serverVote'), this.props.servers).slice(0, 1);
2015-07-29 14:35:58 +00:00
},
2015-08-11 00:19:04 +00:00
render() {
2015-08-08 19:14:16 +00:00
var maps = this.selectedMaps();
var server = this.selectedServer().pop();
2015-07-29 14:35:58 +00:00
return (
<div className="panel panel-default">
<div className="panel-heading">
<strong>Previous Gather</strong>
2015-07-29 14:35:58 +00:00
</div>
2015-08-08 19:14:16 +00:00
<GatherTeams gather={this.props.gather} />
2015-07-29 14:35:58 +00:00
<div className="panel-body">
2015-08-08 19:14:16 +00:00
<dl className="dl-horizontal">
2015-09-05 17:22:23 +00:00
<dt>Maps</dt>
<dd>{maps.map(map => map.name).join(" & ")}</dd>
<dt>Server</dt>
<dd>{server.name}</dd>
<dt>Address</dt>
<dd>{server.ip}:{server.port}</dd>
<dt>Password</dt>
<dd>{server.password}</dd>
<br />
<dt>&nbsp;</dt>
2015-08-08 19:14:16 +00:00
<dd><a href={["steam://run/4920/connect", server.ip +":"+server.port, server.password].join("/")}
className="btn btn-primary">Click to Join</a></dd>
</dl>
2015-07-29 14:35:58 +00:00
</div>
</div>
);
}
});