|
|
|
@ -6,11 +6,17 @@ import { getEmail, updateContainer, gotoPage } from './Helpers';
|
|
|
|
|
import { TerminalService } from './terminal.service';
|
|
|
|
|
import { SocketIOService } from '../notifications/socket-io.service';
|
|
|
|
|
import { Socket } from 'socket.io-client';
|
|
|
|
|
import { AddFlagComponent } from '../add-flag/add-flag.component';
|
|
|
|
|
import { Submission } from '../models/submission.model';
|
|
|
|
|
import { User } from '../models/user.model';
|
|
|
|
|
|
|
|
|
|
let subs: Submission[] = [];
|
|
|
|
|
let UserID: number = 0;
|
|
|
|
|
|
|
|
|
|
export async function loadPage(renderer: Renderer2, el: ElementRef, ts: any): Promise<void> {
|
|
|
|
|
const isPractice = window.location.href.includes("Prac");
|
|
|
|
|
const taskbar: HTMLElement = document.getElementById('Taskbar')!;
|
|
|
|
|
|
|
|
|
|
// basics for use in multiple methods
|
|
|
|
|
const elements = {
|
|
|
|
|
flagName: el.nativeElement.querySelector('#Flag_Name') as HTMLElement,
|
|
|
|
@ -31,6 +37,21 @@ export function getAdmin(): string | null {
|
|
|
|
|
return params.get('admin');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get the user
|
|
|
|
|
async function getUser() {
|
|
|
|
|
const data = { email: getEmail() };
|
|
|
|
|
const res = await fetch('api/users/getUser', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type' : 'application/json'
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(data)
|
|
|
|
|
});
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
let user = await res.json();
|
|
|
|
|
UserID = user.UserID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// load the current active contest
|
|
|
|
|
async function LoadContest(el: ElementRef, elements: any, ts: any) {
|
|
|
|
|
const contestID = new URLSearchParams(window.location.search).get('contestID');
|
|
|
|
@ -120,6 +141,8 @@ async function LoadElements(contest: Contest, el: ElementRef, elements: any, ts:
|
|
|
|
|
if(submitFlag) submitFlag.classList.add('hidden');
|
|
|
|
|
hintStuff.classList.add('hidden');
|
|
|
|
|
|
|
|
|
|
getUser();
|
|
|
|
|
await getSubs();
|
|
|
|
|
flagdata.forEach(flag => {
|
|
|
|
|
|
|
|
|
|
console.log(flag);
|
|
|
|
@ -129,11 +152,36 @@ async function LoadElements(contest: Contest, el: ElementRef, elements: any, ts:
|
|
|
|
|
li.onclick = () => setNewFlag(flag, el, elements, ts);
|
|
|
|
|
|
|
|
|
|
// add to list
|
|
|
|
|
CheckIfCorrect(li,flag);
|
|
|
|
|
li.appendChild(a);
|
|
|
|
|
UL.appendChild(li);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get all of the submissions
|
|
|
|
|
async function getSubs() {
|
|
|
|
|
const res = await fetch('api/submissions/getSubs', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type' : 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
subs = await res.json();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// checks whether to add the correct class to the flag
|
|
|
|
|
async function CheckIfCorrect(li: HTMLLIElement, flag: Flag) {
|
|
|
|
|
for (let i=0; i < subs.length; i++) {
|
|
|
|
|
if (subs[i].FlagID === flag.FlagID) {
|
|
|
|
|
if (subs[i].UserID == UserID && subs[i].IsCorrect == true) {
|
|
|
|
|
li.classList.add('CorrectSub');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get the active flag of a user
|
|
|
|
|
async function getActiveFlag(email: string, contest: number, el: ElementRef, elements: any) {
|
|
|
|
|
const data = { email: email };
|
|
|
|
@ -294,16 +342,32 @@ async function checkSubmission(isPractice: boolean, el: ElementRef, socket: Sock
|
|
|
|
|
}
|
|
|
|
|
result = await res.json();
|
|
|
|
|
|
|
|
|
|
// correct flag
|
|
|
|
|
if(result.correct){
|
|
|
|
|
resultelement.classList.add('Correct');
|
|
|
|
|
resultelement.classList.remove('Incorrect');
|
|
|
|
|
resultelement.textContent = 'Correct! :)';
|
|
|
|
|
|
|
|
|
|
// change flag li to green
|
|
|
|
|
const flaglist = document.getElementById('FlagList') as HTMLUListElement;
|
|
|
|
|
for (let i=0; i < flaglist.children.length; i++) {
|
|
|
|
|
|
|
|
|
|
// grab the li and add a classlist of correct
|
|
|
|
|
let flag = flaglist.childNodes[i] as HTMLLIElement;
|
|
|
|
|
if (flag.firstChild?.textContent === flagName) {
|
|
|
|
|
flag.classList.add('CorrectSub');
|
|
|
|
|
console.log('added correct color');
|
|
|
|
|
console.log(flag.firstChild);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("SENDING NOTIF", email, flagName);
|
|
|
|
|
/*socket.emit('submission-notification', {
|
|
|
|
|
email, flagName, time: new Date().toISOString()
|
|
|
|
|
});*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// incorrect flag
|
|
|
|
|
else{
|
|
|
|
|
resultelement.classList.add('Incorrect');
|
|
|
|
|
resultelement.classList.remove('Correct');
|
|
|
|
|