From 49a6b8de38b359e51b73630d58949eee1f622431 Mon Sep 17 00:00:00 2001 From: MaxJa4 <74194322+MaxJa4@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:01:51 +0100 Subject: [PATCH] Sync both clan lists. --- controllers/clan_controller.go | 15 ++++ isc_data.db | Bin 16384 -> 16384 bytes isc_rest.log | 106 ++++++++++++++++++++++++ main.go | 1 + static/index.js | 25 ++++++ templates/components/header.html | 1 + templates/components/home_clan_bar.html | 14 +--- templates/components/opp_clan_bar.html | 13 +-- templates/modals/add_clan.html | 17 ++-- templates/modals/delete_clan.html | 25 ++++-- templates/modals/edit_clan.html | 18 ++-- 11 files changed, 193 insertions(+), 42 deletions(-) create mode 100644 static/index.js diff --git a/controllers/clan_controller.go b/controllers/clan_controller.go index e8ab648..23572de 100644 --- a/controllers/clan_controller.go +++ b/controllers/clan_controller.go @@ -31,6 +31,21 @@ func GetAllClans(c *gin.Context) { c.JSON(http.StatusOK, clans) } +// GetAllClanOptions GET /clan_options +func GetAllClanOptions(c *gin.Context) { + var clans []models.Clan + models.DB.Find(&clans) + + var htmlOptions string + htmlOptions = `Auswählen...` + for _, clan := range clans { + htmlOptions += fmt.Sprintf(`[%s] %s`, clan.ID, clan.Tag, clan.Name) + } + + c.Header("Content-Type", "text/html") + c.String(http.StatusOK, htmlOptions) +} + // AddClan POST /clan func AddClan(c *gin.Context) { var input AddClanInput diff --git a/isc_data.db b/isc_data.db index 98c0d09f3a2bb4b3ade1c339a7dd855f4f1eb40e..133885f34d053dbe286bc98698bb9c0aaf1f3bfe 100644 GIT binary patch delta 540 zcmZut%}T>S5S|o+5lOd&{utBzlv*Mb!DJsn=mYo!E^PPc!3~HYG(Lc!6mj`T$-8XSS$RwFzzMq*)QCLM`-T2n{ws&NW=O;6ky+DmEfGyb5Z@8~j zJi7nH{Oa1BhCLg&=Ljv87E&px(u}7(OF89?w|pD?z~DlwHLc!+O@HV#0~zAy1J2ngu!O~39LJKvON@_tg6kaBQQ;E(eXHqMzFyj+neN6nWB2+BYWb89qmeS&dft@y41QXvOj^ z3^$PXP`-z|RNR$Glu&V69!Kf)9=7{~EiIaL#%$!X delta 265 zcmZo@U~Fh$oFL68I#I@%QFLR%B7TJ?22Q?94E%5S=kcfT`|(@xEAzARJ?FawgPR2v z=JII>GO{wrigG3vr=%GIL0U?2qA)KjgS0efYI$l=VQLYOEC*7PpUcTH$#748DJR1s z%EihsSzTV8MT7&$2$DCf-^3uJsLWZM2-KdE1|&hofiMsWv9dCV%W@Pa0(l?;B+S6T zU0ksPOohy%Ut})2HybPO}6#nuv@-8wE F003)0NtOTr diff --git a/isc_rest.log b/isc_rest.log index 0fdf4c4..84cc2c7 100644 --- a/isc_rest.log +++ b/isc_rest.log @@ -52,3 +52,109 @@ Deleted clan 'safdsdfafd' with tag 'asdfasdfsdf' [GIN] 2024/01/14 - 21:49:32 | 200 | 75.1µs | 127.0.0.1 | GET "/players" [GIN] 2024/01/14 - 21:50:57 | 200 | 1.1241ms | 127.0.0.1 | GET "/" [GIN] 2024/01/14 - 22:05:47 | 200 | 1.1526ms | 127.0.0.1 | GET "/" +[GIN] 2024/01/15 - 09:55:07 | 200 | 2.5532ms | ::1 | GET "/" +[GIN] 2024/01/15 - 09:55:07 | 200 | 31.8818ms | ::1 | GET "/static/index.css" +[GIN] 2024/01/15 - 09:55:07 | 404 | 0s | ::1 | GET "/favicon.ico" +[GIN] 2024/01/15 - 09:55:19 | 200 | 79.4µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 09:56:19 | 200 | 1.0013ms | ::1 | GET "/" +[GIN] 2024/01/15 - 09:56:19 | 200 | 548.6µs | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 09:56:20 | 200 | 187.6µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 09:56:22 | 200 | 687.1µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 09:56:23 | 200 | 1.0003ms | ::1 | GET "/" +[GIN] 2024/01/15 - 09:59:53 | 200 | 0s | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:00:08 | 200 | 848.8µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:02:47 | 200 | 1.295ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:02:47 | 304 | 0s | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:02:52 | 200 | 785.3µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:03:16 | 200 | 1.4718ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:03:17 | 200 | 2.6971ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:03:18 | 200 | 0s | ::1 | GET "/" +[GIN] 2024/01/15 - 10:03:23 | 200 | 695µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:07:23 | 200 | 999.7µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:07:23 | 304 | 0s | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:07:26 | 200 | 966µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:07:35 | 200 | 1.1975ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:07:58 | 200 | 921.1µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:08:18 | 200 | 504µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:08:20 | 200 | 738.1µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:08:20 | 200 | 32.1015ms | ::1 | GET "/static/index.css" +[GIN] 2024/01/15 - 10:08:20 | 200 | 32.1015ms | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:08:21 | 404 | 0s | ::1 | GET "/favicon.ico" +[GIN] 2024/01/15 - 10:08:23 | 200 | 1.0003ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:09:12 | 200 | 393.6µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:24 | 200 | 386.1µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:09:36 | 200 | 249.7µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:38 | 200 | 728.4µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:39 | 200 | 510.8µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:50 | 200 | 938.7µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:55 | 200 | 101.5µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:59 | 200 | 552.2µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:14:57 | 200 | 1.3826ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:14:57 | 304 | 0s | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:15:03 | 200 | 614.5µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:15:14 | 200 | 345.9µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:15:46 | 200 | 1.5371ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:15:46 | 200 | 32.727ms | ::1 | GET "/static/index.css" +[GIN] 2024/01/15 - 10:15:46 | 200 | 32.727ms | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:15:47 | 404 | 0s | ::1 | GET "/favicon.ico" +[GIN] 2024/01/15 - 10:15:53 | 200 | 142.4µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:16:11 | 200 | 1.0272ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:16:16 | 200 | 849.7µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:18:18 | 200 | 427.3µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:18:18 | 304 | 301.7µs | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:18:18 | 200 | 541.7µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:18:25 | 200 | 1.4775ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:18:25 | 200 | 937.3µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:03 | 200 | 1.0007ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:19:03 | 200 | 603.9µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:03 | 200 | 71.5µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:08 | 200 | 999.9µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:19:08 | 200 | 831.5µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:08 | 200 | 1.254ms | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:08 | 200 | 1.9087ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:19:08 | 200 | 211.1µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:08 | 200 | 403µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:09 | 200 | 607.6µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:19:09 | 200 | 226.1µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:09 | 200 | 146.4µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:13 | 200 | 1.3485ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:19:13 | 200 | 938.6µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:13 | 200 | 1.0501ms | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:26:17 | 200 | 516.5µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:26:17 | 304 | 581.2µs | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:26:18 | 200 | 552µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:26:18 | 200 | 379.7µs | ::1 | GET "/clan_options" +Added clan 'testinger' with tag 'asd' +[GIN] 2024/01/15 - 10:26:24 | 200 | 2.1851ms | ::1 | POST "/clan" +[GIN] 2024/01/15 - 10:26:24 | 200 | 551.3µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:27:54 | 200 | 1.4677ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:27:54 | 200 | 520.6µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:27:54 | 200 | 471µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:27:57 | 200 | 764.4µs | ::1 | GET "/players" +Deleted clan 'testinger' with tag 'asd' +[GIN] 2024/01/15 - 10:27:58 | 200 | 1.8567ms | ::1 | DELETE "/clan/14" +[GIN] 2024/01/15 - 10:27:58 | 200 | 940.8µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:27:59 | 200 | 950.2µs | ::1 | GET "/players" +Deleted clan 'ewerqer' with tag 'werwqer' +[GIN] 2024/01/15 - 10:28:01 | 200 | 18.0168ms | ::1 | DELETE "/clan/13" +[GIN] 2024/01/15 - 10:28:01 | 200 | 112µs | ::1 | GET "/players" +Deleted clan 'ewerqer' with tag 'werwqer' +[GIN] 2024/01/15 - 10:28:01 | 200 | 31.2637ms | ::1 | DELETE "/clan/13" +[GIN] 2024/01/15 - 10:28:01 | 200 | 999.4µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:28:03 | 200 | 1.2154ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:28:03 | 200 | 519µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:28:03 | 200 | 1.103ms | ::1 | GET "/clan_options" +Added clan '12333' with tag '12333' +[GIN] 2024/01/15 - 10:28:08 | 200 | 2.6491ms | ::1 | POST "/clan" +[GIN] 2024/01/15 - 10:28:08 | 200 | 966.7µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:30:21 | 200 | 1.0749ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:30:21 | 304 | 362.4µs | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:30:21 | 200 | 993.8µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:30:21 | 200 | 167.3µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:30:24 | 200 | 962.3µs | ::1 | GET "/players" +Added clan 'zrdz' with tag 'zrdz' +[GIN] 2024/01/15 - 10:30:28 | 200 | 1.3631ms | ::1 | POST "/clan" +[GIN] 2024/01/15 - 10:30:28 | 200 | 0s | ::1 | GET "/players" +Added clan 'zrdz' with tag 'zrdz' +[GIN] 2024/01/15 - 10:30:28 | 200 | 7.0468ms | ::1 | POST "/clan" +[GIN] 2024/01/15 - 10:30:28 | 200 | 489.7µs | ::1 | GET "/players" diff --git a/main.go b/main.go index b1f2692..cbf1b94 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,7 @@ func main() { }) router.GET("/clans", controllers.GetAllClans) + router.GET("/clan_options", controllers.GetAllClanOptions) router.GET("/clan/:id", controllers.GetClanByID) router.POST("/clan", controllers.AddClan) router.PATCH("/clan/:id", controllers.UpdateClanByID) diff --git a/static/index.js b/static/index.js new file mode 100644 index 0000000..bb2c1fd --- /dev/null +++ b/static/index.js @@ -0,0 +1,25 @@ +function setupClanButtons(dropdownId, delBtnId, editBtnId) { + const dropdown = document.getElementById(dropdownId); + const deleteButton = document.getElementById(delBtnId); + const editButton = document.getElementById(editBtnId); + + dropdown.addEventListener('change', function () { + deleteButton.disabled = !this.value; + editButton.disabled = !this.value; + }); +} + +function getClanLists(event) { + const button = event.relatedTarget; + const clanListId = button.getAttribute('data-bs-list'); + const clanList = document.querySelector(clanListId); + + let otherClanListId; + if (clanListId === '#home-clan') + otherClanListId = '#opponent-clan' + else + otherClanListId = '#home-clan' + const otherClanList = document.querySelector(otherClanListId); + + return [clanList, otherClanList]; +} \ No newline at end of file diff --git a/templates/components/header.html b/templates/components/header.html index 6eee6f3..ec06537 100644 --- a/templates/components/header.html +++ b/templates/components/header.html @@ -4,6 +4,7 @@ Infantry Skill Calculator + diff --git a/templates/components/home_clan_bar.html b/templates/components/home_clan_bar.html index 6226a64..c217087 100644 --- a/templates/components/home_clan_bar.html +++ b/templates/components/home_clan_bar.html @@ -8,9 +8,7 @@ Auswählen... - {{ range .clans }} - [{{ .Tag }}] {{ .Name }} - {{ end }} + @@ -27,14 +25,8 @@ diff --git a/templates/components/opp_clan_bar.html b/templates/components/opp_clan_bar.html index 259c789..2f44920 100644 --- a/templates/components/opp_clan_bar.html +++ b/templates/components/opp_clan_bar.html @@ -8,9 +8,6 @@ Auswählen... - {{ range .clans }} - [{{ .Tag }}] {{ .Name }} - {{ end }} @@ -27,14 +24,8 @@ diff --git a/templates/modals/add_clan.html b/templates/modals/add_clan.html index bc89287..771e325 100644 --- a/templates/modals/add_clan.html +++ b/templates/modals/add_clan.html @@ -36,10 +36,11 @@ if (addClanModal) { addClanModal.addEventListener('shown.bs.modal', event => { const submitButton = addClanModal.querySelector('button[name="submit"]'); - submitButton.addEventListener('click', function () { - const button = event.relatedTarget; - const clanListId = button.getAttribute('data-bs-list'); - const clanList = document.querySelector(clanListId); + submitButton.addEventListener('click', function (e) { + e.preventDefault(); + submitButton.onclick = function () {} + + const [clanList, otherClanList] = getClanLists(event); const clanName = addClanModal.querySelector('#clanName'); const clanTag = addClanModal.querySelector('#clanTag'); @@ -61,9 +62,15 @@ const opt = document.createElement('option'); opt.innerText = "[" + clanTag.value + "]" + " " + clanName.value; opt.value = response.json()['ID']; - clanList.appendChild(opt); + + clanList.appendChild(opt.cloneNode(true)); clanList.selectedIndex = clanList.children.length - 1; clanList.dispatchEvent(new Event('change')); + + const lastIndex = otherClanList.selectedIndex; + otherClanList.appendChild(opt); + otherClanList.selectedIndex = lastIndex; + addClanModalBS.hide(); clanName.value = ""; clanTag.value = ""; diff --git a/templates/modals/delete_clan.html b/templates/modals/delete_clan.html index 8e47a78..aed3954 100644 --- a/templates/modals/delete_clan.html +++ b/templates/modals/delete_clan.html @@ -26,19 +26,16 @@ const deleteClanModalBS = new bootstrap.Modal('#deleteClanModal'); if (deleteClanModal) { deleteClanModal.addEventListener('show.bs.modal', event => { - const button = event.relatedTarget; - const clanListId = button.getAttribute('data-bs-list'); - const clanList = document.querySelector(clanListId); - const selectedClan = clanList.options[clanList.selectedIndex].text; + const [clanList, otherClanList] = getClanLists(event); + const selectedClan = clanList.options[clanList.selectedIndex].text; const modalBodyInput = deleteClanModal.querySelector('#clan'); modalBodyInput.innerText = selectedClan; const submitButton = deleteClanModal.querySelector('button[name="submit"]'); - submitButton.addEventListener('click', function () { - const button = event.relatedTarget; - const clanListId = button.getAttribute('data-bs-list'); - const clanList = document.querySelector(clanListId); + submitButton.addEventListener('click', function (e) { + e.preventDefault(); + submitButton.onclick = function () {} const clanId = parseInt(clanList.value); @@ -50,9 +47,19 @@ }) .then((response) => { if (response.ok) { - clanList.removeChild(clanList.children[clanList.selectedIndex]); + const clanToRemove = clanList.children[clanList.selectedIndex]; + const clanIndex = clanToRemove.index; + clanList.removeChild(clanToRemove); clanList.selectedIndex = 0; clanList.dispatchEvent(new Event('change')); + + const lastOtherIndex = otherClanList.selectedIndex; + otherClanList.children.item(clanIndex).remove(); + if (lastOtherIndex === clanIndex) { + otherClanList.selectedIndex = 0; + otherClanList.dispatchEvent(new Event('change')); + } + deleteClanModalBS.hide(); } else throw new Error(response.error) diff --git a/templates/modals/edit_clan.html b/templates/modals/edit_clan.html index 28900d8..5539d37 100644 --- a/templates/modals/edit_clan.html +++ b/templates/modals/edit_clan.html @@ -37,10 +37,11 @@ const editClanModalBS = new bootstrap.Modal('#editClanModal'); if (editClanModal) { editClanModal.addEventListener('show.bs.modal', event => { - const button = event.relatedTarget; - const clanListId = button.getAttribute('data-bs-list'); - const clanList = document.querySelector(clanListId); - const selectedClanItem = clanList.options[clanList.selectedIndex]; + const [clanList, otherClanList] = getClanLists(event); + + const selectedClanIndex = clanList.selectedIndex; + const selectedClanItem = clanList.options[selectedClanIndex]; + const otherSelClanItem = otherClanList.options[selectedClanIndex]; const clanName = editClanModal.querySelector('#editClanName'); const clanTag = editClanModal.querySelector('#editClanTag'); @@ -66,7 +67,9 @@ throw new Error(error); }); - submitButton.addEventListener('click', function () { + submitButton.addEventListener('click', function (e) { + e.preventDefault(); + submitButton.onclick = function () {} fetch("/clan/" + clanId, { method: "PATCH", body: JSON.stringify({ @@ -80,7 +83,10 @@ }) .then((response) => { if (response.ok) { - selectedClanItem.innerText = "[" + clanTag.value + "]" + " " + clanName.value; + const newName = "[" + clanTag.value + "]" + " " + clanName.value; + selectedClanItem.innerText = newName; + otherSelClanItem.innerText = newName; + editClanModalBS.hide(); clanName.value = ""; clanTag.value = "";
neN6nWB2+BYWb89qmeS&dft@y41QXvOj^ z3^$PXP`-z|RNR$Glu&V69!Kf)9=7{~EiIaL#%$!X delta 265 zcmZo@U~Fh$oFL68I#I@%QFLR%B7TJ?22Q?94E%5S=kcfT`|(@xEAzARJ?FawgPR2v z=JII>GO{wrigG3vr=%GIL0U?2qA)KjgS0efYI$l=VQLYOEC*7PpUcTH$#748DJR1s z%EihsSzTV8MT7&$2$DCf-^3uJsLWZM2-KdE1|&hofiMsWv9dCV%W@Pa0(l?;B+S6T zU0ksPOohy%Ut})2HybPO}6#nuv@-8wE F003)0NtOTr diff --git a/isc_rest.log b/isc_rest.log index 0fdf4c4..84cc2c7 100644 --- a/isc_rest.log +++ b/isc_rest.log @@ -52,3 +52,109 @@ Deleted clan 'safdsdfafd' with tag 'asdfasdfsdf' [GIN] 2024/01/14 - 21:49:32 | 200 | 75.1µs | 127.0.0.1 | GET "/players" [GIN] 2024/01/14 - 21:50:57 | 200 | 1.1241ms | 127.0.0.1 | GET "/" [GIN] 2024/01/14 - 22:05:47 | 200 | 1.1526ms | 127.0.0.1 | GET "/" +[GIN] 2024/01/15 - 09:55:07 | 200 | 2.5532ms | ::1 | GET "/" +[GIN] 2024/01/15 - 09:55:07 | 200 | 31.8818ms | ::1 | GET "/static/index.css" +[GIN] 2024/01/15 - 09:55:07 | 404 | 0s | ::1 | GET "/favicon.ico" +[GIN] 2024/01/15 - 09:55:19 | 200 | 79.4µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 09:56:19 | 200 | 1.0013ms | ::1 | GET "/" +[GIN] 2024/01/15 - 09:56:19 | 200 | 548.6µs | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 09:56:20 | 200 | 187.6µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 09:56:22 | 200 | 687.1µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 09:56:23 | 200 | 1.0003ms | ::1 | GET "/" +[GIN] 2024/01/15 - 09:59:53 | 200 | 0s | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:00:08 | 200 | 848.8µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:02:47 | 200 | 1.295ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:02:47 | 304 | 0s | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:02:52 | 200 | 785.3µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:03:16 | 200 | 1.4718ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:03:17 | 200 | 2.6971ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:03:18 | 200 | 0s | ::1 | GET "/" +[GIN] 2024/01/15 - 10:03:23 | 200 | 695µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:07:23 | 200 | 999.7µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:07:23 | 304 | 0s | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:07:26 | 200 | 966µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:07:35 | 200 | 1.1975ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:07:58 | 200 | 921.1µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:08:18 | 200 | 504µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:08:20 | 200 | 738.1µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:08:20 | 200 | 32.1015ms | ::1 | GET "/static/index.css" +[GIN] 2024/01/15 - 10:08:20 | 200 | 32.1015ms | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:08:21 | 404 | 0s | ::1 | GET "/favicon.ico" +[GIN] 2024/01/15 - 10:08:23 | 200 | 1.0003ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:09:12 | 200 | 393.6µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:24 | 200 | 386.1µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:09:36 | 200 | 249.7µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:38 | 200 | 728.4µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:39 | 200 | 510.8µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:50 | 200 | 938.7µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:55 | 200 | 101.5µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:09:59 | 200 | 552.2µs | ::1 | GET "/clans" +[GIN] 2024/01/15 - 10:14:57 | 200 | 1.3826ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:14:57 | 304 | 0s | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:15:03 | 200 | 614.5µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:15:14 | 200 | 345.9µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:15:46 | 200 | 1.5371ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:15:46 | 200 | 32.727ms | ::1 | GET "/static/index.css" +[GIN] 2024/01/15 - 10:15:46 | 200 | 32.727ms | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:15:47 | 404 | 0s | ::1 | GET "/favicon.ico" +[GIN] 2024/01/15 - 10:15:53 | 200 | 142.4µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:16:11 | 200 | 1.0272ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:16:16 | 200 | 849.7µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:18:18 | 200 | 427.3µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:18:18 | 304 | 301.7µs | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:18:18 | 200 | 541.7µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:18:25 | 200 | 1.4775ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:18:25 | 200 | 937.3µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:03 | 200 | 1.0007ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:19:03 | 200 | 603.9µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:03 | 200 | 71.5µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:08 | 200 | 999.9µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:19:08 | 200 | 831.5µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:08 | 200 | 1.254ms | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:08 | 200 | 1.9087ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:19:08 | 200 | 211.1µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:08 | 200 | 403µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:09 | 200 | 607.6µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:19:09 | 200 | 226.1µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:09 | 200 | 146.4µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:13 | 200 | 1.3485ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:19:13 | 200 | 938.6µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:19:13 | 200 | 1.0501ms | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:26:17 | 200 | 516.5µs | ::1 | GET "/" +[GIN] 2024/01/15 - 10:26:17 | 304 | 581.2µs | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:26:18 | 200 | 552µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:26:18 | 200 | 379.7µs | ::1 | GET "/clan_options" +Added clan 'testinger' with tag 'asd' +[GIN] 2024/01/15 - 10:26:24 | 200 | 2.1851ms | ::1 | POST "/clan" +[GIN] 2024/01/15 - 10:26:24 | 200 | 551.3µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:27:54 | 200 | 1.4677ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:27:54 | 200 | 520.6µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:27:54 | 200 | 471µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:27:57 | 200 | 764.4µs | ::1 | GET "/players" +Deleted clan 'testinger' with tag 'asd' +[GIN] 2024/01/15 - 10:27:58 | 200 | 1.8567ms | ::1 | DELETE "/clan/14" +[GIN] 2024/01/15 - 10:27:58 | 200 | 940.8µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:27:59 | 200 | 950.2µs | ::1 | GET "/players" +Deleted clan 'ewerqer' with tag 'werwqer' +[GIN] 2024/01/15 - 10:28:01 | 200 | 18.0168ms | ::1 | DELETE "/clan/13" +[GIN] 2024/01/15 - 10:28:01 | 200 | 112µs | ::1 | GET "/players" +Deleted clan 'ewerqer' with tag 'werwqer' +[GIN] 2024/01/15 - 10:28:01 | 200 | 31.2637ms | ::1 | DELETE "/clan/13" +[GIN] 2024/01/15 - 10:28:01 | 200 | 999.4µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:28:03 | 200 | 1.2154ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:28:03 | 200 | 519µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:28:03 | 200 | 1.103ms | ::1 | GET "/clan_options" +Added clan '12333' with tag '12333' +[GIN] 2024/01/15 - 10:28:08 | 200 | 2.6491ms | ::1 | POST "/clan" +[GIN] 2024/01/15 - 10:28:08 | 200 | 966.7µs | ::1 | GET "/players" +[GIN] 2024/01/15 - 10:30:21 | 200 | 1.0749ms | ::1 | GET "/" +[GIN] 2024/01/15 - 10:30:21 | 304 | 362.4µs | ::1 | GET "/static/index.js" +[GIN] 2024/01/15 - 10:30:21 | 200 | 993.8µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:30:21 | 200 | 167.3µs | ::1 | GET "/clan_options" +[GIN] 2024/01/15 - 10:30:24 | 200 | 962.3µs | ::1 | GET "/players" +Added clan 'zrdz' with tag 'zrdz' +[GIN] 2024/01/15 - 10:30:28 | 200 | 1.3631ms | ::1 | POST "/clan" +[GIN] 2024/01/15 - 10:30:28 | 200 | 0s | ::1 | GET "/players" +Added clan 'zrdz' with tag 'zrdz' +[GIN] 2024/01/15 - 10:30:28 | 200 | 7.0468ms | ::1 | POST "/clan" +[GIN] 2024/01/15 - 10:30:28 | 200 | 489.7µs | ::1 | GET "/players" diff --git a/main.go b/main.go index b1f2692..cbf1b94 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,7 @@ func main() { }) router.GET("/clans", controllers.GetAllClans) + router.GET("/clan_options", controllers.GetAllClanOptions) router.GET("/clan/:id", controllers.GetClanByID) router.POST("/clan", controllers.AddClan) router.PATCH("/clan/:id", controllers.UpdateClanByID) diff --git a/static/index.js b/static/index.js new file mode 100644 index 0000000..bb2c1fd --- /dev/null +++ b/static/index.js @@ -0,0 +1,25 @@ +function setupClanButtons(dropdownId, delBtnId, editBtnId) { + const dropdown = document.getElementById(dropdownId); + const deleteButton = document.getElementById(delBtnId); + const editButton = document.getElementById(editBtnId); + + dropdown.addEventListener('change', function () { + deleteButton.disabled = !this.value; + editButton.disabled = !this.value; + }); +} + +function getClanLists(event) { + const button = event.relatedTarget; + const clanListId = button.getAttribute('data-bs-list'); + const clanList = document.querySelector(clanListId); + + let otherClanListId; + if (clanListId === '#home-clan') + otherClanListId = '#opponent-clan' + else + otherClanListId = '#home-clan' + const otherClanList = document.querySelector(otherClanListId); + + return [clanList, otherClanList]; +} \ No newline at end of file diff --git a/templates/components/header.html b/templates/components/header.html index 6eee6f3..ec06537 100644 --- a/templates/components/header.html +++ b/templates/components/header.html @@ -4,6 +4,7 @@ Infantry Skill Calculator + diff --git a/templates/components/home_clan_bar.html b/templates/components/home_clan_bar.html index 6226a64..c217087 100644 --- a/templates/components/home_clan_bar.html +++ b/templates/components/home_clan_bar.html @@ -8,9 +8,7 @@ Auswählen... - {{ range .clans }} - [{{ .Tag }}] {{ .Name }} - {{ end }} + @@ -27,14 +25,8 @@ diff --git a/templates/components/opp_clan_bar.html b/templates/components/opp_clan_bar.html index 259c789..2f44920 100644 --- a/templates/components/opp_clan_bar.html +++ b/templates/components/opp_clan_bar.html @@ -8,9 +8,6 @@ Auswählen... - {{ range .clans }} - [{{ .Tag }}] {{ .Name }} - {{ end }} @@ -27,14 +24,8 @@ diff --git a/templates/modals/add_clan.html b/templates/modals/add_clan.html index bc89287..771e325 100644 --- a/templates/modals/add_clan.html +++ b/templates/modals/add_clan.html @@ -36,10 +36,11 @@ if (addClanModal) { addClanModal.addEventListener('shown.bs.modal', event => { const submitButton = addClanModal.querySelector('button[name="submit"]'); - submitButton.addEventListener('click', function () { - const button = event.relatedTarget; - const clanListId = button.getAttribute('data-bs-list'); - const clanList = document.querySelector(clanListId); + submitButton.addEventListener('click', function (e) { + e.preventDefault(); + submitButton.onclick = function () {} + + const [clanList, otherClanList] = getClanLists(event); const clanName = addClanModal.querySelector('#clanName'); const clanTag = addClanModal.querySelector('#clanTag'); @@ -61,9 +62,15 @@ const opt = document.createElement('option'); opt.innerText = "[" + clanTag.value + "]" + " " + clanName.value; opt.value = response.json()['ID']; - clanList.appendChild(opt); + + clanList.appendChild(opt.cloneNode(true)); clanList.selectedIndex = clanList.children.length - 1; clanList.dispatchEvent(new Event('change')); + + const lastIndex = otherClanList.selectedIndex; + otherClanList.appendChild(opt); + otherClanList.selectedIndex = lastIndex; + addClanModalBS.hide(); clanName.value = ""; clanTag.value = ""; diff --git a/templates/modals/delete_clan.html b/templates/modals/delete_clan.html index 8e47a78..aed3954 100644 --- a/templates/modals/delete_clan.html +++ b/templates/modals/delete_clan.html @@ -26,19 +26,16 @@ const deleteClanModalBS = new bootstrap.Modal('#deleteClanModal'); if (deleteClanModal) { deleteClanModal.addEventListener('show.bs.modal', event => { - const button = event.relatedTarget; - const clanListId = button.getAttribute('data-bs-list'); - const clanList = document.querySelector(clanListId); - const selectedClan = clanList.options[clanList.selectedIndex].text; + const [clanList, otherClanList] = getClanLists(event); + const selectedClan = clanList.options[clanList.selectedIndex].text; const modalBodyInput = deleteClanModal.querySelector('#clan'); modalBodyInput.innerText = selectedClan; const submitButton = deleteClanModal.querySelector('button[name="submit"]'); - submitButton.addEventListener('click', function () { - const button = event.relatedTarget; - const clanListId = button.getAttribute('data-bs-list'); - const clanList = document.querySelector(clanListId); + submitButton.addEventListener('click', function (e) { + e.preventDefault(); + submitButton.onclick = function () {} const clanId = parseInt(clanList.value); @@ -50,9 +47,19 @@ }) .then((response) => { if (response.ok) { - clanList.removeChild(clanList.children[clanList.selectedIndex]); + const clanToRemove = clanList.children[clanList.selectedIndex]; + const clanIndex = clanToRemove.index; + clanList.removeChild(clanToRemove); clanList.selectedIndex = 0; clanList.dispatchEvent(new Event('change')); + + const lastOtherIndex = otherClanList.selectedIndex; + otherClanList.children.item(clanIndex).remove(); + if (lastOtherIndex === clanIndex) { + otherClanList.selectedIndex = 0; + otherClanList.dispatchEvent(new Event('change')); + } + deleteClanModalBS.hide(); } else throw new Error(response.error) diff --git a/templates/modals/edit_clan.html b/templates/modals/edit_clan.html index 28900d8..5539d37 100644 --- a/templates/modals/edit_clan.html +++ b/templates/modals/edit_clan.html @@ -37,10 +37,11 @@ const editClanModalBS = new bootstrap.Modal('#editClanModal'); if (editClanModal) { editClanModal.addEventListener('show.bs.modal', event => { - const button = event.relatedTarget; - const clanListId = button.getAttribute('data-bs-list'); - const clanList = document.querySelector(clanListId); - const selectedClanItem = clanList.options[clanList.selectedIndex]; + const [clanList, otherClanList] = getClanLists(event); + + const selectedClanIndex = clanList.selectedIndex; + const selectedClanItem = clanList.options[selectedClanIndex]; + const otherSelClanItem = otherClanList.options[selectedClanIndex]; const clanName = editClanModal.querySelector('#editClanName'); const clanTag = editClanModal.querySelector('#editClanTag'); @@ -66,7 +67,9 @@ throw new Error(error); }); - submitButton.addEventListener('click', function () { + submitButton.addEventListener('click', function (e) { + e.preventDefault(); + submitButton.onclick = function () {} fetch("/clan/" + clanId, { method: "PATCH", body: JSON.stringify({ @@ -80,7 +83,10 @@ }) .then((response) => { if (response.ok) { - selectedClanItem.innerText = "[" + clanTag.value + "]" + " " + clanName.value; + const newName = "[" + clanTag.value + "]" + " " + clanName.value; + selectedClanItem.innerText = newName; + otherSelClanItem.innerText = newName; + editClanModalBS.hide(); clanName.value = ""; clanTag.value = "";