diff --git a/public/obj/js/issues.js b/public/obj/js/issues.js index 6c3bebf..14b9a2b 100644 --- a/public/obj/js/issues.js +++ b/public/obj/js/issues.js @@ -1,12 +1,42 @@ const issuesDiv = document.querySelector("#issues"); const issuesHolderDiv = document.querySelector("#issues-holder"); +issuesHolderDiv.innerHTML = "
Loading items...
" + +async function getStatus(issueIndex) { + let response = await fetch(`/relay/hub_issue_timeline/${issueIndex}`); + let json = await response.json(); + let status = "pending"; + let time_trackers = -1; + json.forEach((entry) => { + switch (entry.type) { + case 'start_tracking': + if (time_trackers === -1) time_trackers = 0; + time_trackers++; + break; + case 'stop_tracking': + time_trackers--; + break; + } + }); + + if (time_trackers > 0) { + status = "in progress" + } else if (time_trackers === -1) { + status = "not started work" + } else { + status = "work is suspended" + } + + return status; +} 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 issueElems = []; + for (const issue of fetchResult) { let issueDiv = document.createElement("div"); issueDiv.classList.add("issue"); let detailsDiv = document.createElement("div"); @@ -40,7 +70,7 @@ async function updateIssues() { let statusSpan = document.createElement("span"); statusSpan.classList.add("issue-status"); dataDiv.append(statusSpan); - statusSpan.innerText = issue.state; + statusSpan.innerText = await getStatus(issue.number); switch (issue.state) { case 'open': statusSpan.style.color = "#ff8f8f"; @@ -55,8 +85,11 @@ async function updateIssues() { dataDiv.append(timeSpan); timeSpan.innerText = issue.updated_at; - issuesHolderDiv.append(issueDiv) - }) + issueElems.push(issueDiv); + } + + issuesHolderDiv.innerHTML = ''; + issueElems.forEach((i) => issuesHolderDiv.append(i)) } else issuesDiv.setAttribute("hidden", "true"); } diff --git a/public/obj/js/updateLoop.js b/public/obj/js/updateLoop.js index af02873..ba2b4da 100644 --- a/public/obj/js/updateLoop.js +++ b/public/obj/js/updateLoop.js @@ -3,7 +3,7 @@ window.updateLoop = []; (() => { let updLoop = setInterval(() => { updateLoop.forEach(f => f()); - }, 15000); + }, 30000); let everythingLoaded = setInterval(function() { if (/loaded|complete/.test(document.readyState)) { diff --git a/src/relay.rs b/src/relay.rs index 011c83c..5bda515 100644 --- a/src/relay.rs +++ b/src/relay.rs @@ -27,10 +27,24 @@ pub async fn get_hub_issues() -> HttpResponse { .body(status_response.text().await.unwrap()) } +#[get("/hub_issue_timeline/{issue_id}")] +pub async fn get_hub_issue_timeline(info: web::Path<(u32,)>) -> HttpResponse { + let status_response = if let Ok(res) = reqwest::get(format!("https://git.ixvd.net/api/v1/repos/ixvd/hub/issues/{}/timeline", info.into_inner().0)).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) + .service(get_hub_issue_timeline) ); } \ No newline at end of file