Tidy up realtime scoring inputs on match play

This commit is contained in:
Ken Schenke
2020-04-18 13:27:27 -05:00
parent 53574dcbc8
commit f91e3460d3
5 changed files with 62 additions and 297 deletions

View File

@@ -108,3 +108,8 @@ td[data-plc-value="true"] {
input[data-changed="true"], select[data-changed="true"] {
border: 2px solid #f00;
}
.score-block {
padding: 5px;
border-radius: 3px;
border: 1px solid #ddd;
}

View File

@@ -70,6 +70,13 @@ var updateRealtimeScore = function() {
})
};
var scoreKeyHandler = function(e) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode == 13) {
$('#' + $(event.target).attr("data-next")).focus().select();
}
};
var confirmCommit = function(isReplay) {
if (isReplay) {
// Show the appropriate message(s) in the confirmation dialog.

View File

@@ -1,105 +0,0 @@
// Copyright 2014 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
//
// Client-side logic for the referee interface.
var websocket;
var foulTeamButton;
var foulRuleButton;
var firstMatchLoad = true;
// Handles a click on a team button.
var setFoulTeam = function(teamButton) {
if (foulTeamButton) {
foulTeamButton.attr("data-selected", false);
}
foulTeamButton = $(teamButton);
foulTeamButton.attr("data-selected", true);
$("#commit").prop("disabled", !(foulTeamButton && foulRuleButton));
};
// Handles a click on a rule button.
var setFoulRule = function(ruleButton) {
if (foulRuleButton) {
foulRuleButton.attr("data-selected", false);
}
foulRuleButton = $(ruleButton);
foulRuleButton.attr("data-selected", true);
$("#commit").prop("disabled", !(foulTeamButton && foulRuleButton));
};
// Resets the buttons to their default selections.
var clearFoul = function() {
if (foulTeamButton) {
foulTeamButton.attr("data-selected", false);
foulTeamButton = null;
}
if (foulRuleButton) {
foulRuleButton.attr("data-selected", false);
foulRuleButton = null;
}
$("#commit").prop("disabled", true);
};
// Sends the foul to the server to add it to the list.
var commitFoul = function() {
websocket.send("addFoul", {Alliance: foulTeamButton.attr("data-alliance"),
TeamId: parseInt(foulTeamButton.attr("data-team")), RuleId: parseInt(foulRuleButton.attr("data-rule-id"))});
};
// Removes the foul with the given parameters from the list.
var deleteFoul = function(alliance, team, ruleId, timeSec) {
websocket.send("deleteFoul", {Alliance: alliance, TeamId: parseInt(team), RuleId: parseInt(ruleId),
TimeInMatchSec: timeSec});
};
// Cycles through no card, yellow card, and red card.
var cycleCard = function(cardButton) {
var newCard = "";
if ($(cardButton).attr("data-card") === "") {
newCard = "yellow";
} else if ($(cardButton).attr("data-card") === "yellow") {
newCard = "red";
}
websocket.send("card", {Alliance: $(cardButton).attr("data-alliance"),
TeamId: parseInt($(cardButton).attr("data-card-team")), Card: newCard});
$(cardButton).attr("data-card", newCard);
};
// Signals to the volunteers that they may enter the field.
var signalVolunteers = function() {
websocket.send("signalVolunteers");
};
// Signals to the teams that they may enter the field.
var signalReset = function() {
websocket.send("signalReset");
};
// Signals the scorekeeper that foul entry is complete for this match.
var commitMatch = function() {
websocket.send("commitMatch");
};
// Handles a websocket message to update the teams for the current match.
var handleMatchLoad = function(data) {
// Since the server always sends a matchLoad message upon establishing the websocket connection, ignore the first one.
if (!firstMatchLoad) {
location.reload();
}
firstMatchLoad = false;
};
$(function() {
// Activate tooltips above the rule buttons.
$("[data-toggle=tooltip]").tooltip({"placement": "top"});
// Set up the websocket back to the server.
websocket = new CheesyWebsocket("/panels/referee/websocket", {
matchLoad: function(event) { handleMatchLoad(event.data) }
});
clearFoul();
});

View File

@@ -1,159 +0,0 @@
// Copyright 2014 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
//
// Client-side logic for the scoring interface.
var websocket;
var alliance;
// Handles a websocket message to update the teams for the current match.
var handleMatchLoad = function(data) {
$("#matchName").text(data.MatchType + " " + data.Match.DisplayName);
if (alliance === "red") {
$("#team1").text(data.Match.Red1);
$("#team2").text(data.Match.Red2);
$("#team3").text(data.Match.Red3);
} else {
$("#team1").text(data.Match.Blue1);
$("#team2").text(data.Match.Blue2);
$("#team3").text(data.Match.Blue3);
}
};
// Handles a websocket message to update the match status.
var handleMatchTime = function(data) {
switch (matchStates[data.MatchState]) {
case "PRE_MATCH":
// Pre-match message state is set in handleRealtimeScore().
$("#postMatchMessage").hide();
$("#commitMatchScore").hide();
break;
case "POST_MATCH":
$("#postMatchMessage").hide();
$("#commitMatchScore").css("display", "flex");
break;
default:
$("#postMatchMessage").hide();
$("#commitMatchScore").hide();
}
};
// Handles a websocket message to update the realtime scoring fields.
var handleRealtimeScore = function(data) {
var realtimeScore;
if (alliance === "red") {
realtimeScore = data.Red;
} else {
realtimeScore = data.Blue;
}
var score = realtimeScore.Score;
var summary = realtimeScore.ScoreSummary;
for (var i = 0; i < 3; i++) {
var i1 = i + 1;
$("#exitedInitiationLine" + i1 + ">.value").text(score.ExitedInitiationLine[i] ? "Yes" : "No");
$("#exitedInitiationLine" + i1).attr("data-value", score.ExitedInitiationLine[i]);
$("#endgameStatus" + i1 + ">.value").text(getEndgameStatusText(score.EndgameStatuses[i]));
$("#endgameStatus" + i1).attr("data-value", score.EndgameStatuses[i]);
setGoalValue($("#autoCellsInner"), score.AutoCellsInner);
setGoalValue($("#autoCellsOuter"), score.AutoCellsOuter);
setGoalValue($("#autoCellsBottom"), score.AutoCellsBottom);
setGoalValue($("#teleopCellsInner"), score.TeleopCellsInner);
setGoalValue($("#teleopCellsOuter"), score.TeleopCellsOuter);
setGoalValue($("#teleopCellsBottom"), score.TeleopCellsBottom);
}
if (score.ControlPanelStatus >= 1) {
$("#rotationControl>.value").text("Yes");
$("#rotationControl").attr("data-value", true);
} else if (summary.StagePowerCellsRemaining[1] === 0) {
$("#rotationControl>.value").text("Unlocked");
$("#rotationControl").attr("data-value", false);
} else {
$("#rotationControl>.value").text("Disabled (" + summary.StagePowerCellsRemaining[1] + " left)");
$("#rotationControl").attr("data-value", "disabled");
}
if (score.ControlPanelStatus === 2) {
$("#positionControl>.value").text("Yes");
$("#positionControl").attr("data-value", true);
} else if (summary.StagePowerCellsRemaining[2] === 0) {
$("#positionControl>.value").text("Unlocked");
$("#positionControl").attr("data-value", false);
} else {
$("#positionControl>.value").text("Disabled (" + summary.StagePowerCellsRemaining[2] + " left)");
$("#positionControl").attr("data-value", "disabled");
}
$("#rungIsLevel>.value").text(score.RungIsLevel ? "Yes" : "No");
$("#rungIsLevel").attr("data-value", score.RungIsLevel);
$("#controlPanelColor>.value").text(getControlPanelColorText(realtimeScore.ControlPanel.CurrentColor));
$("#controlPanelColor").attr("data-value", realtimeScore.ControlPanel.CurrentColor);
$("#controlPanelColor").attr("data-control-panel-status", score.ControlPanelStatus)
};
// Handles a keyboard event and sends the appropriate websocket message.
var handleKeyPress = function(event) {
websocket.send(String.fromCharCode(event.keyCode));
};
// Handles an element click and sends the appropriate websocket message.
var handleClick = function(shortcut) {
websocket.send(shortcut);
};
// Sends a websocket message to indicate that the score for this alliance is ready.
var commitMatchScore = function() {
websocket.send("commitMatch");
$("#postMatchMessage").css("display", "flex");
$("#commitMatchScore").hide();
};
// Returns the display text corresponding to the given integer endgame status value.
var getEndgameStatusText = function(level) {
switch (level) {
case 1:
return "Park";
case 2:
return "Hang";
default:
return "None";
}
};
// Returns the display text corresponding to the given integer Control Panel color value.
var getControlPanelColorText = function(level) {
switch (level) {
case 1:
return "Red";
case 2:
return "Green";
case 3:
return "Blue";
case 4:
return "Yellow";
default:
return "Unknown";
}
};
// Updates the power cell count for a goal, given the element and score values.
var setGoalValue = function(element, powerCells) {
var total = 0;
$.each(powerCells, function(k, v) {
total += v;
});
element.text(total);
};
$(function() {
alliance = window.location.href.split("/").slice(-1)[0];
$("#alliance").attr("data-alliance", alliance);
// Set up the websocket back to the server.
websocket = new CheesyWebsocket("/panels/scoring/" + alliance + "/websocket", {
matchLoad: function(event) { handleMatchLoad(event.data); },
matchTime: function(event) { handleMatchTime(event.data); },
realtimeScore: function(event) { handleRealtimeScore(event.data); },
});
$(document).keypress(handleKeyPress);
});