widget:policycheck: introduce message passing
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -25,14 +25,17 @@ use crate::{
|
|||||||
services::imports::allianzdirectcall,
|
services::imports::allianzdirectcall,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Valid `actions` that are handled as state changes in the `Policycheck` widget.
|
/// Enumeration of valid `action variants` that need to be handled as
|
||||||
#[derive(Debug, Clone, Copy)]
|
/// state changes for the `PolicycheckView` widget.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub enum PolicycheckAction {
|
pub enum PolicycheckAction {
|
||||||
ClearEntry(Entity),
|
ClearEntry(Entity),
|
||||||
ChangeTheme(),
|
ChangeTheme(),
|
||||||
|
SendPolicynumber(),
|
||||||
InputTextChanged(Entity),
|
InputTextChanged(Entity),
|
||||||
ImportData,
|
ImportData,
|
||||||
ParseEntry(Entity),
|
NewTicket,
|
||||||
|
ParsePolicyNumber(Entity),
|
||||||
RemoveFocus(Entity),
|
RemoveFocus(Entity),
|
||||||
RemovePopup(Entity),
|
RemovePopup(Entity),
|
||||||
ResetProgress,
|
ResetProgress,
|
||||||
@@ -43,6 +46,7 @@ pub enum PolicycheckAction {
|
|||||||
SetEntry(Entity),
|
SetEntry(Entity),
|
||||||
SetVisibility(Entity),
|
SetVisibility(Entity),
|
||||||
TextChanged(Entity, usize),
|
TextChanged(Entity, usize),
|
||||||
|
UpdatePolicyNumber(String),
|
||||||
UpdateProgress(f64)
|
UpdateProgress(f64)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,16 +62,20 @@ struct Environment {
|
|||||||
/// Valid `structures` that are handled inside the state of the `Policycheck` widget.
|
/// 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>,
|
actions: Vec<PolicycheckAction>,
|
||||||
|
button_menu: Entity,
|
||||||
duration: Duration,
|
duration: Duration,
|
||||||
label_result: Entity,
|
label_result: Entity,
|
||||||
lang: String,
|
lang: String,
|
||||||
button_menu: Entity,
|
|
||||||
policy_data_count: u64,
|
policy_data_count: u64,
|
||||||
|
policy_number: Entity,
|
||||||
policy_numbers: HashMap<u64, PolicyCode>,
|
policy_numbers: HashMap<u64, PolicyCode>,
|
||||||
progress_bar: Entity,
|
progress_bar: Entity,
|
||||||
progress_count: f64,
|
progress_count: f64,
|
||||||
progress_popup: Entity
|
progress_popup: Entity,
|
||||||
|
// target that recieves messages
|
||||||
|
target: Entity,
|
||||||
|
ticketdata: Entity
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlobalState for PolicycheckState {}
|
impl GlobalState for PolicycheckState {}
|
||||||
@@ -168,8 +176,16 @@ impl PolicycheckState {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create new ticket
|
||||||
|
pub fn new_ticket(&mut self, ctx: &mut Context<'_>) {
|
||||||
|
println!("WIP: new ticket.");
|
||||||
|
self.navigate(self.ticketdata, ctx);
|
||||||
|
//ctx.widget().get_mut::<TicketdataView>(0).
|
||||||
|
//ctx.get_widget(self.ticketdata_view);
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse validity of the given policy number.
|
/// Parse validity of the given policy number.
|
||||||
fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
pub fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
||||||
ctx: &mut Context<'_>) {
|
ctx: &mut Context<'_>) {
|
||||||
trace!(target: "advotracker", parse_entry = "started");
|
trace!(target: "advotracker", parse_entry = "started");
|
||||||
|
|
||||||
@@ -308,6 +324,11 @@ impl PolicycheckState {
|
|||||||
trace!(target: "advotracker", parse_entry = "finished");
|
trace!(target: "advotracker", parse_entry = "finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// parse message 'ParseEntry'
|
||||||
|
pub fn parse_policy_number(&mut self, entity: Entity) {
|
||||||
|
self.actions.push(PolicycheckAction::ParsePolicyNumber(entity));
|
||||||
|
}
|
||||||
|
|
||||||
/// Remove the popup box
|
/// Remove the popup box
|
||||||
fn remove_popup(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
fn remove_popup(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
||||||
ctx.remove_child(self.progress_popup);
|
ctx.remove_child(self.progress_popup);
|
||||||
@@ -327,9 +348,10 @@ 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.
|
/// Sending message 'UpdatePolicyNumber'
|
||||||
pub fn set_action(&mut self, action: PolicycheckAction) {
|
pub fn send_message_update_policynumber(&mut self) {
|
||||||
self.action = action.into();
|
self.actions.push(PolicycheckAction::UpdatePolicyNumber("4711".to_string()));
|
||||||
|
//self.actions.push(PolicycheckAction::UpdatePolicyNumber(self.policy_number));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change status of given text box to edit mode.
|
/// Change status of given text box to edit mode.
|
||||||
@@ -408,17 +430,27 @@ impl State for PolicycheckState {
|
|||||||
// Initialize required entities
|
// Initialize required entities
|
||||||
self.button_menu = ctx
|
self.button_menu = ctx
|
||||||
.entity_of_child(ID_POLICY_CHECK_BUTTON_MENU)
|
.entity_of_child(ID_POLICY_CHECK_BUTTON_MENU)
|
||||||
.expect("PolicycheckState.init: Can't find resource entity 'ID_POLICY_CHECK_BUTTON_MENU'.");
|
.expect("PolicycheckState::init: Can't find resource entity 'ID_POLICY_CHECK_BUTTON_MENU'.");
|
||||||
|
|
||||||
self.label_result = ctx
|
self.label_result = ctx
|
||||||
.entity_of_child(ID_POLICY_CHECK_LABEL_RESULT)
|
.entity_of_child(ID_POLICY_CHECK_LABEL_RESULT)
|
||||||
.expect("PolicycheckState.init: Can't find resource entity 'ID_POLICY_CHECK_LABEL_RESULT'.");
|
.expect("PolicycheckState::init: Can't find resource entity 'ID_POLICY_CHECK_LABEL_RESULT'.");
|
||||||
|
|
||||||
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
||||||
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), Visibility::Collapsed);
|
||||||
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Collapsed);
|
||||||
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Collapsed);
|
||||||
|
|
||||||
|
//self.policy_number = Entity::from(ctx.widget().try_clone::<u32>(ID_POLICY_CHECK_POLICY_NUMBER)
|
||||||
|
// .expect("PolicycheckState::init(): Can't find resource entity 'ID_POLICY_CHECK_POLICY_NUMBER'."));
|
||||||
|
|
||||||
|
self.target = Entity::from(ctx.widget().try_clone::<u32>("target")
|
||||||
|
.expect("PolicycheckState::init(): Can't find resource entity 'target'."));
|
||||||
|
|
||||||
|
//self.ticketdata_view = (*ctx.widget().get::<u32>("ticketdata_view")).into();
|
||||||
|
//self.ticketdata = Entity::from(ctx.widget().try_clone::<u32>(ID_TICKET_DATA_VIEW)
|
||||||
|
// .expect("PolicycheckState::init(): Can't find resource entity 'ticketdata'."));
|
||||||
|
|
||||||
// // Load the saved data from a file in 'ron' format into our data structure.
|
// // Load the saved data from a file in 'ron' format into our data structure.
|
||||||
// // The cargo package identifier (default: 'nwx.advotracker') is used as the
|
// // The cargo package identifier (default: 'nwx.advotracker') is used as the
|
||||||
// // app directory name. The directory location is OS dependant
|
// // app directory name. The directory location is OS dependant
|
||||||
@@ -445,8 +477,8 @@ impl State for PolicycheckState {
|
|||||||
ctx: &mut Context<'_>,
|
ctx: &mut Context<'_>,
|
||||||
) {
|
) {
|
||||||
for message in messages.read::<PolicycheckAction>() {
|
for message in messages.read::<PolicycheckAction>() {
|
||||||
if let PolicycheckAction::UpdateProgress(increment) = message {
|
match message {
|
||||||
println!("Message received");
|
PolicycheckAction::UpdateProgress(increment) => {
|
||||||
let old_width = ProgressBar::val_clone(&ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
let old_width = ProgressBar::val_clone(&ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
||||||
|
|
||||||
let new_width = old_width + increment;
|
let new_width = old_width + increment;
|
||||||
@@ -458,6 +490,11 @@ impl State for PolicycheckState {
|
|||||||
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 1.);
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 1.);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
PolicycheckAction::NewTicket => {
|
||||||
|
self.new_ticket(ctx);
|
||||||
|
}
|
||||||
|
_ => { println!("TicketdataAction: action not implemented!"); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,7 +510,10 @@ impl State for PolicycheckState {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if let Some(action) = self.action {
|
// Create `actions`, a drained iterator (".." => full range that clears the vector)
|
||||||
|
let actions: Vec<PolicycheckAction> = self.actions.drain(..).collect();
|
||||||
|
|
||||||
|
for action in actions {
|
||||||
match action {
|
match action {
|
||||||
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);
|
||||||
@@ -492,7 +532,10 @@ impl State for PolicycheckState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PolicycheckAction::ParseEntry(text_box) => {
|
PolicycheckAction::NewTicket => {
|
||||||
|
self.new_ticket(ctx);
|
||||||
|
}
|
||||||
|
PolicycheckAction::ParsePolicyNumber(text_box) => {
|
||||||
self.parse_entry(text_box, ctx);
|
self.parse_entry(text_box, ctx);
|
||||||
}
|
}
|
||||||
PolicycheckAction::RemoveFocus(policy_check_policy_number) => {
|
PolicycheckAction::RemoveFocus(policy_check_policy_number) => {
|
||||||
@@ -524,11 +567,27 @@ impl State for PolicycheckState {
|
|||||||
PolicycheckAction::TextChanged(entity, _index) => {
|
PolicycheckAction::TextChanged(entity, _index) => {
|
||||||
self.set_entry(entity, ctx);
|
self.set_entry(entity, ctx);
|
||||||
}
|
}
|
||||||
|
PolicycheckAction::UpdatePolicyNumber(policy_number) => {
|
||||||
|
info!("Message send: 'PolicycheckAction::UpdatePolicyNumber({:?}) -> {:?}'", policy_number, self.target);
|
||||||
|
println!("WIP: send policy_number");
|
||||||
|
ctx.send_message(PolicycheckAction::UpdatePolicyNumber(policy_number), self.target);
|
||||||
|
|
||||||
|
//let mut widget_container : WidgetContainer = ctx.widget();
|
||||||
|
//widget_container.get::<String16>("text");
|
||||||
|
//let polnum: TextBox = TextBox::get(ctx.child(ID_POLICY_CHECK_POLICY_NUMBER));
|
||||||
|
//println!("Policy number: {:?}", polnum);
|
||||||
|
|
||||||
|
//let policy_number = ctx.get_widget(self.policy_check_policy_number);
|
||||||
|
//let policy_number2 = TextBox::text_clone(&ctx.get_widget(ID_POLICY_CHECK_POLICY_NUMBER));
|
||||||
|
|
||||||
|
//let policy_number_string = ctx.get_widget(entity).get::<String16>("text").is_empty();
|
||||||
|
//let policy_number = TextBox::text_clone(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER));
|
||||||
|
//ctx.send_message(PolicycheckAction::UpdatePolicyNumber(policy_check_policy_number), self.target);
|
||||||
|
//info!("Message send: 'PolicycheckAction::UpdatePolicyNumber({:?}) -> {:?}'", policy_check_policy_number, self.target);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Reset action
|
|
||||||
self.action = None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Update the view after the layout is rendered.
|
// /// Update the view after the layout is rendered.
|
||||||
@@ -546,10 +605,10 @@ fn create_popup_progress(id: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
|||||||
.width(280)
|
.width(280)
|
||||||
.height(100)
|
.height(100)
|
||||||
.visibility(Visibility::Visible)
|
.visibility(Visibility::Visible)
|
||||||
.on_click(move |ctx, _| {
|
.on_click(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>(id)
|
//ctx.get_mut::<PolicycheckState>(id)
|
||||||
.set_action(PolicycheckAction::RemovePopup(id));
|
// .set_action(PolicycheckAction::RemovePopup(id));
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
|
|||||||
@@ -23,10 +23,16 @@ widget!(
|
|||||||
/// 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>: KeyDownHandler {
|
||||||
PolicycheckView<PolicycheckState> {
|
PolicycheckView<PolicycheckState> {
|
||||||
|
// holds the language code
|
||||||
lang: String,
|
lang: String,
|
||||||
|
// provides a struct with `PolicyCheck` members
|
||||||
policy_check: PolicyCheck,
|
policy_check: PolicyCheck,
|
||||||
|
// holds number of imported data
|
||||||
|
policy_data_count: u32,
|
||||||
|
// holds the title string
|
||||||
policy_check_title: String,
|
policy_check_title: String,
|
||||||
policy_data_count: u32
|
// widget entity that will receive the message
|
||||||
|
target: u32
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -113,6 +119,34 @@ impl Template for PolicycheckView {
|
|||||||
.child(policy_check_button_menu)
|
.child(policy_check_button_menu)
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
|
|
||||||
|
let policy_check_form_action = Container::new()
|
||||||
|
.id(ID_POLICY_CHECK_ACTION_GRID)
|
||||||
|
.attach(Grid::row(3))
|
||||||
|
.attach(Grid::column(1))
|
||||||
|
//.style(STYLE_CONTAINER_ACTION)
|
||||||
|
.padding(14)
|
||||||
|
.h_align("center")
|
||||||
|
.child(
|
||||||
|
Stack::new()
|
||||||
|
//.style(STYLE_STACK_ACTION)
|
||||||
|
.orientation("horizontal")
|
||||||
|
.spacing(50)
|
||||||
|
.child(
|
||||||
|
Button::new()
|
||||||
|
.id(ID_POLICY_CHECK_ACTION_BUTTON_CREATE)
|
||||||
|
.style(STYLE_BUTTON_ACTION)
|
||||||
|
.text("Create ticket")
|
||||||
|
.on_click(move |states, _entity| {
|
||||||
|
states.get_mut::<PolicycheckState>(id).send_message_update_policynumber();
|
||||||
|
states.send_message(PolicycheckAction::NewTicket, id);
|
||||||
|
false
|
||||||
|
})
|
||||||
|
.build(ctx),
|
||||||
|
)
|
||||||
|
.build(ctx),
|
||||||
|
)
|
||||||
|
.build(ctx);
|
||||||
|
|
||||||
let policy_check_form = Container::new()
|
let policy_check_form = Container::new()
|
||||||
.id(ID_POLICY_CHECK_FORM)
|
.id(ID_POLICY_CHECK_FORM)
|
||||||
.name(ID_POLICY_CHECK_FORM)
|
.name(ID_POLICY_CHECK_FORM)
|
||||||
@@ -161,11 +195,9 @@ impl Template for PolicycheckView {
|
|||||||
//.lose_focus_on_activation(false)
|
//.lose_focus_on_activation(false)
|
||||||
//WIP: localization for water_mark
|
//WIP: localization for water_mark
|
||||||
.water_mark("10-stellig")
|
.water_mark("10-stellig")
|
||||||
.on_activate(move |ctx, entity| {
|
.on_activate(move |states, entity| {
|
||||||
// Entity is entered/activated via Mouse/Keyboard
|
// Entity is entered/activated via Mouse/Keyboard
|
||||||
//ctx.get_mut::<PolicycheckState>(policy_check_view)
|
states.get_mut::<PolicycheckState>(id).parse_policy_number(entity);
|
||||||
ctx.get_mut::<PolicycheckState>(id)
|
|
||||||
.set_action(PolicycheckAction::ParseEntry(entity));
|
|
||||||
})
|
})
|
||||||
.on_key_down(move |_, key_event| {
|
.on_key_down(move |_, key_event| {
|
||||||
if key_event.key == Key::A(true) {
|
if key_event.key == Key::A(true) {
|
||||||
@@ -279,7 +311,8 @@ impl Template for PolicycheckView {
|
|||||||
.child(policy_check_header_bar) // row 0
|
.child(policy_check_header_bar) // row 0
|
||||||
.child(policy_check_form) // row 2
|
.child(policy_check_form) // row 2
|
||||||
.child(policy_data_stack) // row 3
|
.child(policy_data_stack) // row 3
|
||||||
.child(policy_check_bottom_bar) // row 4
|
.child(policy_check_form_action) // row 4
|
||||||
|
.child(policy_check_bottom_bar) // row 5
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user