From 288b6e9ec42747c344fdb4f2eea70a72e6995462 Mon Sep 17 00:00:00 2001
From: Dominic Grimm
Date: Tue, 28 Feb 2023 12:16:33 +0100
Subject: [PATCH] Update
---
.env.example | 18 +++++------
bvplan/Dockerfile | 7 +++--
bvplan/js/bvplan.js | 43 ++++++++++++++++++++++++++
bvplan/scss/bvplan.scss | 4 +++
bvplan/src/bin/web.rs | 25 ++++++++++++---
bvplan/src/bin/worker.rs | 11 ++-----
bvplan/src/config.rs | 28 ++++++++---------
bvplan/src/templates.rs | 6 ++++
bvplan/src/worker/get_substitutions.rs | 11 +++----
bvplan/static/.keep | 0
bvplan/templates/bvplan.html | 43 +-------------------------
docker-compose.yml | 24 +++++++-------
12 files changed, 119 insertions(+), 101 deletions(-)
create mode 100644 bvplan/js/bvplan.js
delete mode 100644 bvplan/static/.keep
diff --git a/.env.example b/.env.example
index 32e16f6..08646ab 100644
--- a/.env.example
+++ b/.env.example
@@ -4,12 +4,12 @@ POSTGRES_PASSWORD="bvplan"
RABBITMQ_USER="bvplan"
RABBITMQ_PASSWORD="bvplan"
-BACKEND_UNTIS_API_URL="https://mese.webuntis.com/WebUntis/"
-BACKEND_UNTIS_RPC_URL="https://mese.webuntis.com/WebUntis/jsonrpc.do"
-BACKEND_UNTIS_CLIENT_NAME="bvplan"
-BACKEND_UNTIS_SCHOOL=
-BACKEND_UNTIS_USERNAME=
-BACKEND_UNTIS_PASSWORD=
-BACKEND_UNTIS_VPLAN_URL=
-BACKEND_UNTIS_VPLAN_USERNAME=
-BACKEND_UNTIS_VPLAN_PASSWORD=
+BVPLAN_UNTIS_API_URL="https://mese.webuntis.com/WebUntis/"
+BVPLAN_UNTIS_RPC_URL="https://mese.webuntis.com/WebUntis/jsonrpc.do"
+BVPLAN_UNTIS_CLIENT_NAME="bvplan"
+BVPLAN_UNTIS_SCHOOL=
+BVPLAN_UNTIS_USERNAME=
+BVPLAN_UNTIS_PASSWORD=
+BVPLAN_UNTIS_VPLAN_URL=
+BVPLAN_UNTIS_VPLAN_USERNAME=
+BVPLAN_UNTIS_VPLAN_PASSWORD=
diff --git a/bvplan/Dockerfile b/bvplan/Dockerfile
index d88cb15..f8dafd1 100644
--- a/bvplan/Dockerfile
+++ b/bvplan/Dockerfile
@@ -8,6 +8,7 @@ RUN find . -name "*.scss" -type f | xargs -I % sh -c 'sassc % > ../dist/$(basena
FROM tdewolff/minify:latest as static
WORKDIR /usr/src/static
COPY --from=css /usr/src/scss/dist ./css
+COPY ./js ./js
RUN minify . -r -o .
FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.65.0 as chef
@@ -24,13 +25,13 @@ RUN cargo chef prepare --recipe-path recipe.json
FROM chef as builder
WORKDIR /usr/src/backend
COPY --from=planner /usr/src/backend/recipe.json .
-RUN cargo chef cook --recipe-path recipe.json
+RUN cargo chef cook --release --recipe-path recipe.json
RUN rm -rf ./src
COPY ./build.rs .
COPY --from=static /usr/src/static ./static
COPY ./templates ./templates
COPY ./src ./src
-RUN cargo build
+RUN cargo build --release
FROM docker.io/debian:bullseye-slim as runner
LABEL maintainer="Dominic Grimm " \
@@ -51,6 +52,6 @@ WORKDIR /usr/src/backend
COPY ./run.sh .
RUN chmod +x ./run.sh
COPY ./migrations ./migrations
-COPY --from=builder /usr/src/backend/target/debug/web /usr/src/backend/target/debug/worker ./bin/
+COPY --from=builder /usr/src/backend/target/release/web /usr/src/backend/target/release/worker ./bin/
EXPOSE 80
ENTRYPOINT [ "./run.sh" ]
diff --git a/bvplan/js/bvplan.js b/bvplan/js/bvplan.js
new file mode 100644
index 0000000..aaa18ad
--- /dev/null
+++ b/bvplan/js/bvplan.js
@@ -0,0 +1,43 @@
+window.onerror = function () {
+ console.log("js error detected");
+ setTimeout(function () {
+ console.log("reloading page because of error");
+ window.location.reload();
+ }, 30_000);
+};
+
+const elementCount = JSON.parse($("#data-element-count").text());
+const waitDelay = 10_000;
+const scrollDuration = elementCount * 200;
+
+function reload() {
+ window.location.reload();
+}
+
+function scrollUp() {
+ $("html, body").animate(
+ {
+ scrollTop: 0,
+ },
+ scrollDuration,
+ "linear"
+ );
+ setTimeout(reload, scrollDuration);
+}
+
+function scrollDown() {
+ $("html, body").animate(
+ {
+ scrollTop: $(document).height() - $(window).height(),
+ },
+ scrollDuration,
+ "linear"
+ );
+ setTimeout(scrollUp, scrollDuration + waitDelay);
+}
+
+window.scrollTo(0, 0);
+setTimeout(
+ $(document).height() > $(window).height() ? scrollDown : reload,
+ waitDelay
+);
diff --git a/bvplan/scss/bvplan.scss b/bvplan/scss/bvplan.scss
index 0662226..e9b9b1f 100644
--- a/bvplan/scss/bvplan.scss
+++ b/bvplan/scss/bvplan.scss
@@ -98,5 +98,9 @@ body {
.element {
margin: 0.5rem 0;
+
+ &:last-of-type {
+ margin-bottom: 0;
+ }
}
}
diff --git a/bvplan/src/bin/web.rs b/bvplan/src/bin/web.rs
index dac6453..a3b7dba 100644
--- a/bvplan/src/bin/web.rs
+++ b/bvplan/src/bin/web.rs
@@ -11,7 +11,6 @@ use r2d2_redis::redis;
use std::ops::DerefMut;
use bvplan::*;
-use templates::TemplateToResponseWithStatusCode;
pub mod static_dir {
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
@@ -22,14 +21,20 @@ async fn not_found() -> HttpResponse {
status_code: http::StatusCode::NOT_FOUND,
message: None,
}
- .to_response_with_status_code(http::StatusCode::NOT_FOUND)
+ .to_response()
}
#[get("/")]
async fn index(redis_pool: web::Data) -> HttpResponse {
let redis_conn = &mut match redis_pool.get() {
Ok(x) => x,
- Err(_) => return HttpResponse::InternalServerError().finish(),
+ Err(_) => {
+ return templates::StatusCode {
+ status_code: http::StatusCode::INTERNAL_SERVER_ERROR,
+ message: None,
+ }
+ .to_response()
+ }
};
if let Some(html) = match redis::cmd("GET")
@@ -37,13 +42,23 @@ async fn index(redis_pool: web::Data) -> HttpResponse {
.query::
-
+