policycheck: introduce policy_check_button_result

* after validation, show suitables glyph and corresponding text
* improve user feedback with corresponding color

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2020-07-07 02:55:48 +02:00
parent 24b9b08566
commit d6703e8df6
4 changed files with 88 additions and 79 deletions

View File

@@ -11,7 +11,7 @@ use crate::services::imports::allianzdirectcall::import;
use crate::{ use crate::{
callbacks::global_state::GlobalState, callbacks::global_state::GlobalState,
data::structures::{PolicyCheck, PolicyCode, PolicyDataList, PolicyList}, data::structures::{PolicyCode, PolicyDataList, PolicyList},
data::keys::*, data::keys::*,
}; };
@@ -42,7 +42,7 @@ pub struct PolicyCheckState {
last_focused: Option<Entity>, last_focused: Option<Entity>,
menu_button: Entity, menu_button: Entity,
//policy_check_clean_button: Entity, //policy_check_clean_button: Entity,
policy_check: PolicyCheck, //policy_check: PolicyCheck,
policy_data_count: usize, policy_data_count: usize,
//policy_number_text_box: Entity, //policy_number_text_box: Entity,
policy_numbers: HashMap<usize, PolicyCode> policy_numbers: HashMap<usize, PolicyCode>
@@ -122,58 +122,66 @@ impl PolicyCheckState {
// Parse policy code: "AS-123456789" // Parse policy code: "AS-123456789"
// DION VERS POLLFNR // DION VERS POLLFNR
// 1 AS 1515735810 // 1 AS 1515735810
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Collapsed);
button(ctx.child("policy_check_button_result")).set_background("transparent");
if policy_number_length == 10 { if policy_number_length == 10 {
// needs to be an integer // needs to be an integer
match policy_string.parse::<usize>() { match policy_string.parse::<usize>() {
Ok(p) => { Ok(p) => {
println!(" ... verify policy Number {:?}", p);
let mut label_wrapper : TextBlockCtx<'_> = text_block(ctx.child("policy_check_label_result"));
let string_label = "Prüfungsergebnis:".to_string();
label_wrapper.set_text(string_label);
label_wrapper.set_visibility(Visibility::Visible);
label_wrapper.set_enabled(true);
let mut result_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result")); let mut result_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
result_wrapper.set_text("Prüfung läuft ..."); result_wrapper.set_text("");
match self.policy_numbers.get(&p) { match self.policy_numbers.get(&p) {
// check hashmap value field // check hashmap value field
Some(policy_code) => { Some(policy_code) => {
trace!(target: "advotracker", state = "success", trace!(target: "advotracker", state = "success",
policy_number = ?p, policy_code = ?policy_code); policy_number = ?p, policy_code = ?policy_code);
result_wrapper.set_enabled(true); result_wrapper.set_enabled(true);
let string_result = format!("gütig! => vollständig: 1-{:?}-{}", let string_result = format!("1-{:?}-{}",
policy_code, p); policy_code, p);
result_wrapper.set_text(string_result); result_wrapper.set_text(string_result);
button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CHECK);
button(ctx.child("policy_check_button_result")).set_icon_brush("#008000");
button(ctx.child("policy_check_button_result")).set_text("gültig!");
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
button(ctx.child("policy_check_button_result")).set_foreground("#008000");
button(ctx.child("policy_check_button_result")).set_background("transparent");
} }
_ => { _ => {
//let res = t!("policy.validation.failed", lang); //let res = t!("policy.validation.failed", lang);
//println!("{:?}", res); //println!("{:?}", res);
trace!(target: "advotracker", state = "failed", trace!(target: "advotracker", state = "failed",
policy_number = ?p); policy_number = ?p);
println!("Noop! Number isn't valid!"); button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CLEAR);
result_wrapper.set_enabled(true); button(ctx.child("policy_check_button_result")).set_icon_brush("#FF0000");
result_wrapper.set_text("noop, ungültig!"); button(ctx.child("policy_check_button_result")).set_text("ungültig!");
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
button(ctx.child("policy_check_button_result")).set_foreground("#FF0000");
} }
} }
}, },
Err(e) => { Err(e) => {
trace!(target: "advotracker", state = "error", error_type = "invalid type"); trace!(target: "advotracker", state = "error", error_type = "invalid type", error = ?e);
println!("invalid: {}", e); button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CLEAR);
// Feedback button(ctx.child("policy_check_button_result")).set_icon_brush("#FF0000");
println!("Please enter an integer!"); button(ctx.child("policy_check_button_result")).set_text("ungültig!");
} button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
} button(ctx.child("policy_check_button_result")).set_foreground("#FF0000");
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
text_block_wrapper.set_enabled(true);
text_block_wrapper.set_text("Nur Nummern sind zulässig!");
} }
}
}
if policy_number_length < 10 { if policy_number_length < 10 {
println!("Policy number is to short!"); //println!("Policy number is to short!");
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result")); let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
text_block_wrapper.set_enabled(true); text_block_wrapper.set_enabled(true);
text_block_wrapper.set_text("zu kurz!"); text_block_wrapper.set_text("zu kurz!");
//ctx.get_widget(policy_check_policy_number).set("policy_check_result", true);
//ctx.child(ID_POLICY_CHECK_POLICY_NUMBER).set("text", String::from(""));
} }
if policy_number_length > 10 { if policy_number_length > 10 {
println!("Policy number is to big!"); //println!("Policy number is to big!");
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result")); let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
text_block_wrapper.set_enabled(true); text_block_wrapper.set_enabled(true);
text_block_wrapper.set_text("zu lang!"); text_block_wrapper.set_text("zu lang!");
@@ -217,8 +225,10 @@ impl PolicyCheckState {
fn set_visibility(&self, entity: Entity, ctx: &mut Context<'_>) { fn set_visibility(&self, entity: Entity, ctx: &mut Context<'_>) {
if ctx.get_widget(entity).get::<String16>("text").is_empty() { if ctx.get_widget(entity).get::<String16>("text").is_empty() {
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Visible); text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Visible);
text_block(ctx.child(ID_POLICY_CHECK_BUTTON_RESULT)).set_visibility(Visibility::Visible);
} else { } else {
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Collapsed); text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Collapsed);
text_block(ctx.child(ID_POLICY_CHECK_BUTTON_RESULT)).set_visibility(Visibility::Collapsed);
//ctx.get_widget(self.policy_check_label_policy_number).set("enabled", false); //ctx.get_widget(self.policy_check_label_policy_number).set("enabled", false);
} }
@@ -237,11 +247,8 @@ impl PolicyCheckState {
impl State for PolicyCheckState { impl State for PolicyCheckState {
fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
self.menu_button = ctx self.menu_button = ctx
.entity_of_child(ID_POLICY_CHECK_MENU_BUTTON) .entity_of_child(ID_POLICY_CHECK_BUTTON_MENU)
.expect("PolicyCheckState.init: Can't find entity id defined as resource 'ID_POLICY_CHECK_POLICY_MENU_BUTTON'."); .expect("PolicyCheckState.init: Can't find entity id defined as resource 'ID_POLICY_CHECK_POLICY_MENU_BUTTON'.");
// self.policy_number_text_box = ctx
// .entity_of_child(ID_POLICY_CHECK_POLICY_NUMBER)
// .expect("PolicyCheckState.init: Can't find entity id defined as resource 'ID_POLICY_CHECK_POLICY_NUMBER'.");
// import data // import data
// WIP: for now, only import once per session // WIP: for now, only import once per session
@@ -327,6 +334,8 @@ impl State for PolicyCheckState {
} }
Action::SetVisibility(entity) => { Action::SetVisibility(entity) => {
//text_block(ctx.child(entity).set_visibility(Visibility::Visible)); //text_block(ctx.child(entity).set_visibility(Visibility::Visible));
println!("Entity: {:?}", entity);
//text_block(ctx.child(entity).set_visibility(Visibility::Collapsed));
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Collapsed); text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Collapsed);
} }
Action::TextChanged(entity, _index) => { Action::TextChanged(entity, _index) => {

View File

@@ -2,11 +2,10 @@
// https://github.com/ron-rs/ronRon // https://github.com/ron-rs/ronRon
// Classes // Classes
pub static CLASS_BOTTOM_BAR: &str = "bottom_bar"; pub static CLASS_FOOTER: &str = "footer";
pub static CLASS_HEADER: &str = ".my_header"; pub static CLASS_HEADER: &str = "header";
pub static CLASS_ICON_ONLY: &str = "icon_only";
pub static CLASS_ITEM_BUTTON: &str = "item_button"; pub static CLASS_ITEM_BUTTON: &str = "item_button";
pub static CLASS_MENU: &str = "menu"; pub static CLASS_MENU_BUTTON: &str = "menu_button";
pub static CLASS_POLICY_CHECK_FORM: &str = "check_form"; pub static CLASS_POLICY_CHECK_FORM: &str = "check_form";
pub static CLASS_TEXT_BOX: &str = "text_box"; pub static CLASS_TEXT_BOX: &str = "text_box";
pub static CLASS_TEXT_BLOCK: &str = "text_block"; pub static CLASS_TEXT_BLOCK: &str = "text_block";
@@ -17,12 +16,13 @@ pub static CLASS_SEPERATOR: &str = "seperator";
// Widget IDs (DCES: Entity[id] => [Component1, .. , Component<n>] -> data or state) // Widget IDs (DCES: Entity[id] => [Component1, .. , Component<n>] -> data or state)
pub static ID_POLICY_CHECK_FORM: &str = "policy_check_form"; pub static ID_POLICY_CHECK_FORM: &str = "policy_check_form";
pub static ID_POLICY_CHECK_HEADER: &str = "policy_check_header"; pub static ID_POLICY_CHECK_HEADER: &str = "policy_check_header";
//pub static ID_POLICY_CHECK_ITEMS_WIDGET: &str = "policy_check_items_widget"; pub static ID_POLICY_CHECK_ITEMS_WIDGET: &str = "policy_check_items_widget";
pub static ID_POLICY_CHECK_CLEAR_BUTTON: &str = "policy_check_clear_button"; pub static ID_POLICY_CHECK_BUTTON_MENU: &str = "policy_check_button_menu";
pub static ID_POLICY_CHECK_MENU_BUTTON: &str = "policy_check_menu_button"; pub static ID_POLICY_CHECK_BUTTON_RESULT: &str = "policy_check_button_result";
pub static ID_POLICY_CHECK_LABEL_POLICY_NUMBER: &str = "policy_check_label_policy_number"; pub static ID_POLICY_CHECK_LABEL_POLICY_NUMBER: &str = "policy_check_label_policy_number";
pub static ID_POLICY_CHECK_LABEL_RESULT: &str = "policy_check_label_result"; pub static ID_POLICY_CHECK_LABEL_RESULT: &str = "policy_check_label_result";
pub static ID_POLICY_CHECK_MENU_TEXT_BLOCK: &str = "policy_check_menu_text_block"; pub static ID_POLICY_CHECK_TEXT_BLOCK_MENU: &str = "policy_check_text_block_menu";
pub static ID_POLICY_CHECK_POLICY_NUMBER: &str = "policy_check_policy_number";
pub static ID_POLICY_CHECK_RESULT: &str = "policy_check_result"; pub static ID_POLICY_CHECK_RESULT: &str = "policy_check_result";
pub static ID_POLICY_CHECK_POLICY_NUMBER: &str = "policy_check_policy_number"; pub static ID_POLICY_CHECK_POLICY_NUMBER: &str = "policy_check_policy_number";
pub static ID_POLICY_CHECK_WIDGET: &str = "policy_check_widget"; pub static ID_POLICY_CHECK_WIDGET: &str = "policy_check_widget";

View File

@@ -36,12 +36,11 @@ struct Environment {
} }
//#[cfg(feature = "light-theme")] //#[cfg(feature = "light-theme")]
//static STYLESHEET: &'static str = include_str!("../resources/stylesheets/advotracker.css"); static STYLESHEET: &'static str = include_str!("../resources/stylesheets/advotracker.css");
static STYLESHEET: &'static str = include_str!("../resources/stylesheets/policyholder-check.css");
fn get_theme() -> ThemeValue { fn get_theme() -> ThemeValue {
//ThemeValue::create_from_css(LIGHT_THEME_EXTENSION_CSS)
ThemeValue::create_from_css(DEFAULT_THEME_CSS) ThemeValue::create_from_css(DEFAULT_THEME_CSS)
//ThemeValue::create_from_css(LIGHT_THEME_EXTENSION_CSS)
.extension_css(STYLESHEET) .extension_css(STYLESHEET)
.build() .build()
} }
@@ -75,9 +74,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut lang = env::var("LANG").unwrap_or("en".to_string()); let mut lang = env::var("LANG").unwrap_or("en".to_string());
let mut res = t!("parse.environment", lang); let mut res = t!("parse.environment", lang);
let mut state = t!("state.started", lang); let mut state = t!("state.started", lang);
trace!(target: "csv-test", message = ?res, state = ?state); trace!(target: "advotracker", message = ?res, state = ?state);
//debug!(message = ?res, state = ?state); //debug!(message = ?res, state = ?state);
trace!(target: "csv-test", environment = "system", lang = ?lang); trace!(target: "advotracker", environment = "system", lang = ?lang);
// testing environment: read from .env file // testing environment: read from .env file
dotenv().ok(); dotenv().ok();
@@ -89,9 +88,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
// how to handle unumplemented lang resources?? // how to handle unumplemented lang resources??
res = t!("parse.environment", lang); res = t!("parse.environment", lang);
trace!(target: "csv-test", environment = "envy", lang = ?lang); trace!(target: "advotracker", environment = "envy", lang = ?lang);
state = t!("state.finished", lang); state = t!("state.finished", lang);
trace!(target: "csv-test", message = ?res, state = ?state); trace!(target: "advotracker", message = ?res, state = ?state);
// initialize viperus structure // initialize viperus structure
let mut viperus = Viperus::new(); let mut viperus = Viperus::new();
@@ -112,17 +111,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// parse commandline arguments // parse commandline arguments
res = t!("parse.arguments", lang); res = t!("parse.arguments", lang);
state = t!("state.started", lang); state = t!("state.started", lang);
trace!(target: "csv-test", process = ?res, state = ?state); trace!(target: "advotracker", process = ?res, state = ?state);
let _ = parse_args(&mut viperus); let _ = parse_args(&mut viperus);
state = t!("state.finished", lang); state = t!("state.finished", lang);
trace!(target: "csv-test", process = ?res, state = ?state); trace!(target: "advotracker", process = ?res, state = ?state);
//trace!(target: "Viperus", "Count of Config parameters: {:?}", VIPERUS_COUNT); //trace!(target: "Viperus", "Count of Config parameters: {:?}", VIPERUS_COUNT);
// main tasks // main tasks
res = t!("main.started", lang); res = t!("main.started", lang);
state = t!("state.started", lang); state = t!("state.started", lang);
trace!(target: "csv-test", process = ?res, state = ?state); trace!(target: "advotracker", process = ?res, state = ?state);
// moved to callback: checkview_state.rs // moved to callback: checkview_state.rs
// // importing policy code elements from csv-file // // importing policy code elements from csv-file
@@ -141,14 +140,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// println!("Imported {:?} records", count); // println!("Imported {:?} records", count);
// } // }
// Err(err) => { // Err(err) => {
// println!("error running Csv-Test: {}", err); // println!("error running Advotracker: {}", err);
// process::exit(1); // process::exit(1);
// } // }
//} //}
// // test if policy_number is_valid // // test if policy_number is_valid
// let test_policy_number = VIPERUS.get::<i32>("test_policy_number").unwrap() as usize; // let test_policy_number = VIPERUS.get::<i32>("test_policy_number").unwrap() as usize;
// trace!(target: "csv-test", test_policy_number = ?test_policy_number); // trace!(target: "advotracker", test_policy_number = ?test_policy_number);
// match policy_numbers.get(&test_policy_number) { // match policy_numbers.get(&test_policy_number) {
// Some(&policy_code) => { // Some(&policy_code) => {
// let res = t!("policy.validation.success", lang); // let res = t!("policy.validation.success", lang);
@@ -165,11 +164,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Application::from_name("rzerres.advotracker") Application::from_name("nwx.advotracker")
.window(move |ctx| { .window(move |ctx| {
Window::new() Window::new()
//.title("OrbTk - Policyholder checker") .title("AdvoTracker - DirectCall")
.title("AdvoTracker - Versicherungsnummern")
.position((500.0, 100.0)) .position((500.0, 100.0))
.size(580.0, 320.0) .size(580.0, 320.0)
.min_width(460.0) .min_width(460.0)
@@ -183,7 +181,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
state = t!("state.finished", lang); state = t!("state.finished", lang);
res = t!("main.finished", lang); res = t!("main.finished", lang);
trace!(target: "csv-test", process = ?res, state = ?state); trace!(target: "advotracker", process = ?res, state = ?state);
}); });
Ok(()) Ok(())

View File

@@ -40,8 +40,7 @@ impl Template for PolicyCheckView {
.id(ID_POLICY_CHECK_MENU_BUTTON) .id(ID_POLICY_CHECK_MENU_BUTTON)
.margin((0.0, 0.0, 12.0, 12.0)) .margin((0.0, 0.0, 12.0, 12.0))
.icon(material_icons_font::MD_MENU) .icon(material_icons_font::MD_MENU)
.class(CLASS_ICON_ONLY) .class("menu_button")
//.attach(Grid::row(0))
.attach(Grid::column(2)) .attach(Grid::column(2))
.margin((8.0, 0.0, 2.0, 0.0)) .margin((8.0, 0.0, 2.0, 0.0))
//.text("Menu Button") //.text("Menu Button")
@@ -59,20 +58,24 @@ impl Template for PolicyCheckView {
}) })
.build(ctx); .build(ctx);
let policy_check_result_button = Button::new()
.id(ID_POLICY_CHECK_BUTTON_RESULT)
.class("single_content")
.h_align("start")
.v_align("center")
.visibility(Visibility::Collapsed)
.enabled(false)
.build(ctx);
let policy_data_count_block = TextBlock::new() let policy_data_count_block = TextBlock::new()
.id(ID_POLICY_DATA_COUNT_BLOCK) .id(ID_POLICY_DATA_COUNT_BLOCK)
//.class(CLASS_TEXT_BLOCK) //.class(CLASS_TEXT_BLOCK)
.attach(Grid::row(2)) .attach(Grid::row(1))
.attach(Grid::column(0)) .attach(Grid::column(1))
.attach(Grid::column_span(3)) .margin((0., 4., 0., 0.))
.margin((0., 0., 0., 16.))
.h_align("end") .h_align("end")
.v_align("end") .v_align("end")
.enabled(true) .enabled(true)
.min_width(250.0)
.min_height(45.0)
.text("Anzahl Prüfsätze:")
.build(ctx); .build(ctx);
// let policy_check_menu_container = Container::new() // let policy_check_menu_container = Container::new()
@@ -108,7 +111,7 @@ impl Template for PolicyCheckView {
.child( .child(
Grid::new() Grid::new()
.id(ID_POLICY_CHECK_WIDGET) .id(ID_POLICY_CHECK_WIDGET)
.background("#fafafa") //.background("#fafafa")
.columns( .columns(
Columns::new() Columns::new()
.add(84.0) .add(84.0)
@@ -118,17 +121,14 @@ impl Template for PolicyCheckView {
) )
.rows( .rows(
Rows::new() Rows::new()
// Top Bar
.add("auto") .add("auto")
.add(1.0) .add("5.")
// Content
.add("*") .add("*")
.add(1.0) .add("18.")
// Bottom Bar .add("auto")
.add(52.0)
/* .add("auto") */
.build(), .build(),
) )
// Header Bar // Header Bar
.child( .child(
//.border_color("transparent") //.border_color("transparent")
@@ -165,6 +165,7 @@ impl Template for PolicyCheckView {
.attach(Grid::column_span(3)) .attach(Grid::column_span(3))
.build(ctx), .build(ctx),
) )
// Policy Check Form // Policy Check Form
.child( .child(
Container::new() Container::new()
@@ -321,6 +322,7 @@ impl Template for PolicyCheckView {
.build(ctx), .build(ctx),
) )
.child(policy_data_count_block) .child(policy_data_count_block)
// Bottom bar // Bottom bar
.child( .child(
Container::new() Container::new()