From d0ff355c11832b69f1ad26b310960c4c16115346 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Sat, 20 Jan 2024 10:27:00 +0100 Subject: [PATCH] Persistent table sort on registration page --- view-webapp/src/main/sass/main.scss | 2 +- view-webapp/src/main/webapp/js/main.js | 1 - .../main/webapp/js/tour-information.inc.js | 1 - .../main/webapp/js/tour-registration.inc.js | 41 ++++++++++++++++++- .../src/main/webapp/js/tour-results.inc.js | 2 - .../lib/tablesort-5.4.0/tablesort.min.js | 7 +--- .../main/webapp/tour-registration.inc.html | 5 ++- .../src/main/webapp/tour-standings.inc.html | 2 +- 8 files changed, 45 insertions(+), 16 deletions(-) diff --git a/view-webapp/src/main/sass/main.scss b/view-webapp/src/main/sass/main.scss index 8d97404..09651bf 100644 --- a/view-webapp/src/main/sass/main.scss +++ b/view-webapp/src/main/sass/main.scss @@ -359,7 +359,7 @@ cursor: pointer; } - thead { + thead th { position: sticky; top: 0; } diff --git a/view-webapp/src/main/webapp/js/main.js b/view-webapp/src/main/webapp/js/main.js index 6ff4174..f416440 100644 --- a/view-webapp/src/main/webapp/js/main.js +++ b/view-webapp/src/main/webapp/js/main.js @@ -200,7 +200,6 @@ onLoad(() => { close_modal(); } } else if (tab === '#pairing') { - console.log('here') $('#pairing-lists .selected.listitem').removeClass('selected'); } break; diff --git a/view-webapp/src/main/webapp/js/tour-information.inc.js b/view-webapp/src/main/webapp/js/tour-information.inc.js index 09a6995..5723567 100644 --- a/view-webapp/src/main/webapp/js/tour-information.inc.js +++ b/view-webapp/src/main/webapp/js/tour-information.inc.js @@ -118,7 +118,6 @@ onLoad(() => { $('#tournament-infos').on('submit', e => { e.preventDefault(); let form = e.target; - console.log(form.val('country')); let tour = { name: form.val('name'), shortName: form.val('shortName'), diff --git a/view-webapp/src/main/webapp/js/tour-registration.inc.js b/view-webapp/src/main/webapp/js/tour-registration.inc.js index ed562e1..27b04c1 100644 --- a/view-webapp/src/main/webapp/js/tour-registration.inc.js +++ b/view-webapp/src/main/webapp/js/tour-registration.inc.js @@ -73,6 +73,7 @@ function fillPlayer(player) { let form = $('#player-form')[0]; form.val('name', player.name); form.val('firstname', player.firstname); + console.log(country); form.val('country', country); form.val('club', player.club); form.val('rank', parseRank(player.rank)); @@ -83,6 +84,8 @@ function fillPlayer(player) { $('#register').focus(); } +let tableSort; + onLoad(() => { $('input.numeric').imask({ mask: Number, @@ -90,7 +93,37 @@ onLoad(() => { min: 0, max: 4000 }); - new Tablesort($('#players')[0]); + + let prevSort = store('registrationSort'); + if (prevSort) { + let columns = $('#players thead th'); + columns.forEach(th => { + th.removeAttribute('data-sort-default'); + th.removeAttribute('aria-sort'); + }) + prevSort.forEach(i => { + let col = columns[Math.abs(i)]; + col.setAttribute('data-sort-default', '1'); + if (i < 0) { + // take into account TableSort initiailization bug + col.setAttribute('aria-sort', 'ascending'); + } + }); + } + tableSort = new Tablesort($('#players')[0]); + $('#players').on('afterSort', e => { + let sort = []; + $('#players thead th').forEach((th, i) => { + let attr = th.attr('aria-sort'); + if (attr) { + let dir = i; + if (attr === 'descending') dir = -dir; + sort.push(dir); + } + }); + store('registrationSort', sort); + }); + $('#add').on('click', e => { let form = $('#player-form')[0]; form.addClass('add'); @@ -110,6 +143,7 @@ onLoad(() => { }); $('#register').on('click', e => { + console.log("clicked") let form = e.target.closest('form'); let valid = true; let required = ['name', 'firstname', 'country', 'club', 'rank', 'rating']; @@ -128,6 +162,7 @@ onLoad(() => { $('#player-form')[0].dispatchEvent(new CustomEvent('submit', {cancelable: true})); }); $('#player-form').on('submit', e => { + console.log("submit") e.preventDefault(); let form = $('#player-form')[0]; let player = { @@ -143,6 +178,7 @@ onLoad(() => { if (form.hasClass('add')) { api.postJson(`tour/${tour_id}/part`, player) .then(player => { + console.log(player) if (player !== 'error') { window.location.reload(); } @@ -152,6 +188,7 @@ onLoad(() => { player['id'] = id; api.putJson(`tour/${tour_id}/part/${id}`, player) .then(player => { + console.log(player) if (player !== 'error') { window.location.reload(); } @@ -171,7 +208,7 @@ onLoad(() => { form.val('firstname', player.firstname); form.val('rating', player.rating); form.val('rank', player.rank); - form.val('country', player.country); + form.val('country', player.country.toLowerCase()); form.val('club', player.club); form.val('final', player.final); if (player.final) $('#final-reg').addClass('final'); diff --git a/view-webapp/src/main/webapp/js/tour-results.inc.js b/view-webapp/src/main/webapp/js/tour-results.inc.js index 5611892..9a76861 100644 --- a/view-webapp/src/main/webapp/js/tour-results.inc.js +++ b/view-webapp/src/main/webapp/js/tour-results.inc.js @@ -38,9 +38,7 @@ onLoad(()=>{ let gameId = e.target.closest('tr').data('id'); let result = cell.data('result'); let index = results.indexOf(result); - console.log(index) result = results[(index + 1)%results.length]; - console.log(result) setResult(gameId, result); }); }); diff --git a/view-webapp/src/main/webapp/lib/tablesort-5.4.0/tablesort.min.js b/view-webapp/src/main/webapp/lib/tablesort-5.4.0/tablesort.min.js index 6fb74cb..f7cc8d0 100644 --- a/view-webapp/src/main/webapp/lib/tablesort-5.4.0/tablesort.min.js +++ b/view-webapp/src/main/webapp/lib/tablesort-5.4.0/tablesort.min.js @@ -1,6 +1 @@ -/*! - * tablesort v5.4.0 (2023-05-04) - * http://tristen.ca/tablesort/demo/ - * Copyright (c) 2023 ; Licensed MIT -*/ -!function(){function r(t,e){if(!(this instanceof r))return new r(t,e);if(!t||"TABLE"!==t.tagName)throw new Error("Element must be a table");this.init(t,e||{})}function m(t){var e;return window.CustomEvent&&"function"==typeof window.CustomEvent?e=new CustomEvent(t):(e=document.createEvent("CustomEvent")).initCustomEvent(t,!1,!1,void 0),e}function p(t,e){return t.getAttribute(e.sortAttribute||"data-sort")||t.textContent||t.innerText||""}function v(t,e){return(t=t.trim().toLowerCase())===(e=e.trim().toLowerCase())?0:t0)if(e.tHead&&e.tHead.rows.length>0){for(s=0;s0&&p.push(c),d++;if(!p)return}for(d=0;dCountry Club Rank - Rating - Participation + ## TableSort bug which inverts specified sort... + Rating + Participation #foreach($part in $parts) diff --git a/view-webapp/src/main/webapp/tour-standings.inc.html b/view-webapp/src/main/webapp/tour-standings.inc.html index 9194f5c..0871ad5 100644 --- a/view-webapp/src/main/webapp/tour-standings.inc.html +++ b/view-webapp/src/main/webapp/tour-standings.inc.html @@ -66,7 +66,7 @@ $part.num $part.place $part.name $part.firstname - #rank($part.rank) + #rank($part.rank) $part.country $number.format('0.#', $part.NBW) #set($mx = $round - 1)