diff options
Diffstat (limited to 'static/main.js')
| -rw-r--r-- | static/main.js | 78 |
1 files changed, 68 insertions, 10 deletions
diff --git a/static/main.js b/static/main.js index 23bb356..aad4a49 100644 --- a/static/main.js +++ b/static/main.js @@ -20,6 +20,73 @@ async function logout() { window.location.reload(); } +function create_problem_element(problem, submissions) { + const problem_div = document.createElement("div"); + problem_div.className = "problem"; + + const title = document.createElement("h2"); + title.innerHTML = problem.title; + problem_div.appendChild(title); + + const description = document.createElement("p"); + description.innerHTML = problem.description; + problem_div.appendChild(description); + + const sub_title = document.createElement("h3"); + sub_title.innerHTML = "Submissions"; + problem_div.appendChild(sub_title); + + const sub_div = document.createElement("div"); + sub_div.className = "submission-div"; + problem_div.appendChild(sub_div); + + const sub_table = document.createElement("table"); + sub_table.className = "submission-table"; + sub_div.appendChild(sub_table); + + const header_row = document.createElement("tr"); + sub_table.appendChild(header_row); + + const header_user = document.createElement("th"); + header_user.innerHTML = "User"; + header_row.appendChild(header_user); + const header_lang = document.createElement("th"); + header_lang.innerHTML = "Language"; + header_row.appendChild(header_lang); + const header_size = document.createElement("th"); + header_size.innerHTML = "Size"; + header_row.appendChild(header_size); + const header_subm = document.createElement("th"); + header_subm.innerHTML = "Submission"; + header_row.appendChild(header_subm); + + for (const submission of submissions) { + const sub_row = document.createElement("tr"); + sub_table.appendChild(sub_row); + + const sub_user = document.createElement("td"); + sub_user.innerHTML = "Username"; + sub_row.appendChild(sub_user); + + const sub_lang = document.createElement("td"); + sub_lang.innerHTML = "Language"; + sub_row.appendChild(sub_lang); + + const sub_size = document.createElement("td"); + sub_size.innerHTML = "Size"; + sub_row.appendChild(sub_size); + + const sub_subm = document.createElement("td"); + const sub_anch = document.createElement("a"); + sub_anch.href = "submission.html?id=5"; + sub_anch.innerText = "view submission"; + sub_subm.appendChild(sub_anch); + sub_row.appendChild(sub_subm); + } + + return problem_div +} + async function fetch_problems() { const response = await fetch("/problem"); if (!response.ok) { @@ -34,17 +101,8 @@ async function fetch_problems() { } for (const problem of result) { - const problem_div = document.createElement("div"); - problem_div.className = "problem"; + const problem_div = create_problem_element(problem, [1, 2, 3]) problems_div.appendChild(problem_div); - - const title = document.createElement("h2"); - title.innerHTML = problem.title; - problem_div.appendChild(title); - - const description = document.createElement("p"); - description.innerHTML = problem.description; - problem_div.appendChild(description); } } |
