bw-hspc-contest-env/extension/bwcontest/webviews/components/Sidebar.svelte

245 lines
6.4 KiB
Svelte
Raw Normal View History

2023-05-06 00:01:27 -04:00
<script lang="ts">
2023-10-15 18:35:49 -04:00
import { onMount } from 'svelte';
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
import SidebarProblemStatus from './SidebarProblemStatus.svelte';
import type { TeamData } from '../../src/sharedTypes';
import type { WebviewMessageType, MessageType, SidebarTeamStatus } from '../../src/SidebarProvider';
2023-10-15 18:35:49 -04:00
let teamname: string;
let password: string;
2023-10-15 18:35:49 -04:00
let loggedIn = false;
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
let teamData: TeamData | null = null;
let teamStatus: SidebarTeamStatus | null = null;
let totalProblems = 0;
function postMessage(message: MessageType) {
vscode.postMessage(message);
}
2023-10-15 18:35:49 -04:00
function onClone() {
if (teamData) {
postMessage({
2023-10-16 13:11:54 -04:00
msg: 'onClone',
data: { contestId: teamData.contestId, teamId: teamData.teamId }
2023-10-15 18:35:49 -04:00
});
}
}
2023-05-06 00:01:27 -04:00
2023-10-15 18:35:49 -04:00
function onLogin() {
postMessage({
2023-10-16 13:11:54 -04:00
msg: 'onLogin',
data: { teamName: teamname, password: password }
2023-10-15 18:35:49 -04:00
});
}
2023-10-15 18:35:49 -04:00
function onLogout() {
postMessage({
2023-10-16 13:11:54 -04:00
msg: 'onLogout'
2023-10-15 18:35:49 -04:00
});
2023-11-15 21:01:12 -05:00
loggedIn = false;
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
teamData = null;
2023-10-15 18:35:49 -04:00
}
2023-10-15 18:35:49 -04:00
function onTestAndSubmit() {
2023-10-16 13:11:54 -04:00
postMessage({ msg: 'onTestAndSubmit' });
2023-10-15 18:35:49 -04:00
}
2023-10-15 18:35:49 -04:00
onMount(() => {
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
postMessage({ msg: 'onUIMount' });
2023-10-15 18:35:49 -04:00
});
2023-05-07 11:01:27 -04:00
2023-10-15 18:35:49 -04:00
window.addEventListener('message', (event) => {
2023-10-16 13:11:54 -04:00
const m = (event as MessageEvent).data as WebviewMessageType;
if (m.msg === 'onLogin') {
2023-10-15 18:35:49 -04:00
loggedIn = true;
2023-10-16 13:11:54 -04:00
teamData = m.data;
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
teamStatus = null;
2023-10-16 13:11:54 -04:00
} else if (m.msg === 'onLogout') {
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
loggedIn = false;
teamStatus = null;
} else if (m.msg === 'teamStatusUpdated') {
teamStatus = m.data;
totalProblems = teamStatus
? teamStatus.correctProblems.length +
teamStatus.processingProblems.length +
teamStatus.incorrectProblems.length +
teamStatus.notStartedProblems.length
: 0;
2023-10-15 18:35:49 -04:00
}
});
2023-05-06 00:01:27 -04:00
</script>
2023-10-15 18:35:49 -04:00
{#if !loggedIn}
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
<h1>Contest Login</h1>
2023-10-15 18:35:49 -04:00
<label for="teamname">Team Name</label>
<input bind:value={teamname} id="teamname" type="text" />
2023-05-06 00:01:27 -04:00
2023-10-15 18:35:49 -04:00
<label for="password">Password</label>
<input bind:value={password} id="password" type="password" />
2023-05-06 00:01:27 -04:00
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
<div class="buttonContainer">
<button on:click={onLogin}>Login</button>
</div>
2023-05-06 00:01:27 -04:00
{:else}
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
<h2 class="sidebarSectionHeader">Contest Info</h2>
2023-10-15 18:35:49 -04:00
{#if teamData}
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
<div class="sidebarSection">
<p>
<span class="infoLabel">Team:</span>
<span class="infoData">{teamData.teamName}</span>
<span class="extraInfo"> (#{teamData.teamId})</span>
</p>
<p>
<span class="infoLabel">Contest:</span>
<span class="infoData">{teamData.contestName}</span>
<span class="extraInfo"> (#{teamData.contestId})</span>
</p>
<p>
<span class="infoLabel">Language:</span>
<span class="infoData">{teamData.language}</span>
</p>
<div class="buttonContainer">
<button on:click={onLogout} class="sidebarButton">Logout</button>
</div>
</div>
<h2 class="sidebarSectionHeader">Actions</h2>
<div class="sidebarSection">
<div class="buttonContainer">
<button on:click={onClone} class="sidebarButton">Clone and Open Repo</button>
<button on:click={onTestAndSubmit} class="sidebarButton">Test & Submit</button>
</div>
</div>
<h2 class="sidebarSectionHeader">Problem Progress</h2>
<div class="sidebarSection">
{#if teamStatus}
<div class="problemResultsSection">
<div>
<span class="problemResultsSectionHeader inProgress">Pending Judgment </span>
</div>
{#if teamStatus.processingProblems.length > 0}
{#each teamStatus.processingProblems as inProgressProblem (JSON.stringify(inProgressProblem))}
<SidebarProblemStatus problem={inProgressProblem} contestState={teamStatus.contestState} />
{/each}
{:else}
<div class="problemSectionExplanation">No pending submissions</div>
{/if}
</div>
<div class="problemResultsSection">
<div>
<span class="problemResultsSectionHeader correct">Correct </span>
<span class="problemResultsSectionCount">{teamStatus.correctProblems.length} of {totalProblems}</span>
</div>
{#if teamStatus.correctProblems.length > 0}
{#each teamStatus.correctProblems as correctProblem (JSON.stringify(correctProblem))}
<SidebarProblemStatus problem={correctProblem} contestState={teamStatus.contestState} />
{/each}
{:else}
<div class="problemSectionExplanation">Solved problems appear here</div>
{/if}
</div>
<div class="problemResultsSection">
<div>
<span class="problemResultsSectionHeader incorrect">Incorrect </span>
<span class="problemResultsSectionCount">{teamStatus.incorrectProblems.length} of {totalProblems}</span>
</div>
{#if teamStatus.incorrectProblems.length > 0}
{#each teamStatus.incorrectProblems as incorrectProblem (JSON.stringify(incorrectProblem))}
<SidebarProblemStatus problem={incorrectProblem} contestState={teamStatus.contestState} />
{/each}
{:else}
<div class="problemSectionExplanation">
Attempted problems appear here until solved
</div>
{/if}
</div>
{#if teamStatus.notStartedProblems.length > 0}
<div class="problemResultsSection">
<div>
<span class="problemResultsSectionHeader notAttempted">Not Attempted </span>
<span class="problemResultsSectionCount">{teamStatus.notStartedProblems.length} of {totalProblems}</span>
</div>
{#each teamStatus.notStartedProblems as notStartedProblem (JSON.stringify(notStartedProblem))}
<SidebarProblemStatus problem={notStartedProblem} contestState={teamStatus.contestState} />
{/each}
</div>
{/if}
{:else}
<span>Fetching data...</span>
{/if}
</div>
2023-10-15 18:35:49 -04:00
{/if}
{/if}
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) * Add an Output Panel channel named "BWContest Log" * Allow client logout when no contest And make login/logout error messages clearer * Show contest name & team name in Code extension side panel * submission icons for sidebar panel * Start VSCode extension "onStartupFinished" instead of waiting for Sidebar to be opened * VSCode: Sidebar UI for up-to-date problem/submissions status - VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team - The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged - Web: "contestState" API to get all info for an activeTeam via their token - Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle - * Add "Compilation Failed" message to submissions that fail to build * Contest Import - Option to create repos & immediately activate the imported contest Useful for testing with old contests (including the submissions) * Test/Submit panel, use fixed-width font in input/output areas * Fix build error for 'pluralize' * Clear all state & halt polling loops on logout, restart them on login * Improve the debug fastPolling option - Toggleable via package.json config - Setting the option changes the initial state as well as ability to toggle states * Web project 'npm run format'
2024-03-05 17:50:16 -05:00
<style>
.sidebarSectionHeader {
font-weight: bold;
border-bottom: 1px solid var(--vscode-charts-yellow);
color: var(--vscode-charts-yellow);
}
.sidebarSection {
margin-bottom: 12px;
padding-left: 8px;
margin-top: 6px;
}
.buttonContainer {
text-align: center;
}
.sidebarButton {
border-radius: 4px;
width: 80%;
margin-top: 4px;
}
.infoLabel {
font-weight: bold;
font-size: 15px;
}
.infoData {
font-weight: bold;
}
.extraInfo {
font-size: smaller;
visibility: collapse;
}
.problemResultsSection {
padding-bottom: 16px;
}
.problemResultsSectionHeader {
font-size: 16px;
font-weight: bold;
}
.problemSectionExplanation {
margin-left: 18px;
font-style: italic;
}
.problemResultsSectionHeader.correct {
color: var(--vscode-charts-green);
}
.problemResultsSectionHeader.inProgress {
color: var(--vscode-editorLightBulb-foreground);
}
.problemResultsSectionHeader.incorrect {
color: var(--vscode-charts-red);
}
.problemResultsSectionCount {
padding-left: 2px;
font-size: 14px;
}
</style>