From d6b55521223affb1f0ec6ad1c43a703075239b0e Mon Sep 17 00:00:00 2001 From: Ralf Zerres Date: Mon, 22 Jun 2020 14:27:30 +0200 Subject: [PATCH] policycheck: wip: view and state handling updates Signed-off-by: Ralf Zerres --- frontend/src/policycheck_state.rs | 84 ++++-- frontend/src/policycheck_view.rs | 429 ++++++++++++++++++++---------- 2 files changed, 346 insertions(+), 167 deletions(-) diff --git a/frontend/src/policycheck_state.rs b/frontend/src/policycheck_state.rs index bec966f..e93e1c9 100644 --- a/frontend/src/policycheck_state.rs +++ b/frontend/src/policycheck_state.rs @@ -9,6 +9,7 @@ use crate::{ /// Actions that can execute on the task view. #[derive(Debug, Clone, Copy)] pub enum Action { + ClearEntry(Entity), InputTextChanged(Entity), ParseEntry(Entity), RemoveFocus(Entity), @@ -23,7 +24,7 @@ pub struct PolicyCheckState { last_focused: Option, pub text_box: Entity, menu_button: Entity, - policy_code_valid: bool, + policy_number_valid: bool, } impl BaseState for PolicyCheckState {} @@ -34,29 +35,59 @@ impl PolicyCheckState { self.action = action.into(); } - - /// Parse and verify given policy code to match a valid policy data element. - fn parse_entry(&self, text_box: Entity, ctx: &mut Context) { - // Old style - //let length = ctx.get_widget(text_box).get::("policy_code").len(); - // 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); - } - } - } + /// Clear text in text box. + pub fn clear_entry(&mut self, text_box: Entity, ctx: &mut Context) { + let mut text_box = TextBox::get(ctx.get_widget(text_box)); + let text = text_box.text_mut(); + println!("reset {}", text); } - /// 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> { + fn parse_entry(&self, text_box: Entity, ctx: &mut Context) { + // Old style + //let length = ctx.get_widget(text_box).get::("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. fn set_check_button(&self, text_box: Entity, ctx: &mut Context) { - if ctx.get_widget(text_box).get::("policy_code_check").is_empty() { + if ctx.get_widget(text_box).get::("policy_number_check").is_empty() { ctx.get_widget(self.text_box).set("enabled", false); } else { ctx.get_widget(self.text_box).set("enabled", true); @@ -85,7 +116,7 @@ impl PolicyCheckState { .start_index = 0; ctx.get_widget(text_box) .get_mut::("text_selection") - .length = ctx.get_widget(text_box).get::("policy_code").len(); + .length = ctx.get_widget(text_box).get::("policy_number").len(); 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) .expect("PolicyState.init: Can't find child 'Menu button'."); self.text_box = ctx - .entity_of_child(ID_POLICY_CHECK_TEXT_BOX) - .expect("PolicyState.init: Can't find child 'Text Box'."); + .entity_of_child(ID_POLICY_CHECK_POLICY_NUMBER) + .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 if self.last_focused != ctx.window().get::("global").focused_widget { if let Some(last_focused) = self.last_focused { @@ -112,6 +143,9 @@ impl State for PolicyCheckState { if let Some(action) = self.action { match action { + Action::ClearEntry(text_box) => { + self.clear_entry(text_box, ctx); + } Action::InputTextChanged(text_box) => { self.set_check_button(text_box, ctx); } @@ -126,7 +160,7 @@ impl State for PolicyCheckState { self.last_focused = Some(text_box); self.set_entry(text_box, ctx); } - Action::TextChanged(entity, index) => { + Action::TextChanged(entity, _index) => { self.set_entry(entity, ctx); } } diff --git a/frontend/src/policycheck_view.rs b/frontend/src/policycheck_view.rs index bb97c56..8f95338 100644 --- a/frontend/src/policycheck_view.rs +++ b/frontend/src/policycheck_view.rs @@ -1,159 +1,304 @@ use orbtk::prelude::*; +use orbtk::theme::vector_graphics::material_icons_font; use crate::{ //data::PolicyList, keys::*, - policycheck_state::{Action, PolicyCheckState}, + //policycheck_state::{Action, PolicyCheckState}, }; -type ListIndex = Option; +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 { +// //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 { - //is_valid: bool, - title: String, - policy_check_text_box: String - } -); impl Template for PolicyCheckView { - fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { - let policy_code_text_box = TextBox::new() - .id(ID_POLICY_CHECK_TEXT_BOX) - .attach(Grid::row(4)) + fn template(self, id: Entity, ctx: &mut BuildContext)-> Self { + // let policy_check_text_box = TextBox::new() + // .id(ID_POLICY_CHECK_TEXT_BOX) + // .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::(id) + // // .action(Action::ParseEntry(entity)); + // // }) + // // .on_changed(move |ctx, entity| { + // // ctx.get_mut::(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::(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") - .margin((4.0, 0.0, 0.0, 0.0)) - .lost_focus_on_activation(false) - .on_activate(move |ctx, entity| { - ctx.get_mut::(id) - .action(Action::ParseEntry(entity)); - }) - .on_changed(move |ctx, entity| { - ctx.get_mut::(id) - .action(Action::InputTextChanged(entity)); - }) + .enabled(true) + //.icon(material_icons_font::MENU_FONT_ICON) + //.icon(material_icons_font_ttf::EDIT_FONT_ICON) + //.icon("") + //.icon("") + .on_mouse_down(|_, _| true) + //.child(policycheck_menu) + // .on_click(move |ctx, _| { + // //ctx.get_mut::(id) + // // .action(Action::NewEntry(policy_check_menu_container)); + // true + //}) .build(ctx); + // The menu implemented as an overlay + //ctx.append_child_to_overlay(policy_check_menu_button).unwrap(); + // Check policy identifier page - self.name("Policy check") - .child( - Grid::new() - .id(ID_POLICY_CHECK_WIDGET) - .v_align("start") - .background("#fafafa") - .columns( - Columns::new() - .add(150.0) - .add("*") - .add(150.0) - .build(), - ) - .rows( - Rows::new() - .add(52.0) - .add(1.0) - .add("*") - .add(1.0) - .add("*") - .build(), - ) - // Top Bar - .child( - Container::new() - .class(CLASS_TOP_BAR) - .attach(Grid::row(0)) - .attach(Grid::column(0)) - .attach(Grid::column_span(3)) - .child( - Grid::new() - .margin((4.0, 24.0, 24.0, 4.0)) - .child( - TextBlock::new() - .class(CLASS_HEADER) - .v_align("center") - .h_align("center") - //.text("Validation number policyholder")) - .text("Validierung Versicherungsnummer") - .build(ctx), - ) - .build(ctx), - ) - .build(ctx), - ) - .child( - Container::new() - .class("separator") - .attach(Grid::row(1)) - .attach(Grid::column_span(3)) - .build(ctx), - ) - .child( - Stack::new() - .spacing(8.0) - .orientation("vertical") - .h_align("center") - .child(policy_code_text_box) - .child( - TextBlock::new() - .class("text_box") - .element("text-block") - .id("result") - .min_width(80.0) - .max_width(180.0) - //.text("Result:") - .text("Ergebnis:") - .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)) - .child( - Grid::new() - .element("logo_customer") - .margin((9.0, 16.0, 16.0, 9.0)) - .attach(Grid::column(0)) - .attach(Grid::row(1)) - .v_align("end") - .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(2)) - .attach(Grid::row(1)) - .v_align("end") - .child( - ImageWidget::new() - .image("../resources/images/networkx_logo.png") - .build(ctx), - ) - .build(ctx), - ) - .build(ctx), - ) - .build(ctx), - ) + self.name("Policy check").child( + Grid::new() + .id(ID_POLICY_CHECK_WIDGET) + //.v_align("start") + //.h_align("center") + .background("#fafafa") + .columns( + Columns::new() + .add(64.0) + .add("*") + .add(50.0) + .build(), + ) + .rows( + Rows::new() + .add("auto") + .add(1.0) + .add("*") + .add(1.0) + .add(52.0) + /* .add("auto") */ + .build(), + ) + // Header Bar + .child( + //.border_color("transparent") + Container::new() + //.class(CLASS_TOP_BAR) + .attach(Grid::row(0)) + .attach(Grid::column(0)) + .attach(Grid::column_span(3)) + .child( + Grid::new() + .child( + TextBlock::new() + //.class(CLASS_HEADER) + .class("h1") + //.class(".myheader") + .id(ID_POLICY_CHECK_HEADER) + //.font_size(24) + //.font("Roboto Medium") + .v_align("center") + .h_align("center") + .margin((32.0, 32.0, 32.0, 32.0)) + .text("Validierung Versicherungsnummer") + .build(ctx), + ) + .build(ctx), + ) + .child(policy_check_menu_button) + .build(ctx), + ) + .child( + Container::new() + .class("separator") + .attach(Grid::row(1)) + .attach(Grid::column_span(3)) + .build(ctx), + ) + // Policy Check Form + .child( + Container::new() + //.class(CLASS_POLICY_CHECK_FORM) + .attach(Grid::row(2)) + .attach(Grid::column(0)) + .attach(Grid::column_span(3)) + .child( + Grid::new() + .id(ID_POLICY_CHECK_FORM) + .columns( + Columns::new() + .add("5.0") + .add("220.0") + .add("5.0") + .add("100.0") + .build(), + ) + .rows( + Rows::new() + .add("45.0") + .add("45.0") + .build(), + ) + .child( + Stack::new() + .attach(Grid::column(1)) + .attach(Grid::row(0)) + .margin((16.0, 16.0, 16.0, 16.0)) + .orientation("vertical") + //.v_align("center") + .child( + TextBlock::new() + .id(ID_POLICY_CHECK_LABEL_POLICY_NUMBER) + //.class(CLASS_TEXT_BLOCK) + .h_align("end") + //.min_width(250.0) + .min_height(45.0) + //.size(250.0, 45.0) + .text("Versicherungsnummer:") + .build(ctx), + ) + .child( + TextBlock::new() + .id(ID_POLICY_CHECK_LABEL_RESULT) + //.class(CLASS_TEXT_BLOCK) + .attach(Grid::column(1)) + .attach(Grid::row(1)) + .h_align("end") + //.min_width(250.0) + //.min_size(120.0, 180.0) + .text("Ergebnis:") + .text("Result:") + .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::(id) + // .action(Action::ParseEntry(entity)); + // }) + // .on_changed(move |ctx, entity| { + // ctx.get_mut::(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::(id) + // .action(Action::ParseEntry(entity)); + // }) + // .on_changed(move |ctx, entity| { + // ctx.get_mut::(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), + ) } }