Implemented gather archive

This commit is contained in:
Chris Blanchard 2015-09-27 12:55:00 +01:00
parent 43c5a592cd
commit c6f2313900
6 changed files with 109 additions and 16 deletions

View file

@ -44,14 +44,17 @@ module.exports = function (namespace) {
var refreshArchive = () => {
ArchivedGather.recent((error, recentGathers) => {
if (error) return winston.error(error);
socket.emit("gather:archive:refresh", {
archive: recentGathers
namespace.emit("gather:archive:refresh", {
archive: recentGathers,
maps: Map.list,
servers: Server.list
});
});
};
Gather.registerCallback('onDone', refreshGather);
Gather.registerCallback('onEvent', refreshGather);
Gather.onArchiveUpdate(refreshArchive);
Gather.restart();
// ***** Generate Test Users *****
@ -64,7 +67,9 @@ module.exports = function (namespace) {
ArchivedGather.recent((error, recentGathers) => {
if (error) return winston.error(error);
socket.emit("gather:archive:refresh", {
archive: recentGathers
archive: recentGathers,
maps: Map.list,
servers: Server.list
});
});

View file

@ -2,6 +2,7 @@
let Gather = require("./gather");
let gatherCallbacks = {};
let archiveUpdatedCallback = () => {};
let winston = require("winston");
let mongoose = require("mongoose");
let ArchivedGather = mongoose.model("ArchivedGather");
@ -32,7 +33,11 @@ let newGather = () => {
let archiveGather = gather => {
ArchivedGather.archive(gather, (error, result) => {
if (error) winston.error(error);
if (error) return winston.error(error);
if (archiveUpdatedCallback
&& typeof archiveUpdatedCallback === 'function') {
archiveUpdatedCallback();
}
});
};
@ -52,6 +57,9 @@ let SingletonClass = {
gatherCallbacks[type] = [method];
}
},
onArchiveUpdate: function (callback) {
archiveUpdatedCallback = callback;
},
restart: function () {
this.previousGather = undefined;
this.current = undefined;

View file

@ -570,7 +570,7 @@ var Gather = React.createClass({
render() {
if (this.props.gather.state === 'done') {
return (<CompletedGather {...this.props} />);
return (<CompletedGather show={true} {...this.props} />);
}
var voting;
@ -599,7 +599,18 @@ var Gather = React.createClass({
var previousGather;
if (this.props.previousGather) {
previousGather = (<CompletedGather {...this.props} gather={this.props.previousGather} />);
previousGather = (
<div className="panel panel-primary">
<div className="panel-heading">
Previous Gather
</div>
<div className="panel-body">
<CompletedGather {...this.props}
gather={this.props.previousGather}
show={true} />
</div>
</div>
);
}
return (
<div>
@ -644,10 +655,12 @@ var LifeformIcons = React.createClass({
return <img
className="lifeform-icon"
alt={lifeform}
key={lifeform}
src={`/images/${lifeform.toLowerCase()}.png`} />
} else {
return <img
className="lifeform-icon"
key={lifeform}
src={`/images/blank.gif`} />
}
});
@ -740,7 +753,10 @@ var Gatherers = React.createClass({
value={gatherer.user.id}
onClick={this.bootGatherer}>
Boot from Gather
</button>
</button>&nbsp;
<AssumeUserIdButton
gatherer={gatherer}
currentUser={this.props.user} />
</dd>
]
}
@ -805,14 +821,34 @@ var CompletedGather = React.createClass({
return d.toLocaleTimeString();
},
getInitialState() {
return {
show: !!this.props.show
};
},
toggleGatherInfo() {
let newState = !this.state.show;
this.setState({
show: newState
});
},
render() {
let gatherInfo = [];
if (this.state.show) {
gatherInfo.push(<GatherTeams gather={this.props.gather} />);
gatherInfo.push(<GatherVotingResults gather={this.props.gather}
maps={this.props.maps}
servers={this.props.servers}/>);
}
return (
<div id="previous_gather">
<div className="panel panel-primary add-bottom">
<div className="panel-heading">Previous Gather ({this.completionDate()})</div>
<div>
<div className="panel panel-success add-bottom pointer"
onClick={this.toggleGatherInfo}>
<div className="panel-heading"><strong>{this.completionDate()}</strong></div>
</div>
<GatherTeams gather={this.props.gather} />
<GatherVotingResults gather={this.props.gather} maps={this.props.maps} servers={this.props.servers}/>
{gatherInfo}
</div>
);
}
@ -868,3 +904,49 @@ var GatherVotingResults = React.createClass({
);
}
});
var ArchivedGathers = React.createClass({
componentDidMount() {
let self = this;
socket.on("gather:archive:refresh", data => {
self.setProps({
archive: data.archive,
maps: data.maps,
servers: data.servers
});
});
},
getDefaultProps() {
return {
archive: [],
maps: [],
servers: []
}
},
render() {
let archive = this.props.archive
.sort((a, b) => {
return new Date(b.createdAt) - new Date(a.createdAt);
})
.map(archivedGather => {
return <CompletedGather
show={false}
gather={archivedGather.gather}
maps={this.props.maps}
servers={this.props.servers} />
});
return (
<div className="panel panel-primary">
<div className="panel-heading">Archived Gathers</div>
<div className="panel-body">
{archive}
</div>
</div>
);
}
});

View file

@ -48,6 +48,7 @@ var renderPage = (socket) => {
React.render(<Gather />, document.getElementById('gathers'));
React.render(<CurrentUser />, document.getElementById('currentuser'));
React.render(<SoundPanel />, document.getElementById('soundcontroller'));
React.render(<ArchivedGathers />, document.getElementById('archived-gathers'));
};
var initialiseComponents = () => {

View file

@ -83,10 +83,6 @@ html, body {
margin-bottom: 1px;
}
#previous_gather {
margin-top: 2em;
}
.gather-actions {
margin-top: 0.5em;
}

View file

@ -49,6 +49,7 @@
</div>
<div class="col-md-4" id="chatroom"></div>
<div class="col-md-6" id="gathers"></div>
<div class="col-md-6 col-md-offset-6" id="archived-gathers"></div>
</div>
</div>
</div>