A-Z browsing

This commit is contained in:
Claude Brisson
2024-02-28 11:37:49 +01:00
parent 57192f166b
commit a13fea13de
4 changed files with 40 additions and 10 deletions

View File

@@ -203,7 +203,7 @@ fun Tournament.Companion.fromJson(json: Json.Object, default: Tournament<*>? = n
shortName = json.getString("shortName") ?: default?.shortName ?: badRequest("missing shortName"), shortName = json.getString("shortName") ?: default?.shortName ?: badRequest("missing shortName"),
startDate = json.getString("startDate")?.let { LocalDate.parse(it) } ?: default?.startDate ?: badRequest("missing startDate"), startDate = json.getString("startDate")?.let { LocalDate.parse(it) } ?: default?.startDate ?: badRequest("missing startDate"),
endDate = json.getString("endDate")?.let { LocalDate.parse(it) } ?: default?.endDate ?: badRequest("missing endDate"), endDate = json.getString("endDate")?.let { LocalDate.parse(it) } ?: default?.endDate ?: badRequest("missing endDate"),
country = json.getString("country") ?: default?.country ?: badRequest("missing country"), country = (json.getString("country") ?: default?.country ?: "fr").let { if (it.isEmpty()) "fr" else it },
location = json.getString("location") ?: default?.location ?: badRequest("missing location"), location = json.getString("location") ?: default?.location ?: badRequest("missing location"),
online = json.getBoolean("online") ?: default?.online ?: false, online = json.getBoolean("online") ?: default?.online ?: false,
komi = json.getDouble("komi") ?: default?.komi ?: 7.5, komi = json.getDouble("komi") ?: default?.komi ?: 7.5,

View File

@@ -103,12 +103,32 @@ object RatingsManager: Runnable {
if (aga && ratingsHandlers[Ratings.AGA]!!.active) mask = mask or Ratings.AGA.flag if (aga && ratingsHandlers[Ratings.AGA]!!.active) mask = mask or Ratings.AGA.flag
if (egf && ratingsHandlers[Ratings.EGF]!!.active) mask = mask or Ratings.EGF.flag if (egf && ratingsHandlers[Ratings.EGF]!!.active) mask = mask or Ratings.EGF.flag
if (ffg && ratingsHandlers[Ratings.FFG]!!.active) mask = mask or Ratings.FFG.flag if (ffg && ratingsHandlers[Ratings.FFG]!!.active) mask = mask or Ratings.FFG.flag
return if (needle == "*") {
sortedPlayers(mask, country)
} else {
val matches = index.match(needle, mask, country) val matches = index.match(needle, mask, country)
return matches.map { it -> players[it] }.toCollection(Json.MutableArray()) matches.map { it -> players[it] }.toCollection(Json.MutableArray())
}
} finally { } finally {
updateLock.readLock().unlock() updateLock.readLock().unlock()
} }
} }
private fun sortedPlayers(mask: Int, country: String?): Json.Array {
val cntry = country?.let { it.uppercase(Locale.ROOT) }
val orig = Ratings.values().filter { (it.flag and mask) != 0 }.map { it.name }.toSet()
return players.filter {
val player = it as Json.Object
(cntry == null || cntry == player.getString("country")) && orig.contains(player.getString("origin"))
}.sortedWith { a,b ->
val left = a as Json.Object
val right = b as Json.Object
val cmp = left.getString("name")!!.compareTo(right.getString("name")!!)
if (cmp == 0) left.getString("firstname")!!.compareTo(right.getString("firstname")!!)
else cmp
}.toCollection(Json.MutableArray())
}
val index = PlayerIndex() val index = PlayerIndex()
} }

View File

@@ -21,19 +21,19 @@ function searchResultShown() {
function search(needle) { function search(needle) {
needle = needle.trim(); needle = needle.trim();
if (needle && needle.length > 2) { if (needle && (needle === '*' || needle.length > 2)) {
let form = $('#player-form')[0]; let form = $('#player-form')[0];
let search = { let search = {
needle: needle, needle: needle,
aga: form.val('aga'), // aga: form.val('aga'),
egf: form.val('egf'), egf: form.val('egf'),
ffg: form.val('ffg'), ffg: form.val('ffg'),
} }
let country = form.val('countryFilter'); let country = form.val('countryFilter');
if (country) search.countryFilter = country; if (country) search.countryFilter = country;
let searchFormState = { let searchFormState = {
countryFilter: country ? true : false, countryFilter: !!country,
aga: search.aga, // aga: search.aga,
egf: search.egf, egf: search.egf,
ffg: search.ffg ffg: search.ffg
}; };
@@ -92,7 +92,7 @@ function addPlayers() {
let status = form.val('final') || false; let status = form.val('final') || false;
form.reset(); form.reset();
// initial search checkboxes position // initial search checkboxes position
['countryFilter', 'aga', 'egf', 'ffg'].forEach(id => { ['countryFilter', /* 'aga', */ 'egf', 'ffg'].forEach(id => {
let value = store(id); let value = store(id);
let ctl = $(`#${id}`); let ctl = $(`#${id}`);
if (value !== null && typeof(value) !== 'undefined' && ctl.length) { if (value !== null && typeof(value) !== 'undefined' && ctl.length) {
@@ -253,7 +253,7 @@ onLoad(() => {
}); });
let searchFormState = store('searchFormState') let searchFormState = store('searchFormState')
if (searchFormState) { if (searchFormState) {
for (let id of ["countryFilter", "aga", "egf", "ffg"]) { for (let id of ["countryFilter", /* "aga", */ "egf", "ffg"]) {
let ctl = $(`#${id}`); let ctl = $(`#${id}`);
if (ctl.length) { if (ctl.length) {
ctl[0].checked = searchFormState[id]; ctl[0].checked = searchFormState[id];
@@ -410,4 +410,7 @@ onLoad(() => {
})); }));
bulkUpdate(players); bulkUpdate(players);
}); });
$('#browse-players').on('click', e => {
search('*');
});
}); });

View File

@@ -84,12 +84,13 @@
</div> </div>
</div> </div>
#end #end
<div class="ten wide field"> <div class="eight wide field">
<div class="ui icon input"> <div class="ui icon input">
<input id="needle" name="needle" type="text" placeholder="Search..."> <input id="needle" name="needle" type="text" placeholder="Search...">
<i id="clear-search" class="clickable close icon"></i> <i id="clear-search" class="clickable close icon"></i>
</div> </div>
</div> </div>
#* Disabled
<div class="two wide field"> <div class="two wide field">
<div class="toggle"> <div class="toggle">
<input id="aga" name="aga" type="checkbox" value="true"/> <input id="aga" name="aga" type="checkbox" value="true"/>
@@ -99,6 +100,7 @@
<label>AGA</label> <label>AGA</label>
</div> </div>
</div> </div>
*#
<div class="two wide field"> <div class="two wide field">
<div class="toggle"> <div class="toggle">
<input id="egf" name="egf" type="checkbox" checked value="true"/> <input id="egf" name="egf" type="checkbox" checked value="true"/>
@@ -117,6 +119,11 @@
<label>FFG</label> <label>FFG</label>
</div> </div>
</div> </div>
<div class="two wide field">
<button id="browse-players" type="button" class="ui basic icon button">
<i class="sort alphabet down icon"></i>
</button>
</div>
<div id="search-result"></div> <div id="search-result"></div>
</div> </div>
<div class="two stackable fields"> <div class="two stackable fields">