feat: more in depth statuses

This commit is contained in:
Strix 2023-10-16 01:36:02 +02:00
parent 8d2a69c366
commit 4decadebfa
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
3 changed files with 53 additions and 6 deletions

View file

@ -1,12 +1,42 @@
const issuesDiv = document.querySelector("#issues"); const issuesDiv = document.querySelector("#issues");
const issuesHolderDiv = document.querySelector("#issues-holder"); const issuesHolderDiv = document.querySelector("#issues-holder");
issuesHolderDiv.innerHTML = "<p><b>Loading items...</b></p>"
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() { async function updateIssues() {
let fetchResult = await (await fetch('/relay/hub_issues')).json() let fetchResult = await (await fetch('/relay/hub_issues')).json()
if (fetchResult.length > 0) { if (fetchResult.length > 0) {
issuesDiv.removeAttribute("hidden"); issuesDiv.removeAttribute("hidden");
issuesHolderDiv.innerHTML = '';
fetchResult.forEach((issue) => { let issueElems = [];
for (const issue of fetchResult) {
let issueDiv = document.createElement("div"); let issueDiv = document.createElement("div");
issueDiv.classList.add("issue"); issueDiv.classList.add("issue");
let detailsDiv = document.createElement("div"); let detailsDiv = document.createElement("div");
@ -40,7 +70,7 @@ async function updateIssues() {
let statusSpan = document.createElement("span"); let statusSpan = document.createElement("span");
statusSpan.classList.add("issue-status"); statusSpan.classList.add("issue-status");
dataDiv.append(statusSpan); dataDiv.append(statusSpan);
statusSpan.innerText = issue.state; statusSpan.innerText = await getStatus(issue.number);
switch (issue.state) { switch (issue.state) {
case 'open': case 'open':
statusSpan.style.color = "#ff8f8f"; statusSpan.style.color = "#ff8f8f";
@ -55,8 +85,11 @@ async function updateIssues() {
dataDiv.append(timeSpan); dataDiv.append(timeSpan);
timeSpan.innerText = issue.updated_at; timeSpan.innerText = issue.updated_at;
issuesHolderDiv.append(issueDiv) issueElems.push(issueDiv);
}) }
issuesHolderDiv.innerHTML = '';
issueElems.forEach((i) => issuesHolderDiv.append(i))
} else issuesDiv.setAttribute("hidden", "true"); } else issuesDiv.setAttribute("hidden", "true");
} }

View file

@ -3,7 +3,7 @@ window.updateLoop = [];
(() => { (() => {
let updLoop = setInterval(() => { let updLoop = setInterval(() => {
updateLoop.forEach(f => f()); updateLoop.forEach(f => f());
}, 15000); }, 30000);
let everythingLoaded = setInterval(function() { let everythingLoaded = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) { if (/loaded|complete/.test(document.readyState)) {

View file

@ -27,10 +27,24 @@ pub async fn get_hub_issues() -> HttpResponse {
.body(status_response.text().await.unwrap()) .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) { pub fn configure(cfg: &mut web::ServiceConfig) {
cfg.service( cfg.service(
web::scope("/relay") web::scope("/relay")
.service(get_gatus_services) .service(get_gatus_services)
.service(get_hub_issues) .service(get_hub_issues)
.service(get_hub_issue_timeline)
); );
} }