UI now specifies, which queue to leave, and also added dropping from tournaments.

This commit is contained in:
marcins78
2013-01-02 16:42:05 +00:00
parent db53135844
commit a1b531d122
4 changed files with 63 additions and 19 deletions

View File

@@ -225,7 +225,18 @@ public class HallServer extends AbstractServer {
}
}
public void leaveQueues(Player player) {
public void leaveQueue(String queueId, Player player) {
_hallDataAccessLock.writeLock().lock();
try {
TournamentQueue tournamentQueue = _tournamentQueues.get(queueId);
if (tournamentQueue != null && tournamentQueue.isPlayerSignedUp(player.getName()))
tournamentQueue.leavePlayer(_collectionsManager, player);
} finally {
_hallDataAccessLock.writeLock().unlock();
}
}
private void leaveQueues(Player player) {
_hallDataAccessLock.writeLock().lock();
try {
for (TournamentQueue tournamentQueue : _tournamentQueues.values()) {
@@ -237,6 +248,17 @@ public class HallServer extends AbstractServer {
}
}
public void dropFromTournament(String tournamentId, Player player) {
_hallDataAccessLock.writeLock().lock();
try {
Tournament tournament = _runningTournaments.get(tournamentId);
if (tournament != null)
tournament.dropPlayer(player.getName());
} finally {
_hallDataAccessLock.writeLock().unlock();
}
}
public void leaveAwaitingTables(Player player) {
_hallDataAccessLock.writeLock().lock();
try {
@@ -346,7 +368,7 @@ public class HallServer extends AbstractServer {
tournamentQueue.getPlayerCount(), tournamentQueue.isPlayerSignedUp(player.getName()));
}
for (Map.Entry<String, Tournament> tournamentEntry: _runningTournaments.entrySet()){
for (Map.Entry<String, Tournament> tournamentEntry : _runningTournaments.entrySet()) {
String tournamentKey = tournamentEntry.getKey();
Tournament tournament = tournamentEntry.getValue();
visitor.visitTournament(tournamentKey, tournament.getCollectionType().getFullName(),

View File

@@ -207,14 +207,27 @@ public class HallResource extends AbstractResource {
}
}
@Path("/queue/leave")
@Path("/queue/{queueId}/leave")
@POST
public void leaveQueue(
@PathParam("queueId") String queueId,
@FormParam("participantId") String participantId,
@Context HttpServletRequest request) throws ParserConfigurationException {
Player resourceOwner = getResourceOwnerSafely(request, participantId);
_hallServer.leaveQueues(resourceOwner);
_hallServer.leaveQueue(queueId, resourceOwner);
}
@Path("/tournament/{tournamentId}/leave")
@POST
public Document dropFromTournament(
@PathParam("tournamentId") String tournamentId,
@FormParam("participantId") String participantId,
@Context HttpServletRequest request) throws ParserConfigurationException {
Player resourceOwner = getResourceOwnerSafely(request, participantId);
_hallServer.dropFromTournament(tournamentId, resourceOwner);
return null;
}
@Path("/{table}")

View File

@@ -525,10 +525,21 @@ var GempLotrCommunication = Class.extend({
dataType:"xml"
});
},
leaveQueue:function (errorMap) {
leaveQueue:function (queueId, errorMap) {
$.ajax({
type:"POST",
url:this.url + "/hall/queue/leave",
url:this.url + "/hall/queue/"+queueId+"/leave",
cache:false,
data:{
participantId:getUrlParam("participantId")},
error:this.errorCheck(errorMap),
dataType:"xml"
});
},
dropFromTournament:function(tournamentId, callback, errorMap) {
$.ajax({
type:"POST",
url:this.url + "/hall/tournament/"+tournamentId+"/leave",
cache:false,
data:{
participantId:getUrlParam("participantId")},

View File

@@ -372,11 +372,9 @@ var GempLotrHallUI = Class.extend({
$(but).button().click((
function(queueId) {
return function() {
var deck = that.decksSelect.val();
if (deck != null)
that.comm.leaveQueue(id, deck, function (xml) {
that.processResponse(xml);
});
that.comm.leaveQueue(queueId, function (xml) {
that.processResponse(xml);
});
}
})(id));
actionsField.append(but);
@@ -419,9 +417,9 @@ var GempLotrHallUI = Class.extend({
$(but).button().click((
function(tournamentId) {
return function () {
that.comm.dropFromTournament(tournamentId, function (xml) {
that.processResponse(xml);
});
that.comm.dropFromTournament(tournamentId, function (xml) {
that.processResponse(xml);
});
};
}
)(id));
@@ -559,11 +557,11 @@ var GempLotrHallUI = Class.extend({
}
}
$(".count", $(".eventHeader.queues")).html("("+($("tr", $("table.queues")).length-1)+")");
$(".count", $(".eventHeader.tournaments")).html("("+($("tr", $("table.tournaments")).length-1)+")");
$(".count", $(".eventHeader.waitingTables")).html("("+($("tr", $("table.waitingTables")).length-1)+")");
$(".count", $(".eventHeader.playingTables")).html("("+($("tr", $("table.playingTables")).length-1)+")");
$(".count", $(".eventHeader.finishedTables")).html("("+($("tr", $("table.finishedTables")).length-1)+")");
$(".count", $(".eventHeader.queues")).html("(" + ($("tr", $("table.queues")).length - 1) + ")");
$(".count", $(".eventHeader.tournaments")).html("(" + ($("tr", $("table.tournaments")).length - 1) + ")");
$(".count", $(".eventHeader.waitingTables")).html("(" + ($("tr", $("table.waitingTables")).length - 1) + ")");
$(".count", $(".eventHeader.playingTables")).html("(" + ($("tr", $("table.playingTables")).length - 1) + ")");
$(".count", $(".eventHeader.finishedTables")).html("(" + ($("tr", $("table.finishedTables")).length - 1) + ")");
var skipReload = false;
var games = root.getElementsByTagName("game");