Standings page in progress

This commit is contained in:
Claude Brisson
2023-12-24 15:45:14 +01:00
parent 864ba82b57
commit 31411eb859
15 changed files with 325 additions and 60 deletions

View File

@@ -7,5 +7,40 @@ import com.republicate.kson.Json
*/
class PairgothTool {
public fun toMap(array: Json.Array) = array.map { ser -> ser as Json.Object }.associateBy { it.getLong("id")!! }
fun toMap(array: Json.Array) = array.map { ser -> ser as Json.Object }.associateBy { it.getLong("id")!! }
fun getCriteria() = mapOf(
"NONE" to "No tie break", // No ranking / tie-break
"CATEGORY" to "Category",
"RANK" to "Rank",
"RATING" to "Rating",
"NBW" to "Number of wins", // Number win
"MMS" to "Mac Mahon score", // Macmahon score
"STS" to "Strasbourg score", // Strasbourg score
"CPS" to "Cup score", // Cup score
"SOSW" to "Sum of opponents wins", // Sum of opponents NBW
"SOSWM1" to "Sum of opponents wins minus 1", //-1
"SOSWM2" to "Sum of opponents wins minus 2", //-2
"SODOSW" to "Sum of defeated opponents wins", // Sum of defeated opponents NBW
"SOSOSW" to "Sum of opponents SOSW", // Sum of opponent SOS
"CUSSW" to "Cumulative sum of opponents wins", // Cumulative sum of scores (NBW)
"SOSM" to "Sum of opponents Mac Mahon score", // Sum of opponents McMahon score
"SOSMM1" to "Sum of opponents Mac Mahon score minus 1", // Same as previous group but with McMahon score
"SOSMM2" to "Sum of opponents Mac Mahon score minus 2",
"SODOSM" to "Sum of defeated opponents Mac Mahon score",
"SOSOSM" to "Sum of opponents SOSM",
"CUSSM" to "Cumulative sum of opponents Mac Mahon score",
"SOSTS" to "Sum of opponents Strasbourg score", // Sum of opponnents Strasbourg score
"EXT" to "Attempted achievements", // Exploits tentes
"EXR" to "Succeeded achievements", // Exploits reussis
// For the two criteria below see the user documentation
"SDC" to "Simplified direct confrontation", // Simplified direct confrontation
"DC" to "Direct confrontation", // Direct confrontation
)
}

View File

@@ -11,6 +11,11 @@
}
}
.active-round-box {
padding: 1em;
font-weight: bold;
}
/* information section */
form {
@@ -232,4 +237,32 @@
}
}
/* standings section */
#standings-params {
display: inline-flex;
flex-flow: row wrap;
justify-content: center;
background-color: #eeeeee;
margin-left: auto;
margin-right: auto;
.criterium {
position: relative;
cursor: pointer;
select {
position: absolute;
top: 100%;
z-index: 2;
&.active {
display: initial;
}
}
select.active {
}
}
#params-submit {
justify-content: space-around;
}
}
}

View File

@@ -0,0 +1,42 @@
onLoad(() => {
$('.criterium').on('click', e => {
let alreadyOpen = e.target.closest('select');
if (alreadyOpen) return;
let select = e.target.closest('.criterium').find('select');
$('.criterium select').removeClass('active');
select.toggleClass('active');
});
document.on('click', e => {
let crit = e.target.closest('.criterium');
if (!crit) $('.criterium select').removeClass('active');
});
$('.criterium select').on('input', e => {
let select = e.target.closest('select');
let info = select.previousElementSibling;
info.textContent = select.selectedOptions[0].value;
$('.criterium select').removeClass('active');
$('#params-submit').removeClass('hidden');
});
$('#params-form .cancel.button').on('click', e => {
$('.criterium select').removeClass('active').forEach(elem => {
elem.value = elem.data('initial');
elem.previousElementSibling.textContent = elem.value;
});
$('#params-submit').addClass('hidden');
});
$('#params-form').on('submit', e => {
if (!$('#params-submit').hasClass('hidden')) {
api.putJson(`tour/${tour_id}`, {
pairing: {
placement: $('.criterium select').map(elem => elem.value)
}
}).then(rst => {
if (rst !== 'error') {
document.location.reload();
}
})
}
e.preventDefault();
return false;
});
});

View File

@@ -15,7 +15,7 @@
#end
<div class="tab-content" id="pairing">
<div id="pairing-content">
<div id="pairing-round">
<div id="pairing-round" class="active-round"-box>
Pairings for round
<button class="ui floating choose-round prev-round button">&laquo;</button>
<span class="active-round">$round</span>

View File

@@ -1,5 +1,5 @@
<div class="tab-content" id="results">
<div id="results-round">
<div id="results-round" class="active-round-box">
Results for round
<button class="ui floating choose-round prev-round button">&laquo;</button>
<span class="active-round">$round</span>

View File

@@ -1,3 +1,52 @@
#macro(placement $i, $p)
<span class="info"></span>
<select name="crit-$i" data-initial="$p" class="short-value">
#foreach($crit in $$utils.criteria.entrySet())
<option value="$crit.key" data-tooltip="$crit.value" #if($p == $crit.key)selected#end>$crit.key - $crit.value</option>
#end
</select>
#end
<div class="tab-content" id="standings">
Standings...
<div id="standings-round" class="active-round-box">
Standings after round
<button class="ui floating choose-round prev-round button">&laquo;</button>
<span class="active-round">$round</span>
<button class="ui floating choose-round next-round button">&raquo;</button>
</div>
<div id="standings-params" class="roundbox">
<form id="params-form" class="ui form">
<div class="inline fields">
#foreach($placement in $tour.pairing.placement)
<div class="criterium field">
#set($num = $foreach.index + 1)
<label>Criterium #$num</label>
#placement($num $placement)
</div>
#end
</div>
<div id="params-submit" class="hidden centered inline fields">
<button type="button" class="ui gray floating cancel button">Cancel</button>
<button type="submit" class="ui blue floating button">Change</button>
</div>
</form>
</div>
<div id="standings-container" class="roundbox">
#set($standings = $api.get("tour/${params.id}/standings/$round"))
#if($standings.isObject() && ($standings.error || $standings.message))
#if($standings.error)
#set($error = $standings.error)
#else
#set($error = $standings.message)
#end
<script type="text/javascript">
onLoad(() => {
showError("$error")
});
</script>
#set($standings = [])
#end
#foreach($line in $standings)
<div class="standings-line">$line</div>
#end
</div>
</div>

View File

@@ -132,7 +132,11 @@
if (input.tagName === 'SELECT') {
let sel = input.selectedOptions;
if (sel && sel.length === 1) {
info.textContent = sel[0].textContent;
let txt = sel[0].textContent
if (input.hasClass('short-value')) {
txt = txt.replace(/ - .*$/, '');
}
info.textContent = txt;
}
} else {
if (input.attr('name') === 'location' && $('input[name="online"]')[0].checked) {
@@ -169,6 +173,7 @@
#include('/js/tour-registration.inc.js')
#include('/js/tour-pairing.inc.js')
#include('/js/tour-results.inc.js')
#include('/js/tour-standings.inc.js')
</script>
<div id="invalid_character" class="hidden">Invalid character</div>
<script type="text/javascript" src="/lib/datepicker-1.3.4/datepicker-full.min.js"></script>