From d692c615905b3a54809197baa9ec508d6d9be671 Mon Sep 17 00:00:00 2001 From: Raine Date: Mon, 16 Oct 2023 01:36:02 +0200 Subject: [PATCH] feat: ixvd/hub integration --- public/index.html | 27 +++++++++------ public/obj/css/main.css | 68 +++++++++++++++++++++++++++++++++++-- public/obj/js/issues.js | 62 +++++++++++++++++++++++++++++++++ public/obj/js/services.js | 6 ++-- public/obj/js/updateLoop.js | 15 ++++++++ src/main.rs | 1 - src/relay.rs | 14 ++++++++ 7 files changed, 177 insertions(+), 16 deletions(-) create mode 100644 public/obj/js/issues.js create mode 100644 public/obj/js/updateLoop.js diff --git a/public/index.html b/public/index.html index 1bf8def..40b0265 100644 --- a/public/index.html +++ b/public/index.html @@ -6,19 +6,26 @@ IXVD - Home + + -
-

IXVD

-

Home of people that love software, games and developing!

-
-

Services

-
- Nothing (yet)! -
+ +
+

IXVD

+

Home of people that love software, games and developing!

+
+

Services

+
+ Nothing (yet)!
-
-
+
+
+
\ No newline at end of file diff --git a/public/obj/css/main.css b/public/obj/css/main.css index 0b4361f..71ce482 100644 --- a/public/obj/css/main.css +++ b/public/obj/css/main.css @@ -11,15 +11,19 @@ body { padding: 0; height: 100%; display: flex; + flex-direction: column; justify-content: center; align-items: center; background-color: #f0f0f0; } -main { +body > * { + width: 50%; padding: 1rem 2rem; +} + +main { border: 1px solid #ddd; - border-radius: 4px; background-color: #fff; } @@ -37,6 +41,62 @@ main { text-align: right; } +#issues { + display: flex; + flex-direction: column; + background: #555555; + color: #fff; + transition: all .3s ease-in-out; + /*box-shadow: inset 0 -10px 10px rgba(0,0,0,.3);*/ +} + +#issues > * { + margin: 0; + padding: 0; +} + +#issues-holder { + display: flex; + flex-direction: column; +} + +#issues-holder .issue { + display: grid; + grid-template-areas: "issue-details issue-data"; + grid-template-columns: 8fr 2fr; + padding: 5px 0; +} + +#issues-holder .issue + .issue { + border-top: 1px solid #777777; +} + +#issues-holder .issue .issue-details { + grid-area: issue-details; + display: flex; + flex-direction: column; +} + +#issues-holder .issue .issue-details .issue-title { + font-size: 1.2em; + font-weight: bold; +} + +#issues-holder .issue .issue-data { + grid-area: issue-data; + display: grid; + align-content: start; +} + +#issues-holder .issue .issue-data > span { + display: flex; + justify-content: right; +} + +#issues-holder .issue .issue-data .issue-status { + font-weight: bold; +} + a { color: #000; transition: 0.5s all; @@ -73,4 +133,8 @@ a:hover { #links a { margin-bottom: 0.5rem; +} + +[hidden] { + display: none !important; } \ No newline at end of file diff --git a/public/obj/js/issues.js b/public/obj/js/issues.js new file mode 100644 index 0000000..85bfdd5 --- /dev/null +++ b/public/obj/js/issues.js @@ -0,0 +1,62 @@ +const issuesDiv = document.querySelector("#issues"); +const issuesHolderDiv = document.querySelector("#issues-holder"); + +async function updateIssues() { + let fetchResult = await (await fetch('/relay/hub_issues')).json() + if (fetchResult.length > 0) { + issuesDiv.removeAttribute("hidden"); + issuesHolderDiv.innerHTML = ''; + fetchResult.forEach((issue) => { + let issueDiv = document.createElement("div"); + issueDiv.classList.add("issue"); + let detailsDiv = document.createElement("div"); + detailsDiv.classList.add("issue-details"); + issueDiv.append(detailsDiv); + + let titleSpan = document.createElement("span"); + titleSpan.classList.add("issue-title"); + detailsDiv.append(titleSpan); + titleSpan.innerText = issue.title; + + + let descriptionSpan = document.createElement("span"); + descriptionSpan.classList.add("issue-description"); + detailsDiv.append(descriptionSpan); + let desc = () => { + let body = issue.body.replaceAll("\r", "").replaceAll("\n", " "); + if (body.length > 100) { + return body.slice(0, 100) + "..." + } else { + return body + } + }; + descriptionSpan.innerText = desc(); + + let dataDiv = document.createElement("div"); + dataDiv.classList.add("issue-data"); + issueDiv.append(dataDiv); + + let statusSpan = document.createElement("span"); + statusSpan.classList.add("issue-status"); + dataDiv.append(statusSpan); + statusSpan.innerText = issue.state; + switch (issue.state) { + case 'open': + statusSpan.style.color = "#ff8f8f"; + break + case 'closed': + statusSpan.style.color = "#8fff91"; + break + } + + let timeSpan = document.createElement("span"); + statusSpan.classList.add("issue-time"); + dataDiv.append(timeSpan); + timeSpan.innerText = issue.updated_at; + + issuesHolderDiv.append(issueDiv) + }) + } else issuesDiv.setAttribute("hidden", "true"); +} + +window.updateLoop.push(updateIssues); diff --git a/public/obj/js/services.js b/public/obj/js/services.js index 1400c9d..e53e6e9 100644 --- a/public/obj/js/services.js +++ b/public/obj/js/services.js @@ -6,9 +6,9 @@ const SERVICE_BLACKLIST = [ ]; const serviceHolderDiv = document.querySelector('#service-holder'); +serviceHolderDiv.innerHTML = 'Loading...'; -async function update() { - serviceHolderDiv.innerHTML = 'Loading...'; +async function updateServices() { let fetchResult = await (await fetch('/relay/gatus')).json() serviceHolderDiv.innerHTML = ''; @@ -27,4 +27,4 @@ async function update() { }) } -update(); \ No newline at end of file +window.updateLoop.push(updateServices); \ No newline at end of file diff --git a/public/obj/js/updateLoop.js b/public/obj/js/updateLoop.js new file mode 100644 index 0000000..af02873 --- /dev/null +++ b/public/obj/js/updateLoop.js @@ -0,0 +1,15 @@ +window.updateLoop = []; + +(() => { + let updLoop = setInterval(() => { + updateLoop.forEach(f => f()); + }, 15000); + + let everythingLoaded = setInterval(function() { + if (/loaded|complete/.test(document.readyState)) { + clearInterval(everythingLoaded); + updateLoop.forEach(f => f()); + } + }, 10); +})(); + diff --git a/src/main.rs b/src/main.rs index 3db6a04..64dc1ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ use std::env; use actix_files as fs; use actix_web::{App, HttpServer, middleware}; -use actix_web::web::Redirect; use env_logger; mod relay; diff --git a/src/relay.rs b/src/relay.rs index cf40221..011c83c 100644 --- a/src/relay.rs +++ b/src/relay.rs @@ -14,9 +14,23 @@ pub async fn get_gatus_services() -> HttpResponse { .body(status_response.text().await.unwrap()) } +#[get("/hub_issues")] +pub async fn get_hub_issues() -> HttpResponse { + let status_response = if let Ok(res) = reqwest::get("https://git.ixvd.net/api/v1/repos/ixvd/hub/issues?state=open").await { + res + } else { + return HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR) + .body("Failed to get status from forgejo"); + }; + + HttpResponse::build(StatusCode::OK) + .body(status_response.text().await.unwrap()) +} + pub fn configure(cfg: &mut web::ServiceConfig) { cfg.service( web::scope("/relay") .service(get_gatus_services) + .service(get_hub_issues) ); } \ No newline at end of file