Initial commit.
This commit is contained in:
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 }
|
||||
})
|
Reference in New Issue
Block a user