Initial commit.
This commit is contained in:
12
front/.dockerignore
Normal file
12
front/.dockerignore
Normal file
@@ -0,0 +1,12 @@
|
||||
*
|
||||
!env.d.ts
|
||||
!src
|
||||
!public
|
||||
!yarn.lock
|
||||
!package.json
|
||||
!index.html
|
||||
!vite.config.ts
|
||||
!tsconfig.json
|
||||
!tsconfig.app.json
|
||||
!tsconfig.node.json
|
||||
!tsconfig.vitest.json
|
6
front/.editorconfig
Normal file
6
front/.editorconfig
Normal file
@@ -0,0 +1,6 @@
|
||||
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}]
|
||||
charset = utf-8
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
30
front/.gitignore
vendored
Normal file
30
front/.gitignore
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-ssr
|
||||
coverage
|
||||
*.local
|
||||
|
||||
/cypress/videos/
|
||||
/cypress/screenshots/
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
*.tsbuildinfo
|
7
front/.prettierrc.json
Normal file
7
front/.prettierrc.json
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/prettierrc",
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"printWidth": 100
|
||||
}
|
8
front/.vscode/extensions.json
vendored
Normal file
8
front/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"Vue.volar",
|
||||
"dbaeumer.vscode-eslint",
|
||||
"EditorConfig.EditorConfig",
|
||||
"esbenp.prettier-vscode"
|
||||
]
|
||||
}
|
11
front/Dockerfile
Normal file
11
front/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM node:23-alpine as builder
|
||||
|
||||
WORKDIR /tmp/app
|
||||
COPY . /tmp/app
|
||||
|
||||
RUN yarn install --frozen-lockfile
|
||||
RUN yarn build
|
||||
|
||||
FROM nginx:stable
|
||||
|
||||
COPY --from=builder /tmp/app/dist /www/data
|
39
front/README.md
Normal file
39
front/README.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# holt59-aoc
|
||||
|
||||
This template should help get you started developing with Vue 3 in Vite.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
|
||||
|
||||
## Type Support for `.vue` Imports in TS
|
||||
|
||||
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
|
||||
|
||||
## Customize configuration
|
||||
|
||||
See [Vite Configuration Reference](https://vite.dev/config/).
|
||||
|
||||
## Project Setup
|
||||
|
||||
```sh
|
||||
yarn
|
||||
```
|
||||
|
||||
### Compile and Hot-Reload for Development
|
||||
|
||||
```sh
|
||||
yarn dev
|
||||
```
|
||||
|
||||
### Type-Check, Compile and Minify for Production
|
||||
|
||||
```sh
|
||||
yarn build
|
||||
```
|
||||
|
||||
### Lint with [ESLint](https://eslint.org/)
|
||||
|
||||
```sh
|
||||
yarn lint
|
||||
```
|
1
front/env.d.ts
vendored
Normal file
1
front/env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
19
front/eslint.config.js
Normal file
19
front/eslint.config.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import pluginVue from 'eslint-plugin-vue'
|
||||
import vueTsEslintConfig from '@vue/eslint-config-typescript'
|
||||
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
|
||||
|
||||
export default [
|
||||
{
|
||||
name: 'app/files-to-lint',
|
||||
files: ['**/*.{ts,mts,tsx,vue}'],
|
||||
},
|
||||
|
||||
{
|
||||
name: 'app/files-to-ignore',
|
||||
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
|
||||
},
|
||||
|
||||
...pluginVue.configs['flat/essential'],
|
||||
...vueTsEslintConfig(),
|
||||
skipFormatting,
|
||||
]
|
16
front/index.html
Normal file
16
front/index.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" class="h-100">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Holt59 - AOC</title>
|
||||
</head>
|
||||
|
||||
<body class="h-100" data-bs-theme="dark">
|
||||
<div id="app" class="d-flex flex-column h-100"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
47
front/package.json
Normal file
47
front/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "holt59-aoc",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "run-p type-check \"build-only {@}\" --",
|
||||
"preview": "vite preview",
|
||||
"build-only": "vite build",
|
||||
"type-check": "vue-tsc --build",
|
||||
"lint": "eslint . --fix",
|
||||
"format": "prettier --write src/"
|
||||
},
|
||||
"dependencies": {
|
||||
"bootstrap": "^5.3.3",
|
||||
"bootstrap-icons": "^1.11.3",
|
||||
"lodash": "^4.17.21",
|
||||
"luxon": "^3.5.0",
|
||||
"pinia": "^2.2.6",
|
||||
"sse.js": "^2.5.0",
|
||||
"vue": "^3.5.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node22": "^22.0.0",
|
||||
"@types/bootstrap": "^5.2.10",
|
||||
"@types/lodash": "^4.17.13",
|
||||
"@types/luxon": "^3.4.2",
|
||||
"@types/node": "^22.9.3",
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"@vue/eslint-config-prettier": "^10.1.0",
|
||||
"@vue/eslint-config-typescript": "^14.1.3",
|
||||
"@vue/tsconfig": "^0.7.0",
|
||||
"eslint": "^9.14.0",
|
||||
"eslint-plugin-vue": "^9.30.0",
|
||||
"npm-run-all2": "^7.0.1",
|
||||
"prettier": "^3.3.3",
|
||||
"sass": "1.77.6",
|
||||
"typescript": "~5.6.3",
|
||||
"vite": "^6.0.1",
|
||||
"vite-plugin-vue-devtools": "^7.6.5",
|
||||
"vue-tsc": "^2.1.10"
|
||||
},
|
||||
"resolutions": {
|
||||
"strip-ansi": "^6.0.1"
|
||||
}
|
||||
}
|
BIN
front/public/favicon.ico
Normal file
BIN
front/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
134
front/src/App.vue
Normal file
134
front/src/App.vue
Normal file
@@ -0,0 +1,134 @@
|
||||
<script setup lang="ts">
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import ResultVue from '@/components/ResultVue.vue'
|
||||
|
||||
import { loadData } from '@/api';
|
||||
import { range } from 'lodash';
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
|
||||
const inAocPeriod = (date: DateTime) => {
|
||||
return !(date.day > 25 || date.month != 12);
|
||||
}
|
||||
|
||||
const currentInput = ref("");
|
||||
const showLogs = ref(false);
|
||||
|
||||
const today = DateTime.now();
|
||||
const maxYear = today.month == 12 ? today.year : today.year - 1;
|
||||
|
||||
const initialDay = ref(inAocPeriod(today) ? today.day : 1);
|
||||
const initialYear = ref(maxYear);
|
||||
|
||||
const currentDay = ref(initialDay.value);
|
||||
const currentYear = ref(maxYear);
|
||||
|
||||
const years = range(2015, maxYear + 1);
|
||||
const days = range(1, 26);
|
||||
|
||||
// handle current day clicked
|
||||
const todayClicked = () => {
|
||||
const today = DateTime.now();
|
||||
|
||||
initialDay.value = inAocPeriod(today) ? today.day : 1;
|
||||
initialYear.value = today.month == 12 ? today.year : today.year - 1;
|
||||
|
||||
currentDay.value = initialDay.value;
|
||||
currentYear.value = initialYear.value;
|
||||
};
|
||||
|
||||
// handle load data + load data of current day on startup
|
||||
const dataLoading = ref(false);
|
||||
const lastInputLoaded = ref("");
|
||||
const lastModeLoaded = ref<"holt59" | "tests">("tests");
|
||||
|
||||
const loadDataClicked = async (mode: "holt59" | "tests" = "tests") => {
|
||||
dataLoading.value = true;
|
||||
currentInput.value = await loadData(currentYear.value, currentDay.value, mode);
|
||||
dataLoading.value = false;
|
||||
|
||||
lastModeLoaded.value = mode;
|
||||
lastInputLoaded.value = currentInput.value;
|
||||
|
||||
};
|
||||
onMounted(loadDataClicked);
|
||||
|
||||
// handle change of day/year
|
||||
watch([currentDay, currentYear], () => {
|
||||
if (currentInput.value == lastInputLoaded.value) {
|
||||
loadDataClicked(lastModeLoaded.value);
|
||||
}
|
||||
});
|
||||
|
||||
// handle submit
|
||||
const resultComponent = ref<typeof ResultVue>();
|
||||
const submitRunning = ref(false);
|
||||
|
||||
const submitClicked = async () => {
|
||||
submitRunning.value = true;
|
||||
await resultComponent.value!.submit(currentYear.value, currentDay.value, currentInput.value, () => { });
|
||||
submitRunning.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<nav class="container mt-3">
|
||||
<h1>Advent-Of-Code — Holt59</h1>
|
||||
<hr />
|
||||
</nav>
|
||||
|
||||
<ResultVue ref="resultComponent" :show-logs="showLogs" />
|
||||
<section class="container d-flex flex-column flex-grow-1 position-relative">
|
||||
<form method="POST" class="d-flex flex-column flex-grow-1">
|
||||
<div class="row mb-2 align-items-center">
|
||||
<div class="col-sm-2">
|
||||
<button class="form-control btn btn-outline-info" @click.prevent="todayClicked"
|
||||
:disabled="initialYear == currentYear && initialDay == currentDay">Today</button>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<select class="form-select" autocomplete="off" v-model="currentYear">
|
||||
<option v-for="year in years" :key="year" :value="year">{{ year }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<select class="form-select" autocomplete="off" v-model="currentDay">
|
||||
<option v-for="day in days" :key="day" :value="day">{{ day }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<button class="form-control btn btn-success" id="load-data"
|
||||
@click.prevent="() => { loadDataClicked('tests') }"
|
||||
@contextmenu.prevent="() => { loadDataClicked('holt59') }">
|
||||
<span class="spinner-border spinner-border-sm" :class="{ 'd-none': !dataLoading }" role="status"
|
||||
aria-hidden="true"></span>
|
||||
<span class="submit-text" :class="{ 'd-none': dataLoading }">Test Data</span></button>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="showLogs" v-model="showLogs">
|
||||
<label class="form-check-label" for="showLogs">
|
||||
Show Logs
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<button type="submit" class="form-control btn btn-primary" @click.prevent="submitClicked">
|
||||
<span class="spinner-border spinner-border-sm" :class="{ 'd-none': !submitRunning }" role="status"
|
||||
aria-hidden="true"></span>
|
||||
<span class="submit-text" :class="{ 'd-none': submitRunning }">Go!</span></button>
|
||||
</div>
|
||||
</div>
|
||||
<textarea class="area-input flex-grow-1 w-100" v-model="currentInput"></textarea>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.area-input {
|
||||
resize: none;
|
||||
font-family: var(--bs-font-monospace);
|
||||
font-size: .9em;
|
||||
}
|
||||
</style>
|
50
front/src/api/index.ts
Normal file
50
front/src/api/index.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { SSE } from 'sse.js';
|
||||
import type { StreamMessage } from './models';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
const API_SUFFIX = "/api/v1";
|
||||
|
||||
export const urlFor = (path: string) => {
|
||||
return window.location.protocol + "//" + window.location.hostname + API_SUFFIX + "/" + path;
|
||||
};
|
||||
|
||||
export const loadData = async (year: number, day: number, mode: "holt59" | "tests") => {
|
||||
const url = new URL(urlFor("data"));
|
||||
url.searchParams.append("year", year.toString());
|
||||
url.searchParams.append("day", day.toString());
|
||||
url.searchParams.append("mode", mode);
|
||||
return await fetch(url, {
|
||||
"method": "GET",
|
||||
}).then(r => r.json()).then(r => r["content"]).catch(() => "");
|
||||
};
|
||||
|
||||
export const submit = async (year: number, day: number, input: string, startCallback: (time: DateTime, commit: string) => void, streamCallback: (message: StreamMessage) => void) => {
|
||||
const data = new FormData();
|
||||
data.append("year", year.toString());
|
||||
data.append("day", day.toString());
|
||||
data.append("input", input.toString());
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const eventSource = new SSE(urlFor("submit-sse"), {
|
||||
"start": false,
|
||||
// @ts-expect-error bad typing from SSE
|
||||
"payload": data
|
||||
});
|
||||
|
||||
eventSource.addEventListener('message', function (e: { data: string }) {
|
||||
const data = JSON.parse(e.data);
|
||||
|
||||
if (data.event == "complete") {
|
||||
resolve(null)
|
||||
}
|
||||
else if (data.event == "start") {
|
||||
startCallback(DateTime.fromISO(data.data.time), data.data.commit);
|
||||
}
|
||||
else if (data.event == "stream") {
|
||||
streamCallback(data.data);
|
||||
}
|
||||
});
|
||||
|
||||
eventSource.stream();
|
||||
});
|
||||
}
|
48
front/src/api/models.ts
Normal file
48
front/src/api/models.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
type _AnswerStream = {
|
||||
type: "answer";
|
||||
time: string;
|
||||
content: {
|
||||
answer: 1 | 2;
|
||||
answerTime_s: number;
|
||||
totalTime_s: number;
|
||||
value: string;
|
||||
}
|
||||
};
|
||||
|
||||
type _ProgressStream = {
|
||||
type: "progress-start";
|
||||
time: string;
|
||||
content: {
|
||||
counter: number;
|
||||
total: number;
|
||||
}
|
||||
} | {
|
||||
type: "progress-step";
|
||||
time: string;
|
||||
content: {
|
||||
counter: number;
|
||||
percent: number;
|
||||
}
|
||||
} | {
|
||||
type: "progress-end";
|
||||
time: string;
|
||||
content: {
|
||||
counter: number;
|
||||
}
|
||||
};
|
||||
|
||||
type _LogStream = {
|
||||
type: "log";
|
||||
time: string;
|
||||
content: {
|
||||
level: "ERROR" | "WARNING" | "INFO" | "DEBUG";
|
||||
message: string;
|
||||
}
|
||||
};
|
||||
|
||||
type _ErrorStream = {
|
||||
type: "error";
|
||||
message: string;
|
||||
};
|
||||
|
||||
export type StreamMessage = _AnswerStream | _ProgressStream | _LogStream | _ErrorStream;
|
78
front/src/assets/base.css
Normal file
78
front/src/assets/base.css
Normal file
@@ -0,0 +1,78 @@
|
||||
/* color palette from <https://github.com/vuejs/theme> */
|
||||
:root {
|
||||
--vt-c-white: #ffffff;
|
||||
--vt-c-white-soft: #f8f8f8;
|
||||
--vt-c-white-mute: #f2f2f2;
|
||||
|
||||
--vt-c-black: #181818;
|
||||
--vt-c-black-soft: #222222;
|
||||
--vt-c-black-mute: #282828;
|
||||
|
||||
--vt-c-indigo: #2c3e50;
|
||||
|
||||
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
|
||||
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
|
||||
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
|
||||
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
|
||||
|
||||
--vt-c-text-light-1: var(--vt-c-indigo);
|
||||
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
|
||||
--vt-c-text-dark-1: var(--vt-c-white);
|
||||
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
|
||||
}
|
||||
|
||||
/* semantic color variables for this project */
|
||||
:root {
|
||||
--color-background: var(--vt-c-white);
|
||||
--color-background-soft: var(--vt-c-white-soft);
|
||||
--color-background-mute: var(--vt-c-white-mute);
|
||||
|
||||
--color-border: var(--vt-c-divider-light-2);
|
||||
--color-border-hover: var(--vt-c-divider-light-1);
|
||||
|
||||
--color-heading: var(--vt-c-text-light-1);
|
||||
--color-text: var(--vt-c-text-light-1);
|
||||
|
||||
--section-gap: 160px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--color-background: var(--vt-c-black);
|
||||
--color-background-soft: var(--vt-c-black-soft);
|
||||
--color-background-mute: var(--vt-c-black-mute);
|
||||
|
||||
--color-border: var(--vt-c-divider-dark-2);
|
||||
--color-border-hover: var(--vt-c-divider-dark-1);
|
||||
|
||||
--color-heading: var(--vt-c-text-dark-1);
|
||||
--color-text: var(--vt-c-text-dark-2);
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
min-height: 100vh;
|
||||
color: var(--color-text);
|
||||
background: var(--color-background);
|
||||
transition:
|
||||
color 0.5s,
|
||||
background-color 0.5s;
|
||||
line-height: 1.6;
|
||||
font-family:
|
||||
Inter,
|
||||
-apple-system,
|
||||
BlinkMacSystemFont,
|
||||
'Segoe UI',
|
||||
Roboto,
|
||||
Oxygen,
|
||||
Ubuntu,
|
||||
Cantarell,
|
||||
'Fira Sans',
|
||||
'Droid Sans',
|
||||
'Helvetica Neue',
|
||||
sans-serif;
|
||||
font-size: 15px;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
39
front/src/assets/bootstrap.scss
vendored
Normal file
39
front/src/assets/bootstrap.scss
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
@use 'sass:map';
|
||||
|
||||
$vt-c-green: #42b883;
|
||||
$primary: $vt-c-green;
|
||||
|
||||
@import '../../node_modules/bootstrap/scss/functions';
|
||||
@import '../../node_modules/bootstrap/scss/variables';
|
||||
@import '../../node_modules/bootstrap/scss/mixins';
|
||||
|
||||
$container-max-widths: map.merge(
|
||||
$container-max-widths,
|
||||
(
|
||||
// 1140px
|
||||
xl: 1140px,
|
||||
|
||||
// 1320px
|
||||
xxl: 1140px
|
||||
)
|
||||
);
|
||||
|
||||
@import '../../node_modules/bootstrap/scss/bootstrap';
|
||||
|
||||
*[data-bs-theme='dark'] {
|
||||
.btn-primary,
|
||||
.btn-outline-primary:hover,
|
||||
.btn-outline-primary:focus-visible,
|
||||
.btn-outline-primary:active {
|
||||
color: rgb(43, 48, 53);
|
||||
}
|
||||
}
|
||||
|
||||
*[data-bs-theme='light'] {
|
||||
.btn-primary,
|
||||
.btn-outline-primary:hover,
|
||||
.btn-outline-primary:focus-visible,
|
||||
.btn-outline-primary:active {
|
||||
color: #fff;
|
||||
}
|
||||
}
|
1
front/src/assets/logo.svg
Normal file
1
front/src/assets/logo.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>
|
After Width: | Height: | Size: 276 B |
15
front/src/assets/main.scss
Normal file
15
front/src/assets/main.scss
Normal file
@@ -0,0 +1,15 @@
|
||||
@use 'sass:map';
|
||||
|
||||
@import '../../node_modules/bootstrap/scss/functions';
|
||||
@import '../../node_modules/bootstrap/scss/variables';
|
||||
@import '../../node_modules/bootstrap/scss/mixins';
|
||||
|
||||
#content-div {
|
||||
min-height: 50px;
|
||||
font-family: var(--bs-font-monospace);
|
||||
}
|
||||
|
||||
#content-div>p,
|
||||
#content-div>.progress {
|
||||
margin-bottom: .3rem;
|
||||
}
|
10
front/src/components/ResultProgressLine.vue
Normal file
10
front/src/components/ResultProgressLine.vue
Normal file
@@ -0,0 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
progress: number
|
||||
}>();
|
||||
</script>
|
||||
<template>
|
||||
<div class="progress" role="progressbar" :aria-valuenow="progress" aria-valuemin="0" aria-valuemax="100">
|
||||
<div class="progress-bar" :style="{ 'width': progress + '%' }"></div>
|
||||
</div>
|
||||
</template>
|
128
front/src/components/ResultVue.vue
Normal file
128
front/src/components/ResultVue.vue
Normal file
@@ -0,0 +1,128 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
import * as Api from '@/api';
|
||||
import type { StreamMessage } from '@/api/models';
|
||||
import type { DateTime } from 'luxon';
|
||||
import { h, reactive, ref, type Reactive, type VNode } from 'vue';
|
||||
import ResultProgressLine from './ResultProgressLine.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
showLogs: boolean
|
||||
}>();
|
||||
|
||||
const hasResult = ref(false);
|
||||
const isRunning = ref(false);
|
||||
|
||||
const commitValue = ref("");
|
||||
// const progressValue = ref(-1);
|
||||
|
||||
const answer1Value = ref<string | null>(null);
|
||||
const answer2Value = ref<string | null>(null);
|
||||
|
||||
const contentDiv = ref<HTMLDivElement>();
|
||||
const contentRows = ref<Array<() => VNode>>([]);
|
||||
const contentProgress: Map<number, Reactive<{ progress: number }>> = new Map();
|
||||
const contentErrors = ref("");
|
||||
|
||||
const addRow = (node: () => VNode) => {
|
||||
contentRows.value = contentRows.value.concat(node);
|
||||
}
|
||||
|
||||
const startCallback = (time: DateTime, commit: string) => {
|
||||
hasResult.value = true;
|
||||
commitValue.value = commit;
|
||||
|
||||
addRow(() => h("p", {}, ["Computing part 1... "]));
|
||||
}
|
||||
|
||||
const streamCallback = (message: StreamMessage) => {
|
||||
switch (message.type) {
|
||||
case "progress-start":
|
||||
const progressProps = reactive({ progress: 0 });
|
||||
contentProgress.set(message.content.counter, progressProps);
|
||||
addRow(() => h(ResultProgressLine, progressProps));
|
||||
break;
|
||||
case "progress-step":
|
||||
contentProgress.get(message.content.counter)!.progress = message.content.percent;
|
||||
break;
|
||||
case "progress-end":
|
||||
contentProgress.get(message.content.counter)!.progress = 100;
|
||||
break;
|
||||
case "log":
|
||||
addRow(() => h("p", { "class": { "log": true, "d-none": !props.showLogs } }, [`[${message.content.level}] ${message.time}: ${message.content.message}`]))
|
||||
break;
|
||||
case "error":
|
||||
contentErrors.value = contentErrors.value + message.message;
|
||||
break;
|
||||
case "answer": {
|
||||
const value = message.content.value;
|
||||
if (value.trim().indexOf("\n") >= 0) {
|
||||
addRow(() => h(
|
||||
"p", {}, [`Answer ${message.content.answer} is`,
|
||||
h('pre', {}, [value]),
|
||||
`...found in ${message.content.answerTime_s}s.`]
|
||||
));
|
||||
|
||||
}
|
||||
else {
|
||||
addRow(() => h(
|
||||
"p", {}, [`Answer ${message.content.answer} is '${message.content.value}', found in ${message.content.answerTime_s}s.`]
|
||||
));
|
||||
}
|
||||
|
||||
if (message.content.answer == 1) {
|
||||
addRow(() => h("p", {}, ["Computing part 2... "]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const submit = async (year: number, day: number, input: string) => {
|
||||
answer1Value.value = null;
|
||||
answer2Value.value = null;
|
||||
contentErrors.value = "";
|
||||
hasResult.value = false;
|
||||
isRunning.value = true;
|
||||
contentRows.value = [];
|
||||
await Api.submit(year, day, input, startCallback, streamCallback);
|
||||
isRunning.value = false;
|
||||
}
|
||||
|
||||
defineExpose({ submit });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="container d-flex flex-column position-relative" :class="{ 'd-none': !hasResult }">
|
||||
<div>
|
||||
<div class="position-absolute" style="top: 0px; right: 12px;">
|
||||
<button class="btn btn-info" type="button" id="btn-clear-output"
|
||||
@click.prevent="() => { hasResult = false }">
|
||||
Clear
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content" ref="contentDiv" id="content-div">
|
||||
<component :is="() => contentRows.map(row => row())"></component>
|
||||
</div>
|
||||
<code class="stderr text-danger" :class="{ 'd-none': !contentErrors }"><pre>{{ contentErrors }}</pre></code>
|
||||
<p class="text-end"><small>AOC package version <code>{{ commitValue }}</code></small></p>
|
||||
<hr />
|
||||
</section>
|
||||
|
||||
<Teleport to="body">
|
||||
<div class="modal fade" id="logsModal" tabindex="-1" aria-labelledby="logsModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="logsModalLabel">Logs</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<code class="stderr text-danger" id="data-logs"><pre>{{ '' }}</pre></code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
14
front/src/main.ts
Normal file
14
front/src/main.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import '@/assets/bootstrap.scss'
|
||||
import '@/assets/main.scss'
|
||||
import 'bootstrap'
|
||||
import 'bootstrap-icons/font/bootstrap-icons.css'
|
||||
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import App from './App.vue'
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
app.use(createPinia())
|
||||
|
||||
app.mount('#app')
|
12
front/src/stores/counter.ts
Normal file
12
front/src/stores/counter.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useCounterStore = defineStore('counter', () => {
|
||||
const count = ref(0)
|
||||
const doubleCount = computed(() => count.value * 2)
|
||||
function increment() {
|
||||
count.value++
|
||||
}
|
||||
|
||||
return { count, doubleCount, increment }
|
||||
})
|
20
front/tsconfig.app.json
Normal file
20
front/tsconfig.app.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "@vue/tsconfig/tsconfig.dom.json",
|
||||
"include": [
|
||||
"env.d.ts",
|
||||
"src/**/*",
|
||||
"src/**/*.vue"
|
||||
],
|
||||
"exclude": [
|
||||
"src/**/__tests__/*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
11
front/tsconfig.json
Normal file
11
front/tsconfig.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
}
|
||||
]
|
||||
}
|
20
front/tsconfig.node.json
Normal file
20
front/tsconfig.node.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "@tsconfig/node22/tsconfig.json",
|
||||
"include": [
|
||||
"vite.config.*",
|
||||
"vitest.config.*",
|
||||
"cypress.config.*",
|
||||
"nightwatch.conf.*",
|
||||
"playwright.config.*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"noEmit": true,
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
}
|
||||
}
|
18
front/vite.config.ts
Normal file
18
front/vite.config.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
vueDevTools(),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
},
|
||||
},
|
||||
})
|
2484
front/yarn.lock
Normal file
2484
front/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user