widget:ticketdata: introduce message passing
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -12,17 +12,17 @@ use serde::Deserialize;
|
|||||||
//use std::process;
|
//use std::process;
|
||||||
//use std::collections::HashMap;
|
//use std::collections::HashMap;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
//use tracing::{error, info, trace};
|
use tracing::{info, trace};
|
||||||
use tracing::trace;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
data::constants::*,
|
data::constants::*,
|
||||||
widgets::global_state::GlobalState,
|
widgets::global_state::GlobalState,
|
||||||
//services::exports::sendticketdata,
|
//services::exports::sendticketdata,
|
||||||
|
widgets::policycheck::policycheck_state::{PolicycheckAction, PolicycheckState},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Valid `actions` that are handled as state changes in the `Ticketdata` widget.
|
/// Valid `actions` that are handled as state changes in the `Ticketdata` widget.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum TicketdataAction {
|
pub enum TicketdataAction {
|
||||||
ClearEntry(Entity),
|
ClearEntry(Entity),
|
||||||
/// Clear text in the form
|
/// Clear text in the form
|
||||||
@@ -35,7 +35,18 @@ pub enum TicketdataAction {
|
|||||||
SetEntry(Entity),
|
SetEntry(Entity),
|
||||||
SendForm(),
|
SendForm(),
|
||||||
SetVisibility(Entity),
|
SetVisibility(Entity),
|
||||||
TextChanged(Entity, usize)
|
TextChanged(Entity, usize),
|
||||||
|
UpdatePolicyNumber(String)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handel fields of an Email (header, body)
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub struct Email {
|
||||||
|
recipient_to: String,
|
||||||
|
recipient_cc: String,
|
||||||
|
sender: String,
|
||||||
|
subject: String,
|
||||||
|
body: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Define valid environment variables provided via .env files
|
/// Define valid environment variables provided via .env files
|
||||||
@@ -50,10 +61,11 @@ struct Environment {
|
|||||||
/// Valid `structures` that are handled inside the state of the `Ticket` widget.
|
/// Valid `structures` that are handled inside the state of the `Ticket` widget.
|
||||||
#[derive(AsAny, Default)]
|
#[derive(AsAny, Default)]
|
||||||
pub struct TicketdataState {
|
pub struct TicketdataState {
|
||||||
action: Option<TicketdataAction>,
|
actions: Vec<TicketdataAction>,
|
||||||
|
button_menu: Entity,
|
||||||
//duration: Duration,
|
//duration: Duration,
|
||||||
lang: String,
|
lang: String,
|
||||||
button_menu: Entity
|
target: Entity
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlobalState for TicketdataState {}
|
impl GlobalState for TicketdataState {}
|
||||||
@@ -61,7 +73,7 @@ impl GlobalState for TicketdataState {}
|
|||||||
/// Method definitions, that react on any given state change inside the `Ticketdata` widget.
|
/// Method definitions, that react on any given state change inside the `Ticketdata` widget.
|
||||||
impl TicketdataState {
|
impl TicketdataState {
|
||||||
/// Clear text in text box.
|
/// Clear text in text box.
|
||||||
pub fn clear_entry(ctx: &mut Context<'_>, entity: Entity) {
|
pub fn clear_entry(entity: Entity, ctx: &mut Context<'_>) {
|
||||||
if let Some(count) = ctx.get_widget(entity).children_count() {
|
if let Some(count) = ctx.get_widget(entity).children_count() {
|
||||||
println!("Widget name: {:?}", ctx.get_widget(entity).get::<String>("name"));
|
println!("Widget name: {:?}", ctx.get_widget(entity).get::<String>("name"));
|
||||||
println!("Widget id: {:?}", ctx.get_widget(entity).get::<String>("id"));
|
println!("Widget id: {:?}", ctx.get_widget(entity).get::<String>("id"));
|
||||||
@@ -79,23 +91,25 @@ impl TicketdataState {
|
|||||||
//println!("Text: {:?}", ctx.get_widget(entity).entity_of_child(entity));
|
//println!("Text: {:?}", ctx.get_widget(entity).entity_of_child(entity));
|
||||||
//TextBlock::text_set(&mut ctx.child(ID_TICKET_DATA_POLICY_HOLDER), "");
|
//TextBlock::text_set(&mut ctx.child(ID_TICKET_DATA_POLICY_HOLDER), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//TextBox::text_set(&mut ctx.widget(entity), String::from(""));
|
//TextBox::text_set(&mut ctx.widget(entity), String::from(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear ticket data form
|
pub fn send_form(entity: Entity, _ctx: &mut Context<'_>) {
|
||||||
pub fn send_message(&mut self) {
|
info!("WIP: Sending form to construct eMail for {:?}", entity);
|
||||||
println!("WIP: send_message");
|
|
||||||
//self.action.push(TicketdataAction::ClearForm());
|
|
||||||
//self.clear_entry(ticket_data_policy_holder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets a new action.
|
/// sending message 'ClearForm'
|
||||||
pub fn set_action(&mut self, action: TicketdataAction) {
|
pub fn send_message_clear_form(&mut self) {
|
||||||
self.action = action.into();
|
info!("Sending message 'TicketdataAction::ClearForm'");
|
||||||
|
self.actions.push(TicketdataAction::ClearForm());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// sending message 'SendForm'
|
||||||
|
pub fn send_message_send_form(&mut self) {
|
||||||
|
info!("Sending message 'TicketdataAction::SendForm'");
|
||||||
|
self.actions.push(TicketdataAction::SendForm());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Supported methods handled inside the `TicketState`
|
/// Supported methods handled inside the `TicketState`
|
||||||
@@ -111,6 +125,9 @@ impl State for TicketdataState {
|
|||||||
.entity_of_child(ID_TICKET_DATA_BUTTON_MENU)
|
.entity_of_child(ID_TICKET_DATA_BUTTON_MENU)
|
||||||
.expect("TicketState.init: Can't find resource entity 'ID_TICKET_DATA_BUTTON_MENU'.");
|
.expect("TicketState.init: Can't find resource entity 'ID_TICKET_DATA_BUTTON_MENU'.");
|
||||||
|
|
||||||
|
self.target = Entity::from(ctx.widget().try_clone::<u32>("target")
|
||||||
|
.expect("TicketState.init: Can't find resource entity 'target'."));
|
||||||
|
|
||||||
// Get language from environment
|
// Get language from environment
|
||||||
self.lang = TicketdataState::get_lang();
|
self.lang = TicketdataState::get_lang();
|
||||||
|
|
||||||
@@ -129,15 +146,48 @@ impl State for TicketdataState {
|
|||||||
for action in messages.read::<TicketdataAction>() {
|
for action in messages.read::<TicketdataAction>() {
|
||||||
match action {
|
match action {
|
||||||
TicketdataAction::ClearForm() => {
|
TicketdataAction::ClearForm() => {
|
||||||
println!("WIP: Message 'ClearForm' received");
|
println!("message: {:?} recieved", action);
|
||||||
TicketdataState::clear_entry(ctx, ctx.entity())
|
info!("message: {:?} recieved", action);
|
||||||
//TicketdataState::clear_entry(ctx, ctx.entity());
|
//TicketdataState::clear_entry(ctx.entity(), ctx);
|
||||||
|
//ctx.clear_children_of(self.ticket_data_form);
|
||||||
|
|
||||||
}
|
}
|
||||||
TicketdataAction::SendForm() => {
|
TicketdataAction::SendForm() => {
|
||||||
println!("WIP: Message 'SendForm' received");
|
println!("message: {:?} recieved", action);
|
||||||
|
info!("message: {:?} recieved", action);
|
||||||
|
TicketdataState::send_form(ctx.entity(), ctx);
|
||||||
|
}
|
||||||
|
_ => { println!("messages: action not implemented!"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for action in messages.read::<PolicycheckAction>() {
|
||||||
|
match action {
|
||||||
|
PolicycheckAction::UpdatePolicyNumber(policy_number) => {
|
||||||
|
info!("Message received: 'PolicycheckAction::UpdatePolicyNumber({:?})'", policy_number);
|
||||||
|
//progress_bar.set::<f64>("val", current_progress + amount);
|
||||||
|
//TextBlock::text_set(&mut ctx.child(ID_TICKET_DATA_POLICY_NUMBER), "9999999992");
|
||||||
|
TextBlock::text_set(&mut ctx.child(ID_TICKET_DATA_POLICY_NUMBER), policy_number);
|
||||||
}
|
}
|
||||||
_ => { println!("messages: action not implemented!"); }
|
_ => { println!("messages: action not implemented!"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
||||||
|
let actions: Vec<TicketdataAction> = self.actions.drain(..).collect();
|
||||||
|
|
||||||
|
for action in actions {
|
||||||
|
match action {
|
||||||
|
TicketdataAction::ClearForm() => {
|
||||||
|
info!("update: send_message {:?}", action);
|
||||||
|
ctx.send_message(TicketdataAction::ClearForm(), self.target);
|
||||||
|
}
|
||||||
|
TicketdataAction::SendForm() => {
|
||||||
|
//ctx.send_message(TicketdataAction::SendForm(), self.ID_TICKETDATA_FORM);
|
||||||
|
info!("update: send_message {:?}", action);
|
||||||
|
}
|
||||||
|
_ => { println!("TicketdataAction: action not implemented!"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,16 +12,20 @@ use orbtk::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
data::constants::*,
|
data::constants::*,
|
||||||
widgets::ticketdata::ticketdata_state::{TicketdataAction, TicketdataState},
|
//widgets::ticketdata::ticketdata_state::{TicketdataAction, TicketdataState},
|
||||||
|
widgets::ticketdata::ticketdata_state::TicketdataState,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Macro that initializes the widget structures/variables for the policy check view
|
// Macro that initializes the widget structures/variables for the policy check view
|
||||||
widget!(
|
widget!(
|
||||||
/// Form to enter data of a ticket record
|
/// Form to enter data of a ticket record
|
||||||
TicketdataView<TicketdataState> {
|
TicketdataView<TicketdataState> {
|
||||||
|
// language used inside the widget
|
||||||
lang: String,
|
lang: String,
|
||||||
policy_data_count: u32,
|
// title used in the header
|
||||||
ticket_data_title: String
|
ticket_data_title: String,
|
||||||
|
// entity id that will receive the messages
|
||||||
|
target: u32
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -262,9 +266,10 @@ impl Template for TicketdataView {
|
|||||||
.style(STYLE_BUTTON_ACTION)
|
.style(STYLE_BUTTON_ACTION)
|
||||||
.text("Clear")
|
.text("Clear")
|
||||||
.on_click(move |states, _| {
|
.on_click(move |states, _| {
|
||||||
println!("WIP: clear from");
|
//println!("WIP: clear from");
|
||||||
states.send_message(TicketdataAction::ClearForm, id);
|
//states.send_message(TicketdataAction::ClearForm, id);
|
||||||
true
|
states.get_mut::<TicketdataState>(id).send_message_clear_form();
|
||||||
|
false
|
||||||
})
|
})
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
@@ -274,10 +279,11 @@ impl Template for TicketdataView {
|
|||||||
.style(STYLE_BUTTON_ACTION)
|
.style(STYLE_BUTTON_ACTION)
|
||||||
.text("Send")
|
.text("Send")
|
||||||
//.visibility(Visibility::Collapsed)
|
//.visibility(Visibility::Collapsed)
|
||||||
.on_click(move |states, _| {
|
.on_click(move |states, _entity| {
|
||||||
println!("WIP: send mail");
|
//println!("WIP: send mail");
|
||||||
states.send_message(TicketdataAction::SendForm, id);
|
//states.get_mut::<TicketdataAction>(id).send_message(TicketdataAction::SendForm, id);
|
||||||
true
|
states.get_mut::<TicketdataState>(id).send_message_send_form();
|
||||||
|
false
|
||||||
})
|
})
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user