mirror of
https://seed.radicle.dev/rad:zwTxygwuz5LDGBq255RA2CbNGrz8.git
synced 2026-11-29 06:40:31 +08:00
feat: hide empty event queue table, show count
This commit is contained in:
+117
-103
@@ -200,113 +200,127 @@ impl PageData {
|
||||
|
||||
fn event_queue(&self, doc: &mut ReportPage) {
|
||||
doc.h2("Event queue");
|
||||
let mut table = Element::new(Tag::Table)
|
||||
.with_class("event-queue")
|
||||
.with_child(
|
||||
Element::new(Tag::Tr)
|
||||
.with_child(Element::new(Tag::Th).with_text("Queue id"))
|
||||
.with_child(Element::new(Tag::Th).with_text("Timestamp"))
|
||||
.with_child(Element::new(Tag::Th).with_text("Event")),
|
||||
);
|
||||
for event in self.events.iter() {
|
||||
fn render_event(
|
||||
repo: &RepoId,
|
||||
alias: Option<String>,
|
||||
refname: &str,
|
||||
commit: &Oid,
|
||||
) -> Element {
|
||||
let alias = if let Some(alias) = alias {
|
||||
Element::new(Tag::Span).with_child(
|
||||
Element::new(Tag::Span)
|
||||
.with_class("alias")
|
||||
.with_text(&alias),
|
||||
)
|
||||
} else {
|
||||
Element::new(Tag::Span)
|
||||
let queue_len = self.events.len();
|
||||
doc.push(Element::p().with_text(format!("{queue_len} events in queue.")));
|
||||
if queue_len > 0 {
|
||||
let mut table = Element::new(Tag::Table)
|
||||
.with_class("event-queue")
|
||||
.with_child(
|
||||
Element::new(Tag::Tr)
|
||||
.with_child(Element::new(Tag::Th).with_text("Queue id"))
|
||||
.with_child(Element::new(Tag::Th).with_text("Timestamp"))
|
||||
.with_child(Element::new(Tag::Th).with_text("Event")),
|
||||
);
|
||||
for event in self.events.iter() {
|
||||
let event_element = match event.event() {
|
||||
CiEvent::V1(CiEventV1::Shutdown) => {
|
||||
Element::new(Tag::Span).with_text("shutdown")
|
||||
}
|
||||
CiEvent::V1(CiEventV1::Terminate(_)) => {
|
||||
Element::new(Tag::Span).with_text("terminate")
|
||||
}
|
||||
CiEvent::V1(CiEventV1::BranchCreated {
|
||||
from_node: _,
|
||||
repo,
|
||||
branch,
|
||||
tip,
|
||||
}) => Self::render_event(repo, self.repo_alias(*repo), branch, tip),
|
||||
CiEvent::V1(CiEventV1::BranchUpdated {
|
||||
from_node: _,
|
||||
repo,
|
||||
branch,
|
||||
tip,
|
||||
old_tip: _,
|
||||
}) => Self::render_event(repo, self.repo_alias(*repo), branch, tip),
|
||||
CiEvent::V1(CiEventV1::BranchDeleted {
|
||||
repo, branch, tip, ..
|
||||
}) => Self::render_event(repo, self.repo_alias(*repo), branch, tip),
|
||||
CiEvent::V1(CiEventV1::TagCreated {
|
||||
from_node: _,
|
||||
repo,
|
||||
tag,
|
||||
tip,
|
||||
}) => Self::render_event(repo, self.repo_alias(*repo), tag.as_str(), tip),
|
||||
CiEvent::V1(CiEventV1::TagUpdated {
|
||||
from_node: _,
|
||||
repo,
|
||||
tag,
|
||||
tip,
|
||||
old_tip: _,
|
||||
}) => Self::render_event(repo, self.repo_alias(*repo), tag.as_str(), tip),
|
||||
CiEvent::V1(CiEventV1::TagDeleted { repo, tag, tip, .. }) => {
|
||||
Self::render_event(repo, self.repo_alias(*repo), tag.as_str(), tip)
|
||||
}
|
||||
CiEvent::V1(CiEventV1::PatchCreated {
|
||||
from_node: _,
|
||||
repo,
|
||||
patch,
|
||||
new_tip,
|
||||
}) => Self::render_event(
|
||||
repo,
|
||||
self.repo_alias(*repo),
|
||||
&patch.to_string(),
|
||||
new_tip,
|
||||
),
|
||||
CiEvent::V1(CiEventV1::PatchUpdated {
|
||||
from_node: _,
|
||||
repo,
|
||||
patch,
|
||||
new_tip,
|
||||
}) => Self::render_event(
|
||||
repo,
|
||||
self.repo_alias(*repo),
|
||||
&patch.to_string(),
|
||||
new_tip,
|
||||
),
|
||||
CiEvent::V1(CiEventV1::CanonicalRefUpdated {
|
||||
from_node: _,
|
||||
repo,
|
||||
refname,
|
||||
target,
|
||||
}) => {
|
||||
Self::render_event(repo, self.repo_alias(*repo), refname.as_str(), target)
|
||||
}
|
||||
};
|
||||
Element::new(Tag::Span)
|
||||
.with_child(alias)
|
||||
.with_child(Element::new(Tag::Br))
|
||||
.with_child(
|
||||
Element::new(Tag::Span)
|
||||
.with_class("repoid")
|
||||
.with_text(repo.to_string()),
|
||||
)
|
||||
.with_child(Element::new(Tag::Br))
|
||||
.with_child(Element::new(Tag::Span).with_class("ref").with_text(refname))
|
||||
.with_child(Element::new(Tag::Br))
|
||||
.with_child(
|
||||
Element::new(Tag::Span)
|
||||
.with_class("commit")
|
||||
.with_text(commit.to_string()),
|
||||
)
|
||||
|
||||
table.push_child(
|
||||
Element::new(Tag::Tr)
|
||||
.with_child(Element::new(Tag::Td).with_text(event.id().to_string()))
|
||||
.with_child(Element::new(Tag::Td).with_text(event.timestamp()))
|
||||
.with_child(Element::new(Tag::Td).with_child(event_element)),
|
||||
);
|
||||
}
|
||||
|
||||
let event_element = match event.event() {
|
||||
CiEvent::V1(CiEventV1::Shutdown) => Element::new(Tag::Span).with_text("shutdown"),
|
||||
CiEvent::V1(CiEventV1::Terminate(_)) => {
|
||||
Element::new(Tag::Span).with_text("terminate")
|
||||
}
|
||||
CiEvent::V1(CiEventV1::BranchCreated {
|
||||
from_node: _,
|
||||
repo,
|
||||
branch,
|
||||
tip,
|
||||
}) => render_event(repo, self.repo_alias(*repo), branch, tip),
|
||||
CiEvent::V1(CiEventV1::BranchUpdated {
|
||||
from_node: _,
|
||||
repo,
|
||||
branch,
|
||||
tip,
|
||||
old_tip: _,
|
||||
}) => render_event(repo, self.repo_alias(*repo), branch, tip),
|
||||
CiEvent::V1(CiEventV1::BranchDeleted {
|
||||
repo, branch, tip, ..
|
||||
}) => render_event(repo, self.repo_alias(*repo), branch, tip),
|
||||
CiEvent::V1(CiEventV1::TagCreated {
|
||||
from_node: _,
|
||||
repo,
|
||||
tag,
|
||||
tip,
|
||||
}) => render_event(repo, self.repo_alias(*repo), tag.as_str(), tip),
|
||||
CiEvent::V1(CiEventV1::TagUpdated {
|
||||
from_node: _,
|
||||
repo,
|
||||
tag,
|
||||
tip,
|
||||
old_tip: _,
|
||||
}) => render_event(repo, self.repo_alias(*repo), tag.as_str(), tip),
|
||||
CiEvent::V1(CiEventV1::TagDeleted { repo, tag, tip, .. }) => {
|
||||
render_event(repo, self.repo_alias(*repo), tag.as_str(), tip)
|
||||
}
|
||||
CiEvent::V1(CiEventV1::PatchCreated {
|
||||
from_node: _,
|
||||
repo,
|
||||
patch,
|
||||
new_tip,
|
||||
}) => render_event(repo, self.repo_alias(*repo), &patch.to_string(), new_tip),
|
||||
CiEvent::V1(CiEventV1::PatchUpdated {
|
||||
from_node: _,
|
||||
repo,
|
||||
patch,
|
||||
new_tip,
|
||||
}) => render_event(repo, self.repo_alias(*repo), &patch.to_string(), new_tip),
|
||||
CiEvent::V1(CiEventV1::CanonicalRefUpdated {
|
||||
from_node: _,
|
||||
repo,
|
||||
refname,
|
||||
target,
|
||||
}) => render_event(repo, self.repo_alias(*repo), refname.as_str(), target),
|
||||
};
|
||||
|
||||
table.push_child(
|
||||
Element::new(Tag::Tr)
|
||||
.with_child(Element::new(Tag::Td).with_text(event.id().to_string()))
|
||||
.with_child(Element::new(Tag::Td).with_text(event.timestamp()))
|
||||
.with_child(Element::new(Tag::Td).with_child(event_element)),
|
||||
);
|
||||
doc.push(table);
|
||||
}
|
||||
doc.push(table);
|
||||
}
|
||||
|
||||
fn render_event(repo: &RepoId, alias: Option<String>, refname: &str, commit: &Oid) -> Element {
|
||||
let alias = if let Some(alias) = alias {
|
||||
Element::new(Tag::Span).with_child(
|
||||
Element::new(Tag::Span)
|
||||
.with_class("alias")
|
||||
.with_text(&alias),
|
||||
)
|
||||
} else {
|
||||
Element::new(Tag::Span)
|
||||
};
|
||||
Element::new(Tag::Span)
|
||||
.with_child(alias)
|
||||
.with_child(Element::new(Tag::Br))
|
||||
.with_child(
|
||||
Element::new(Tag::Span)
|
||||
.with_class("repoid")
|
||||
.with_text(repo.to_string()),
|
||||
)
|
||||
.with_child(Element::new(Tag::Br))
|
||||
.with_child(Element::new(Tag::Span).with_class("ref").with_text(refname))
|
||||
.with_child(Element::new(Tag::Br))
|
||||
.with_child(
|
||||
Element::new(Tag::Span)
|
||||
.with_class("commit")
|
||||
.with_text(commit.to_string()),
|
||||
)
|
||||
}
|
||||
|
||||
fn recent_status(&self, doc: &mut ReportPage) -> Result<(), PageError> {
|
||||
|
||||
Reference in New Issue
Block a user