@@ -8,25 +8,25 @@
|
||||
// suppress creation of a new console window on window
|
||||
#![windows_subsystem = "windows"]
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use locales::t;
|
||||
use orbtk::{
|
||||
prelude::*,
|
||||
theme_default::{THEME_DEFAULT, THEME_DEFAULT_COLORS_DARK, THEME_DEFAULT_FONTS},
|
||||
theming::config::ThemeConfig,
|
||||
};
|
||||
use cfg_if::cfg_if;
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
use std::time::SystemTime;
|
||||
use tracing::{Level, info, trace};
|
||||
use tracing::{info, trace, Level};
|
||||
|
||||
use advotracker::{
|
||||
data::{constants::*, structures::Email},
|
||||
widgets::global_state::GlobalState,
|
||||
widgets::main_view,
|
||||
//services::exports::send_ticketdata::sendticketdata,
|
||||
widgets::policycheck::*,
|
||||
widgets::policycheck_state::*,
|
||||
widgets::main_view,
|
||||
widgets::ticketdata::*,
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@ use orbtk::theme_fluent::{THEME_FLUENT, THEME_FLUENT_COLORS_DARK, THEME_FLUENT_F
|
||||
pub enum TicketdataAction {
|
||||
ClearForm(),
|
||||
SendForm(),
|
||||
UpdatePolicyCode(String)
|
||||
UpdatePolicyCode(String),
|
||||
}
|
||||
|
||||
// German localization file.
|
||||
@@ -46,7 +46,7 @@ static ADVOTRACKER_DE_DE: &str = include_str!("../assets/advotracker/advotracker
|
||||
fn get_lang() -> String {
|
||||
// get system environment
|
||||
let mut lang = env::var("LANG").unwrap_or_else(|_| "C".to_string());
|
||||
lang = lang.substring(0,5).to_string(); // "de_DE.UTF-8" -> "de_DE"
|
||||
lang = lang.substring(0, 5).to_string(); // "de_DE.UTF-8" -> "de_DE"
|
||||
info!("GUI-Language: preset to {:?}", lang);
|
||||
|
||||
// return the active language
|
||||
@@ -92,7 +92,6 @@ cfg_if! {
|
||||
|
||||
// Main
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// initialize the tracing subsystem
|
||||
// a drop in replacement for classical logging
|
||||
// reference: https://tokio.rs/blog/2019-08-tracing/
|
||||
@@ -167,18 +166,13 @@ widget!(MainView {
|
||||
policycheck_view: PolicyCheck
|
||||
});
|
||||
|
||||
|
||||
impl Template for MainView {
|
||||
fn template(self, _id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
let ticketdata_view = TicketdataView::new()
|
||||
.build(ctx);
|
||||
let ticketdata_view = TicketdataView::new().build(ctx);
|
||||
|
||||
let policycheck_view = PolicycheckView::new()
|
||||
.target(ticketdata_view.0)
|
||||
.build(ctx);
|
||||
let policycheck_view = PolicycheckView::new().target(ticketdata_view.0).build(ctx);
|
||||
|
||||
self.name("MainView")
|
||||
.child(
|
||||
self.name("MainView").child(
|
||||
TabWidget::new()
|
||||
.tab(ID_POLICY_CHECK_VIEW, policycheck_view)
|
||||
.tab(ID_TICKET_DATA_VIEW, ticketdata_view)
|
||||
@@ -232,7 +226,7 @@ impl Template for TicketdataView {
|
||||
TextBlock::new()
|
||||
.margin((0, 9, 48, 0))
|
||||
.text("©Networkx GmbH")
|
||||
.build(ctx)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
@@ -263,7 +257,7 @@ impl Template for TicketdataView {
|
||||
.push("auto") // Label
|
||||
.push(16) // Delimiter
|
||||
.push("*") // Data
|
||||
.push(32) // Delimiter (2x margin)
|
||||
.push(32), // Delimiter (2x margin)
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
@@ -280,7 +274,7 @@ impl Template for TicketdataView {
|
||||
.push("auto") // Row 10
|
||||
.push(14) // Seperator
|
||||
.push("auto") // Row 12
|
||||
.push(14) // Seperator
|
||||
.push(14), // Seperator
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
@@ -470,10 +464,7 @@ impl Template for TicketdataView {
|
||||
let items_mail_to_count = items_mail_to.len();
|
||||
|
||||
// vector with valid carbon copy recipients addresses (mail_to)
|
||||
let items_mail_cc = vec![
|
||||
PROP_MAIL_CC_1,
|
||||
PROP_MAIL_CC_2,
|
||||
];
|
||||
let items_mail_cc = vec![PROP_MAIL_CC_1, PROP_MAIL_CC_2];
|
||||
let items_mail_cc_count = items_mail_cc.len();
|
||||
|
||||
let ticket_data_form_mail = Container::new()
|
||||
@@ -490,14 +481,14 @@ impl Template for TicketdataView {
|
||||
.push("stretch") // Label
|
||||
.push(16) // Delimiter
|
||||
.push("auto") // MailAddress
|
||||
.push("32") // Delimiter (2x margin)
|
||||
.push("32"), // Delimiter (2x margin)
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
.push("auto") // Row 0
|
||||
.push(2) // Seperator
|
||||
.push("auto") // Row 2
|
||||
.push(2) // Seperator
|
||||
.push(2), // Seperator
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
@@ -517,7 +508,9 @@ impl Template for TicketdataView {
|
||||
.style(STYLE_MAIL_TO)
|
||||
.count(items_mail_to_count)
|
||||
.items_builder(move |ibc, index| {
|
||||
let text_mail_to = TicketdataView::items_mail_to_ref(&ibc.get_widget(id))[index].clone();
|
||||
let text_mail_to =
|
||||
TicketdataView::items_mail_to_ref(&ibc.get_widget(id))[index]
|
||||
.clone();
|
||||
TextBox::new()
|
||||
.text(text_mail_to)
|
||||
.v_align("center")
|
||||
@@ -543,7 +536,9 @@ impl Template for TicketdataView {
|
||||
.style(STYLE_MAIL_CC)
|
||||
.count(items_mail_cc_count)
|
||||
.items_builder(move |ibc, index| {
|
||||
let text_mail_cc = TicketdataView::items_mail_cc_ref(&ibc.get_widget(id))[index].clone();
|
||||
let text_mail_cc =
|
||||
TicketdataView::items_mail_cc_ref(&ibc.get_widget(id))[index]
|
||||
.clone();
|
||||
TextBox::new()
|
||||
.text(text_mail_cc)
|
||||
.v_align("center")
|
||||
@@ -584,7 +579,7 @@ impl Template for TicketdataView {
|
||||
Columns::create()
|
||||
.push(50) // Left margin
|
||||
.push("*") // Content
|
||||
.push(50) // Right margin
|
||||
.push(50), // Right margin
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
@@ -592,9 +587,8 @@ impl Template for TicketdataView {
|
||||
.push("auto") // Mail_Form
|
||||
.push("*") // Input_Form
|
||||
.push("auto") // Action
|
||||
.push("auto") // Bottom_Bar
|
||||
.push("auto"), // Bottom_Bar
|
||||
)
|
||||
|
||||
.child(ticket_data_header_bar) // row 0
|
||||
.child(ticket_data_form_mail) // row 1
|
||||
.child(ticket_data_form) // row 2
|
||||
@@ -613,14 +607,26 @@ impl TicketdataState {
|
||||
/// Clear the text property of all children of the given form entity
|
||||
pub fn clear_form(entity: Entity, ctx: &mut Context<'_>) {
|
||||
if let Some(count) = ctx.get_widget(entity).children_count() {
|
||||
info!("Widget name: {:?}", ctx.get_widget(entity).get::<String>("name"));
|
||||
info!("Widget id: {:?}", ctx.get_widget(entity).get::<String>("id"));
|
||||
info!(
|
||||
"Widget name: {:?}",
|
||||
ctx.get_widget(entity).get::<String>("name")
|
||||
);
|
||||
info!(
|
||||
"Widget id: {:?}",
|
||||
ctx.get_widget(entity).get::<String>("id")
|
||||
);
|
||||
}
|
||||
|
||||
// identify the form by its id
|
||||
if let form_entity = ctx.child(ID_TICKET_DATA_GRID).entity() {
|
||||
info!("Form id: {:?}", ctx.get_widget(form_entity).get::<String>("id"));
|
||||
info!("Form node name: {:?}", ctx.get_widget(form_entity).get::<String>("name"));
|
||||
info!(
|
||||
"Form id: {:?}",
|
||||
ctx.get_widget(form_entity).get::<String>("id")
|
||||
);
|
||||
info!(
|
||||
"Form node name: {:?}",
|
||||
ctx.get_widget(form_entity).get::<String>("name")
|
||||
);
|
||||
|
||||
// Loop through children
|
||||
if let Some(count) = ctx.get_widget(form_entity).children_count() {
|
||||
@@ -633,7 +639,6 @@ impl TicketdataState {
|
||||
}
|
||||
|
||||
pub fn send_form(entity: Entity, ctx: &mut Context<'_>, lang: &str) {
|
||||
|
||||
// type conversion (String -> u64)
|
||||
//let policy_code = ctx.child(ID_TICKET_DATA_POLICY_CODE).get::<String>("text").unwrap().parse::<u64>().unwrap();
|
||||
|
||||
@@ -647,20 +652,40 @@ impl TicketdataState {
|
||||
//mail_to: ctx.child(ID_TICKET_DATA_MAIL_TO).get::<String>("text").to_string(),
|
||||
// WIP: mail_cc -> selected index auslesen
|
||||
//mail_cc: ctx.child(ID_TICKET_DATA_MAIL_CC).get::<String>("text").to_string(),
|
||||
|
||||
mail_to: PROP_MAIL_TO_1.to_string(),
|
||||
mail_cc: PROP_MAIL_CC_1.to_string(),
|
||||
mail_bcc: PROP_MAIL_BCC_1.to_string(),
|
||||
mail_from: PROP_MAIL_FROM.to_string(),
|
||||
mail_reply: PROP_MAIL_REPLY.to_string(),
|
||||
subject: PROP_MAIL_SUBJECT.to_string(),
|
||||
policy_code: ctx.child(ID_TICKET_DATA_POLICY_CODE).get::<String>("text").to_string(),
|
||||
policy_holder: ctx.child(ID_TICKET_DATA_POLICY_HOLDER).get::<String>("text").to_string(),
|
||||
deductible: ctx.child(ID_TICKET_DATA_DEDUCTIBLE).get::<String>("text").to_string(),
|
||||
callback_number: ctx.child(ID_TICKET_DATA_CALLBACK_NUMBER).get::<String>("text").to_string(),
|
||||
callback_date: ctx.child(ID_TICKET_DATA_CALLBACK_DATE).get::<String>("text").to_string(),
|
||||
harm_type: ctx.child(ID_TICKET_DATA_HARM_TYPE).get::<String>("text").to_string(),
|
||||
ivr_comment: ctx.child(ID_TICKET_DATA_IVR_COMMENT).get::<String>("text").to_string(),
|
||||
policy_code: ctx
|
||||
.child(ID_TICKET_DATA_POLICY_CODE)
|
||||
.get::<String>("text")
|
||||
.to_string(),
|
||||
policy_holder: ctx
|
||||
.child(ID_TICKET_DATA_POLICY_HOLDER)
|
||||
.get::<String>("text")
|
||||
.to_string(),
|
||||
deductible: ctx
|
||||
.child(ID_TICKET_DATA_DEDUCTIBLE)
|
||||
.get::<String>("text")
|
||||
.to_string(),
|
||||
callback_number: ctx
|
||||
.child(ID_TICKET_DATA_CALLBACK_NUMBER)
|
||||
.get::<String>("text")
|
||||
.to_string(),
|
||||
callback_date: ctx
|
||||
.child(ID_TICKET_DATA_CALLBACK_DATE)
|
||||
.get::<String>("text")
|
||||
.to_string(),
|
||||
harm_type: ctx
|
||||
.child(ID_TICKET_DATA_HARM_TYPE)
|
||||
.get::<String>("text")
|
||||
.to_string(),
|
||||
ivr_comment: ctx
|
||||
.child(ID_TICKET_DATA_IVR_COMMENT)
|
||||
.get::<String>("text")
|
||||
.to_string(),
|
||||
};
|
||||
|
||||
info!("WIP: Sending form to construct eMail to {:?}", email);
|
||||
@@ -673,7 +698,7 @@ impl TicketdataState {
|
||||
impl State for TicketdataState {
|
||||
/// Initialize the state of widgets inside `TicketState`
|
||||
fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
||||
let time_start= SystemTime::now();
|
||||
let time_start = SystemTime::now();
|
||||
|
||||
trace!(target: "advotracker", ticketdata_state = "init", status = "started");
|
||||
|
||||
@@ -682,8 +707,11 @@ impl State for TicketdataState {
|
||||
.entity_of_child(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'."));
|
||||
self.target = Entity::from(
|
||||
ctx.widget()
|
||||
.try_clone::<u32>("target")
|
||||
.expect("TicketState.init: Can't find resource entity 'target'."),
|
||||
);
|
||||
|
||||
// Get language from environment
|
||||
self.lang = TicketdataState::get_lang();
|
||||
@@ -710,7 +738,9 @@ impl State for TicketdataState {
|
||||
info!("message: {:?} recieved", message);
|
||||
TicketdataState::send_form(ctx.entity(), ctx, &self.lang);
|
||||
}
|
||||
_ => { println!("messages: action not implemented!"); }
|
||||
_ => {
|
||||
println!("messages: action not implemented!");
|
||||
}
|
||||
}
|
||||
}
|
||||
for message in messages.read::<PolicycheckAction>() {
|
||||
@@ -719,7 +749,9 @@ impl State for TicketdataState {
|
||||
info!("Message received: 'PolicycheckAction::UpdatePolicyCode'");
|
||||
TextBlock::text_set(&mut ctx.child(ID_TICKET_DATA_POLICY_CODE), policy_code);
|
||||
}
|
||||
_ => { println!("messages: action not implemented!"); }
|
||||
_ => {
|
||||
println!("messages: action not implemented!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -737,13 +769,14 @@ impl State for TicketdataState {
|
||||
//ctx.send_message(TicketdataAction::SendForm(), self.ID_TICKETDATA_FORM);
|
||||
info!("update: send_message {:?}", action);
|
||||
}
|
||||
_ => { println!("TicketdataAction: action not implemented!"); }
|
||||
_ => {
|
||||
println!("TicketdataAction: action not implemented!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// send ticket data via eMail
|
||||
pub fn sendticketdata(email: &Email, lang: &str) -> Result<(), Box<dyn Error>> {
|
||||
let mut res = t!("sendticketdata.export.started", lang);
|
||||
@@ -751,13 +784,27 @@ pub fn sendticketdata(email: &Email, lang: &str) -> Result<(), Box<dyn Error>> {
|
||||
trace!(target: "sendticketdata", process = ?res, state = ?state);
|
||||
|
||||
let ascii_body = String::new()
|
||||
+ &"Vers.-Schein/Schadennummer".to_string() + &(email.policy_code) + &"\n"
|
||||
+ &"Versicherungsnehmer: ".to_string() + &(email.policy_holder) + &"\n"
|
||||
+ &"Selbstbehalt: ".to_string() + &(email.deductible) + &"\n"
|
||||
+ &"Rückrufnummer: ".to_string()+ &(email.callback_number) + &"\n"
|
||||
+ &"Erreichbarkeit: ".to_string() + &(email.callback_date) + &"\n"
|
||||
+ &"Rechtsproblem: ".to_string() + &(email.harm_type) + &"\n"
|
||||
+ &"Rechtsrat: ".to_string() + &(email.ivr_comment) + &"\n";
|
||||
+ &"Vers.-Schein/Schadennummer".to_string()
|
||||
+ &(email.policy_code)
|
||||
+ &"\n"
|
||||
+ &"Versicherungsnehmer: ".to_string()
|
||||
+ &(email.policy_holder)
|
||||
+ &"\n"
|
||||
+ &"Selbstbehalt: ".to_string()
|
||||
+ &(email.deductible)
|
||||
+ &"\n"
|
||||
+ &"Rückrufnummer: ".to_string()
|
||||
+ &(email.callback_number)
|
||||
+ &"\n"
|
||||
+ &"Erreichbarkeit: ".to_string()
|
||||
+ &(email.callback_date)
|
||||
+ &"\n"
|
||||
+ &"Rechtsproblem: ".to_string()
|
||||
+ &(email.harm_type)
|
||||
+ &"\n"
|
||||
+ &"Rechtsrat: ".to_string()
|
||||
+ &(email.ivr_comment)
|
||||
+ &"\n";
|
||||
|
||||
info!("email body: {:?}", ascii_body);
|
||||
|
||||
@@ -770,11 +817,12 @@ pub fn sendticketdata(email: &Email, lang: &str) -> Result<(), Box<dyn Error>> {
|
||||
//.cc((email.mail_cc).parse().unwrap())
|
||||
//.bcc((email.mail_bcc).parse().unwrap())
|
||||
.from((email.mail_from).parse().unwrap())
|
||||
.subject(String::new()
|
||||
.subject(
|
||||
String::new()
|
||||
+ &email.subject.to_string()
|
||||
+ &" (".to_string()
|
||||
+ &email.policy_code.to_string()
|
||||
+ &")".to_string()
|
||||
+ &")".to_string(),
|
||||
)
|
||||
.multipart(
|
||||
MultiPart::alternative() // This is composed of two parts.
|
||||
@@ -784,11 +832,10 @@ pub fn sendticketdata(email: &Email, lang: &str) -> Result<(), Box<dyn Error>> {
|
||||
"text/plain; charset=utf8".parse().unwrap(),
|
||||
))
|
||||
.body(String::from(ascii_body)),
|
||||
)
|
||||
),
|
||||
)
|
||||
.expect("failed to build email");
|
||||
|
||||
|
||||
info!("message: {:?}", message);
|
||||
|
||||
trace!(target: "sendticketdata", email = ?email);
|
||||
|
||||
Reference in New Issue
Block a user