policycheck: function update
* 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 orbtk::prelude::*;
|
||||
use orbtk::shell::event::Key;
|
||||
@@ -15,10 +22,11 @@ use crate::{
|
||||
structures::{PolicyCode, PolicyDataList, PolicyList},
|
||||
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)]
|
||||
pub enum PolicycheckAction {
|
||||
AddProgress(f64),
|
||||
@@ -41,16 +49,16 @@ pub enum PolicycheckAction {
|
||||
TextChanged(Entity, usize)
|
||||
}
|
||||
|
||||
/// define valid environment variables provided via .env files
|
||||
/// located in the current call directory
|
||||
/// this is primarily used in testing scenarios (eg. debugging)
|
||||
/// Define valid environment variables provided via .env files
|
||||
/// located in the current call directory.
|
||||
/// This is primarily used in testing scenarios (eg. debugging).
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Environment {
|
||||
test_lang: String,
|
||||
rust_log: String,
|
||||
}
|
||||
|
||||
/// Handles the requests from `PolicycheckView`.
|
||||
/// Valid `structures` that are handled inside the state of the `Policycheck` widget.
|
||||
#[derive(AsAny, Default)]
|
||||
pub struct PolicycheckState {
|
||||
action: Option<PolicycheckAction>,
|
||||
@@ -70,13 +78,8 @@ pub struct 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 {
|
||||
/// Sets a new action.
|
||||
pub fn action(&mut self, action: PolicycheckAction) {
|
||||
self.action = action.into();
|
||||
}
|
||||
|
||||
/// Create a hashmap (key: policy number, value: policy type).
|
||||
pub fn create_hashmap(&mut self, _ctx: &mut Context<'_>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
trace!(target: "advotracker", create_hashmap = "started");
|
||||
@@ -94,7 +97,7 @@ impl PolicycheckState {
|
||||
// Wip: use cli parameter stored in viperus ...
|
||||
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
||||
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,
|
||||
&self.lang) {
|
||||
Ok((count, duration)) => {
|
||||
@@ -131,7 +134,6 @@ impl PolicycheckState {
|
||||
|
||||
if self.policy_numbers.len() == 0 {
|
||||
// initialize popup widget
|
||||
//let sender = ctx.send_window_request();
|
||||
self.set_popup_progress(ctx);
|
||||
self.progress_count += 0.33;
|
||||
self.update_progress_bar(ctx);
|
||||
@@ -344,6 +346,11 @@ impl PolicycheckState {
|
||||
// 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.
|
||||
fn set_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
||||
if ctx.get_widget(text_box).get::<String16>("text").is_empty() {
|
||||
@@ -444,7 +451,7 @@ impl PolicycheckState {
|
||||
|
||||
/// upported states for our view
|
||||
impl State for PolicycheckState {
|
||||
/// Initialize the widget state
|
||||
/// Initialize the state of widget PolicyState
|
||||
fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
||||
let time_start= SystemTime::now();
|
||||
|
||||
@@ -487,7 +494,7 @@ impl State for PolicycheckState {
|
||||
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(
|
||||
&mut self,
|
||||
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<'_>) {
|
||||
// // clear focus on focus moved
|
||||
// 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 {
|
||||
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) => {
|
||||
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)
|
||||
.width(280)
|
||||
.height(140)
|
||||
.on_key_down(move | ctx, key_event | {
|
||||
.on_key_down(move | _ctx, key_event | {
|
||||
match key_event.key {
|
||||
Key::Q(..) => {
|
||||
//if is_ctrl_home_down(ctx) {
|
||||
@@ -631,8 +638,9 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
//}
|
||||
},
|
||||
Key::Escape => {
|
||||
ctx.get_mut::<PolicycheckState>(menu)
|
||||
.action(PolicycheckAction::RemoveMenu(menu));
|
||||
println!("got: Escape");
|
||||
//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)
|
||||
.columns(
|
||||
Columns::create()
|
||||
// Menu Button
|
||||
.push("80")
|
||||
// Seperator
|
||||
.push("1")
|
||||
// Keyboard Shortcut
|
||||
.push("*")
|
||||
.push("80") // Menu Button
|
||||
.push("1") // Seperator
|
||||
.push("*") // Keyboard Shortcut
|
||||
.build(),
|
||||
)
|
||||
.rows(
|
||||
@@ -680,7 +685,7 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
.text("Toggle theme")
|
||||
.on_click(move |states, _| {
|
||||
states.get_mut::<PolicycheckState>(menu)
|
||||
.action(PolicycheckAction::SetToggleTheme(menu));
|
||||
.set_action(PolicycheckAction::SetToggleTheme(menu));
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
@@ -767,7 +772,7 @@ fn create_popup_progress(popup_progress: Entity, ctx: &mut BuildContext<'_>) ->
|
||||
.on_mouse_down(move |ctx, _| {
|
||||
println!("create_popup_progress: on_click -> remove_popup(popup_progress)");
|
||||
ctx.get_mut::<PolicycheckState>(popup_progress)
|
||||
.action(PolicycheckAction::RemovePopup(popup_progress));
|
||||
.set_action(PolicycheckAction::RemovePopup(popup_progress));
|
||||
true
|
||||
})
|
||||
.child(
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
use orbtk::shell::event::Key;
|
||||
|
||||
use crate::{
|
||||
data::{
|
||||
constants::*,
|
||||
structures::PolicyCheck,
|
||||
},
|
||||
widgets::policycheck::policycheck_state::*,
|
||||
widgets::policycheck::policycheck_state::{PolicycheckAction, PolicycheckState},
|
||||
};
|
||||
|
||||
type List = Vec<String>;
|
||||
@@ -21,6 +22,7 @@ type List = Vec<String>;
|
||||
widget!(
|
||||
/// Dialog to enter a policy identifier/number.
|
||||
/// This identifier is checked agains a map of valid policy codes.
|
||||
// PolicycheckView<PolicycheckState>: KeyDownHandler {
|
||||
PolicycheckView<PolicycheckState> {
|
||||
lang: String,
|
||||
policy_check: PolicyCheck,
|
||||
@@ -99,7 +101,7 @@ impl Template for PolicycheckView {
|
||||
.on_click(move |ctx, _| {
|
||||
//ctx.get_mut::<PolicycheckState>(policycheck_state)
|
||||
ctx.get_mut::<PolicycheckState>(id)
|
||||
.action(PolicycheckAction::OpenMenu(policy_check_label_menu));
|
||||
.set_action(PolicycheckAction::OpenMenu(policy_check_label_menu));
|
||||
true
|
||||
})
|
||||
.build(ctx);
|
||||
@@ -169,32 +171,34 @@ impl Template for PolicycheckView {
|
||||
.on_activate(move |ctx, entity| {
|
||||
// Entity is entered/activated via Mouse/Keyboard
|
||||
//ctx.get_mut::<PolicycheckState>(policy_check_view)
|
||||
println!("ParseEntry: {:?}", entity);
|
||||
ctx.get_mut::<PolicycheckState>(id)
|
||||
.action(PolicycheckAction::ParseEntry(entity));
|
||||
.set_action(PolicycheckAction::ParseEntry(entity));
|
||||
})
|
||||
//.on_changed(|_, entity, _, _| println!("Selection changed: {:?}", entity))
|
||||
// .on_changed(move |ctx, entity, _| {
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::SetProgressBox(entity));
|
||||
// .set_action(Action::SetProgressBox(entity));
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::AddProgress(0.5));
|
||||
// .set_action(Action::AddProgress(0.5));
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::InputTextChanged(entity));
|
||||
// .set_action(Action::InputTextChanged(entity));
|
||||
// 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_mut::<PolicycheckState>(id)
|
||||
// .action(Action::SetVisility(entity));
|
||||
// .set_action(Action::SetVisility(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, _| {
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::ImportData);
|
||||
// true
|
||||
//})
|
||||
.on_key_down(move |_, key_event| {
|
||||
if key_event.key == Key::A(true) {
|
||||
println!("A key down");
|
||||
}
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .set_action(Action::ImportData);
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(policy_check_button_result)
|
||||
@@ -313,7 +317,8 @@ impl Template for PolicycheckView {
|
||||
.build(ctx);
|
||||
|
||||
// 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()
|
||||
.id(ID_POLICY_CHECK_POLICY_NUMBER)
|
||||
.h_align("start")
|
||||
@@ -326,14 +331,16 @@ impl Template for PolicycheckView {
|
||||
// WIP code @kivimango
|
||||
// .on_activate(move |ctx, entity| {
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::ParseEntry(entity));
|
||||
// .set_action(Action::ParseEntry(entity));
|
||||
// })
|
||||
// .on_changed(move |ctx, entity| {
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::InputTextChanged(entity));
|
||||
// .set_action(Action::InputTextChanged(entity));
|
||||
//})
|
||||
.build(ctx);
|
||||
|
||||
// row3: only shown, if we read in `policy numbers` in
|
||||
// a hashmap as values
|
||||
let policy_data_stack = Stack::new()
|
||||
.id(ID_POLICY_DATA_STACK)
|
||||
.attach(Grid::row(3))
|
||||
|
||||
Reference in New Issue
Block a user