bw-hspc-contest-env/web
David Poeschl 4a3ff56e7a
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
..
docker Initial public scoreboard 2024-02-26 13:52:55 -05:00
prisma [web] Format and add CPP to db 2024-01-16 17:20:21 -05:00
src VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14) 2024-03-05 17:50:16 -05:00
static [web] Working scoreboard 2023-05-08 21:21:53 -04:00
.dockerignore [web] Update docker stuff 2023-10-15 14:17:45 -04:00
.env.example [web] Refactor docker stuff 2024-02-17 14:02:30 -05:00
.eslintignore Add initial web framework 2023-04-26 12:20:01 -04:00
.eslintrc.cjs Update web deps 2023-08-23 22:06:53 -04:00
.gitignore [web] Refactor docker stuff 2024-02-17 14:02:30 -05:00
.npmrc Add initial web framework 2023-04-26 12:20:01 -04:00
.prettierignore Add initial web framework 2023-04-26 12:20:01 -04:00
.prettierrc Update web deps 2023-08-23 22:06:53 -04:00
docker-compose.yml [web] Refactor docker stuff 2024-02-17 14:02:30 -05:00
Dockerfile [web] Update Dockerfile 2024-01-16 20:19:18 -05:00
package-lock.json [web] Update deps 2024-02-26 14:35:18 -05:00
package.json [web] Update deps 2024-02-26 14:35:18 -05:00
README.md [web] README 2023-11-19 21:05:29 -05:00
svelte.config.js [web] Upgrade major deps (Sveltekit 2) 2023-12-19 16:58:34 -05:00
tsconfig.json Add initial web framework 2023-04-26 12:20:01 -04:00
vite.config.ts Add initial web framework 2023-04-26 12:20:01 -04:00

BW Contest Web

Development Environment Setup for Windows

First install WSL on windows by going to the terminal and entering

wsl --install

Then you will need to restart your computer. More details about WSL can be found here. WSL is essentially an Ubuntu VM on windows, this is where all development will be done. Once WSL is installed, you should be able to open it by searching for Ubuntu in the start menu which will then open a terminal into the Ubuntu VM. First you will need to install NodeJS. We want NodeJS 20 but the current version on Ubuntu is outdated so we will use the NodeSource repository to download a later version. Run these commands to do so.

sudo apt update
sudo apt install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt update
sudo apt install nodejs -y

More details can be found here.

You can verify you then have the right version by running

node --version
# You should get back 20.x.x

You will need a database to work with so you need to install Postgres.

sudo apt install postgresql

Then start and enable it

sudo service postgresql start
sudo service postgresql enable

We will now create a database and user to work with

sudo -u postgres psql

This will open the postgres terminal, run these commands

CREATE ROLE bwcontest WITH LOGIN PASSWORD 'pass123';
CREATE DATABASE bwcontest;
ALTER DATABASE bwcontest OWNER TO bwcontest;
GRANT ALL PRIVILEGES ON DATABASE bwcontest TO bwcontest;

Then type \q to exit. Feel free to change the role name, database name, and password to whatever you want. Just make sure to remember them. This is only for local development so it doesn't need to be very secure.

Now we can clone the repo. Remember, all development must be in WSL so we will clone the repo in WSL. So inside of WSL, I like to create a folder called dev inside my home folder, but feel free to clone it anywhere else inside of WSL. Ensure git is installed in WSL with sudo apt install git -y

cd ~/dev # or wherever else
git clone https://github.com/orosmatthew/bw-hspc-contest-env

Next, you want to use VSCode for development which can be downloaded here

Make sure you have the WSL extension installed. You can then connect WSL by opening VSCode and pressing ctrl+shift+p and searching for Connect to WSL and pressing enter. I would also install the Svelte and Prisma extensions. Note that you need to click install in WSL on the extension as well. You can now press File -> Open Folder and it will now show the WSL file directories instead of Windows. Find and open the web directory in the bw-hspc-contest-env repo. You can now open the terminal in VSCode by pressing ctrl+j. This should be the terminal inside of WSL. This can be verified by running uname and it should return Linux. Install node dependencies by running...

# make sure you are in the bw-hspc-contest-env/web dir
npm install

Now you need to fill out an environment file for local development. Create a .env file in web/.env. Add this information or changed with the relevant details related to how you set up your database.

DATABASE_URL=postgresql://bwcontest:pass123@127.0.0.1:5432/bwcontest

You now need to push the schema generated via the Prisma ORM to set up the tables in the database. This can be done by running...

npx prisma db push

This should be run anytime you change the database schema. Next I would recommend trying to build the entire project to make sure you don't get any errors by running...

npm run build

If everything was set up correctly, this should succeed.

For local development, you can start the development server by running...

INIT=true npm run dev

The INIT=true environment variable indicates that the git server should start and that the default login account of username admin and password bw123 should be created. Note that the development server should always be running when programming as it generates types for proper intellisense even if you don't necessarily need to look at the browser output.

If you want to change the port of the development server to match the same port as the built project then you can add the -- --port=3000 to the end of the dev command as so.

INIT=true npm run dev -- --port=3000

Some useful commands for development are...

# This will format all files
npm run format

# This will report any linting errors/warnings
npm run lint

# This will report any typescript/svelte errors
npm run check

I usually run all 3 of these commands before I commit to make sure everything is formatted and checked.

Build Instructions

For all builds

You must fill out a .env file. An example is provided in .env.example. This is used for dev, production, and docker.

Build dependencies:

  • NodeJS
  • Docker (for docker build)

For Development

npm i
npm run dev

For Production

npm i
npm run build
node build

Docker

Copy the example docker compose file

# pwd web/
cp docker/docker-compose.example.yml ./docker-compose.yml

Fill out .env file

cp .env.example .env

Run the container

docker compose up --build