use same request for receiving point by number
This commit is contained in:
		
							parent
							
								
									fbaff3bdf3
								
							
						
					
					
						commit
						a4ac19e516
					
				
							
								
								
									
										37
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								main.js
									
									
									
									
									
								
							| @ -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() { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user