Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions coman/src/app/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub enum Id {
Toolbar,
WorkloadList,
WorkloadLogs,
WorkloadDetails,
GlobalListener,
Menu,
InfoPopup,
Expand Down
9 changes: 7 additions & 2 deletions coman/src/app/messages.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::path::PathBuf;

use crate::{app::user_events::UserEvent, cscs::api_client::System};
use crate::{
app::user_events::UserEvent,
cscs::api_client::{JobDetail, System},
};

#[derive(Debug, PartialEq)]
pub enum MenuMsg {
Expand Down Expand Up @@ -49,7 +52,9 @@ pub enum CscsMsg {
}
#[derive(Debug, PartialEq)]
pub enum JobMsg {
Show(usize),
Log(usize),
Details(JobDetail),
GetDetails(usize),
Switch,
Close,
}
Expand Down
75 changes: 58 additions & 17 deletions coman/src/app/model.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use eyre::{Context, Report};
use tokio::sync::mpsc;
use tuirealm::{
Application, Update,
Application, AttrValue, Attribute, Update,
ratatui::{
Frame,
layout::{Constraint, Direction, Layout, Rect},
Expand All @@ -21,12 +21,12 @@ use crate::{
},
components::{
context_menu::ContextMenu, download_popup::DownloadTargetInput, error_popup::ErrorPopup, info_popup::InfoPopup,
login_popup::LoginPopup, system_select_popup::SystemSelectPopup, workload_list::WorkloadList,
workload_log::WorkloadLog,
login_popup::LoginPopup, system_select_popup::SystemSelectPopup, workload_details::WorkloadDetails,
workload_list::WorkloadList, workload_log::WorkloadLog,
},
cscs::{
handlers::{cscs_login, cscs_system_set},
ports::{JobLogAction, TreeAction},
ports::{BackgroundTask, JobLogAction},
},
trace_dbg,
util::ui::{draw_area_in_absolute, draw_area_in_absolute_fixed_height},
Expand Down Expand Up @@ -62,7 +62,7 @@ where
pub user_event_tx: mpsc::Sender<UserEvent>,

/// Allows interacting with the file Api
pub file_tree_tx: mpsc::Sender<TreeAction>,
pub background_task_tx: mpsc::Sender<BackgroundTask>,
}

impl<T> Model<T>
Expand All @@ -76,7 +76,7 @@ where
select_system_tx: mpsc::Sender<()>,
job_log_tx: mpsc::Sender<JobLogAction>,
user_event_tx: mpsc::Sender<UserEvent>,
file_tree_tx: mpsc::Sender<TreeAction>,
background_task_tx: mpsc::Sender<BackgroundTask>,
) -> Self {
Self {
app,
Expand All @@ -88,7 +88,7 @@ where
select_system_tx,
job_log_tx,
user_event_tx,
file_tree_tx,
background_task_tx,
}
}

Expand All @@ -101,7 +101,6 @@ where
.draw(|f| {
let chunks = Layout::default()
.direction(Direction::Vertical)
.margin(1)
.constraints(
[
Constraint::Max(3), //Statusbar
Expand Down Expand Up @@ -149,11 +148,9 @@ where
}

fn view_workloads(app: &mut Application<Id, Msg, UserEvent>, frame: &mut Frame, area: Rect) {
if app.mounted(&Id::WorkloadList) {
app.view(&Id::WorkloadList, frame, area);
} else if app.mounted(&Id::WorkloadLogs) {
app.view(&Id::WorkloadLogs, frame, area);
}
app.view(&Id::WorkloadList, frame, area);
app.view(&Id::WorkloadLogs, frame, area);
app.view(&Id::WorkloadDetails, frame, area);
}
fn view_files(app: &mut Application<Id, Msg, UserEvent>, frame: &mut Frame, area: Rect) {
if app.mounted(&Id::FileView) {
Expand Down Expand Up @@ -263,9 +260,9 @@ where
}
DownloadPopupMsg::PathSet(remote, local) => {
assert!(self.app.umount(&Id::DownloadPopup).is_ok());
let file_tx = self.file_tree_tx.clone();
let file_tx = self.background_task_tx.clone();
tokio::spawn(async move {
file_tx.send(TreeAction::Download(remote, local)).await.unwrap();
file_tx.send(BackgroundTask::DownloadFile(remote, local)).await.unwrap();
});
None
}
Expand Down Expand Up @@ -306,9 +303,13 @@ where
}
fn handle_job_msg(&mut self, msg: JobMsg) -> Option<Msg> {
match msg {
JobMsg::Show(jobid) => {
JobMsg::Log(jobid) => {
if self.app.mounted(&Id::WorkloadList) {
assert!(self.app.umount(&Id::WorkloadList).is_ok());
assert!(
self.app
.attr(&Id::WorkloadList, Attribute::Display, AttrValue::Flag(false))
.is_ok()
);
}
if !self.app.mounted(&Id::WorkloadLogs) {
assert!(
Expand All @@ -324,6 +325,38 @@ where
});
None
}
JobMsg::GetDetails(jobid) => {
let background_tx = self.background_task_tx.clone();
let event_tx = self.user_event_tx.clone();
tokio::spawn(async move {
background_tx.send(BackgroundTask::GetJobDetails(jobid)).await.unwrap();
event_tx
.send(UserEvent::Status(StatusEvent::Info(
"getting job details...".to_owned(),
)))
.await
.unwrap();
});
None
}
JobMsg::Details(jobdetail) => {
if self.app.mounted(&Id::WorkloadList) {
assert!(
self.app
.attr(&Id::WorkloadList, Attribute::Display, AttrValue::Flag(false))
.is_ok()
);
}
if !self.app.mounted(&Id::WorkloadDetails) {
assert!(
self.app
.mount(Id::WorkloadDetails, Box::new(WorkloadDetails::new(jobdetail)), vec![])
.is_ok()
);
}
assert!(self.app.active(&Id::WorkloadDetails).is_ok());
None
}
JobMsg::Switch => {
let job_log_tx = self.job_log_tx.clone();
tokio::spawn(async move {
Expand All @@ -335,13 +368,21 @@ where
if self.app.mounted(&Id::WorkloadLogs) {
assert!(self.app.umount(&Id::WorkloadLogs).is_ok());
}
if self.app.mounted(&Id::WorkloadDetails) {
assert!(self.app.umount(&Id::WorkloadDetails).is_ok());
}
if !self.app.mounted(&Id::WorkloadList) {
assert!(
self.app
.mount(Id::WorkloadList, Box::new(WorkloadList::default()), vec![])
.is_ok()
);
}
assert!(
self.app
.attr(&Id::WorkloadList, Attribute::Display, AttrValue::Flag(true))
.is_ok()
);
assert!(self.app.active(&Id::WorkloadList).is_ok());
let job_log_tx = self.job_log_tx.clone();
tokio::spawn(async move {
Expand Down
3 changes: 2 additions & 1 deletion coman/src/app/user_events.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::{
app::messages::View,
cscs::api_client::{Job, PathEntry, System},
cscs::api_client::{Job, JobDetail, PathEntry, System},
};

#[derive(Debug, Eq, Clone, PartialEq, PartialOrd, Ord)]
pub enum CscsEvent {
LoggedIn,
GotWorkloadData(Vec<Job>),
GotJobLog(String),
GotJobDetails(JobDetail),
SelectSystemList(Vec<System>),
SystemSelected(String),
}
Expand Down
2 changes: 2 additions & 0 deletions coman/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub enum CscsJobCommands {

#[clap(alias("s"), about = "Submit a new compute job [aliases: s]")]
Submit {
#[clap(short, long, help = "name of the job")]
name: Option<String>,
#[clap(short, long, help = "the path to the srun script file to use")]
script_file: Option<PathBuf>,
#[clap(
Expand Down
18 changes: 13 additions & 5 deletions coman/src/components/file_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
messages::{DownloadPopupMsg, Msg},
user_events::{FileEvent, UserEvent},
},
cscs::{api_client::PathType, ports::TreeAction},
cscs::{api_client::PathType, ports::BackgroundTask},
};

#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Clone)]
Expand Down Expand Up @@ -47,16 +47,21 @@ impl NodeValue for FileNode {
#[derive(MockComponent)]
pub struct FileTree {
component: TreeView<FileNode>,
file_tree_tx: mpsc::Sender<TreeAction>,
file_tree_tx: mpsc::Sender<BackgroundTask>,
}
impl FileTree {
pub fn new(file_tree_tx: mpsc::Sender<TreeAction>) -> Self {
pub fn new(file_tree_tx: mpsc::Sender<BackgroundTask>) -> Self {
let root_node: Node<FileNode> = Node::new("/".to_owned(), FileNode::default());
let tree = Tree::new(root_node.clone());

// Load root node
let tree_tx = file_tree_tx.clone();
tokio::spawn(async move { tree_tx.send(TreeAction::List(PathBuf::from("/"))).await.unwrap() });
tokio::spawn(async move {
tree_tx
.send(BackgroundTask::ListPaths(PathBuf::from("/")))
.await
.unwrap()
});

Self {
component: TreeView::default()
Expand Down Expand Up @@ -110,7 +115,10 @@ impl Component<Msg, UserEvent> for FileTree {
// try loading children if there are none
let tree_tx = self.file_tree_tx.clone();
tokio::spawn(async move {
tree_tx.send(TreeAction::List(PathBuf::from(current_id))).await.unwrap();
tree_tx
.send(BackgroundTask::ListPaths(PathBuf::from(current_id)))
.await
.unwrap();
});
CmdResult::None
} else {
Expand Down
3 changes: 2 additions & 1 deletion coman/src/components/global_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tuirealm::{
};

use crate::app::{
messages::{MenuMsg, Msg, StatusMsg, SystemSelectMsg, View},
messages::{JobMsg, MenuMsg, Msg, StatusMsg, SystemSelectMsg, View},
user_events::{CscsEvent, FileEvent, UserEvent},
};

Expand Down Expand Up @@ -48,6 +48,7 @@ impl Component<Msg, UserEvent> for GlobalListener {
Event::User(UserEvent::Cscs(CscsEvent::SelectSystemList(systems))) => {
Some(Msg::SystemSelectPopup(SystemSelectMsg::Opened(systems)))
}
Event::User(UserEvent::Cscs(CscsEvent::GotJobDetails(details))) => Some(Msg::Job(JobMsg::Details(details))),
Event::User(UserEvent::File(FileEvent::DownloadSuccessful)) => {
Some(Msg::Status(StatusMsg::Info("File successfully downloaded".to_owned())))
}
Expand Down
1 change: 1 addition & 0 deletions coman/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pub(crate) mod login_popup;
pub(crate) mod status_bar;
pub(crate) mod system_select_popup;
pub(crate) mod toolbar;
pub(crate) mod workload_details;
pub(crate) mod workload_list;
pub(crate) mod workload_log;
2 changes: 1 addition & 1 deletion coman/src/components/status_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl MockComponent for StatusBar {
.border_style(borders.style())
.border_type(borders.modifiers);
let layout = Layout::default()
.constraints(&[Constraint::Percentage(30), Constraint::Percentage(70)])
.constraints(&[Constraint::Min(34), Constraint::Fill(1)])
.direction(Direction::Horizontal)
.margin(1);
frame.render_widget(div, area);
Expand Down
Loading