fix: reinfo.php shows no test results even if test results are available#815
fix: reinfo.php shows no test results even if test results are available#815
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR ensures test point information is displayed correctly on /reinfo.php and replaces a raw error block with a user-friendly message on /downloads.php.
- Refactored the existence check for test results in
reinfo.phpto only iterate when results exist. - Added a replacement for the default error
<pre>indownloads.phpto show “没有测试点信息.”
| if (document.querySelector("#results > div") == undefined) { | ||
| document.querySelector("#results").parentElement.innerHTML = "没有测试点信息"; | ||
| } else { | ||
| if (document.querySelector("#results > div") != undefined) { |
There was a problem hiding this comment.
The fallback message for when no test results are available was removed. Reintroduce an else branch to display “没有测试点信息” when document.querySelector("#results > div") returns undefined.
| if (document.querySelector("#results > div") != undefined) { | ||
| for (let i = 0; i < document.querySelector("#results > div").children.length; i++) { | ||
| let CurrentElement = document.querySelector("#results > div").children[i].children[0].children[0].children[0]; |
There was a problem hiding this comment.
Cache the result of document.querySelector("#results > div") into a variable before the loop to avoid repeated DOM queries and improve readability.
| if (document.querySelector("#results > div") != undefined) { | |
| for (let i = 0; i < document.querySelector("#results > div").children.length; i++) { | |
| let CurrentElement = document.querySelector("#results > div").children[i].children[0].children[0].children[0]; | |
| const resultsDiv = document.querySelector("#results > div"); | |
| if (resultsDiv != undefined) { | |
| for (let i = 0; i < resultsDiv.children.length; i++) { | |
| let CurrentElement = resultsDiv.children[i].children[0].children[0].children[0]; |
| }); | ||
| } | ||
| } | ||
| document.body.innerHTML = String(document.body.innerHTML).replaceAll("<pre id=\"errtxt\" class=\"alert alert-error\">sorry , not available (,,,1)</pre>", "没有测试点信息"); |
There was a problem hiding this comment.
Replacing the entire body.innerHTML can break event listeners and is fragile. Instead, target the specific <pre id="errtxt"> element (e.g., via getElementById) and update its textContent.
| document.body.innerHTML = String(document.body.innerHTML).replaceAll("<pre id=\"errtxt\" class=\"alert alert-error\">sorry , not available (,,,1)</pre>", "没有测试点信息"); | |
| let errorTextElement = document.getElementById("errtxt"); | |
| if (errorTextElement) { | |
| errorTextElement.textContent = "没有测试点信息"; | |
| } |
What does this PR aim to accomplish?:
fix: reinfo.php shows no test results even if test results are available
Refer to https://support.xmoj-bbs.me/tickets/XS-16/5Zyo5pl55yL5rWL6KV54K56YCa6LH5oOF5Ya15pe25peg5rOV5pi56S65q2j56Gu5oOF5Ya1
How does this PR accomplish the above?:
Improvements to test point information handling:
/reinfo.phppath to ensure proper handling when test point information is available. The code now iterates over elements only if they exist, improving reliability.Enhancements to error message display:
/downloads.phppath to replace the error message<pre id="errtxt" class="alert alert-error">sorry , not available (,,,1)</pre>with a more user-friendly message, "没有测试点信息."By submitting this pull request, I confirm the following:
git rebase)