Skip to content

Commit 12825b3

Browse files
committed
testing issue tracking search (imported from jira) to have something with more data to try out on
1 parent 5f2a698 commit 12825b3

File tree

5 files changed

+146
-7
lines changed

5 files changed

+146
-7
lines changed

binc/src/attributes.rs

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ pub enum AttributeValue {
1515
F64(f64),
1616
}
1717

18+
impl AttributeValue {
19+
pub (crate) fn too_long_for_display(&self) -> bool {
20+
match self {
21+
AttributeValue::String(s) => s.len() > 100,
22+
_ => false,
23+
}
24+
}
25+
}
26+
1827
impl std::fmt::Display for AttributeValue {
1928
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2029
match self {

binc/src/change.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,12 @@ impl Display for Change {
687687
value,
688688
} => if value.too_long_for_display() {
689689
write!(
690-
f,
691-
"Set{}({}, {} = {})",
692-
attribute_type(value),
693-
node,
694-
attribute,
695-
"<...>")
690+
f,
691+
"Set{}({}, {} = {})",
692+
attribute_type(value),
693+
node,
694+
attribute,
695+
"<...>")
696696
} else {
697697
write!(
698698
f,

binc/src/node_store.rs

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ impl FlatNodeStore {
2626
}
2727
}
2828

29+
pub fn nodes(&self) -> &Vec<Node> {
30+
&self.nodes
31+
}
32+
2933
pub fn find_roots(&self) -> &Vec<NodeId> {
3034
let x = self.nodes.get(0).expect("Root node should exist");
3135
x.children.as_ref()

gui/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ path = "src/bin/explorer.rs"
2323

2424
[[bin]]
2525
name = "binc-notes"
26-
path = "src/bin/notes.rs"
26+
path = "src/bin/notes.rs"
27+
28+
[[bin]]
29+
name = "binc-issues"
30+
path = "src/bin/issues.rs"

gui/src/bin/issues.rs

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#![cfg_attr(
2+
not(debug_assertions),
3+
windows_subsystem = "windows"
4+
)] // hide console window on Windows in release
5+
#![allow(rustdoc::missing_crate_level_docs)]
6+
7+
use binc::node_id::NodeId;
8+
use binc::node_store::Node;
9+
use bincgui::app::{create_toolbar, Application};
10+
use eframe::egui::Ui;
11+
use eframe::{egui, Storage};
12+
use eframe::egui::UiKind::Frame;
13+
14+
fn main() -> eframe::Result {
15+
env_logger::init();
16+
17+
let options = eframe::NativeOptions {
18+
viewport: egui::ViewportBuilder::default().with_inner_size([900.0, 600.0]),
19+
..Default::default()
20+
};
21+
eframe::run_native(
22+
"Got issues",
23+
options,
24+
Box::new(|_cc| Ok(Box::new(IssuesApp::new()))),
25+
)
26+
}
27+
28+
struct IssuesApp {
29+
application: Application,
30+
search_string: String,
31+
found_issues: Vec<NodeId>,
32+
}
33+
34+
impl IssuesApp {
35+
fn new() -> Self {
36+
Self {
37+
application: Application::new(),
38+
search_string: String::new(),
39+
found_issues: vec![],
40+
}
41+
}
42+
43+
fn update_search(&mut self) {
44+
self.found_issues = self.get_issues_for_search(&self.search_string);
45+
}
46+
47+
fn get_issues_for_search(&self, search_string: &str) -> Vec<NodeId> {
48+
if !search_string.is_empty() {
49+
let terms = search_string.split(" ");
50+
51+
if let Some(issue_id) = self.application.document.nodes.type_names.get_index("issue") {
52+
let mut issues = vec![];
53+
let summary_id = self.application.document.nodes.attribute_names.get_index("summary");
54+
55+
for node in self.application.document.nodes.nodes() {
56+
if Some(issue_id) == node.type_id {
57+
if let Some(summary) = node.get_string_attribute(summary_id.unwrap()) {
58+
let mut found = true;
59+
let mut t = terms.clone();
60+
while let Some(term) = t.next() {
61+
if !summary.to_lowercase().contains(&term.to_lowercase()) {
62+
found = false;
63+
break;
64+
}
65+
}
66+
if found {
67+
issues.push(node.id);
68+
}
69+
}
70+
}
71+
}
72+
return issues;
73+
}
74+
}
75+
vec![]
76+
}
77+
}
78+
79+
impl eframe::App for IssuesApp {
80+
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
81+
let summary_id = self.application.document.nodes.attribute_names.get_index("summary").unwrap_or(0);
82+
let permalink_id = self.application.document.nodes.attribute_names.get_index("permalink").unwrap_or(0);
83+
84+
let frame = egui::Frame::default()
85+
.inner_margin(8.0)
86+
.fill(ctx.style().visuals.panel_fill);
87+
egui::TopBottomPanel::top("toolbar")
88+
.frame(frame)
89+
.show(ctx, |ui| {
90+
create_toolbar(&mut self.application, ui, |ui| {});
91+
});
92+
93+
egui::CentralPanel::default().show(ctx, |ui| {
94+
95+
ui.vertical_centered(|ui| {
96+
if ui.text_edit_singleline(&mut self.search_string).changed() {
97+
self.update_search();
98+
}
99+
100+
let f = egui::Frame::default()
101+
.inner_margin(16.0)
102+
.fill(ctx.style().visuals.panel_fill)
103+
.shadow(ctx.style().visuals.window_shadow)
104+
.stroke(ctx.style().visuals.widgets.noninteractive.bg_stroke);
105+
106+
107+
for id in &self.found_issues {
108+
f.show(ui, |ui| {
109+
let node = self.application.document.nodes.get(*id).unwrap();
110+
let label = node.get_string_attribute(summary_id).unwrap_or("?".to_string());
111+
let url = node.get_string_attribute(permalink_id) .unwrap_or("?".to_string());
112+
ui.hyperlink_to(label, url);
113+
});
114+
}
115+
})
116+
});
117+
}
118+
119+
fn save(&mut self, _storage: &mut dyn Storage) {
120+
// Save app state here
121+
}
122+
}

0 commit comments

Comments
 (0)