Libra-1995 commited on
Commit
03e8aba
·
1 Parent(s): 6e2a8df

feat: update register alert

Browse files
Files changed (1) hide show
  1. competitions/templates/index.html +125 -124
competitions/templates/index.html CHANGED
@@ -9,13 +9,102 @@
9
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
10
  <link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.css" rel="stylesheet" />
11
  <script>
12
- document.addEventListener('DOMContentLoaded', function () {
13
- function showSubmissionModal() {
14
- const modal = document.getElementById('submission-modal');
15
- modal.classList.add('flex');
16
- modal.classList.remove('hidden');
17
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
 
 
 
 
 
 
 
19
  function hideSubmissionModal() {
20
  const modal = document.getElementById('submission-modal');
21
  modal.classList.remove('flex');
@@ -119,95 +208,6 @@
119
  // fetchAndDisplayLeaderboard('private');
120
  // }
121
 
122
- function fetchAndDisplaySubmissions() {
123
- const apiEndpoint = '/my_submissions';
124
- const articleLoadingSpinner = document.getElementById('articleLoadingSpinner');
125
- articleLoadingSpinner.classList.remove('hidden');
126
-
127
- const requestOptions = {
128
- method: 'POST',
129
- headers: {
130
- 'Content-Type': 'application/json',
131
- }
132
- };
133
-
134
- fetch(apiEndpoint, requestOptions)
135
- .then(response => {
136
- if (!response.ok) {
137
- throw new Error('Network response was not ok');
138
- }
139
- return response.json();
140
- })
141
- .then(data => {
142
- const contentDiv = document.getElementById('content');
143
- const teamNameDiv = `
144
- <div class="flex items-center">
145
- <input type="text" name="team_name" id="team_name" class="mt-1 mb-1 block me-2" value="${data.response.team_name}">
146
- <button id="updateTeamNameButton" type="button" class="confirm text-white bg-green-600 hover:bg-green-800 focus:ring-4 focus:outline-none focus:ring-green-300 font-medium rounded-lg text-sm inline-flex items-center px-5 py-2.5 text-center me-2">Update Team Name</button>
147
- </div>`;
148
- // console.log(data.response.submissions);
149
- // contentDiv.innerHTML = marked.parse(data.response.submission_text) + data.response.submissions;
150
- if (data.response.submissions && data.response.submissions.length > 0 && data.response.error.length == 0) {
151
- // Start building the table HTML
152
- let tableHTML = teamNameDiv;
153
- tableHTML += '<table border="1"><tr><th width: 17%;>Datetime</th><th style="width: 40%;">Submission ID</th><th style="width: 20%;">Score</th><th style="width: 8%;">Status</th><th style="width: 15%;">Error</th></tr>';
154
-
155
- // Iterate over each submission and add it to the table
156
- data.response.submissions.forEach(submission => {
157
- tableHTML += `<tr>
158
- <td>${submission.datetime}</td>
159
- <td>${submission.submission_id}</td>
160
- <td>${submission.score}</td>
161
- <td>${submission.status}</td>
162
- <td>${submission.error_message}</td>
163
- </tr>`;
164
- });
165
-
166
- // Close the table HTML and set it as the content
167
- tableHTML += '</table>';
168
- // add a text field which displays team name and a button to update team name
169
- contentDiv.innerHTML = marked.parse(data.response.submission_text) + tableHTML;
170
- document.getElementById('updateSelectedSubmissionsButton').addEventListener('click', function () {
171
- updateSelectedSubmissions();
172
- });
173
- } else {
174
- // Display message if there are no submissions
175
- contentDiv.innerHTML = teamNameDiv + marked.parse(data.response.submission_text) + marked.parse(data.response.error);
176
- }
177
- document.getElementById('updateTeamNameButton').addEventListener('click', function () {
178
- updateTeamName();
179
- });
180
- articleLoadingSpinner.classList.add('hidden');
181
- })
182
- .catch(error => {
183
- console.error('There was a problem with the fetch operation:', error);
184
- articleLoadingSpinner.classList.add('hidden');
185
- });
186
- }
187
-
188
- function fetchAndDisplaySubmissionInfo() {
189
- const articleLoadingSpinner = document.getElementById('articleLoadingSpinner');
190
- articleLoadingSpinner.classList.remove('hidden');
191
- fetch('/submission_info')
192
- .then(response => {
193
- if (!response.ok) {
194
- throw new Error('Network response was not ok');
195
- }
196
- return response.json(); // Parse the JSON response
197
- })
198
- .then(data => {
199
- // Populate the 'content' div with the HTML from the response
200
- const contentDiv = document.getElementById('content');
201
- contentDiv.innerHTML = marked.parse(data.response);
202
- addTargetBlankToLinks();
203
- articleLoadingSpinner.classList.add('hidden');
204
- })
205
- .catch(error => {
206
- console.error('There has been a problem with your fetch operation:', error);
207
- articleLoadingSpinner.classList.add('hidden');
208
- });
209
- }
210
-
211
  function fetchAndDisplayTeamInfo() {
212
  const apiEndpoint = '/team_info';
213
  const articleLoadingSpinner = document.getElementById('articleLoadingSpinner');
@@ -295,9 +295,6 @@
295
  const datasetLink = document.getElementById('dataset');
296
  // const publicLBLink = document.getElementById('public_lb');
297
  // const privateLBLink = document.getElementById('private_lb');
298
- const newSubmission = document.getElementById('new_submission');
299
- const mySubmissions = document.getElementById('my_submissions');
300
- const submissionInfo = document.getElementById('submission_info');
301
  const rulesLink = document.getElementById('rules');
302
  const leaderBoardLink = document.getElementById('leaderboard');
303
 
@@ -326,19 +323,6 @@
326
  // event.preventDefault(); // Prevent the default link behavior
327
  // fetchAndDisplayPrivateLeaderboard(); // Fetch and display info on click
328
  // });
329
-
330
- newSubmission.addEventListener('click', function (event) {
331
- event.preventDefault(); // Prevent the default link behavior
332
- showSubmissionModal(); // Fetch and display info on click
333
- });
334
- mySubmissions.addEventListener('click', function (event) {
335
- event.preventDefault(); // Prevent the default link behavior
336
- fetchAndDisplaySubmissions(); // Fetch and display info on click
337
- });
338
- submissionInfo.addEventListener('click', function (event) {
339
- event.preventDefault(); // Prevent the default link behavior
340
- fetchAndDisplaySubmissionInfo(); // Fetch and display info on click
341
- });
342
  rulesLink.addEventListener('click', function (event) {
343
  event.preventDefault(); // Prevent the default link behavior
344
  fetchAndDisplayRules(); // Fetch and display info on click
@@ -370,6 +354,9 @@
370
 
371
  function checkOAuth() {
372
  var url = "/login_status";
 
 
 
373
  makeApiRequest(url, function ({is_login, is_admin, is_registered, is_white_team}) {
374
  const registerRemoveStyle = ["pointer-events-none", "text-gray-400", "cursor-not-allowed"];
375
  const registerNewStyle = ["ext-gray-900", "hover:bg-gray-100"]
@@ -383,19 +370,33 @@
383
  if (is_admin) {
384
  document.getElementById("admin").classList.remove("hidden");
385
  }
386
- if (is_registered) {
387
- document.getElementById("submission_info").classList.remove(...registerRemoveStyle);
388
- document.getElementById("submission_info").classList.add(...registerNewStyle);
389
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  if (is_login && !is_registered) {
391
  document.getElementById("registerButton").style.display = "block";
392
  }
393
- if (is_white_team) {
394
- document.getElementById("my_submissions").classList.remove(...registerRemoveStyle);
395
- document.getElementById("my_submissions").classList.add(...registerNewStyle);
396
- document.getElementById("new_submission").classList.remove(...registerRemoveStyle);
397
- document.getElementById("new_submission").classList.add(...registerNewStyle);
398
- }
399
  });
400
  }
401
  window.onload = checkOAuth;
@@ -485,17 +486,17 @@
485
  <ul id="submissions-dropdown" class="py-2 space-y-2">
486
  <li>
487
  <a href="#" id="submission_info"
488
- class="flex items-center w-full p-2 transition duration-75 rounded-lg pl-11 group pointer-events-none text-gray-400 cursor-not-allowed">Submission
489
  information</a>
490
  </li>
491
  <li>
492
  <a href="#" id="my_submissions"
493
- class="flex items-center w-full p-2 transition duration-75 rounded-lg pl-11 group pointer-events-none text-gray-400 cursor-not-allowed">My
494
  submissions</a>
495
  </li>
496
  <li>
497
  <a href="#" id="new_submission"
498
- class="flex items-center w-full p-2 transition duration-75 rounded-lg pl-11 group pointer-events-none text-gray-400 cursor-not-allowed">New
499
  submission</a>
500
  </li>
501
  </ul>
 
9
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
10
  <link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.css" rel="stylesheet" />
11
  <script>
12
+ function fetchAndDisplaySubmissionInfo() {
13
+ const articleLoadingSpinner = document.getElementById('articleLoadingSpinner');
14
+ articleLoadingSpinner.classList.remove('hidden');
15
+ fetch('/submission_info')
16
+ .then(response => {
17
+ if (!response.ok) {
18
+ throw new Error('Network response was not ok');
19
+ }
20
+ return response.json(); // Parse the JSON response
21
+ })
22
+ .then(data => {
23
+ // Populate the 'content' div with the HTML from the response
24
+ const contentDiv = document.getElementById('content');
25
+ contentDiv.innerHTML = marked.parse(data.response);
26
+ addTargetBlankToLinks();
27
+ articleLoadingSpinner.classList.add('hidden');
28
+ })
29
+ .catch(error => {
30
+ console.error('There has been a problem with your fetch operation:', error);
31
+ articleLoadingSpinner.classList.add('hidden');
32
+ });
33
+ }
34
+
35
+ function fetchAndDisplaySubmissions() {
36
+ const apiEndpoint = '/my_submissions';
37
+ const articleLoadingSpinner = document.getElementById('articleLoadingSpinner');
38
+ articleLoadingSpinner.classList.remove('hidden');
39
+
40
+ const requestOptions = {
41
+ method: 'POST',
42
+ headers: {
43
+ 'Content-Type': 'application/json',
44
+ }
45
+ };
46
+
47
+ fetch(apiEndpoint, requestOptions)
48
+ .then(response => {
49
+ if (!response.ok) {
50
+ throw new Error('Network response was not ok');
51
+ }
52
+ return response.json();
53
+ })
54
+ .then(data => {
55
+ const contentDiv = document.getElementById('content');
56
+ const teamNameDiv = `
57
+ <div class="flex items-center">
58
+ <input type="text" name="team_name" id="team_name" class="mt-1 mb-1 block me-2" value="${data.response.team_name}">
59
+ <button id="updateTeamNameButton" type="button" class="confirm text-white bg-green-600 hover:bg-green-800 focus:ring-4 focus:outline-none focus:ring-green-300 font-medium rounded-lg text-sm inline-flex items-center px-5 py-2.5 text-center me-2">Update Team Name</button>
60
+ </div>`;
61
+ // console.log(data.response.submissions);
62
+ // contentDiv.innerHTML = marked.parse(data.response.submission_text) + data.response.submissions;
63
+ if (data.response.submissions && data.response.submissions.length > 0 && data.response.error.length == 0) {
64
+ // Start building the table HTML
65
+ let tableHTML = teamNameDiv;
66
+ tableHTML += '<table border="1"><tr><th width: 17%;>Datetime</th><th style="width: 40%;">Submission ID</th><th style="width: 20%;">Score</th><th style="width: 8%;">Status</th><th style="width: 15%;">Error</th></tr>';
67
+
68
+ // Iterate over each submission and add it to the table
69
+ data.response.submissions.forEach(submission => {
70
+ tableHTML += `<tr>
71
+ <td>${submission.datetime}</td>
72
+ <td>${submission.submission_id}</td>
73
+ <td>${submission.score}</td>
74
+ <td>${submission.status}</td>
75
+ <td>${submission.error_message}</td>
76
+ </tr>`;
77
+ });
78
+
79
+ // Close the table HTML and set it as the content
80
+ tableHTML += '</table>';
81
+ // add a text field which displays team name and a button to update team name
82
+ contentDiv.innerHTML = marked.parse(data.response.submission_text) + tableHTML;
83
+ document.getElementById('updateSelectedSubmissionsButton').addEventListener('click', function () {
84
+ updateSelectedSubmissions();
85
+ });
86
+ } else {
87
+ // Display message if there are no submissions
88
+ contentDiv.innerHTML = teamNameDiv + marked.parse(data.response.submission_text) + marked.parse(data.response.error);
89
+ }
90
+ document.getElementById('updateTeamNameButton').addEventListener('click', function () {
91
+ updateTeamName();
92
+ });
93
+ articleLoadingSpinner.classList.add('hidden');
94
+ })
95
+ .catch(error => {
96
+ console.error('There was a problem with the fetch operation:', error);
97
+ articleLoadingSpinner.classList.add('hidden');
98
+ });
99
+ }
100
 
101
+ function showSubmissionModal() {
102
+ const modal = document.getElementById('submission-modal');
103
+ modal.classList.add('flex');
104
+ modal.classList.remove('hidden');
105
+ }
106
+
107
+ document.addEventListener('DOMContentLoaded', function () {
108
  function hideSubmissionModal() {
109
  const modal = document.getElementById('submission-modal');
110
  modal.classList.remove('flex');
 
208
  // fetchAndDisplayLeaderboard('private');
209
  // }
210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  function fetchAndDisplayTeamInfo() {
212
  const apiEndpoint = '/team_info';
213
  const articleLoadingSpinner = document.getElementById('articleLoadingSpinner');
 
295
  const datasetLink = document.getElementById('dataset');
296
  // const publicLBLink = document.getElementById('public_lb');
297
  // const privateLBLink = document.getElementById('private_lb');
 
 
 
298
  const rulesLink = document.getElementById('rules');
299
  const leaderBoardLink = document.getElementById('leaderboard');
300
 
 
323
  // event.preventDefault(); // Prevent the default link behavior
324
  // fetchAndDisplayPrivateLeaderboard(); // Fetch and display info on click
325
  // });
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  rulesLink.addEventListener('click', function (event) {
327
  event.preventDefault(); // Prevent the default link behavior
328
  fetchAndDisplayRules(); // Fetch and display info on click
 
354
 
355
  function checkOAuth() {
356
  var url = "/login_status";
357
+ const submissionInfo = document.getElementById('submission_info');
358
+ const mySubmissions = document.getElementById('my_submissions');
359
+ const newSubmission = document.getElementById('new_submission');
360
  makeApiRequest(url, function ({is_login, is_admin, is_registered, is_white_team}) {
361
  const registerRemoveStyle = ["pointer-events-none", "text-gray-400", "cursor-not-allowed"];
362
  const registerNewStyle = ["ext-gray-900", "hover:bg-gray-100"]
 
370
  if (is_admin) {
371
  document.getElementById("admin").classList.remove("hidden");
372
  }
373
+ submissionInfo.addEventListener('click', function (event) {
374
+ event.preventDefault(); // Prevent the default link behavior
375
+ if (is_registered) {
376
+ fetchAndDisplaySubmissionInfo(); // Fetch and display info on click
377
+ } else {
378
+ alert(`You need to register to access the "Submission Information."`)
379
+ }
380
+ });
381
+ mySubmissions.addEventListener('click', function (event) {
382
+ event.preventDefault(); // Prevent the default link behavior
383
+ if (is_white_team) {
384
+ fetchAndDisplaySubmissions(); // Fetch and display info on click
385
+ } else {
386
+ alert(`Access to the "Submit" will be granted after we manually review your registration. This process usually takes up to 24 hours.`)
387
+ }
388
+ });
389
+ newSubmission.addEventListener('click', function (event) {
390
+ event.preventDefault(); // Prevent the default link behavior
391
+ if (is_white_team) {
392
+ showSubmissionModal(); // Show the submission modal
393
+ } else {
394
+ alert(`Access to the "Submit" will be granted after we manually review your registration. This process usually takes up to 24 hours.`)
395
+ }
396
+ });
397
  if (is_login && !is_registered) {
398
  document.getElementById("registerButton").style.display = "block";
399
  }
 
 
 
 
 
 
400
  });
401
  }
402
  window.onload = checkOAuth;
 
486
  <ul id="submissions-dropdown" class="py-2 space-y-2">
487
  <li>
488
  <a href="#" id="submission_info"
489
+ class="flex items-center w-full p-2 transition duration-75 rounded-lg pl-11 group ext-gray-900 hover:bg-gray-100">Submission
490
  information</a>
491
  </li>
492
  <li>
493
  <a href="#" id="my_submissions"
494
+ class="flex items-center w-full p-2 transition duration-75 rounded-lg pl-11 group ext-gray-900 hover:bg-gray-100">My
495
  submissions</a>
496
  </li>
497
  <li>
498
  <a href="#" id="new_submission"
499
+ class="flex items-center w-full p-2 transition duration-75 rounded-lg pl-11 group ext-gray-900 hover:bg-gray-100">New
500
  submission</a>
501
  </li>
502
  </ul>