widget:ticketdata: error handling and button glyphs
* assign glyphs depending on action state * feedback on send_ticketdata return code * cleanup Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -127,6 +127,7 @@ pub static ID_POLICY_LIST_TEXT_BOX: &str = "policy_list_text_box";
|
||||
pub static ID_TICKET_DATA_ACTION_BUTTON_CLEAR: &str = "ticket_data_action_button_clear";
|
||||
pub static ID_TICKET_DATA_ACTION_BUTTON_SEND: &str = "ticket_data_action_button_send";
|
||||
pub static ID_TICKET_DATA_ACTION_GRID: &str = "ticket_data_action_grid";
|
||||
pub static ID_TICKET_DATA_ACTION_STACK: &str = "ticket_data_action_stack";
|
||||
pub static ID_TICKET_DATA_BOTTOM_BAR: &str = "ticket_data_bottom_bar";
|
||||
pub static ID_TICKET_DATA_BUTTON_MENU: &str = "ticket_data_button_menu";
|
||||
pub static ID_TICKET_DATA_BUTTON_RESULT: &str = "ticket_data_button_result";
|
||||
|
||||
@@ -14,7 +14,7 @@ use locales::t;
|
||||
use maud::html;
|
||||
use std::error::Error;
|
||||
//use std::process;
|
||||
use tracing::{info, error, trace};
|
||||
use tracing::{info, trace};
|
||||
|
||||
use crate::data::structures::Email;
|
||||
|
||||
@@ -109,13 +109,11 @@ pub fn sendticketdata(email: &Email, lang: &str) -> Result<(), Box<dyn Error>> {
|
||||
.credentials(credentials)
|
||||
.build();
|
||||
|
||||
// Send the email
|
||||
match mailer.send(&message) {
|
||||
Ok(_) => info!("Email sent successfully!"),
|
||||
Err(e) => error!("Could not send email: {:?}", e),
|
||||
}
|
||||
|
||||
trace!(target: "sendticketdata", email = ?email);
|
||||
|
||||
// Send the email and catch the error if it isn't successfully
|
||||
let _result = mailer.send(&message)?;
|
||||
|
||||
state = t!("state.finished", lang);
|
||||
res = t!("sendticketdata.export.finished", lang);
|
||||
trace!(target: "sendticketdata", process = ?res, state = ?state);
|
||||
|
||||
@@ -242,15 +242,8 @@ impl Template for PolicycheckView {
|
||||
.text("Policy code")
|
||||
.build(ctx),
|
||||
)
|
||||
// .child(
|
||||
// TextBlock::new()
|
||||
// .id(ID_POLICY_CHECK_RESULT)
|
||||
// .style("body")
|
||||
// .attach(Grid::row(2))
|
||||
// .attach(Grid::column(2))
|
||||
// .build(ctx)
|
||||
//)
|
||||
.child(policy_check_policy_code)
|
||||
|
||||
//.child(policy_check_form_row_2)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
|
||||
@@ -12,35 +12,24 @@ use serde::Deserialize;
|
||||
//use std::process;
|
||||
//use std::collections::HashMap;
|
||||
use std::time::SystemTime;
|
||||
use tracing::{info, trace};
|
||||
use tracing::{error, info, trace};
|
||||
|
||||
use crate::{
|
||||
data::{constants::*, structures::Email},
|
||||
widgets::global_state::GlobalState,
|
||||
services::exports::send_ticketdata::sendticketdata,
|
||||
widgets::ticketdata::ticketdata_view::TicketdataView,
|
||||
widgets::policycheck::policycheck_state::PolicycheckAction,
|
||||
//widgets::policycheck::policycheck_state::PolicycheckAction,
|
||||
};
|
||||
|
||||
/// Valid `actions` that are handled as state changes in the `Ticketdata` widget.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TicketdataAction {
|
||||
ClearEntry(Entity),
|
||||
/// Clear text in the form
|
||||
ClearForm(String),
|
||||
ChangeTheme(),
|
||||
//ChangeMailCc(),
|
||||
//ChangeMailTo(),
|
||||
InputTextChanged(Entity),
|
||||
ParseEntry(Entity),
|
||||
RemoveFocus(Entity),
|
||||
SendForm(),
|
||||
SetToggleTheme(Entity),
|
||||
SetEntry(Entity),
|
||||
SetVisibility(Entity),
|
||||
TextChanged(Entity, usize),
|
||||
UpdatePolicyCode(String),
|
||||
UpdateSelectedIndex(String)
|
||||
UpdatePolicyCode(String)
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +47,6 @@ struct Environment {
|
||||
pub struct TicketdataState {
|
||||
actions: Vec<TicketdataAction>,
|
||||
button_menu: Entity,
|
||||
//duration: Duration,
|
||||
lang: String,
|
||||
target: Entity
|
||||
}
|
||||
@@ -111,12 +99,18 @@ impl TicketdataState {
|
||||
// "ticket_data_policy_callback_ivr_comment" => TextBox::text_set(child, ""),
|
||||
// _ => info!("don't act on child_id '{:?}", child_id),
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// switch back to parent entity
|
||||
ctx.change_into(entity) }
|
||||
ctx.change_into(entity);
|
||||
|
||||
Stack::visibility_set(&mut ctx.child(ID_TICKET_DATA_ACTION_STACK), Visibility::Collapsed);
|
||||
Button::background_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#008000"));
|
||||
Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_SEND);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_form(entity: Entity, ctx: &mut Context<'_>, lang: &str) {
|
||||
@@ -147,26 +141,24 @@ impl TicketdataState {
|
||||
|
||||
info!("WIP: Sending form to construct eMail to {:?}", email);
|
||||
// send email via service
|
||||
if let Err(_e) = sendticketdata(&email, &lang) {
|
||||
if let Err(err) = sendticketdata(&email, &lang) {
|
||||
error!("sendticketdata error: {:?}", err);
|
||||
Button::icon_brush_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#008000"));
|
||||
//Button::foreground_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#CC000000"));
|
||||
Button::background_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#CC000000"));
|
||||
Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_THUMB_DOWN);
|
||||
//Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_ERROR);
|
||||
} else {
|
||||
Button::icon_brush_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#FF0000"));
|
||||
Button::foreground_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#FF0000"));
|
||||
Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_CLEAR);
|
||||
//Button::foreground_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#FF0000"));
|
||||
Button::background_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#FF0000"));
|
||||
Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_THUMB_UP);
|
||||
};
|
||||
}
|
||||
|
||||
pub fn update_selected_index(entity: Entity, id: &str, ctx: &mut Context<'_>) {
|
||||
info!("TicketdataState: processing entity[{:?}]: id: {:?}]", entity, id);
|
||||
|
||||
if ctx.entity_of_child(id).is_some() {
|
||||
let combobox_entity = ctx.entity_of_child(id).unwrap();
|
||||
let combobox_container: WidgetContainer<'_> = ctx.get_widget(combobox_entity);
|
||||
info!("combobox name: {:?}", combobox_container.get::<String>("id"));
|
||||
info!("combobox selected_index: {:?}", combobox_container.get::<i32>("selected_index"));
|
||||
|
||||
//let mail_index = *ComboBox::selected_index_ref(&combobox_container) as usize;
|
||||
//let mail_item = ComboBox::mail_to_ref(&combobox_container)[mail_index].clone();
|
||||
//info!("selected mail_to item[{:?}]: {:?}]", mail_index, mail_item);
|
||||
}
|
||||
pub fn update_policy_code(_entity: Entity, _id: &str, ctx: &mut Context<'_>) {
|
||||
Stack::visibility_set(&mut ctx.child(ID_TICKET_DATA_ACTION_STACK), Visibility::Visible);
|
||||
//self.actions.push(TicketdataAction::UpdatePolicyCode(entity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +182,10 @@ impl State for TicketdataState {
|
||||
// Get language from environment
|
||||
self.lang = TicketdataState::get_lang();
|
||||
|
||||
Stack::visibility_set(&mut ctx.child(ID_TICKET_DATA_ACTION_STACK), Visibility::Collapsed);
|
||||
Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_CLEAR), material_icons_font::MD_CLEAR);
|
||||
Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_SEND);
|
||||
|
||||
let time_end = SystemTime::now();
|
||||
let duration = time_end.duration_since(time_start);
|
||||
|
||||
@@ -206,26 +202,13 @@ impl State for TicketdataState {
|
||||
for message in messages.read::<TicketdataAction>() {
|
||||
match message {
|
||||
TicketdataAction::ClearForm(id) => {
|
||||
info!("message: {:?} recieved", id);
|
||||
TicketdataState::clear_form(ctx.entity(), &id, ctx);
|
||||
}
|
||||
TicketdataAction::SendForm() => {
|
||||
info!("message: {:?} recieved", message);
|
||||
TicketdataState::send_form(ctx.entity(), ctx, &self.lang);
|
||||
}
|
||||
TicketdataAction::UpdateSelectedIndex(id) => {
|
||||
info!("message: UpdateSelectedIndex for {:?} recieved", id);
|
||||
TicketdataState::update_selected_index(ctx.entity(), &id, ctx);
|
||||
}
|
||||
_ => { println!("messages: action not implemented!"); }
|
||||
}
|
||||
}
|
||||
|
||||
for message in messages.read::<PolicycheckAction>() {
|
||||
match message {
|
||||
PolicycheckAction::UpdatePolicyCode => {
|
||||
info!("Message received: 'PolicycheckAction::UpdatePolicyCode'");
|
||||
//TextBlock::text_set(&mut ctx.child(ID_TICKET_DATA_POLICY_CODE), policy_code);
|
||||
TicketdataAction::UpdatePolicyCode(id) => {
|
||||
TicketdataState::update_policy_code(ctx.entity(), &id, ctx);
|
||||
}
|
||||
_ => { println!("messages: action not implemented!"); }
|
||||
}
|
||||
@@ -238,17 +221,12 @@ impl State for TicketdataState {
|
||||
for action in actions {
|
||||
match action {
|
||||
TicketdataAction::ClearForm(ref id) => {
|
||||
info!("update: got send_message {:?}", action);
|
||||
ctx.send_message(TicketdataAction::ClearForm(id.to_string()), self.target);
|
||||
}
|
||||
TicketdataAction::SendForm() => {
|
||||
//ctx.send_message(TicketdataAction::SendForm(), self.ID_TICKETDATA_FORM);
|
||||
info!("update: got send_message {:?}", action);
|
||||
}
|
||||
//TicketdataAction::UpdateSelectedIndex(ref id) => {
|
||||
// info!("update: got send_message {:?}", action);
|
||||
// ctx.send_message(TicketdataAction::UpdateSelectedIndex(id.to_string()), self.target);
|
||||
//}
|
||||
// TicketdataAction::SendForm() => {
|
||||
// //ctx.send_message(TicketdataAction::SendForm(), self.ID_TICKETDATA_FORM);
|
||||
// info!("update: got send_message {:?}", action);
|
||||
// }
|
||||
_ => { println!("TicketdataAction: action not implemented!"); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,8 +154,12 @@ impl Template for TicketdataView {
|
||||
.id(ID_TICKET_DATA_POLICY_CODE)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(2))
|
||||
.text("9999999990")
|
||||
.text("")
|
||||
.v_align("center")
|
||||
.water_mark("ID, bzw. Nummer")
|
||||
.on_activate(move |states, _entity| {
|
||||
states.send_message(TicketdataAction::UpdatePolicyCode(ID_TICKET_DATA_POLICY_CODE.to_string()), id);
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
@@ -287,6 +291,7 @@ impl Template for TicketdataView {
|
||||
.h_align("center")
|
||||
.child(
|
||||
Stack::new()
|
||||
.id(ID_TICKET_DATA_ACTION_STACK)
|
||||
//.style(STYLE_STACK_ACTION)
|
||||
.orientation("horizontal")
|
||||
.spacing(50)
|
||||
|
||||
Reference in New Issue
Block a user