policycheck: wip: view and state handling updates

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2020-06-22 14:27:30 +02:00
parent 717dc9ba03
commit 62c786b671
2 changed files with 346 additions and 167 deletions

View File

@@ -9,6 +9,7 @@ use crate::{
/// Actions that can execute on the task view. /// Actions that can execute on the task view.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub enum Action { pub enum Action {
ClearEntry(Entity),
InputTextChanged(Entity), InputTextChanged(Entity),
ParseEntry(Entity), ParseEntry(Entity),
RemoveFocus(Entity), RemoveFocus(Entity),
@@ -23,7 +24,7 @@ pub struct PolicyCheckState {
last_focused: Option<Entity>, last_focused: Option<Entity>,
pub text_box: Entity, pub text_box: Entity,
menu_button: Entity, menu_button: Entity,
policy_code_valid: bool, policy_number_valid: bool,
} }
impl BaseState for PolicyCheckState {} impl BaseState for PolicyCheckState {}
@@ -34,29 +35,59 @@ impl PolicyCheckState {
self.action = action.into(); self.action = action.into();
} }
/// Clear text in text box.
/// Parse and verify given policy code to match a valid policy data element. pub fn clear_entry(&mut self, text_box: Entity, ctx: &mut Context) {
fn parse_entry(&self, text_box: Entity, ctx: &mut Context) { let mut text_box = TextBox::get(ctx.get_widget(text_box));
// Old style let text = text_box.text_mut();
//let length = ctx.get_widget(text_box).get::<String>("policy_code").len(); println!("reset {}", text);
// New style
let text_box = TextBox::get(ctx.widget());
println!("parsing policy code: {}", text_box.text());
// Parse policy code: "AS-123456789"
if let policy_code = text_box.text() {
match policy_code {
_ => {
println!("policycode: {} is valid!", policy_code);
}
}
}
} }
/// If TextBox 'policy_code' is empty, disable button "check"
/// Parse and verify given policy code to match a valid policy data element.
//fn parse_entry(&self, text_box: Entity, ctx: &mut Context) -> Result<(), Box<dyn std::error::Error>> {
fn parse_entry(&self, text_box: Entity, ctx: &mut Context) {
// Old style
//let length = ctx.get_widget(text_box).get::<String>("policy_number").len();
// New style
let mut text_box = TextBox::get(ctx.get_widget(text_box));
let policy_number = text_box.text_mut();
println!("parsing policy Number: {}", policy_number);
// Parse policy code: "AS-123456789"
// DION VERS POLLFNR
// 1 AS 1515735810
let policy_number_length = policy_number.len();
if policy_number_length == 10 {
println!("Verify {} ...", policy_number);
// check against hash-table
//ctx.get_widget(text_box).set("policy_number_valid", true);
//TextBox::get(ctx.child("text_box")).set_foreground(colors::LINK_WATER_COLOR);
}
if policy_number_length < 10 {
println!("Policy number is to short!");
//TextBox::get(ctx.child("text_box")).set_foreground("#ffffff");
//TextBox::get(ctx.child("text_box")).set_background("#5b0f22");
}
if policy_number_length > 10 {
println!("Policy number is to big!");
//TextBox::get(ctx.child("text_box")).set_foreground("#ffffff");
//TextBox::get(ctx.child("text_box")).set_background("#5b0f22");
}
// if let policy_number = text_box.text() {
// match policy_number {
// _ => {
// println!("policynumber: {} is valid!", policy_number);
// }
// }
// }
}
/// If TextBox 'policy_number' is empty, disable button "check"
/// otherwise enabled it. /// otherwise enabled it.
fn set_check_button(&self, text_box: Entity, ctx: &mut Context) { fn set_check_button(&self, text_box: Entity, ctx: &mut Context) {
if ctx.get_widget(text_box).get::<String>("policy_code_check").is_empty() { if ctx.get_widget(text_box).get::<String>("policy_number_check").is_empty() {
ctx.get_widget(self.text_box).set("enabled", false); ctx.get_widget(self.text_box).set("enabled", false);
} else { } else {
ctx.get_widget(self.text_box).set("enabled", true); ctx.get_widget(self.text_box).set("enabled", true);
@@ -85,7 +116,7 @@ impl PolicyCheckState {
.start_index = 0; .start_index = 0;
ctx.get_widget(text_box) ctx.get_widget(text_box)
.get_mut::<TextSelection>("text_selection") .get_mut::<TextSelection>("text_selection")
.length = ctx.get_widget(text_box).get::<String>("policy_code").len(); .length = ctx.get_widget(text_box).get::<String>("policy_number").len();
ctx.push_event_by_window(FocusEvent::RequestFocus(text_box)); ctx.push_event_by_window(FocusEvent::RequestFocus(text_box));
} }
} }
@@ -96,11 +127,11 @@ impl State for PolicyCheckState {
.entity_of_child(ID_POLICY_CHECK_MENU_BUTTON) .entity_of_child(ID_POLICY_CHECK_MENU_BUTTON)
.expect("PolicyState.init: Can't find child 'Menu button'."); .expect("PolicyState.init: Can't find child 'Menu button'.");
self.text_box = ctx self.text_box = ctx
.entity_of_child(ID_POLICY_CHECK_TEXT_BOX) .entity_of_child(ID_POLICY_CHECK_POLICY_NUMBER)
.expect("PolicyState.init: Can't find child 'Text Box'."); .expect("PolicyState.init: Can't find child 'Text Box'.");
} }
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 {
if let Some(last_focused) = self.last_focused { if let Some(last_focused) = self.last_focused {
@@ -112,6 +143,9 @@ impl State for PolicyCheckState {
if let Some(action) = self.action { if let Some(action) = self.action {
match action { match action {
Action::ClearEntry(text_box) => {
self.clear_entry(text_box, ctx);
}
Action::InputTextChanged(text_box) => { Action::InputTextChanged(text_box) => {
self.set_check_button(text_box, ctx); self.set_check_button(text_box, ctx);
} }
@@ -126,7 +160,7 @@ impl State for PolicyCheckState {
self.last_focused = Some(text_box); self.last_focused = Some(text_box);
self.set_entry(text_box, ctx); self.set_entry(text_box, ctx);
} }
Action::TextChanged(entity, index) => { Action::TextChanged(entity, _index) => {
self.set_entry(entity, ctx); self.set_entry(entity, ctx);
} }
} }

View File

@@ -1,159 +1,304 @@
use orbtk::prelude::*; use orbtk::prelude::*;
use orbtk::theme::vector_graphics::material_icons_font;
use crate::{ use crate::{
//data::PolicyList, //data::PolicyList,
keys::*, keys::*,
policycheck_state::{Action, PolicyCheckState}, //policycheck_state::{Action, PolicyCheckState},
}; };
type ListIndex = Option<usize>; widget!(PolicyCheckView);
// widget!(
// /// Starter page that offers the dialog to enter an identifier of a policy.
// /// This identifier is checked agains a map of valid policy codes.
// PolicyCheckView<PolicyCheckState> {
// //is_valid: bool,
// title: String,
// policy_check_text_box: String
// }
// );
widget!(
/// Starter page that offers the dialog to enter an identifier of a policy.
/// This identifier is checked agains a map of valid policy codes.
PolicyCheckView<PolicyCheckState> {
//is_valid: bool,
title: String,
policy_check_text_box: String
}
);
impl Template for PolicyCheckView { impl Template for PolicyCheckView {
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { fn template(self, id: Entity, ctx: &mut BuildContext)-> Self {
let policy_code_text_box = TextBox::new() // let policy_check_text_box = TextBox::new()
.id(ID_POLICY_CHECK_TEXT_BOX) // .id(ID_POLICY_CHECK_TEXT_BOX)
.attach(Grid::row(4)) // .attach(Grid::row(4))
// .attach(Grid::row(0))
// .attach(Grid::column(0))
// .v_align("top")
// .margin((4.0, 0.0, 0.0, 0.0))
// .lost_focus_on_activation(false)
// //.text(("policy_number", id))
// // .on_activate(move |ctx, entity| {
// // ctx.get_mut::<PolicyCheckState>(id)
// // .action(Action::ParseEntry(entity));
// // })
// // .on_changed(move |ctx, entity| {
// // ctx.get_mut::<PolicyCheckState>(id)
// // .action(Action::InputTextChanged(entity));
// // })
// .build(ctx);
// let policy_check_menu_container = Container::new()
// .id(ID_POLICY_CHECK_MENU_CONTAINER)
// .class(CLASS_MENU)
// .attach(Grid::row(3))
// .attach(Grid::column(8))
// .margin((0.0, 0.0, 4.0, 0.0))
// .enabled(false)
// .min_size(120.0, 180.0)
// .v_align("center")
// .on_click(move |ctx, _| {
// ctx.get_mut::<PolicyCheckState>(id)
// .action(Action::NewEntry(quit));
// true
// })
// .build(ctx);
let policy_check_menu_button = Button::new()
.id(ID_POLICY_CHECK_MENU_BUTTON)
//.class(CLASS_ICON_ONLY)
//.attach(Grid::row(0))
.attach(Grid::column(2))
//.margin((0.0, 0.0, 12.0, 12.0))
//.min_size(8.0, 8.0)
.min_size(16.0, 16.0)
.h_align("end")
.v_align("center") .v_align("center")
.margin((4.0, 0.0, 0.0, 0.0)) .enabled(true)
.lost_focus_on_activation(false) //.icon(material_icons_font::MENU_FONT_ICON)
.on_activate(move |ctx, entity| { //.icon(material_icons_font_ttf::EDIT_FONT_ICON)
ctx.get_mut::<PolicyCheckState>(id) //.icon("")
.action(Action::ParseEntry(entity)); //.icon("")
}) .on_mouse_down(|_, _| true)
.on_changed(move |ctx, entity| { //.child(policycheck_menu)
ctx.get_mut::<PolicyCheckState>(id) // .on_click(move |ctx, _| {
.action(Action::InputTextChanged(entity)); // //ctx.get_mut::<PolicyCheckState>(id)
}) // // .action(Action::NewEntry(policy_check_menu_container));
// true
//})
.build(ctx); .build(ctx);
// The menu implemented as an overlay
//ctx.append_child_to_overlay(policy_check_menu_button).unwrap();
// Check policy identifier page // Check policy identifier page
self.name("Policy check") self.name("Policy check").child(
.child( Grid::new()
Grid::new() .id(ID_POLICY_CHECK_WIDGET)
.id(ID_POLICY_CHECK_WIDGET) //.v_align("start")
.v_align("start") //.h_align("center")
.background("#fafafa") .background("#fafafa")
.columns( .columns(
Columns::new() Columns::new()
.add(150.0) .add(64.0)
.add("*") .add("*")
.add(150.0) .add(50.0)
.build(), .build(),
) )
.rows( .rows(
Rows::new() Rows::new()
.add(52.0) .add("auto")
.add(1.0) .add(1.0)
.add("*") .add("*")
.add(1.0) .add(1.0)
.add("*") .add(52.0)
.build(), /* .add("auto") */
) .build(),
// Top Bar )
.child( // Header Bar
Container::new() .child(
.class(CLASS_TOP_BAR) //.border_color("transparent")
.attach(Grid::row(0)) Container::new()
.attach(Grid::column(0)) //.class(CLASS_TOP_BAR)
.attach(Grid::column_span(3)) .attach(Grid::row(0))
.child( .attach(Grid::column(0))
Grid::new() .attach(Grid::column_span(3))
.margin((4.0, 24.0, 24.0, 4.0)) .child(
.child( Grid::new()
TextBlock::new() .child(
.class(CLASS_HEADER) TextBlock::new()
.v_align("center") //.class(CLASS_HEADER)
.h_align("center") .class("h1")
//.text("Validation number policyholder")) //.class(".myheader")
.text("Validierung Versicherungsnummer") .id(ID_POLICY_CHECK_HEADER)
.build(ctx), //.font_size(24)
) //.font("Roboto Medium")
.build(ctx), .v_align("center")
) .h_align("center")
.build(ctx), .margin((32.0, 32.0, 32.0, 32.0))
) .text("Validierung Versicherungsnummer")
.child( .build(ctx),
Container::new() )
.class("separator") .build(ctx),
.attach(Grid::row(1)) )
.attach(Grid::column_span(3)) .child(policy_check_menu_button)
.build(ctx), .build(ctx),
) )
.child( .child(
Stack::new() Container::new()
.spacing(8.0) .class("separator")
.orientation("vertical") .attach(Grid::row(1))
.h_align("center") .attach(Grid::column_span(3))
.child(policy_code_text_box) .build(ctx),
.child( )
TextBlock::new() // Policy Check Form
.class("text_box") .child(
.element("text-block") Container::new()
.id("result") //.class(CLASS_POLICY_CHECK_FORM)
.min_width(80.0) .attach(Grid::row(2))
.max_width(180.0) .attach(Grid::column(0))
//.text("Result:") .attach(Grid::column_span(3))
.text("Ergebnis:") .child(
.build(ctx), Grid::new()
) .id(ID_POLICY_CHECK_FORM)
.build(ctx), .columns(
) Columns::new()
.child( .add("5.0")
Container::new() .add("220.0")
.class("separator") .add("5.0")
.attach(Grid::row(3)) .add("100.0")
.attach(Grid::column_span(3)) .build(),
.build(ctx), )
) .rows(
// Bottom bar Rows::new()
.child( .add("45.0")
Container::new() .add("45.0")
.class(CLASS_BOTTOM_BAR) .build(),
.attach(Grid::row(4)) )
.attach(Grid::column(0)) .child(
.attach(Grid::column_span(3)) Stack::new()
.child( .attach(Grid::column(1))
Grid::new() .attach(Grid::row(0))
.element("logo_customer") .margin((16.0, 16.0, 16.0, 16.0))
.margin((9.0, 16.0, 16.0, 9.0)) .orientation("vertical")
.attach(Grid::column(0)) //.v_align("center")
.attach(Grid::row(1)) .child(
.v_align("end") TextBlock::new()
.child( .id(ID_POLICY_CHECK_LABEL_POLICY_NUMBER)
ImageWidget::new() //.class(CLASS_TEXT_BLOCK)
.image("../resources/images/hiedemann_logo.png") .h_align("end")
.build(ctx), //.min_width(250.0)
) .min_height(45.0)
.build(ctx), //.size(250.0, 45.0)
) .text("Versicherungsnummer:")
.child( .build(ctx),
Grid::new() )
.element("logo_vendor") .child(
.margin((9.0, 16.0, 16.0, 9.0)) TextBlock::new()
.attach(Grid::column(2)) .id(ID_POLICY_CHECK_LABEL_RESULT)
.attach(Grid::row(1)) //.class(CLASS_TEXT_BLOCK)
.v_align("end") .attach(Grid::column(1))
.child( .attach(Grid::row(1))
ImageWidget::new() .h_align("end")
.image("../resources/images/networkx_logo.png") //.min_width(250.0)
.build(ctx), //.min_size(120.0, 180.0)
) .text("Ergebnis:")
.build(ctx), .text("Result:")
) .build(ctx),
.build(ctx), )
) .build(ctx)
.build(ctx), )
) .child(
Stack::new()
.attach(Grid::column(2))
.attach(Grid::row(0))
//.attach(Grid::column_span(3))
.orientation("vertical")
.margin((16.0, 16.0, 16.0, 16.0))
//.child(policy_check_text_box)
.child(
TextBox::new()
.id(ID_POLICY_CHECK_POLICY_NUMBER)
.h_align("start")
.margin((4.0, 0.0, 0.0, 0.0))
.lost_focus_on_activation(false)
.water_mark("10-stellige Nummer (ohne 'AS')")
.text("")
// .on_activate(move |ctx, entity| {
// ctx.get_mut::<PolicyCheckState>(id)
// .action(Action::ParseEntry(entity));
// })
// .on_changed(move |ctx, entity| {
// ctx.get_mut::<PolicyCheckState>(id)
// .action(Action::InputTextChanged(entity));
// })
.build(ctx),
)
.child(
TextBlock::new()
.id(ID_POLICY_CHECK_RESULT)
.h_align("start")
.attach(Grid::column(3))
.attach(Grid::row(1))
//.margin((4.0, 0.0, 0.0, 0.0))
//.lost_focus_on_activation(false)
// .on_activate(move |ctx, entity| {
// ctx.get_mut::<PolicyCheckState>(id)
// .action(Action::ParseEntry(entity));
// })
// .on_changed(move |ctx, entity| {
// ctx.get_mut::<PolicyCheckState>(id)
// .action(Action::InputTextChanged(entity));
// })
.build(ctx),
)
.build(ctx)
)
.build(ctx)
)
.build(ctx)
)
.child(
Container::new()
.class("separator")
.attach(Grid::row(3))
.attach(Grid::column_span(3))
.build(ctx),
)
// Bottom bar
.child(
Container::new()
.class(CLASS_BOTTOM_BAR)
.attach(Grid::row(4))
.attach(Grid::column(0))
.attach(Grid::column_span(3))
.v_align("end")
.child(
Grid::new()
.element("logo_customer")
.margin((9.0, 16.0, 16.0, 9.0))
.attach(Grid::column(0))
.attach(Grid::row(1))
.h_align("start")
.v_align("center")
.child(
ImageWidget::new()
.image("resources/images/hiedemann_logo.png")
.build(ctx),
)
.build(ctx),
)
.child(
Grid::new()
.element("logo_vendor")
.margin((9.0, 16.0, 16.0, 9.0))
.attach(Grid::column(0))
.attach(Grid::row(4))
.h_align("end")
.v_align("center")
.child(
ImageWidget::new()
.image("resources/images/networkx_logo.png")
.build(ctx),
)
.build(ctx),
)
.build(ctx),
)
.build(ctx),
)
} }
} }