feat: more in depth statuses
This commit is contained in:
parent
8d2a69c366
commit
4decadebfa
3 changed files with 53 additions and 6 deletions
|
@ -1,12 +1,42 @@
|
|||
const issuesDiv = document.querySelector("#issues");
|
||||
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() {
|
||||
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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
14
src/relay.rs
14
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)
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue