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,
|
||||
};
|
||||
|
||||
/// Valid `actions` that are handled as state changes in the `Policycheck` widget.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
/// Enumeration of valid `action variants` that need to be handled as
|
||||
/// state changes for the `PolicycheckView` widget.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PolicycheckAction {
|
||||
ClearEntry(Entity),
|
||||
ChangeTheme(),
|
||||
SendPolicynumber(),
|
||||
InputTextChanged(Entity),
|
||||
ImportData,
|
||||
ParseEntry(Entity),
|
||||
NewTicket,
|
||||
ParsePolicyNumber(Entity),
|
||||
RemoveFocus(Entity),
|
||||
RemovePopup(Entity),
|
||||
ResetProgress,
|
||||
@@ -43,6 +46,7 @@ pub enum PolicycheckAction {
|
||||
SetEntry(Entity),
|
||||
SetVisibility(Entity),
|
||||
TextChanged(Entity, usize),
|
||||
UpdatePolicyNumber(String),
|
||||
UpdateProgress(f64)
|
||||
}
|
||||
|
||||
@@ -58,16 +62,20 @@ struct Environment {
|
||||
/// Valid `structures` that are handled inside the state of the `Policycheck` widget.
|
||||
#[derive(AsAny, Default)]
|
||||
pub struct PolicycheckState {
|
||||
action: Option<PolicycheckAction>,
|
||||
actions: Vec<PolicycheckAction>,
|
||||
button_menu: Entity,
|
||||
duration: Duration,
|
||||
label_result: Entity,
|
||||
lang: String,
|
||||
button_menu: Entity,
|
||||
policy_data_count: u64,
|
||||
policy_number: Entity,
|
||||
policy_numbers: HashMap<u64, PolicyCode>,
|
||||
progress_bar: Entity,
|
||||
progress_count: f64,
|
||||
progress_popup: Entity
|
||||
progress_popup: Entity,
|
||||
// target that recieves messages
|
||||
target: Entity,
|
||||
ticketdata: Entity
|
||||
}
|
||||
|
||||
impl GlobalState for PolicycheckState {}
|
||||
@@ -168,8 +176,16 @@ impl PolicycheckState {
|
||||
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.
|
||||
fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
||||
pub fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
||||
ctx: &mut Context<'_>) {
|
||||
trace!(target: "advotracker", parse_entry = "started");
|
||||
|
||||
@@ -308,6 +324,11 @@ impl PolicycheckState {
|
||||
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
|
||||
fn remove_popup(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
||||
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);
|
||||
// }
|
||||
|
||||
/// Sets a new action.
|
||||
pub fn set_action(&mut self, action: PolicycheckAction) {
|
||||
self.action = action.into();
|
||||
/// Sending message 'UpdatePolicyNumber'
|
||||
pub fn send_message_update_policynumber(&mut self) {
|
||||
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.
|
||||
@@ -408,17 +430,27 @@ impl State for PolicycheckState {
|
||||
// Initialize required entities
|
||||
self.button_menu = ctx
|
||||
.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
|
||||
.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_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_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.
|
||||
// // The cargo package identifier (default: 'nwx.advotracker') is used as the
|
||||
// // app directory name. The directory location is OS dependant
|
||||
@@ -445,19 +477,24 @@ impl State for PolicycheckState {
|
||||
ctx: &mut Context<'_>,
|
||||
) {
|
||||
for message in messages.read::<PolicycheckAction>() {
|
||||
if let PolicycheckAction::UpdateProgress(increment) = message {
|
||||
println!("Message received");
|
||||
let old_width = ProgressBar::val_clone(&ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
||||
match message {
|
||||
PolicycheckAction::UpdateProgress(increment) => {
|
||||
let old_width = ProgressBar::val_clone(&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.);
|
||||
}
|
||||
}
|
||||
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.);
|
||||
}
|
||||
}
|
||||
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 {
|
||||
PolicycheckAction::ClearEntry(policy_check_policy_number) => {
|
||||
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);
|
||||
}
|
||||
PolicycheckAction::RemoveFocus(policy_check_policy_number) => {
|
||||
@@ -524,11 +567,27 @@ impl State for PolicycheckState {
|
||||
PolicycheckAction::TextChanged(entity, _index) => {
|
||||
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.
|
||||
@@ -546,10 +605,10 @@ fn create_popup_progress(id: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
.width(280)
|
||||
.height(100)
|
||||
.visibility(Visibility::Visible)
|
||||
.on_click(move |ctx, _| {
|
||||
.on_click(move |_ctx, _| {
|
||||
println!("create_popup_progress: on_click -> remove_popup(popup_progress)");
|
||||
ctx.get_mut::<PolicycheckState>(id)
|
||||
.set_action(PolicycheckAction::RemovePopup(id));
|
||||
//ctx.get_mut::<PolicycheckState>(id)
|
||||
// .set_action(PolicycheckAction::RemovePopup(id));
|
||||
true
|
||||
})
|
||||
.child(
|
||||
|
||||
@@ -23,10 +23,16 @@ widget!(
|
||||
/// This identifier is checked agains a map of valid policy codes.
|
||||
// PolicycheckView<PolicycheckState>: KeyDownHandler {
|
||||
PolicycheckView<PolicycheckState> {
|
||||
// holds the language code
|
||||
lang: String,
|
||||
// provides a struct with `PolicyCheck` members
|
||||
policy_check: PolicyCheck,
|
||||
// holds number of imported data
|
||||
policy_data_count: u32,
|
||||
// holds the 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)
|
||||
.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()
|
||||
.id(ID_POLICY_CHECK_FORM)
|
||||
.name(ID_POLICY_CHECK_FORM)
|
||||
@@ -161,11 +195,9 @@ impl Template for PolicycheckView {
|
||||
//.lose_focus_on_activation(false)
|
||||
//WIP: localization for water_mark
|
||||
.water_mark("10-stellig")
|
||||
.on_activate(move |ctx, entity| {
|
||||
.on_activate(move |states, entity| {
|
||||
// Entity is entered/activated via Mouse/Keyboard
|
||||
//ctx.get_mut::<PolicycheckState>(policy_check_view)
|
||||
ctx.get_mut::<PolicycheckState>(id)
|
||||
.set_action(PolicycheckAction::ParseEntry(entity));
|
||||
states.get_mut::<PolicycheckState>(id).parse_policy_number(entity);
|
||||
})
|
||||
.on_key_down(move |_, key_event| {
|
||||
if key_event.key == Key::A(true) {
|
||||
@@ -276,10 +308,11 @@ impl Template for PolicycheckView {
|
||||
.push("auto") // Bottom_Bar
|
||||
)
|
||||
|
||||
.child(policy_check_header_bar) // row 0
|
||||
.child(policy_check_form) // row 2
|
||||
.child(policy_data_stack) // row 3
|
||||
.child(policy_check_bottom_bar) // row 4
|
||||
.child(policy_check_header_bar) // row 0
|
||||
.child(policy_check_form) // row 2
|
||||
.child(policy_data_stack) // row 3
|
||||
.child(policy_check_form_action) // row 4
|
||||
.child(policy_check_bottom_bar) // row 5
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user