policycheck:
* insert copyright hint * more descriptive import of allianzdirectcall function * documentation update * introduce KeyHandler in menu popup * rename action function to `set_action` Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* advotracker - Hotline tackingtool for Advocats
|
||||||
|
*
|
||||||
|
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||||
|
* SPDX-License-Identifier: (0BSD or MIT)
|
||||||
|
*/
|
||||||
|
|
||||||
use locales::t;
|
use locales::t;
|
||||||
use orbtk::prelude::*;
|
use orbtk::prelude::*;
|
||||||
use orbtk::shell::event::Key;
|
use orbtk::shell::event::Key;
|
||||||
@@ -15,10 +22,11 @@ use crate::{
|
|||||||
structures::{PolicyCode, PolicyDataList, PolicyList},
|
structures::{PolicyCode, PolicyDataList, PolicyList},
|
||||||
constants::*,
|
constants::*,
|
||||||
},
|
},
|
||||||
services::imports::allianzdirectcall::import,
|
//services::imports::allianzdirectcall::import,
|
||||||
|
services::imports::allianzdirectcall,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Actions that can execute on the task view.
|
/// Valid `actions` that are handled as state changes in the `Policycheck` widget.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum PolicycheckAction {
|
pub enum PolicycheckAction {
|
||||||
AddProgress(f64),
|
AddProgress(f64),
|
||||||
@@ -41,16 +49,16 @@ pub enum PolicycheckAction {
|
|||||||
TextChanged(Entity, usize)
|
TextChanged(Entity, usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// define valid environment variables provided via .env files
|
/// Define valid environment variables provided via .env files
|
||||||
/// located in the current call directory
|
/// located in the current call directory.
|
||||||
/// this is primarily used in testing scenarios (eg. debugging)
|
/// This is primarily used in testing scenarios (eg. debugging).
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct Environment {
|
struct Environment {
|
||||||
test_lang: String,
|
test_lang: String,
|
||||||
rust_log: String,
|
rust_log: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the requests from `PolicycheckView`.
|
/// Valid `structures` that are handled inside the state of the `Policycheck` widget.
|
||||||
#[derive(AsAny, Default)]
|
#[derive(AsAny, Default)]
|
||||||
pub struct PolicycheckState {
|
pub struct PolicycheckState {
|
||||||
action: Option<PolicycheckAction>,
|
action: Option<PolicycheckAction>,
|
||||||
@@ -70,13 +78,8 @@ pub struct PolicycheckState {
|
|||||||
|
|
||||||
impl GlobalState for PolicycheckState {}
|
impl GlobalState for PolicycheckState {}
|
||||||
|
|
||||||
/// method definitions, that react on any given state change inside the view
|
/// method definitions, that react on any given state change inside the `Policycheck` widget.
|
||||||
impl PolicycheckState {
|
impl PolicycheckState {
|
||||||
/// Sets a new action.
|
|
||||||
pub fn action(&mut self, action: PolicycheckAction) {
|
|
||||||
self.action = action.into();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a hashmap (key: policy number, value: policy type).
|
/// Create a hashmap (key: policy number, value: policy type).
|
||||||
pub fn create_hashmap(&mut self, _ctx: &mut Context<'_>) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn create_hashmap(&mut self, _ctx: &mut Context<'_>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
trace!(target: "advotracker", create_hashmap = "started");
|
trace!(target: "advotracker", create_hashmap = "started");
|
||||||
@@ -94,7 +97,7 @@ impl PolicycheckState {
|
|||||||
// Wip: use cli parameter stored in viperus ...
|
// Wip: use cli parameter stored in viperus ...
|
||||||
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
||||||
let mut csv_import_path = String::from("POLLFNR_WOECHENTLICH.txt");
|
let mut csv_import_path = String::from("POLLFNR_WOECHENTLICH.txt");
|
||||||
match import(&mut csv_import_path, &mut policy_data,
|
match allianzdirectcall::import(&mut csv_import_path, &mut policy_data,
|
||||||
&mut policy_numbers, &mut self.policy_data_count,
|
&mut policy_numbers, &mut self.policy_data_count,
|
||||||
&self.lang) {
|
&self.lang) {
|
||||||
Ok((count, duration)) => {
|
Ok((count, duration)) => {
|
||||||
@@ -131,7 +134,6 @@ impl PolicycheckState {
|
|||||||
|
|
||||||
if self.policy_numbers.len() == 0 {
|
if self.policy_numbers.len() == 0 {
|
||||||
// initialize popup widget
|
// initialize popup widget
|
||||||
//let sender = ctx.send_window_request();
|
|
||||||
self.set_popup_progress(ctx);
|
self.set_popup_progress(ctx);
|
||||||
self.progress_count += 0.33;
|
self.progress_count += 0.33;
|
||||||
self.update_progress_bar(ctx);
|
self.update_progress_bar(ctx);
|
||||||
@@ -344,6 +346,11 @@ impl PolicycheckState {
|
|||||||
// ctx.get_widget(self.policy_check_policy_number).update_theme_by_state(true);
|
// ctx.get_widget(self.policy_check_policy_number).update_theme_by_state(true);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/// Sets a new action.
|
||||||
|
pub fn set_action(&mut self, action: PolicycheckAction) {
|
||||||
|
self.action = action.into();
|
||||||
|
}
|
||||||
|
|
||||||
/// Change status of given text box to edit mode.
|
/// Change status of given text box to edit mode.
|
||||||
fn set_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
fn set_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
||||||
if ctx.get_widget(text_box).get::<String16>("text").is_empty() {
|
if ctx.get_widget(text_box).get::<String16>("text").is_empty() {
|
||||||
@@ -444,7 +451,7 @@ impl PolicycheckState {
|
|||||||
|
|
||||||
/// upported states for our view
|
/// upported states for our view
|
||||||
impl State for PolicycheckState {
|
impl State for PolicycheckState {
|
||||||
/// Initialize the widget state
|
/// Initialize the state of widget PolicyState
|
||||||
fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
||||||
let time_start= SystemTime::now();
|
let time_start= SystemTime::now();
|
||||||
|
|
||||||
@@ -487,7 +494,7 @@ impl State for PolicycheckState {
|
|||||||
trace!(target: "advotracker", policycheck_state = "init", status = "finished", duration = ?duration);
|
trace!(target: "advotracker", policycheck_state = "init", status = "finished", duration = ?duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle messages inside the widget state.
|
/// Handle messages inside the state of widget Policycheck.
|
||||||
fn messages(
|
fn messages(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut messages: MessageReader,
|
mut messages: MessageReader,
|
||||||
@@ -508,12 +515,24 @@ impl State for PolicycheckState {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => (),
|
PolicycheckAction::AddProgress(increment) => {
|
||||||
|
let old_width = ProgressBar::val_clone(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
||||||
|
|
||||||
|
let new_width = old_width + increment;
|
||||||
|
// Set the ProgressBar's val property to the calculated percentage
|
||||||
|
// (whereas 0.0 means 0%, and 1.0 means 100%)
|
||||||
|
if new_width <= 1. {
|
||||||
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), new_width);
|
||||||
|
} else {
|
||||||
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 1.);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the widget state.
|
/// Update the state of widget Policycheck.
|
||||||
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
|
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
|
||||||
// // clear focus on focus moved
|
// // clear focus on focus moved
|
||||||
// if self.last_focused != ctx.window().get::<Global>("global").focused_widget {
|
// if self.last_focused != ctx.window().get::<Global>("global").focused_widget {
|
||||||
@@ -527,18 +546,6 @@ impl State for PolicycheckState {
|
|||||||
|
|
||||||
if let Some(action) = self.action {
|
if let Some(action) = self.action {
|
||||||
match action {
|
match action {
|
||||||
PolicycheckAction::AddProgress(increment) => {
|
|
||||||
let old_width = ProgressBar::val_clone(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
|
||||||
|
|
||||||
let new_width = old_width + increment;
|
|
||||||
// Set the ProgressBar's val property to the calculated percentage
|
|
||||||
// (whereas 0.0 means 0 %, and 1.0 means 100 %) to increment the progress
|
|
||||||
if new_width <= 1. {
|
|
||||||
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), new_width);
|
|
||||||
} else {
|
|
||||||
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 1.);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PolicycheckAction::ClearEntry(policy_check_policy_number) => {
|
PolicycheckAction::ClearEntry(policy_check_policy_number) => {
|
||||||
ctx.get_widget(policy_check_policy_number).set("enabled", false);
|
ctx.get_widget(policy_check_policy_number).set("enabled", false);
|
||||||
}
|
}
|
||||||
@@ -622,7 +629,7 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
|||||||
.open(true)
|
.open(true)
|
||||||
.width(280)
|
.width(280)
|
||||||
.height(140)
|
.height(140)
|
||||||
.on_key_down(move | ctx, key_event | {
|
.on_key_down(move | _ctx, key_event | {
|
||||||
match key_event.key {
|
match key_event.key {
|
||||||
Key::Q(..) => {
|
Key::Q(..) => {
|
||||||
//if is_ctrl_home_down(ctx) {
|
//if is_ctrl_home_down(ctx) {
|
||||||
@@ -631,8 +638,9 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
|||||||
//}
|
//}
|
||||||
},
|
},
|
||||||
Key::Escape => {
|
Key::Escape => {
|
||||||
ctx.get_mut::<PolicycheckState>(menu)
|
println!("got: Escape");
|
||||||
.action(PolicycheckAction::RemoveMenu(menu));
|
//ctx.get::<PolicycheckState>(menu)
|
||||||
|
// .set_action(PolicycheckAction::RemoveMenu(menu));
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
@@ -643,12 +651,9 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
|||||||
.id(ID_POLICY_CHECK_MENU)
|
.id(ID_POLICY_CHECK_MENU)
|
||||||
.columns(
|
.columns(
|
||||||
Columns::create()
|
Columns::create()
|
||||||
// Menu Button
|
.push("80") // Menu Button
|
||||||
.push("80")
|
.push("1") // Seperator
|
||||||
// Seperator
|
.push("*") // Keyboard Shortcut
|
||||||
.push("1")
|
|
||||||
// Keyboard Shortcut
|
|
||||||
.push("*")
|
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.rows(
|
.rows(
|
||||||
@@ -680,7 +685,7 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
|||||||
.text("Toggle theme")
|
.text("Toggle theme")
|
||||||
.on_click(move |states, _| {
|
.on_click(move |states, _| {
|
||||||
states.get_mut::<PolicycheckState>(menu)
|
states.get_mut::<PolicycheckState>(menu)
|
||||||
.action(PolicycheckAction::SetToggleTheme(menu));
|
.set_action(PolicycheckAction::SetToggleTheme(menu));
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
@@ -767,7 +772,7 @@ fn create_popup_progress(popup_progress: Entity, ctx: &mut BuildContext<'_>) ->
|
|||||||
.on_mouse_down(move |ctx, _| {
|
.on_mouse_down(move |ctx, _| {
|
||||||
println!("create_popup_progress: on_click -> remove_popup(popup_progress)");
|
println!("create_popup_progress: on_click -> remove_popup(popup_progress)");
|
||||||
ctx.get_mut::<PolicycheckState>(popup_progress)
|
ctx.get_mut::<PolicycheckState>(popup_progress)
|
||||||
.action(PolicycheckAction::RemovePopup(popup_progress));
|
.set_action(PolicycheckAction::RemovePopup(popup_progress));
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
|
|||||||
@@ -6,13 +6,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use orbtk::prelude::*;
|
use orbtk::prelude::*;
|
||||||
|
use orbtk::shell::event::Key;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
data::{
|
data::{
|
||||||
constants::*,
|
constants::*,
|
||||||
structures::PolicyCheck,
|
structures::PolicyCheck,
|
||||||
},
|
},
|
||||||
widgets::policycheck::policycheck_state::*,
|
widgets::policycheck::policycheck_state::{PolicycheckAction, PolicycheckState},
|
||||||
};
|
};
|
||||||
|
|
||||||
type List = Vec<String>;
|
type List = Vec<String>;
|
||||||
@@ -21,6 +22,7 @@ type List = Vec<String>;
|
|||||||
widget!(
|
widget!(
|
||||||
/// Dialog to enter a policy identifier/number.
|
/// Dialog to enter a policy identifier/number.
|
||||||
/// This identifier is checked agains a map of valid policy codes.
|
/// This identifier is checked agains a map of valid policy codes.
|
||||||
|
// PolicycheckView<PolicycheckState>: KeyDownHandler {
|
||||||
PolicycheckView<PolicycheckState> {
|
PolicycheckView<PolicycheckState> {
|
||||||
lang: String,
|
lang: String,
|
||||||
policy_check: PolicyCheck,
|
policy_check: PolicyCheck,
|
||||||
@@ -99,7 +101,7 @@ impl Template for PolicycheckView {
|
|||||||
.on_click(move |ctx, _| {
|
.on_click(move |ctx, _| {
|
||||||
//ctx.get_mut::<PolicycheckState>(policycheck_state)
|
//ctx.get_mut::<PolicycheckState>(policycheck_state)
|
||||||
ctx.get_mut::<PolicycheckState>(id)
|
ctx.get_mut::<PolicycheckState>(id)
|
||||||
.action(PolicycheckAction::OpenMenu(policy_check_label_menu));
|
.set_action(PolicycheckAction::OpenMenu(policy_check_label_menu));
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
@@ -169,32 +171,34 @@ impl Template for PolicycheckView {
|
|||||||
.on_activate(move |ctx, entity| {
|
.on_activate(move |ctx, entity| {
|
||||||
// Entity is entered/activated via Mouse/Keyboard
|
// Entity is entered/activated via Mouse/Keyboard
|
||||||
//ctx.get_mut::<PolicycheckState>(policy_check_view)
|
//ctx.get_mut::<PolicycheckState>(policy_check_view)
|
||||||
println!("ParseEntry: {:?}", entity);
|
|
||||||
ctx.get_mut::<PolicycheckState>(id)
|
ctx.get_mut::<PolicycheckState>(id)
|
||||||
.action(PolicycheckAction::ParseEntry(entity));
|
.set_action(PolicycheckAction::ParseEntry(entity));
|
||||||
})
|
})
|
||||||
//.on_changed(|_, entity, _, _| println!("Selection changed: {:?}", entity))
|
//.on_changed(|_, entity, _, _| println!("Selection changed: {:?}", entity))
|
||||||
// .on_changed(move |ctx, entity, _| {
|
// .on_changed(move |ctx, entity, _| {
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::SetProgressBox(entity));
|
// .set_action(Action::SetProgressBox(entity));
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::AddProgress(0.5));
|
// .set_action(Action::AddProgress(0.5));
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::InputTextChanged(entity));
|
// .set_action(Action::InputTextChanged(entity));
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::SetVisibility(entity));
|
// .set_action(Action::SetVisibility(entity));
|
||||||
// ctx.get_widget(policy_check_label_policy_number).set("visible");
|
// ctx.get_widget(policy_check_label_policy_number).set("visible");
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::SetVisility(entity));
|
// .set_action(Action::SetVisility(entity));
|
||||||
// })
|
// })
|
||||||
// .on_mouse_down | .on_mouse_move | .on_mouse_up (move |ctx, entity| {
|
// .on_mouse_down | .on_mouse_move | .on_mouse_up (move |ctx, entity| {
|
||||||
// state(id, states).action(Action::AddItem);
|
// state(id, states).set_action(Action::AddItem);
|
||||||
// })
|
// })
|
||||||
//.on_key_down(move |ctx, _| {
|
.on_key_down(move |_, key_event| {
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
if key_event.key == Key::A(true) {
|
||||||
// .action(Action::ImportData);
|
println!("A key down");
|
||||||
// true
|
}
|
||||||
//})
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
|
// .set_action(Action::ImportData);
|
||||||
|
true
|
||||||
|
})
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
.child(policy_check_button_result)
|
.child(policy_check_button_result)
|
||||||
@@ -313,7 +317,8 @@ impl Template for PolicycheckView {
|
|||||||
.build(ctx);
|
.build(ctx);
|
||||||
|
|
||||||
// WIP: this widget type should handle our target natively
|
// WIP: this widget type should handle our target natively
|
||||||
// but it isn't able to get textinput ... yet
|
// but it isn't able to get textinput, nor handle usize values
|
||||||
|
// ... yet
|
||||||
let _policy_check_numeric_box = NumericBox::new()
|
let _policy_check_numeric_box = NumericBox::new()
|
||||||
.id(ID_POLICY_CHECK_POLICY_NUMBER)
|
.id(ID_POLICY_CHECK_POLICY_NUMBER)
|
||||||
.h_align("start")
|
.h_align("start")
|
||||||
@@ -326,14 +331,16 @@ impl Template for PolicycheckView {
|
|||||||
// WIP code @kivimango
|
// WIP code @kivimango
|
||||||
// .on_activate(move |ctx, entity| {
|
// .on_activate(move |ctx, entity| {
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::ParseEntry(entity));
|
// .set_action(Action::ParseEntry(entity));
|
||||||
// })
|
// })
|
||||||
// .on_changed(move |ctx, entity| {
|
// .on_changed(move |ctx, entity| {
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::InputTextChanged(entity));
|
// .set_action(Action::InputTextChanged(entity));
|
||||||
//})
|
//})
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
|
|
||||||
|
// row3: only shown, if we read in `policy numbers` in
|
||||||
|
// a hashmap as values
|
||||||
let policy_data_stack = Stack::new()
|
let policy_data_stack = Stack::new()
|
||||||
.id(ID_POLICY_DATA_STACK)
|
.id(ID_POLICY_DATA_STACK)
|
||||||
.attach(Grid::row(3))
|
.attach(Grid::row(3))
|
||||||
|
|||||||
Reference in New Issue
Block a user