[web] Auto refresh submisisons
This commit is contained in:
parent
36a8050a4b
commit
bd91cb7044
@ -64,6 +64,8 @@ export const actions = {
|
|||||||
return { success: false };
|
return { success: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await db.submission.deleteMany({ where: { contestId: contest.id } });
|
||||||
|
|
||||||
contest.teams.forEach(async (team) => {
|
contest.teams.forEach(async (team) => {
|
||||||
await db.activeTeam.create({ data: { teamId: team.id, contestId: contest.id } });
|
await db.activeTeam.create({ data: { teamId: team.id, contestId: contest.id } });
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import { db } from '$lib/server/prisma';
|
import { db } from '$lib/server/prisma';
|
||||||
import path, { join } from 'path';
|
|
||||||
import type { Actions, PageServerLoad } from './$types';
|
import type { Actions, PageServerLoad } from './$types';
|
||||||
import fs from 'fs';
|
|
||||||
import { simpleGit } from 'simple-git';
|
|
||||||
import { createRepos } from '../util';
|
import { createRepos } from '../util';
|
||||||
|
|
||||||
export const load = (async () => {
|
export const load = (async () => {
|
||||||
@ -18,22 +15,6 @@ export const load = (async () => {
|
|||||||
};
|
};
|
||||||
}) satisfies PageServerLoad;
|
}) satisfies PageServerLoad;
|
||||||
|
|
||||||
function copyFolderSync(source: string, target: string) {
|
|
||||||
if (!fs.existsSync(target)) {
|
|
||||||
fs.mkdirSync(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.readdirSync(source).forEach((file) => {
|
|
||||||
const sourcePath = path.join(source, file);
|
|
||||||
const targetPath = path.join(target, file);
|
|
||||||
|
|
||||||
if (fs.lstatSync(sourcePath).isDirectory()) {
|
|
||||||
copyFolderSync(sourcePath, targetPath);
|
|
||||||
} else {
|
|
||||||
fs.copyFileSync(sourcePath, targetPath);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
create: async ({ request }) => {
|
create: async ({ request }) => {
|
||||||
const data = await request.formData();
|
const data = await request.formData();
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import { db } from '$lib/server/prisma';
|
import { db } from '$lib/server/prisma';
|
||||||
import { SubmissionState } from '@prisma/client';
|
import { SubmissionState } from '@prisma/client';
|
||||||
import type {PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load = (async () => {
|
export const load = (async () => {
|
||||||
const submissions = await db.submission.findMany({ where: { state: SubmissionState.InReview } });
|
const submissions = await db.submission.findMany({ where: { state: SubmissionState.InReview } });
|
||||||
const teams = await db.team.findMany();
|
const teams = await db.team.findMany();
|
||||||
const problems = await db.problem.findMany();
|
const problems = await db.problem.findMany();
|
||||||
return {
|
return {
|
||||||
|
timestamp: new Date(),
|
||||||
reviewList: submissions.map((row) => {
|
reviewList: submissions.map((row) => {
|
||||||
return { id: row.id, createdAt: row.createdAt };
|
return { id: row.id, createdAt: row.createdAt };
|
||||||
}),
|
}),
|
||||||
@ -18,4 +19,3 @@ export const load = (async () => {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
}) satisfies PageServerLoad;
|
}) satisfies PageServerLoad;
|
||||||
|
|
||||||
|
@ -1,7 +1,26 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { onDestroy, onMount } from 'svelte';
|
||||||
import type { PageData } from './$types';
|
import type { PageData } from './$types';
|
||||||
|
import { invalidateAll } from '$app/navigation';
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
|
||||||
|
let updateInterval: ReturnType<typeof setInterval> | undefined;
|
||||||
|
let updating = false;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
updateInterval = setInterval(async () => {
|
||||||
|
updating = true;
|
||||||
|
await invalidateAll();
|
||||||
|
updating = false;
|
||||||
|
}, 10000);
|
||||||
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (updateInterval) {
|
||||||
|
clearInterval(updateInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@ -10,6 +29,13 @@
|
|||||||
|
|
||||||
<h1 style="text-align:center" class="mb-4">Reviews</h1>
|
<h1 style="text-align:center" class="mb-4">Reviews</h1>
|
||||||
|
|
||||||
|
<div class="mb-3 text-end">
|
||||||
|
{#if updating}
|
||||||
|
<div class="spinner-border spinner-border-sm text-secondary" />
|
||||||
|
{/if}
|
||||||
|
<strong>Last Updated: </strong>{data.timestamp.toLocaleTimeString()}
|
||||||
|
</div>
|
||||||
|
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{#if data.reviewList.length === 0}
|
{#if data.reviewList.length === 0}
|
||||||
<div class="alert alert-success">No Submission to Review!</div>
|
<div class="alert alert-success">No Submission to Review!</div>
|
||||||
|
@ -6,6 +6,7 @@ export const load = (async () => {
|
|||||||
const problems = await db.problem.findMany();
|
const problems = await db.problem.findMany();
|
||||||
const teams = await db.team.findMany();
|
const teams = await db.team.findMany();
|
||||||
return {
|
return {
|
||||||
|
timestamp: new Date(),
|
||||||
submissions: submissions.map((row) => {
|
submissions: submissions.map((row) => {
|
||||||
return {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
|
@ -1,12 +1,30 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PageData } from './$types';
|
import type { PageData } from './$types';
|
||||||
import { goto } from '$app/navigation';
|
import { goto, invalidateAll } from '$app/navigation';
|
||||||
|
import { onDestroy, onMount } from 'svelte';
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
|
||||||
$: data.submissions.sort((a, b) => {
|
$: data.submissions.sort((a, b) => {
|
||||||
return b.createdAt.valueOf() - a.createdAt.valueOf();
|
return b.createdAt.valueOf() - a.createdAt.valueOf();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let updateInterval: ReturnType<typeof setInterval> | undefined;
|
||||||
|
let updating = false;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
updateInterval = setInterval(async () => {
|
||||||
|
updating = true;
|
||||||
|
await invalidateAll();
|
||||||
|
updating = false;
|
||||||
|
}, 10000);
|
||||||
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (updateInterval) {
|
||||||
|
clearInterval(updateInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@ -15,7 +33,17 @@
|
|||||||
|
|
||||||
<h1 style="text-align:center" class="mb-4">Submissions</h1>
|
<h1 style="text-align:center" class="mb-4">Submissions</h1>
|
||||||
|
|
||||||
<p>Rows are color coded: Red - Incorrect, Green - Correct, Yellow - In Review</p>
|
<div class="row">
|
||||||
|
<div class="col-8">
|
||||||
|
<p>Rows are color coded: Red - Incorrect, Green - Correct, Yellow - In Review</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-4 text-end">
|
||||||
|
{#if updating}
|
||||||
|
<div class="spinner-border spinner-border-sm text-secondary" />
|
||||||
|
{/if}
|
||||||
|
<strong>Last Updated: </strong>{data.timestamp.toLocaleTimeString()}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table class="table table-bordered table-hover">
|
<table class="table table-bordered table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
|
Loading…
Reference in New Issue
Block a user