use same request for receiving point by number

This commit is contained in:
Zhora Shalyapin 2025-03-26 08:36:27 +00:00
parent fbaff3bdf3
commit a4ac19e516

37
main.js
View File

@ -312,8 +312,12 @@
})
}
async function getPointIdByNumber(number) {
let response = await fetch(`https://${adminSite}/api/competitions/${getCompetition()}/${number}`, {
async function getPointIdByNumber(numbers) {
let params = new URLSearchParams()
for (const number of numbers) {
params.append("number[]", number)
}
let response = await fetch(`https://${adminSite}/api/competitions/${getCompetition()}/points?${params.toString()}`, {
method: 'GET'
})
return await response.json()
@ -1171,8 +1175,8 @@
on: {
click: async function () {
let number = document.querySelector("#go-to-cp").value
let json = await getPointIdByNumber(number)
let id = json.id
let json = await getPointIdByNumber([number])
let id = json[number].cp_id
if (id == null) {
alert("Нет КП с таким номером")
@ -2192,21 +2196,28 @@
function addLinksToCp() {
let pointCells = [...document.querySelectorAll(`#props table td:first-child`)]
for (const pointCell of pointCells) {
let cellContent = pointCell.textContent
let pointNumber = cellContent.trim().match(/^\d+/)
if (pointNumber == null) continue
let pointNumbers = {}
for (const [i, pointCell] of pointCells.entries()) {
let pointNumber = pointCell.textContent.trim().match(/^\d+/)?.[0]
if (pointNumber != null)
pointNumbers[i] = pointNumber
}
;(async () => {
let cpId = (await getPointIdByNumber(pointNumber)).id
;(async () => {
let cpIds = await getPointIdByNumber(Object.values(pointNumbers))
for (const [i, pointCell] of pointCells.entries()) {
if (pointNumbers[i] == null) continue
let cellContent = pointCell.textContent
pointCell.innerHTML = ''
pointCell.append(Tag.a({
href: cpLink(cpId),
href: cpLink(cpIds[pointNumbers[i]].cp_id),
target: "_blank",
textContent: cellContent
}))
})()
}
}
})()
}
function getRouteName() {