Skip to content

Commit

Permalink
Make container and image ids links that redirect to details
Browse files Browse the repository at this point in the history
Closes: #1
  • Loading branch information
vv9k committed Dec 3, 2021
1 parent 28971fb commit 8b7a3b5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
- Add images prune button to remove unused images
- Add containers prune button to remove all stopped containers
- Add a way to follow container logs, the logs are now paginated
- Make container and image ids open their respective page with details
41 changes: 32 additions & 9 deletions src/app/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use crate::app::{
ui::{color, key, key_val, val},
App,
};
use crate::event::{ContainerEvent, EventRequest};
use crate::event::{ContainerEvent, EventRequest, GuiEvent};
use crate::worker::RunningContainerStats;

use docker_api::api::{
ContainerCreateOpts, ContainerDetails, ContainerId, ContainerInfo, ContainerStatus,
ContainerCreateOpts, ContainerDetails, ContainerId, ContainerIdRef, ContainerInfo,
ContainerStatus,
};
use egui::containers::Frame;
use egui::widgets::plot::{self, Line, Plot};
Expand Down Expand Up @@ -241,6 +242,29 @@ impl ContainersTab {
}

impl App {
pub fn link_container(&self, ui: &mut egui::Ui, id: ContainerIdRef, name: Option<&str>) {
if ui
.add(
egui::Label::new(name.map(|n| n.trim_start_matches('/')).unwrap_or(id))
.strong()
.sense(egui::Sense {
click: true,
focusable: true,
drag: false,
}),
)
.on_hover_text("click to follow")
.clicked()
{
let _ = self.send_event(EventRequest::Container(ContainerEvent::TraceStart {
id: id.to_string(),
}));
let _ = self.send_event(EventRequest::NotifyGui(GuiEvent::SetTab(
crate::app::Tab::Containers,
)));
}
}

pub fn containers_side(&mut self, ui: &mut egui::Ui) {
ui.vertical(|ui| {
self.containers_menu(ui);
Expand Down Expand Up @@ -336,14 +360,9 @@ impl App {
);
}
});
let image = if container.image.starts_with("sha256") {
&container.image.trim_start_matches("sha256:")[..12]
} else {
container.image.as_str()
};
ui.end_row();
ui.add_space(5.);
ui.add(Label::new(image).italics().strong().wrap(true));
self.link_image(ui, &container.image, None);
ui.end_row();

ui.add_space(5.);
Expand Down Expand Up @@ -573,7 +592,11 @@ impl App {
fn container_info(&self, ui: &mut egui::Ui, container: &ContainerDetails) {
Grid::new("container_info").show(ui, |ui| {
key_val!(ui, "ID:", &container.id);
key_val!(ui, "Image:", &container.image);

key!(ui, "Image:");
self.link_image(ui, &container.image, None);
ui.end_row();

key_val!(
ui,
"Command:",
Expand Down
32 changes: 30 additions & 2 deletions src/app/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::app::{
ui::{key, key_val, val},
App,
};
use crate::event::{EventRequest, ImageEvent};
use crate::event::{EventRequest, GuiEvent, ImageEvent};
use crate::ImageInspectInfo;
use docker_api::api::{ImageBuildChunk, ImageIdRef, ImageInfo, RegistryAuth, SearchResult};

Expand Down Expand Up @@ -90,6 +90,31 @@ impl ImagesTab {
}

impl App {
pub fn link_image(&self, ui: &mut egui::Ui, id: ImageIdRef, name: Option<&str>) {
if ui
.add(
egui::Label::new(
name.map(|n| n.trim_start_matches('/'))
.unwrap_or_else(|| trim_id(id)),
)
.strong()
.sense(egui::Sense {
click: true,
focusable: true,
drag: false,
}),
)
.on_hover_text("click to follow")
.clicked()
{
let _ = self.send_event(EventRequest::Image(ImageEvent::Inspect {
id: id.to_string(),
}));
let _ = self.send_event(EventRequest::NotifyGui(GuiEvent::SetTab(
crate::app::Tab::Images,
)));
}
}
pub fn images_view(&mut self, ui: &mut egui::Ui) {
match self.images.central_view {
CentralView::Image => self.image_details(ui),
Expand Down Expand Up @@ -329,7 +354,10 @@ impl App {
ui.end_row();
}

key_val!(ui, "Parent:", &details.parent);
key!(ui, "Parent:");
self.link_image(ui, &details.parent, None);
ui.end_row();

key_val!(ui, "Comment:", &details.comment);
key_val!(ui, "Author:", &details.author);
key_val!(ui, "Created:", &details.created.to_rfc2822());
Expand Down

0 comments on commit 8b7a3b5

Please sign in to comment.