mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-22 12:41:11 +00:00
Make server votes toggleable, rename map and server vote methods in gather
This commit is contained in:
parent
cc95d9789e
commit
ae5b566eef
6 changed files with 38 additions and 44 deletions
|
@ -166,11 +166,11 @@ module.exports = function (namespace) {
|
|||
}
|
||||
|
||||
if (data.map) {
|
||||
gather.voteForMap(socket._user, data.map.id);
|
||||
gather.toggleMapVote(socket._user, data.map.id);
|
||||
}
|
||||
|
||||
if (data.server) {
|
||||
gather.voteForServer(socket._user, data.server.id);
|
||||
gather.toggleServerVote(socket._user, data.server.id);
|
||||
}
|
||||
|
||||
if (typeof data.regather === 'boolean' && gather.can("regather")) {
|
||||
|
|
|
@ -322,12 +322,12 @@ Gather.prototype.toJson = function () {
|
|||
}
|
||||
};
|
||||
|
||||
Gather.prototype.voteForMap = function (voter, mapId) {
|
||||
Gather.prototype.toggleMapVote = function (voter, mapId) {
|
||||
this.modifyGatherer(voter, gatherer => gatherer.toggleMapVote(mapId));
|
||||
};
|
||||
|
||||
Gather.prototype.voteForServer = function (voter, serverId) {
|
||||
this.modifyGatherer(voter, gatherer => gatherer.voteForServer(serverId));
|
||||
Gather.prototype.toggleServerVote = function (voter, serverId) {
|
||||
this.modifyGatherer(voter, gatherer => gatherer.toggleServerVote(serverId));
|
||||
};
|
||||
|
||||
// Returns an array of IDs representing votes for leaders
|
||||
|
|
|
@ -29,7 +29,7 @@ function Gatherer (user) {
|
|||
|
||||
Gatherer.prototype.toggleMapVote = function (mapId) {
|
||||
if (this.mapVote.some(votedId => votedId === mapId)) {
|
||||
this.mapVote = this.mapVote.filter(voteId => voteId !== mapId)
|
||||
this.mapVote = this.mapVote.filter(voteId => voteId !== mapId);
|
||||
return;
|
||||
}
|
||||
this.mapVote.push(mapId);
|
||||
|
@ -37,8 +37,11 @@ Gatherer.prototype.toggleMapVote = function (mapId) {
|
|||
this.mapVote.length);
|
||||
};
|
||||
|
||||
Gatherer.prototype.voteForServer = function (serverId) {
|
||||
if (this.serverVote.some(votedId => votedId === serverId)) return;
|
||||
Gatherer.prototype.toggleServerVote = function (serverId) {
|
||||
if (this.serverVote.some(votedId => votedId === serverId)) {
|
||||
this.serverVote = this.serverVote.filter(voteId => voteId !== serverId);
|
||||
return;
|
||||
}
|
||||
this.serverVote.push(serverId);
|
||||
this.serverVote = this.serverVote.slice(this.serverVote.length -
|
||||
MAX_SERVER_VOTES, this.serverVote.length);
|
||||
|
|
|
@ -504,26 +504,17 @@ var ServerVoting = React.createClass({
|
|||
return bVotes - aVotes;
|
||||
}).map(server => {
|
||||
let votes = self.votesForServer(server);
|
||||
if (thisGatherer.serverVote.some(voteId => voteId === server.id)) {
|
||||
return (
|
||||
<a href="#"
|
||||
className="list-group-item list-group-item-success"
|
||||
onClick={ e => e.preventDefault() }
|
||||
key={server.id}>
|
||||
<span className="badge">{votes}</span>
|
||||
{server.name || server.description}
|
||||
</a>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<a href="#" className="list-group-item"
|
||||
onClick={self.voteHandler(server.id)}
|
||||
key={server.id}>
|
||||
<span className="badge">{votes}</span>
|
||||
{server.name || server.description}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
let style = thisGatherer.serverVote.some(voteId => voteId === server.id) ?
|
||||
"list-group-item list-group-item-success" : "list-group-item";
|
||||
return (
|
||||
<a href="#"
|
||||
className={style}
|
||||
onClick={ e => e.preventDefault() }
|
||||
key={server.id}>
|
||||
<span className="badge">{votes}</span>
|
||||
{server.name || server.description}
|
||||
</a>
|
||||
);
|
||||
});
|
||||
|
||||
let votes = thisGatherer.serverVote.length;
|
||||
|
|
|
@ -364,25 +364,25 @@ describe("Gather Model:", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("voteForMap", function () {
|
||||
describe("toggleMapVote", function () {
|
||||
beforeEach(function() {
|
||||
gather.addGatherer(user);
|
||||
});
|
||||
it ("assigns map vote to gatherer", function () {
|
||||
var mapId = 1;
|
||||
gather.voteForMap(user, mapId);
|
||||
gather.toggleMapVote(user, mapId);
|
||||
var gatherer = gather.getGatherer(user);
|
||||
assert.equal(gatherer.mapVote, mapId);
|
||||
});
|
||||
});
|
||||
|
||||
describe("voteForServer", function () {
|
||||
describe("toggleServerVote", function () {
|
||||
beforeEach(function() {
|
||||
gather.addGatherer(user);
|
||||
});
|
||||
it ("assigns map vote to gatherer", function () {
|
||||
var serverId = 1;
|
||||
gather.voteForServer(user, serverId);
|
||||
gather.toggleServerVote(user, serverId);
|
||||
var gatherer = gather.getGatherer(user);
|
||||
assert.equal(gatherer.serverVote, serverId);
|
||||
});
|
||||
|
|
|
@ -55,27 +55,27 @@ describe("Gather Model:", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("#voteForServer", function () {
|
||||
describe("#toggleServerVote", function () {
|
||||
it ("assigns vote for server id", function () {
|
||||
assert.equal(gatherer.serverVote.length, 0);
|
||||
gatherer.voteForServer(1);
|
||||
gatherer.toggleServerVote(1);
|
||||
assert.isTrue(gatherer.serverVote.some(voteId => voteId === 1));
|
||||
});
|
||||
it ("only assigns vote once", function () {
|
||||
gatherer.voteForServer(1);
|
||||
gatherer.voteForServer(1);
|
||||
assert.equal(gatherer.serverVote.length, 1);
|
||||
it ("removes server vote if toggled twice", function () {
|
||||
gatherer.toggleServerVote(1);
|
||||
gatherer.toggleServerVote(1);
|
||||
assert.equal(gatherer.serverVote.length, 0);
|
||||
});
|
||||
it ("allows a maximum of 2 votes", function () {
|
||||
gatherer.voteForServer(1);
|
||||
gatherer.voteForServer(2);
|
||||
gatherer.voteForServer(3);
|
||||
gatherer.toggleServerVote(1);
|
||||
gatherer.toggleServerVote(2);
|
||||
gatherer.toggleServerVote(3);
|
||||
assert.equal(gatherer.serverVote.length, 2);
|
||||
});
|
||||
it ("removes oldest vote if maximum vote exceeded", function () {
|
||||
gatherer.voteForServer(1);
|
||||
gatherer.voteForServer(2);
|
||||
gatherer.voteForServer(3);
|
||||
gatherer.toggleServerVote(1);
|
||||
gatherer.toggleServerVote(2);
|
||||
gatherer.toggleServerVote(3);
|
||||
assert.isFalse(gatherer.serverVote.some(voteId => voteId === 1));
|
||||
assert.isTrue(gatherer.serverVote.some(voteId => voteId === 2));
|
||||
assert.isTrue(gatherer.serverVote.some(voteId => voteId === 3));
|
||||
|
|
Loading…
Reference in a new issue