dnetview: replace Vec<SelectableObject> with NodeInfo on model and view

this commit fixes ui::ui(). it's a temporary measure until we finish the
refactor.
This commit is contained in:
lunar-mining
2022-04-16 10:47:47 +02:00
parent 668fae0617
commit 566bdf55ea
4 changed files with 49 additions and 50 deletions

View File

@@ -258,10 +258,10 @@ async fn poll(client: DNetView, model: Arc<Model>) -> Result<()> {
node_info.insert(&node_name, infos.clone());
// insert into model
for (key, _value) in node_info.clone() {
for (key, value) in node_info.clone() {
model.id_list.node_id.lock().await.insert(key.to_string().clone());
// value
model.info_list.infos.lock().await.insert(key.to_string(), model_vec.clone());
model.info_list.infos.lock().await.insert(key.to_string(), value);
}
} else {
// TODO: error handling

View File

@@ -4,7 +4,6 @@ use fxhash::{FxHashMap, FxHashSet};
use serde::Deserialize;
use tui::widgets::ListState;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum SelectableObject {
// top level selectable object
Node(NodeInfo),
@@ -39,7 +38,7 @@ impl IdList {
pub struct InfoList {
pub index: Mutex<usize>,
pub infos: Mutex<FxHashMap<String, Vec<SelectableObject>>>,
pub infos: Mutex<FxHashMap<String, NodeInfo>>,
}
impl InfoList {

View File

@@ -27,48 +27,48 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
// render as a sub node
match &view.info_list.infos.get(id) {
Some(node) => {
//if !node.[0].outbound.iter().all(|node| node.is_empty) {
// lines.push(Spans::from(Span::styled(" Outgoing", Style::default())));
//}
//for outbound in &node.outbound.clone() {
// for slot in outbound.slots.clone() {
// let addr = Span::styled(format!(" {}", slot.addr), style);
// let msg: Span = match slot.channel.last_status.as_str() {
// "recv" => Span::styled(
// format!(" [R: {}]", slot.channel.last_msg),
// style,
// ),
// "sent" => Span::styled(
// format!(" [S: {}]", slot.channel.last_msg),
// style,
// ),
// a => Span::styled(a.to_string(), style),
// };
// lines.push(Spans::from(vec![addr, msg]));
// }
//}
//if !node.inbound.iter().all(|node| node.is_empty) {
// lines.push(Spans::from(Span::styled(" Incoming", Style::default())));
//}
//for inbound in &node.inbound {
// let addr = Span::styled(format!(" {}", inbound.connected), style);
// let msg: Span = match inbound.channel.last_status.as_str() {
// "recv" => Span::styled(
// format!(" [R: {}]", inbound.channel.last_msg),
// style,
// ),
// "sent" => Span::styled(
// format!(" [R: {}]", inbound.channel.last_msg),
// style,
// ),
// a => Span::styled(a.to_string(), style),
// };
// lines.push(Spans::from(vec![addr, msg]));
//}
//lines.push(Spans::from(Span::styled(" Manual", Style::default())));
//for connect in &node.manual {
// lines.push(Spans::from(Span::styled(format!(" {}", connect.key), style)));
//}
if !node.outbound.iter().all(|node| node.is_empty) {
lines.push(Spans::from(Span::styled(" Outgoing", Style::default())));
}
for outbound in &node.outbound.clone() {
for slot in outbound.slots.clone() {
let addr = Span::styled(format!(" {}", slot.addr), style);
let msg: Span = match slot.channel.last_status.as_str() {
"recv" => Span::styled(
format!(" [R: {}]", slot.channel.last_msg),
style,
),
"sent" => Span::styled(
format!(" [S: {}]", slot.channel.last_msg),
style,
),
a => Span::styled(a.to_string(), style),
};
lines.push(Spans::from(vec![addr, msg]));
}
}
if !node.inbound.iter().all(|node| node.is_empty) {
lines.push(Spans::from(Span::styled(" Incoming", Style::default())));
}
for inbound in &node.inbound {
let addr = Span::styled(format!(" {}", inbound.connected), style);
let msg: Span = match inbound.channel.last_status.as_str() {
"recv" => Span::styled(
format!(" [R: {}]", inbound.channel.last_msg),
style,
),
"sent" => Span::styled(
format!(" [R: {}]", inbound.channel.last_msg),
style,
),
a => Span::styled(a.to_string(), style),
};
lines.push(Spans::from(vec![addr, msg]));
}
lines.push(Spans::from(Span::styled(" Manual", Style::default())));
for connect in &node.manual {
lines.push(Spans::from(Span::styled(format!(" {}", connect.key), style)));
}
}
None => {
// TODO

View File

@@ -2,7 +2,7 @@ use fxhash::{FxHashMap, FxHashSet};
//use log::debug;
use tui::widgets::ListState;
use crate::model::{NodeInfo, SelectableObject};
use crate::model::NodeInfo;
#[derive(Clone)]
pub struct View {
@@ -15,7 +15,7 @@ impl View {
View { id_list, info_list }
}
pub fn update(&mut self, infos: FxHashMap<String, Vec<SelectableObject>>) {
pub fn update(&mut self, infos: FxHashMap<String, NodeInfo>) {
for (id, info) in infos {
self.id_list.node_id.insert(id.clone());
self.info_list.infos.insert(id, info);
@@ -69,11 +69,11 @@ impl IdListView {
#[derive(Clone)]
pub struct InfoListView {
pub index: usize,
pub infos: FxHashMap<String, Vec<SelectableObject>>,
pub infos: FxHashMap<String, NodeInfo>,
}
impl InfoListView {
pub fn new(infos: FxHashMap<String, Vec<SelectableObject>>) -> InfoListView {
pub fn new(infos: FxHashMap<String, NodeInfo>) -> InfoListView {
let index = 0;
InfoListView { index, infos }