[Web] Recreate repos for specific teams and during contest
This commit is contained in:
parent
c54643d8f9
commit
8344cbe2bc
@ -68,7 +68,7 @@ async function addProblemsCPP(opts: OptsAddProblems) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function createRepos(contestId: number) {
|
||||
export async function createRepos(contestId: number, teamIds: number[]) {
|
||||
const vol = new memfs.Volume();
|
||||
const fs = createFsFromVolume(vol);
|
||||
|
||||
@ -81,35 +81,37 @@ export async function createRepos(contestId: number) {
|
||||
return;
|
||||
}
|
||||
|
||||
contest.teams.forEach(async (team) => {
|
||||
fs.mkdirSync(team.id.toString(), { recursive: true });
|
||||
await git.init({ fs: fs, bare: false, defaultBranch: 'master', dir: team.id.toString() });
|
||||
if (team.language === 'Java') {
|
||||
addProblemsJava({ fs, dir: team.id.toString(), contest });
|
||||
} else if (team.language === 'CSharp') {
|
||||
addProblemsCSharp({ fs, dir: team.id.toString(), contest });
|
||||
fs.writeFileSync(join(team.id.toString(), '.gitignore'), templateCSharpGitIgnore);
|
||||
} else if (team.language === 'CPP') {
|
||||
addProblemsCPP({ fs, dir: team.id.toString(), contest });
|
||||
fs.writeFileSync(join(team.id.toString(), '.gitignore'), templateCppGitIgnore);
|
||||
} else {
|
||||
console.error('Language not supported');
|
||||
return;
|
||||
}
|
||||
await git.add({ fs: fs, dir: team.id.toString(), filepath: '.' });
|
||||
await git.commit({
|
||||
fs: fs,
|
||||
dir: team.id.toString(),
|
||||
message: 'Initial',
|
||||
author: { name: 'Admin' }
|
||||
contest.teams
|
||||
.filter((t) => teamIds.includes(t.id))
|
||||
.forEach(async (team) => {
|
||||
fs.mkdirSync(team.id.toString(), { recursive: true });
|
||||
await git.init({ fs: fs, bare: false, defaultBranch: 'master', dir: team.id.toString() });
|
||||
if (team.language === 'Java') {
|
||||
addProblemsJava({ fs, dir: team.id.toString(), contest });
|
||||
} else if (team.language === 'CSharp') {
|
||||
addProblemsCSharp({ fs, dir: team.id.toString(), contest });
|
||||
fs.writeFileSync(join(team.id.toString(), '.gitignore'), templateCSharpGitIgnore);
|
||||
} else if (team.language === 'CPP') {
|
||||
addProblemsCPP({ fs, dir: team.id.toString(), contest });
|
||||
fs.writeFileSync(join(team.id.toString(), '.gitignore'), templateCppGitIgnore);
|
||||
} else {
|
||||
console.error('Language not supported');
|
||||
return;
|
||||
}
|
||||
await git.add({ fs: fs, dir: team.id.toString(), filepath: '.' });
|
||||
await git.commit({
|
||||
fs: fs,
|
||||
dir: team.id.toString(),
|
||||
message: 'Initial',
|
||||
author: { name: 'Admin' }
|
||||
});
|
||||
await git.push({
|
||||
fs: fs,
|
||||
http,
|
||||
dir: team.id.toString(),
|
||||
url: `http://127.0.0.1:${
|
||||
process.env.GIT_PORT ?? 7006
|
||||
}/${contest.id.toString()}/${team.id.toString()}`
|
||||
});
|
||||
});
|
||||
await git.push({
|
||||
fs: fs,
|
||||
http,
|
||||
dir: team.id.toString(),
|
||||
url: `http://127.0.0.1:${
|
||||
process.env.GIT_PORT ?? 7006
|
||||
}/${contest.id.toString()}/${team.id.toString()}`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ export const actions = {
|
||||
});
|
||||
return { success: true };
|
||||
},
|
||||
repo: async ({ params }) => {
|
||||
repo: async ({ params, request }) => {
|
||||
if (!params.contestId) {
|
||||
return { success: false };
|
||||
}
|
||||
@ -104,10 +104,20 @@ export const actions = {
|
||||
if (isNaN(contestId)) {
|
||||
return { success: false };
|
||||
}
|
||||
if (fs.existsSync(join('repo', contestId.toString()))) {
|
||||
fs.removeSync(join('repo', contestId.toString()));
|
||||
}
|
||||
await createRepos(contestId);
|
||||
const form = await request.formData();
|
||||
const formEntries = Array.from(form.entries());
|
||||
const resetTeamIds = formEntries
|
||||
.filter((e) => e[0].startsWith('teamId'))
|
||||
.map((e) => {
|
||||
return parseInt(e[1].toString());
|
||||
});
|
||||
resetTeamIds.forEach((teamId) => {
|
||||
const repoPath = join('repo', contestId.toString(), `${teamId.toString()}.git`);
|
||||
if (fs.existsSync(repoPath) === true) {
|
||||
fs.removeSync(repoPath);
|
||||
}
|
||||
});
|
||||
await createRepos(contestId, resetTeamIds);
|
||||
return { success: true };
|
||||
},
|
||||
'freeze-time': async ({ params, request }) => {
|
||||
|
@ -11,10 +11,12 @@
|
||||
|
||||
$: if (form) {
|
||||
freezeModal.hide();
|
||||
repoModal.hide();
|
||||
}
|
||||
|
||||
let confirmModal: ConfirmModal;
|
||||
let freezeModal: Modal;
|
||||
let repoModal: Modal;
|
||||
|
||||
function enhanceConfirm(form: HTMLFormElement, text: string) {
|
||||
enhance(form, async ({ cancel }) => {
|
||||
@ -32,6 +34,18 @@
|
||||
$: if (freezeTimeInputLocal !== undefined) {
|
||||
freezeTimeInput = new Date(freezeTimeInputLocal).toISOString();
|
||||
}
|
||||
|
||||
function repoSelectNone() {
|
||||
document.querySelectorAll<HTMLInputElement>('.repoCheck').forEach((e) => {
|
||||
e.checked = false;
|
||||
});
|
||||
}
|
||||
|
||||
function repoSelectAll() {
|
||||
document.querySelectorAll<HTMLInputElement>('.repoCheck').forEach((e) => {
|
||||
e.checked = true;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@ -65,6 +79,43 @@
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<Modal title="Reset Repos" bind:this={repoModal}>
|
||||
<form action="?/repo" method="POST" use:enhance>
|
||||
<div class="modal-body">
|
||||
<div class="d-flex flex-row gap-2 pb-2">
|
||||
<button on:click={repoSelectNone} type="button" class="btn btn-sm btn-outline-secondary"
|
||||
>Select None</button
|
||||
>
|
||||
<button on:click={repoSelectAll} type="button" class="btn btn-sm btn-outline-secondary"
|
||||
>Select All</button
|
||||
>
|
||||
</div>
|
||||
{#each data.teams as team}
|
||||
<div class="form-check">
|
||||
<input
|
||||
name={`teamId${team.id}`}
|
||||
class="form-check-input repoCheck"
|
||||
type="checkbox"
|
||||
value={team.id}
|
||||
id={`repoCheck${team.id}`}
|
||||
/>
|
||||
<label class="form-check-label" for={`repoCheck${team.id}`}>{team.name}</label>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-secondary"
|
||||
on:click={() => {
|
||||
repoModal.hide();
|
||||
}}>Cancel</button
|
||||
>
|
||||
<button type="submit" class="btn btn-warning">Reset Selected</button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<h1 style="text-align:center" class="mb-4"><i class="bi bi-flag"></i> Contest - {data.name}</h1>
|
||||
|
||||
<FormAlert />
|
||||
@ -85,6 +136,13 @@
|
||||
freezeModal.show();
|
||||
}}>Set Freeze Time</button
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-warning"
|
||||
on:click={() => {
|
||||
repoModal.show();
|
||||
}}>Reset Repos</button
|
||||
>
|
||||
{#if data.activeTeams === 0}
|
||||
<form
|
||||
method="POST"
|
||||
@ -94,19 +152,11 @@
|
||||
>
|
||||
<button type="submit" class="btn btn-danger">Delete</button>
|
||||
</form>
|
||||
<form
|
||||
method="POST"
|
||||
action="?/repo"
|
||||
class="d-inline"
|
||||
use:enhanceConfirm={'Are you sure you want to recreate repos? This WILL DELETE ALL DATA on the repos currently.'}
|
||||
>
|
||||
<button type="submit" class="btn btn-warning">Recreate Repos</button>
|
||||
</form>
|
||||
<form
|
||||
method="POST"
|
||||
action="?/start"
|
||||
class="d-inline"
|
||||
use:enhanceConfirm={'Are you sure you want to start the contest?'}
|
||||
use:enhanceConfirm={'Are you sure you want to start the contest? (THIS WILL DELETE ALL DATA IF THE CONTEST HAS ALREADY BEEN RUN)'}
|
||||
>
|
||||
<button type="submit" class="btn btn-success">Start</button>
|
||||
</form>
|
||||
|
@ -45,7 +45,10 @@ export const actions = {
|
||||
include: { teams: true, problems: true }
|
||||
});
|
||||
|
||||
await createRepos(createdContest.id);
|
||||
await createRepos(
|
||||
createdContest.id,
|
||||
teams.map((t) => t.id)
|
||||
);
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
@ -153,7 +153,10 @@ export const actions = {
|
||||
await db.activeTeam.create({ data: { teamId: team.id, contestId: contest.id } });
|
||||
});
|
||||
|
||||
await createRepos(contest.id);
|
||||
await createRepos(
|
||||
contest.id,
|
||||
fullContest.teams.map((t) => t.id)
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user