diff --git a/crates/advotracker_client/Cargo.toml b/crates/advotracker_client/Cargo.toml index 3949a6f..5827220 100644 --- a/crates/advotracker_client/Cargo.toml +++ b/crates/advotracker_client/Cargo.toml @@ -39,7 +39,8 @@ viperus = { git = "https://github.com/maurocordioli/viperus", features = ["cach [build-dependencies] winres = { version = "0.1.11" } -twine = { version = "~0.3.8", features = ["serde"] } +#twine = { version = "0.3.8" } +twine = { path = "../../../twine", features = ["serde"] } [features] default = [] diff --git a/crates/advotracker_client/build.rs b/crates/advotracker_client/build.rs index cbd06ee..784d518 100644 --- a/crates/advotracker_client/build.rs +++ b/crates/advotracker_client/build.rs @@ -7,11 +7,11 @@ extern crate winres; -use twine; +use twine::build_translations; fn main() { println!("cargo:rerun-if-changed=build.rs"); - twine::build_translations(&["./src/i18n/localization.ini"], "i18n.rs").unwrap(); + build_translations(&["./src/i18n/localization.ini"], "i18n.rs").unwrap(); if cfg!(target_os = "windows") { let mut res = winres::WindowsResource::new(); diff --git a/crates/advotracker_client/src/lib.rs b/crates/advotracker_client/src/lib.rs index 3eefad7..94ab35f 100644 --- a/crates/advotracker_client/src/lib.rs +++ b/crates/advotracker_client/src/lib.rs @@ -26,6 +26,9 @@ //! WIP: provide a workflow image //! +// i18n: get the macro (t!) accessing translated strings +include!(concat!(env!("OUT_DIR"), "/i18n.rs")); + // /// The client specific services // pub mod clients; diff --git a/crates/advotracker_client/src/main.rs b/crates/advotracker_client/src/main.rs index 03af3ab..7c3e4e1 100644 --- a/crates/advotracker_client/src/main.rs +++ b/crates/advotracker_client/src/main.rs @@ -16,7 +16,6 @@ use std::env; //use std::process; use substring::Substring; use tracing::{info, trace, Level}; -use twine::t; use orbtk::{ prelude::*, @@ -30,6 +29,9 @@ use orbtk::theme_fluent::{THEME_FLUENT, THEME_FLUENT_COLORS_DARK, THEME_FLUENT_F // The Main view use advotracker_client::widgets::main_view; +// get the macro (t!) accessing the internationalization strings +include!(concat!(env!("OUT_DIR"), "/i18n.rs")); + mod parse_args; /// define valid environment variables provided via .env files @@ -37,7 +39,7 @@ mod parse_args; /// this is primarily used in testing scenarios (eg. debugging) #[derive(Debug, Deserialize)] struct Environment { - lang: String, + lang: Lang, test_lang: String, rust_log: String, } @@ -46,8 +48,8 @@ struct Environment { static DEFAULT_DARK_EXT: &str = include_str!("../assets/advotracker/default_dark.ron"); cfg_if! { if #[cfg(windows)] { - static FLUENT_DARK_EXT: &str = include_str!("../assets/advotracker/fluent_dark.ron"); - static FLUENT_LIGHT_EXT: &str = include_str!("../assets/advotracker/fluent_light.ron"); + static FLUENT_DARK_EXT: &str = include_str!("../assets/advotracker/fluent_dark.ron"); + static FLUENT_LIGHT_EXT: &str = include_str!("../assets/advotracker/fluent_light.ron"); } } @@ -64,10 +66,10 @@ fn get_lang() -> String { // testing environment: read from .env file dotenv().ok(); match envy::from_env::() { - Ok(environment) => { - if environment.test_lang != lang { lang = environment.test_lang; } - }, - Err(e) => { info!(target: "advotracker", "{}", e) } + Ok(environment) => { + if environment.test_lang != lang { lang = environment.test_lang; } + }, + Err(e) => { info!(target: "advotracker", "{}", e) } } trace!(target: "advotracker", lang = ?lang); @@ -77,38 +79,38 @@ fn get_lang() -> String { cfg_if! { if #[cfg(windows)] { - /// Extend and register theme assets. - fn theme() -> Theme { - register_default_fonts(Theme::from_config( - ThemeConfig::from(DEFAULT_DARK_EXT) - .extend(ThemeConfig::from(THEME_DEFAULT)) - .extend(ThemeConfig::from(THEME_DEFAULT_COLORS_DARK)) - .extend(ThemeConfig::from(THEME_DEFAULT_FONTS)), - )) - } - fn theme_fluent() -> Theme { - register_fluent_fonts(Theme::from_config( - ThemeConfig::from(FLUENT_DARK_EXT) - .extend(ThemeConfig::from(THEME_FLUENT)) - .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK)) - .extend(ThemeConfig::from(THEME_FLUENT_FONTS)), - )) - // register_fluent_fonts(Theme::from_config( - // ThemeConfig::from(FLUENT_LIGHT_EXT) - // .extend(ThemeConfig::from(THEME_FLUENT)) - // .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK)) - // .extend(ThemeConfig::from(THEME_FLUENT_FONTS)), - } + /// Extend and register theme assets. + fn theme() -> Theme { + register_default_fonts(Theme::from_config( + ThemeConfig::from(DEFAULT_DARK_EXT) + .extend(ThemeConfig::from(THEME_DEFAULT)) + .extend(ThemeConfig::from(THEME_DEFAULT_COLORS_DARK)) + .extend(ThemeConfig::from(THEME_DEFAULT_FONTS)), + )) + } + fn theme_fluent() -> Theme { + register_fluent_fonts(Theme::from_config( + ThemeConfig::from(FLUENT_DARK_EXT) + .extend(ThemeConfig::from(THEME_FLUENT)) + .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK)) + .extend(ThemeConfig::from(THEME_FLUENT_FONTS)), + )) + // register_fluent_fonts(Theme::from_config( + // ThemeConfig::from(FLUENT_LIGHT_EXT) + // .extend(ThemeConfig::from(THEME_FLUENT)) + // .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK)) + // .extend(ThemeConfig::from(THEME_FLUENT_FONTS)), + } } else { - /// Extend and register theme assets. - fn theme() -> Theme { - register_default_fonts(Theme::from_config( - ThemeConfig::from(DEFAULT_DARK_EXT) - .extend(ThemeConfig::from(THEME_DEFAULT)) - .extend(ThemeConfig::from(THEME_DEFAULT_COLORS_DARK)) - .extend(ThemeConfig::from(THEME_DEFAULT_FONTS)), - )) - } + /// Extend and register theme assets. + fn theme() -> Theme { + register_default_fonts(Theme::from_config( + ThemeConfig::from(DEFAULT_DARK_EXT) + .extend(ThemeConfig::from(THEME_DEFAULT)) + .extend(ThemeConfig::from(THEME_DEFAULT_COLORS_DARK)) + .extend(ThemeConfig::from(THEME_DEFAULT_FONTS)), + )) + } } } @@ -118,11 +120,11 @@ fn main() -> Result<(), Box> { use viperus::Viperus; let machine_kind = if cfg!(unix) { - "unix" + "unix" } else if cfg!(windows) { - "windows" + "windows" } else { - "unknown/unsupported" + "unknown/unsupported" }; // respect dotenv environment (e.g for testing) @@ -134,81 +136,79 @@ fn main() -> Result<(), Box> { // reference: https://tokio.rs/blog/2019-08-tracing/ let span = tracing::span!(Level::TRACE, "advotracker"); let _enter = span.enter(); - let subscriber = fmt::Subscriber::builder() - .with_env_filter(&rust_log) - //.with_max_level(tracing::Level::DEBUG) - .finish(); + let collector = fmt::Subscriber::builder() + .with_env_filter(&rust_log) + //.with_max_level(tracing::Level::DEBUG) + .finish(); - tracing::subscriber::with_default(subscriber, || { - // get system environment - let lang = get_lang(); + tracing::subscriber::with_default(collector, || { + // get system environment + //let lang = get_lang(); + let lang = Lang::De("de"); - // include localization strings - include!(concat!(env!("OUTDIR"), "/i18n.rs")); + let mut state = t!(state_started => lang); + let mut res = t!(parse_environment => lang); + trace!(target: "advotracker", process = ?res, state = ?state); + trace!(target: "advotracker", environment = "system", lang = ?lang); + trace!(target: "advotracker", machine = ?&machine_kind); - let mut state = t!(state_started => lang); - let mut res = t!(parse_environment => lang); - trace!(target: "advotracker", process = ?res, state = ?state); - trace!(target: "advotracker", environment = "system", lang = ?lang); - trace!(target: "advotracker", machine = ?&machine_kind); + // how to handle unimplemented lang resources?? + res = t!(parse_environment => lang); + trace!(target: "advotracker", environment = "envy", lang = ?lang); + state = t!(state_finished => lang); + trace!(target: "advotracker", process = ?res, state = ?state); - // how to handle unimplemented lang resources?? - res = t!(parse_environment => lang); - trace!(target: "advotracker", environment = "envy", lang = ?lang); - state = t!(state_finished => lang); - trace!(target: "advotracker", process = ?res, state = ?state); + // initialize viperus structure + let mut viperus = Viperus::new(); - // initialize viperus structure - let mut viperus = Viperus::new(); + // parse commandline arguments + res = t!(parse_arguments => lang); + state = t!(state_started => lang); + trace!(target: "advotracker", process = ?res, state = ?state); - // parse commandline arguments - res = t!(parse_arguments => lang); - state = t!(state_started => lang); - trace!(target: "advotracker", process = ?res, state = ?state); + let _ = parse_args(&mut viperus); + state = t!(state_finished => lang); + trace!(target: "advotracker", process = ?res, state = ?state); - let _ = parse_args(&mut viperus); - state = t!(state_finished => lang); - trace!(target: "advotracker", process = ?res, state = ?state); + // type conversion (viperus String -> u64) + let test_policy_number = viperus.get::("test_policy_number").unwrap().parse::().unwrap(); + trace!(target: "advotracker", test_policy_number = ?test_policy_number); - // type conversion (viperus String -> u64) - let test_policy_number = viperus.get::("test_policy_number").unwrap().parse::().unwrap(); - trace!(target: "advotracker", test_policy_number = ?test_policy_number); + // main tasks + res = t!(main_started => lang); + state = t!(state_started => lang); + trace!(target: "advotracker", process = ?res, state = ?state); - // main tasks - res = t!(main_started => lang); - state = t!(state_started => lang); - trace!(target: "advotracker", process = ?res, state = ?state); + // use this only if you want to run it as web application. + orbtk::initialize(); - // use this only if you want to run it as web application. - orbtk::initialize(); + // Preset localization and language from given environment. + // if no dictionary is set for the chosen default language + // the content of the text property will be drawn. + let localization = RonLocalization::create() + .language("de") + .dictionary("de_DE", ADVOTRACKER_DE_DE) + .build(); - // Preset localization and language from given environment. - // if no dictionary is set for the chosen default language - // the content of the text property will be drawn. - let localization = RonLocalization::create() - .language(&lang) - .dictionary("de_DE", ADVOTRACKER_DE_DE) - .build(); + Application::from_name("nwx.advotracker") + .localization(localization) + .theme(theme()) + .window(|ctx| { + Window::new() + .title("AdvoTracker - DirectCall") + .position((500.0, 100.0)) + .size(800.0, 620.0) + //.min_width(460.0) + //.min_height(380.0) + .resizeable(true) + .child(main_view::MainView::new().build(ctx)) + .build(ctx) + }) + .run(); - Application::from_name("nwx.advotracker") - .localization(localization) - .theme(theme()) - .window(|ctx| { - Window::new() - .title("AdvoTracker - DirectCall") - .position((500.0, 100.0)) - .size(800.0, 620.0) - //.min_width(460.0) - //.min_height(380.0) - .resizeable(true) - .child(main_view::MainView::new().build(ctx)) - .build(ctx) - }) - .run(); - - state = t!(state_finished => lang); - res = t!(main_finished => lang); - trace!(target: "advotracker", process = ?res, state = ?state); + state = t!(state_finished => lang); + res = t!(main_finished => lang); + trace!(target: "advotracker", process = ?res, state = ?state); }); Ok(()) @@ -218,6 +218,6 @@ fn main() -> Result<(), Box> { mod tests { #[test] fn it_works() { - assert_eq!(2 + 2, 4); + assert_eq!(2 + 2, 4); } } diff --git a/crates/advotracker_client/src/services/exports/allianzdirectcall.rs b/crates/advotracker_client/src/services/exports/allianzdirectcall.rs index 30c038d..aa4a0da 100644 --- a/crates/advotracker_client/src/services/exports/allianzdirectcall.rs +++ b/crates/advotracker_client/src/services/exports/allianzdirectcall.rs @@ -6,21 +6,19 @@ */ //use chrono::{Local, DateTime}; -use locales::t; use std::error::Error; use tracing::trace; +use crate::Lang; + /// export as csv format /// https://docs.rs/csv/1.1.3/csv/cookbook/index.html /// https://blog.burntsushi.net/csv/ -pub fn export(p: &mut String, lang: &str) -> Result<(), Box> { +pub fn export(p: &mut String, lang: &Lang) -> Result<(), Box> { use std::fs::File; use std::path::Path; //use std::ffi::OsStr; - // include localization strings - include!(concat!(env!("OUT_DIR"), "/i18n.rs")); - let mut res = t!(csv_export_started => lang); let mut state = t!(state_started => lang); trace!(target: "csv-export", process = ?res, state = ?state); @@ -33,7 +31,7 @@ pub fn export(p: &mut String, lang: &str) -> Result<(), Box> { trace!(target: "csv.export", extension = ?path.extension(), file = ?file); state = t!(state_finished => lang); - res = t!(csv_export_finished", lang); + res = t!(csv_export_finished => lang); trace!(target: "csv-export", process = ?res, state = ?state); Ok(()) diff --git a/crates/advotracker_client/src/services/exports/send_ticketdata.rs b/crates/advotracker_client/src/services/exports/send_ticketdata.rs index 2268564..7037bf0 100644 --- a/crates/advotracker_client/src/services/exports/send_ticketdata.rs +++ b/crates/advotracker_client/src/services/exports/send_ticketdata.rs @@ -10,19 +10,18 @@ use lettre::{ Message, SmtpTransport, Transport, transport::smtp::authentication::Credentials, }; -use locales::t; use maud::html; use std::error::Error; //use std::process; use tracing::{info, trace}; -use crate::data::structures::Email; +use crate::{ + data::structures::Email, + Lang, +}; /// send ticket data via eMail -pub fn sendticketdata(email: &Email, lang: &str) -> Result<(), Box> { - // include localization strings - include!(concat!(env!("OUT_DIR"), "/i18n.rs")); - +pub fn sendticketdata(email: &Email, lang: &Lang) -> Result<(), Box> { let mut res = t!(sendticketdata_export_started => lang); let mut state = t!(state_started =>lang); trace!(target: "sendticketdata", process = ?res, state = ?state); @@ -30,67 +29,67 @@ pub fn sendticketdata(email: &Email, lang: &str) -> Result<(), Box> { // The html we want to send. // It uses https://crates.io/crates/maud let html = html! { - head { - title { (email.subject) " (" (email.policy_code) ")" } - style type="text/css" { - "h2, h4 { font-family: Arial, Helvetica, sans-serif; }" - } - } - div style="display: flex; flex-direction: column; align-items: left;" { - // compose with variables and strings - h2 { (email.subject) " (" (email.policy_code) ")" } - p { "Vers.-Schein/Schadennummer: " (email.policy_code) } - p { "Versicherungsnehmer: " (email.policy_holder) } - p { "Selbstbehalt: " (email.deductible) } - p { "Rückrufnummer: " (email.callback_number) } - p { "Erreichbarkeit: " (email.callback_date) } - p { "Rechtsproblem: " (email.harm_type) } - p { "Rechtsrat: " (email.ivr_comment) } - } + head { + title { (email.subject) " (" (email.policy_code) ")" } + style type="text/css" { + "h2, h4 { font-family: Arial, Helvetica, sans-serif; }" + } + } + div style="display: flex; flex-direction: column; align-items: left;" { + // compose with variables and strings + h2 { (email.subject) " (" (email.policy_code) ")" } + p { "Vers.-Schein/Schadennummer: " (email.policy_code) } + p { "Versicherungsnehmer: " (email.policy_holder) } + p { "Selbstbehalt: " (email.deductible) } + p { "Rückrufnummer: " (email.callback_number) } + p { "Erreichbarkeit: " (email.callback_date) } + p { "Rechtsproblem: " (email.harm_type) } + p { "Rechtsrat: " (email.ivr_comment) } + } }; 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); let message = Message::builder() - .from((email.mail_from).parse().unwrap()) - .reply_to((email.mail_reply).parse().unwrap()) - .to((email.mail_to).parse().unwrap()) - .cc((email.mail_cc).parse().unwrap()) - // we do not use bcc yet - //.bcc((email.mail_bcc).parse().unwrap()) - .subject(String::new() - + &email.subject.to_string() - + &" (".to_string() - + &email.policy_code.to_string() - + &")".to_string() - ) - .multipart( - MultiPart::alternative() // This is composed of two parts. - .singlepart( - SinglePart::builder() - .header(header::ContentType( - "text/plain; charset=utf8".parse().unwrap(), - )) - .body(String::from(ascii_body)), - ) - .singlepart( - SinglePart::builder() - .header(header::ContentType( - "text/html; charset=utf8".parse().unwrap(), - )) - .body(html.into_string()), - ), - ) - .expect("failed to build email"); + .from((email.mail_from).parse().unwrap()) + .reply_to((email.mail_reply).parse().unwrap()) + .to((email.mail_to).parse().unwrap()) + .cc((email.mail_cc).parse().unwrap()) + // we do not use bcc yet + //.bcc((email.mail_bcc).parse().unwrap()) + .subject(String::new() + + &email.subject.to_string() + + &" (".to_string() + + &email.policy_code.to_string() + + &")".to_string() + ) + .multipart( + MultiPart::alternative() // This is composed of two parts. + .singlepart( + SinglePart::builder() + .header(header::ContentType( + "text/plain; charset=utf8".parse().unwrap(), + )) + .body(String::from(ascii_body)), + ) + .singlepart( + SinglePart::builder() + .header(header::ContentType( + "text/html; charset=utf8".parse().unwrap(), + )) + .body(html.into_string()), + ), + ) + .expect("failed to build email"); info!("message: {:?}", message); @@ -108,9 +107,9 @@ pub fn sendticketdata(email: &Email, lang: &str) -> Result<(), Box> { let relay = "smtp.strato.de"; let mailer = SmtpTransport::relay(relay) - .unwrap() - .credentials(credentials) - .build(); + .unwrap() + .credentials(credentials) + .build(); trace!(target: "sendticketdata", email = ?email); diff --git a/crates/advotracker_client/src/services/imports/allianzdirectcall.rs b/crates/advotracker_client/src/services/imports/allianzdirectcall.rs index fd1bbe5..b9c1d19 100644 --- a/crates/advotracker_client/src/services/imports/allianzdirectcall.rs +++ b/crates/advotracker_client/src/services/imports/allianzdirectcall.rs @@ -6,34 +6,32 @@ */ use chrono::{Local, DateTime}; -use locales::t; use std::error::Error; use std::collections::HashMap; use std::time::{Duration, SystemTime}; use tracing::trace; //use crate::db::redis; -use crate::data::structures::{PolicyCode, PolicyDataList, PolicyData}; -//use crate::data::structures::PolicyDataList; +use crate::{ + data::structures::{PolicyCode, PolicyDataList, PolicyData}, + Lang, +}; /// import AllianzDirectCall data from a csv delimeted file /// save records to redis backend /// https://docs.rs/csv/1.1.3/csv/cookbook/index.html /// https://blog.burntsushi.net/csv/ pub fn import(p: &mut String, data_list: &mut PolicyDataList, - policy_numbers: &mut HashMap, - policy_data_count: &mut u64, - lang: &str) - -> Result<(u64, Duration), Box> { + policy_numbers: &mut HashMap, + policy_data_count: &mut u64) + -> Result<(u64, Duration), Box> { use std::fs::File; use std::path::Path; use std::ffi::OsStr; - // include localization strings - include!(concat!(env!("OUT_DIR"), "/i18n.rs")); - - let mut res = t!("csv.import.started", lang); - let mut state = t!("state.started", lang); + let lang = Lang::De(""); + let mut res = t!(csv_import_started => lang); + let mut state = t!(state_started => lang); let time_start = SystemTime::now(); let datetime: DateTime = time_start.into(); @@ -56,45 +54,45 @@ pub fn import(p: &mut String, data_list: &mut PolicyDataList, // Build the CSV reader let mut csv_reader = csv::ReaderBuilder::new() - .has_headers(true) - .delimiter(b' ') - //.comment(Some(b'#')) - //.flexible(true) - .from_reader(file); + .has_headers(true) + .delimiter(b' ') + //.comment(Some(b'#')) + //.flexible(true) + .from_reader(file); { - // We nest this call in its own scope because of lifetimes. - let headers = csv_reader.headers()?; - trace!(target: "csv-import", header = ?headers); + // We nest this call in its own scope because of lifetimes. + let headers = csv_reader.headers()?; + trace!(target: "csv-import", header = ?headers); } // Iterate over each record, deserialize und write to our structures let mut count : u64 = 0; for result in csv_reader.deserialize() { - // The iterator yields Result, so we check the - // error here. - let record: PolicyData = result?; - //if verbose > 3 { - // println!("{:?}", record); - //} + // The iterator yields Result, so we check the + // error here. + let record: PolicyData = result?; + //if verbose > 3 { + // println!("{:?}", record); + //} - // WIP: write to redis backend - // for now: append the policy_number to the HashMap - policy_numbers.insert(record.policy_number, record.policy_code); + // WIP: write to redis backend + // for now: append the policy_number to the HashMap + policy_numbers.insert(record.policy_number, record.policy_code); - // push record as new vector elements - data_list.push(record); + // push record as new vector elements + data_list.push(record); - count +=1; - *policy_data_count = count; + count +=1; + *policy_data_count = count; }; let time_end = SystemTime::now(); let duration = time_end.duration_since(time_start) - .expect("Clock may have gone backwards"); + .expect("Clock may have gone backwards"); trace!(target: "csv-import", record_count = ?count, duration = ?duration); - state = t!("state.finished", lang); - res = t!("csv.import.finished", lang); + state = t!(state_finished => lang); + res = t!(csv_import_finished => lang); let datetime: DateTime = time_end.into(); trace!(target: "csv-import", process = ?res, state = ?state, date_stop = ?datetime.to_string()); @@ -114,23 +112,23 @@ fn test_import() { let lang = "en".to_string(); match import(&mut csv_import_path, &mut policy_data, - &mut policy_numbers, &mut policy_data_count, - &lang) { - Ok((count, duration)) => { - println!("import {:?} records. Duration: {:?}", count, duration); - } - Err(err) => { - println!("error running CSV-Import: {}", err); - } + &mut policy_numbers, &mut policy_data_count, + &lang) { + Ok((count, duration)) => { + println!("import {:?} records. Duration: {:?}", count, duration); + } + Err(err) => { + println!("error running CSV-Import: {}", err); + } }; for p in &my_policy_numbers { - match policy_numbers.get(&p) { - Some(policy_code) => { - println!("Test: Policy-Number {:?} => Policy-Type {:?}, as expected!", - p, policy_code); - }, - _ => println!("Test: Policy-Number {:?} => not valid, can't dereference the Policy-Type as expected", p), - } + match policy_numbers.get(&p) { + Some(policy_code) => { + println!("Test: Policy-Number {:?} => Policy-Type {:?}, as expected!", + p, policy_code); + }, + _ => println!("Test: Policy-Number {:?} => not valid, can't dereference the Policy-Type as expected", p), + } } } diff --git a/crates/advotracker_client/src/widgets/policycheck/policycheck_state.rs b/crates/advotracker_client/src/widgets/policycheck/policycheck_state.rs index 6e82e0b..07aa529 100644 --- a/crates/advotracker_client/src/widgets/policycheck/policycheck_state.rs +++ b/crates/advotracker_client/src/widgets/policycheck/policycheck_state.rs @@ -5,7 +5,6 @@ * SPDX-License-Identifier: (0BSD or MIT) */ -use locales::t; use orbtk::prelude::*; use serde::Deserialize; @@ -16,9 +15,10 @@ use tracing::{error, info, trace}; use crate::{ data::{ - structures::{PolicyCode, PolicyDataList, PolicyList}, - constants::*, + structures::{PolicyCode, PolicyDataList, PolicyList}, + constants::*, }, + Lang, //services::imports::allianzdirectcall::import, services::imports::allianzdirectcall, widgets::global_state::GlobalState, @@ -68,7 +68,7 @@ pub struct PolicycheckState { button_menu: Entity, duration: Duration, label_result: Entity, - lang: String, + lang: Lang, policy_data_count: u64, //policy_number: Entity, policy_numbers: HashMap, @@ -86,267 +86,263 @@ impl GlobalState for PolicycheckState {} impl PolicycheckState { /// Create a hashmap (key: policy number, value: policy type). pub fn create_hashmap(&mut self, _ctx: &mut Context<'_>) - -> Result<(), Box> { - trace!(target: "advotracker", create_hashmap = "started"); + -> Result<(), Box> { + trace!(target: "advotracker", create_hashmap = "started"); - let policy_list = PolicyList::new("policy list"); - trace!(target: "advotracker", policy_list = ?policy_list); + let policy_list = PolicyList::new("policy list"); + trace!(target: "advotracker", policy_list = ?policy_list); - // include localization strings - include!(concat!(env!("OUTDIR"), "/i18n.rs")); + // create vector to hold imported data + let res = t!(policy_string_label_policy_data => self.lang); + let mut policy_data = PolicyDataList::new(res); + trace!(target: "advotracker", policy_data = ?policy_data); - // create vector to hold imported data - let res = t!(policy_string_label_policy_data => self.lang); - let mut policy_data = PolicyDataList::new(res); - trace!(target: "advotracker", policy_data = ?policy_data); + let mut policy_numbers : HashMap = HashMap::new(); - let mut policy_numbers : HashMap = HashMap::new(); + // Wip: use cli parameter stored in viperus ... + //let mut csv_import_path = v.get::("import_file").unwrap(); + let mut csv_import_path = String::from("POLLFNR_WOECHENTLICH.txt"); + match allianzdirectcall::import(&mut csv_import_path, &mut policy_data, + &mut policy_numbers, &mut self.policy_data_count) { + Ok((count, duration)) => { + self.policy_data_count = count; + self.duration = duration; + trace!(target: "advotracker", csv_import_path = ?csv_import_path, + policy_data_count = ?&self.policy_data_count, + duration = ?&self.duration); + } + Err(err) => { + error!("error running CSV-Import: {}", err); + process::exit(1); + } + }; - // Wip: use cli parameter stored in viperus ... - //let mut csv_import_path = v.get::("import_file").unwrap(); - let mut csv_import_path = String::from("POLLFNR_WOECHENTLICH.txt"); - match allianzdirectcall::import(&mut csv_import_path, &mut policy_data, - &mut policy_numbers, &mut self.policy_data_count, - &self.lang) { - Ok((count, duration)) => { - self.policy_data_count = count; - self.duration = duration; - trace!(target: "advotracker", csv_import_path = ?csv_import_path, - policy_data_count = ?&self.policy_data_count, - duration = ?&self.duration); - } - Err(err) => { - error!("error running CSV-Import: {}", err); - process::exit(1); - } - }; + self.policy_numbers = policy_numbers; - self.policy_numbers = policy_numbers; + trace!(target: "advotracker", create_hashmap = "finished"); - trace!(target: "advotracker", create_hashmap = "finished"); - - Ok(()) + Ok(()) } /// Clear text in text box. pub fn clear_policy_number(&mut self, ctx: &mut Context<'_>) { - TextBox::text_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("")); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); - Stack::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_STACK), Visibility::Collapsed); + TextBox::text_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("")); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); + Stack::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_STACK), Visibility::Collapsed); } /// Import policy numbers into hashmap fn import_data(&mut self, ctx: &mut Context<'_>) - -> Result<(), Box> { - // WIP: for now, only import once per session - if self.policy_data_count == 0 { - TextBlock::enabled_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), true); + -> Result<(), Box> { + // WIP: for now, only import once per session + if self.policy_data_count == 0 { + TextBlock::enabled_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), true); - if self.policy_numbers.is_empty() { - // initialize popup widget - self.set_popup_progress(ctx); - self.progress_count += 0.33; - self.update_progress_bar(ctx); + if self.policy_numbers.is_empty() { + // initialize popup widget + self.set_popup_progress(ctx); + self.progress_count += 0.33; + self.update_progress_bar(ctx); - for _ in 1..4 { - self.progress_count += 0.33; - self.update_progress_bar(ctx); - ctx.send_message(PolicycheckAction::UpdateProgress(self.progress_count), self.progress_popup); - } + for _ in 1..4 { + self.progress_count += 0.33; + self.update_progress_bar(ctx); + ctx.send_message(PolicycheckAction::UpdateProgress(self.progress_count), self.progress_popup); + } - // importing policy code elements from csv-file - match self.create_hashmap(ctx) { - Ok(()) => { - let res = t!(policy_hashmap_success => self.lang); - info!("hashmap has: {:?} entries", self.policy_data_count); - trace!(target: "advotracker", - hashmap_status = ?res, - hashmap_entries = ?self.policy_data_count); + // importing policy code elements from csv-file + match self.create_hashmap(ctx) { + Ok(()) => { + let res = t!(policy_hashmap_success => self.lang); + info!("hashmap has: {:?} entries", self.policy_data_count); + trace!(target: "advotracker", + hashmap_status = ?res, + hashmap_entries = ?self.policy_data_count); - self.progress_count = 1.; - self.update_progress_bar(ctx); + self.progress_count = 1.; + self.update_progress_bar(ctx); - } - _ => { - let res = t!(policy_hashmap_failed => self.lang); - error!("{:?}", res); - trace!(target: "advotracker", hashmap_status = ?res); - } - } - } - } else { - trace!(target: "advotracker", - hashmap_status = "consume", - hashmap_entries = ?self.policy_data_count); - } + } + _ => { + let res = t!(policy_hashmap_failed => self.lang); + error!("{:?}", res); + trace!(target: "advotracker", hashmap_status = ?res); + } + } + } + } else { + trace!(target: "advotracker", + hashmap_status = "consume", + hashmap_entries = ?self.policy_data_count); + } - Ok(()) + Ok(()) } /// Create new ticket pub fn new_ticket(&mut self, _ctx: &mut Context<'_>) { - println!("WIP: new ticket."); - self.ticketdata_view.0; - //ctx.widget().get_mut::(0). - //ctx.get_widget(self.ticketdata_view); + println!("WIP: new ticket."); + self.ticketdata_view.0; + //ctx.widget().get_mut::(0). + //ctx.get_widget(self.ticketdata_view); } /// Parse validity of the given policy number. pub fn parse_entry(&mut self, policy_check_policy_number: Entity, - ctx: &mut Context<'_>) { - trace!(target: "advotracker", parse_entry = "started"); + ctx: &mut Context<'_>) { + trace!(target: "advotracker", parse_entry = "started"); - let policy_number_string = TextBox::text_clone(&ctx.get_widget(policy_check_policy_number)); - let policy_number_length = policy_number_string.len(); + let policy_number_string = TextBox::text_clone(&ctx.get_widget(policy_check_policy_number)); + let policy_number_length = policy_number_string.len(); - if self.policy_data_count == 0 { - // Load data into hashmap - match self.import_data(ctx) { - Ok(()) => { - trace!(target: "advotracker", policycheck_state = "init", import_data = "success"); - Stack::visibility_set(&mut ctx.child(ID_POLICY_DATA_STACK), Visibility::Visible); - let policy_data_count_string = format!("{:?}", &self.policy_data_count); - TextBlock::text_set(&mut ctx.child(ID_POLICY_DATA_COUNT), String::from(&policy_data_count_string)); - }, + if self.policy_data_count == 0 { + // Load data into hashmap + match self.import_data(ctx) { + Ok(()) => { + trace!(target: "advotracker", policycheck_state = "init", import_data = "success"); + Stack::visibility_set(&mut ctx.child(ID_POLICY_DATA_STACK), Visibility::Visible); + let policy_data_count_string = format!("{:?}", &self.policy_data_count); + TextBlock::text_set(&mut ctx.child(ID_POLICY_DATA_COUNT), String::from(&policy_data_count_string)); + }, - Err(e) => trace!(target: "advotracker", policycheck_state = "init", import_data = ?e), - } - } + Err(e) => trace!(target: "advotracker", policycheck_state = "init", import_data = ?e), + } + } - trace!(target: "advotracker", state = "parsing", policy_number = ?policy_number_string); + trace!(target: "advotracker", state = "parsing", policy_number = ?policy_number_string); - // Parse policy code: "AS-123456789" - // DION VERS POLLFNR - // 1 AS 1515735810 - Stack::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_STACK), Visibility::Collapsed); - Button::background_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("transparent")); + // Parse policy code: "AS-123456789" + // DION VERS POLLFNR + // 1 AS 1515735810 + Stack::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_STACK), Visibility::Collapsed); + Button::background_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("transparent")); - if policy_number_length == 10 { - // cast policy_number_sting to - match policy_number_string.parse::() { - Ok(p) => { - TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), String::from("")); + if policy_number_length == 10 { + // cast policy_number_sting to + match policy_number_string.parse::() { + Ok(p) => { + TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), String::from("")); - // match hashmap's key - match self.policy_numbers.get(&p) { - Some(policy_code) => { - // matching key, get associated value - trace!(target: "advotracker", state = "success", - policy_number = ?p, policy_code = ?policy_code); + // match hashmap's key + match self.policy_numbers.get(&p) { + Some(policy_code) => { + // matching key, get associated value + trace!(target: "advotracker", state = "success", + policy_number = ?p, policy_code = ?policy_code); - let string_result = format!("1-{:?}-{}", - policy_code, p); + let string_result = format!("1-{:?}-{}", + policy_code, p); - // adapt the view properties - TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), string_result); - TextBox::foreground_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("#008000")); + // adapt the view properties + TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), string_result); + TextBox::foreground_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("#008000")); - Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#008000")); - Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#008000")); - Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CHECK); - Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); + Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#008000")); + Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#008000")); + Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CHECK); + Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_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_LABEL_RESULT), Visibility::Visible); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Visible); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Collapsed); - Stack::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_STACK), Visibility::Visible); - Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_BUTTON_CLEAR), Visibility::Visible); - } - _ => { - // no matching key - let res = t!(policy_validation_failed => self.lang); - trace!(target: "advotracker", state = ?res, policy_number = ?p); + Stack::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_STACK), Visibility::Visible); + Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_BUTTON_CLEAR), Visibility::Visible); + } + _ => { + // no matching key + let res = t!(policy_validation_failed => self.lang); + trace!(target: "advotracker", state = ?res, policy_number = ?p); - TextBox::foreground_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("#FF0000")); - TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_HINT), String::from("The given policy number is invalid")); + TextBox::foreground_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("#FF0000")); + TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_HINT), String::from("The given policy number is invalid")); - Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); - Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); - Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CLEAR); - Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); + Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); + Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); + Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CLEAR); + Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); - } - } - }, - Err(e) => { - trace!(target: "advotracker", state = "error", error_type = "invalid type", error = ?e); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); + } + } + }, + Err(e) => { + trace!(target: "advotracker", state = "error", error_type = "invalid type", error = ?e); - TextBox::foreground_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("#FF0000")); + TextBox::foreground_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("#FF0000")); - TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_HINT), String::from("Only numbers are valid")); + TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_HINT), String::from("Only numbers are valid")); - Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); - Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); - Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CLEAR); - Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); + Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); + Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); + Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CLEAR); + Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); - } - } - } - if policy_number_length < 10 { - let res = t!(policy_validation_failed => self.lang); - trace!(target: "advotracker", state = ?res, reason = "number to short"); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); + } + } + } + if policy_number_length < 10 { + let res = t!(policy_validation_failed => self.lang); + trace!(target: "advotracker", state = ?res, reason = "number to short"); - TextBox::foreground_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("#FF0000")); + TextBox::foreground_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("#FF0000")); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); - TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_HINT), String::from("Policy number is to short")); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); + TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_HINT), String::from("Policy number is to short")); - Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); - Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); - Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CLEAR); - Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); + Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); + Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); + Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CLEAR); + Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); - } - if policy_number_length > 10 { - let res = t!(policy_validation_failed => self.lang); - trace!(target: "advotracker", state = ?res, reason = "number to long"); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); + } + if policy_number_length > 10 { + let res = t!(policy_validation_failed => self.lang); + trace!(target: "advotracker", state = ?res, reason = "number to long"); - TextBox::foreground_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("#FF0000")); + TextBox::foreground_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_NUMBER), String::from("#FF0000")); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); - TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_HINT), String::from("Policy number is to long")); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); + TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_HINT), String::from("Policy number is to long")); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); - Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); - Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); - Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CLEAR); - Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); + Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); + Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000")); + Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CLEAR); + Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); - } + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_HINT), Visibility::Visible); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_HINT), Visibility::Visible); + } - 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)); + 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); - println!("Popup {:?} removed !", id); + ctx.remove_child(self.progress_popup); + println!("Popup {:?} removed !", id); } // /// If TextBox 'policy_check_policy_number' is empty, disable button "clear" @@ -364,79 +360,79 @@ impl PolicycheckState { /// Sending message 'UpdatePolicyCode' pub fn send_message_update_policy_code(&mut self, entity: Entity) { - println!("WIP: send_message_update_policy_code = {:?}", entity); - //self.actions.push(PolicycheckAction::UpdatePolicyNumber("4711".to_string())); - //let policy_number = (ctx.get_child(entity).get::("text")); - //println!("WIP: poliy_number = {:?}", policy_number); - //self.actions.push(PolicycheckAction::UpdatePolicyNumber(self.policy_number)); + println!("WIP: send_message_update_policy_code = {:?}", entity); + //self.actions.push(PolicycheckAction::UpdatePolicyNumber("4711".to_string())); + //let policy_number = (ctx.get_child(entity).get::("text")); + //println!("WIP: poliy_number = {:?}", policy_number); + //self.actions.push(PolicycheckAction::UpdatePolicyNumber(self.policy_number)); } /// Change status of given text box to edit mode. fn set_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) { - if ctx.get_widget(text_box).get::("text").is_empty() { - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); - } else { - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Visible); - } + if ctx.get_widget(text_box).get::("text").is_empty() { + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Collapsed); + } else { + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), Visibility::Visible); + } } /// Set a progress popup that updates the import status in a progress bar fn set_popup_progress(&mut self, ctx: &mut Context<'_>) { - // create a stack as a child of entity "ID_POLICY_CHECK_POLICY_NUMBER" - let stack = ctx - .entity_of_child(ID_POLICY_CHECK_POLICY_NUMBER) - .expect("PolicycheckState: Can't find entity of resource 'ID_POLICY_CHECK_POLICY_NUMBER'."); - let current_entity = ctx.entity(); - let build_context = &mut ctx.build_context(); + // create a stack as a child of entity "ID_POLICY_CHECK_POLICY_NUMBER" + let stack = ctx + .entity_of_child(ID_POLICY_CHECK_POLICY_NUMBER) + .expect("PolicycheckState: Can't find entity of resource 'ID_POLICY_CHECK_POLICY_NUMBER'."); + let current_entity = ctx.entity(); + let build_context = &mut ctx.build_context(); - // create the progress_popup widget - self.progress_popup = create_popup_progress(current_entity, build_context); - info!("set_popup_progress: New entity 'popup_progress' {:?} created", self.progress_popup); + // create the progress_popup widget + self.progress_popup = create_popup_progress(current_entity, build_context); + info!("set_popup_progress: New entity 'popup_progress' {:?} created", self.progress_popup); - // append the stack inside the progress_popup - build_context.append_child(stack, self.progress_popup); + // append the stack inside the progress_popup + build_context.append_child(stack, self.progress_popup); - // make sure we have a progress bar - self.progress_bar = ctx - .entity_of_child(ID_POLICY_CHECK_PROGRESS_BAR) - .expect("PolicycheckState.init: Can't find entity of resource 'ID_POLICY_CHECK_PROGRESS_BAR'."); - info!("set_popup_progress: New entity 'progress_bar' created: {:?}", self.progress_bar); + // make sure we have a progress bar + self.progress_bar = ctx + .entity_of_child(ID_POLICY_CHECK_PROGRESS_BAR) + .expect("PolicycheckState.init: Can't find entity of resource 'ID_POLICY_CHECK_PROGRESS_BAR'."); + info!("set_popup_progress: New entity 'progress_bar' created: {:?}", self.progress_bar); } /// Change visibility of the result label. fn _set_visibility(&self, entity: Entity, ctx: &mut Context<'_>) { - if ctx.get_widget(entity).get::("text").is_empty() { - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Collapsed); - } else { - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); - } + if ctx.get_widget(entity).get::("text").is_empty() { + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Collapsed); + } else { + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible); + } } /// Update count of elements in the policy data list. fn _update_data_count(&self, ctx: &mut Context<'_>) { - let data_list_count = ctx.widget().get::(PROP_POLICY_DATA_LIST).len(); - ctx.widget().set(PROP_POLICY_DATA_COUNT, data_list_count); + let data_list_count = ctx.widget().get::(PROP_POLICY_DATA_LIST).len(); + ctx.widget().set(PROP_POLICY_DATA_COUNT, data_list_count); } fn update_progress_bar(&self, ctx: &mut Context<'_>) { - let res = t!(policy_string_progress_time => self.lang); - let string_duration = format!("{}: {:?}", res, self.duration); + let res = t!(policy_string_progress_time => self.lang); + let string_duration = format!("{}: {:?}", res, self.duration); - TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_TIME), string_duration); + TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_TIME), string_duration); - let mut progress_bar = ctx.child(ID_POLICY_CHECK_PROGRESS_BAR); - progress_bar.set::("val", self.progress_count); + let mut progress_bar = ctx.child(ID_POLICY_CHECK_PROGRESS_BAR); + progress_bar.set::("val", self.progress_count); } /// Update the policy code policy data list. fn update_policy_code(&self, _ctx: &mut Context<'_>) { - println!("update internal: policy_code"); - //let policy_code = ctx.widget().get::(ID_POLICY_CHECK_POLICY_CODE); - //ctx.widget().set(PROP_POLICY_DATA_COUNT, policy_code); + println!("update internal: policy_code"); + //let policy_code = ctx.widget().get::(ID_POLICY_CHECK_POLICY_CODE); + //ctx.widget().set(PROP_POLICY_DATA_COUNT, policy_code); } } @@ -445,188 +441,189 @@ impl PolicycheckState { impl State for PolicycheckState { /// Initialize the state of widgets inside `PolicycheckState` fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { - let time_start= SystemTime::now(); + let time_start= SystemTime::now(); - trace!(target: "advotracker", policycheck_state = "init", status = "started"); + trace!(target: "advotracker", policycheck_state = "init", status = "started"); - // Get language from environment - self.lang = PolicycheckState::get_lang(); + // Get language from environment + // self.lang = PolicycheckState::get_lang(); + self.lang = Lang::De(""); - // 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'."); + // 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'."); - 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'."); + 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'."); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), 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_LABEL_RESULT), Visibility::Collapsed); + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_POLICY_CODE), 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); - Stack::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_STACK), Visibility::Collapsed); + Stack::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_STACK), Visibility::Collapsed); - //self.policy_number = Entity::from(ctx.widget().try_clone::(ID_POLICY_CHECK_POLICY_NUMBER) - // .expect("PolicycheckState::init(): Can't find resource entity 'ID_POLICY_CHECK_POLICY_NUMBER'.")); + //self.policy_number = Entity::from(ctx.widget().try_clone::(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::("target") - .expect("PolicycheckState::init(): Can't find resource entity 'target'.")); + self.target = Entity::from(ctx.widget().try_clone::("target") + .expect("PolicycheckState::init(): Can't find resource entity 'target'.")); - //self.ticketdata_view = (*ctx.widget().get::("ticketdata_view")).into(); - //self.ticketdata = Entity::from(ctx.widget().try_clone::(ID_TICKET_DATA_VIEW) - // .expect("PolicycheckState::init(): Can't find resource entity 'ticketdata'.")); + //self.ticketdata_view = (*ctx.widget().get::("ticketdata_view")).into(); + //self.ticketdata = Entity::from(ctx.widget().try_clone::(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 - // // (Windows: AppData, Unix: XDG_CONFIG_HOME, MacOS: $HOME/Library/Preferences). - // // The filename is taken from the propertey PROP_ADVOTRACKER (default: 'advotracker'.ron). - // if let Ok(policy_data) = registry - // .get::("settings") - // .load::(PROP_ADVOTRACKER) - // { - // ctx.widget().set(PROP_ADVOTRACKER, policy_data); - // } + // // 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 + // // (Windows: AppData, Unix: XDG_CONFIG_HOME, MacOS: $HOME/Library/Preferences). + // // The filename is taken from the propertey PROP_ADVOTRACKER (default: 'advotracker'.ron). + // if let Ok(policy_data) = registry + // .get::("settings") + // .load::(PROP_ADVOTRACKER) + // { + // ctx.widget().set(PROP_ADVOTRACKER, policy_data); + // } - let time_end = SystemTime::now(); - let duration = time_end.duration_since(time_start); + let time_end = SystemTime::now(); + let duration = time_end.duration_since(time_start); - trace!(target: "advotracker", policycheck_state = "init", status = "finished", duration = ?duration); + trace!(target: "advotracker", policycheck_state = "init", status = "finished", duration = ?duration); } /// Handle messages for `PolicycheckState`. fn messages( - &mut self, - mut messages: MessageReader, - _registry: &mut Registry, - ctx: &mut Context<'_>, + &mut self, + mut messages: MessageReader, + _registry: &mut Registry, + ctx: &mut Context<'_>, ) { - for message in messages.read::() { - match message { - PolicycheckAction::ClearPolicyNumber => { - self.clear_policy_number(ctx); - } - PolicycheckAction::NewTicket => { - self.new_ticket(ctx); - } - PolicycheckAction::UpdatePolicyCode => { - self.update_policy_code(ctx); - } - PolicycheckAction::UpdateProgress(increment) => { - let old_width = ProgressBar::val_clone(&ctx.child(ID_POLICY_CHECK_PROGRESS_BAR)); + for message in messages.read::() { + match message { + PolicycheckAction::ClearPolicyNumber => { + self.clear_policy_number(ctx); + } + PolicycheckAction::NewTicket => { + self.new_ticket(ctx); + } + PolicycheckAction::UpdatePolicyCode => { + self.update_policy_code(ctx); + } + 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.); - } - } - _ => { println!("PolicycheckAction: action not implemented!"); } - } - } + 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.); + } + } + _ => { println!("PolicycheckAction: action not implemented!"); } + } + } } /// Update the state of widgets inside the `Policycheck` view. fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) { - // // clear focus on focus moved - // if self.last_focused != ctx.window().get::("global").focused_widget { - // if let Some(last_focused) = self.last_focused { - // ctx.get_widget(last_focused).set("focused", false); - // // widget is unvisible, but takes space to be considered - // ctx.get_widget(last_focused) - // .set("visibility", Visibility::Collapsed); - // } - //} + // // clear focus on focus moved + // if self.last_focused != ctx.window().get::("global").focused_widget { + // if let Some(last_focused) = self.last_focused { + // ctx.get_widget(last_focused).set("focused", false); + // // widget is unvisible, but takes space to be considered + // ctx.get_widget(last_focused) + // .set("visibility", Visibility::Collapsed); + // } + //} - // Create `actions`, a drained iterator (".." => full range that clears the vector) - let actions: Vec = self.actions.drain(..).collect(); + // Create `actions`, a drained iterator (".." => full range that clears the vector) + let actions: Vec = self.actions.drain(..).collect(); - for action in actions { - match action { - PolicycheckAction::ClearPolicyNumber => { - println!("clear entry"); - self.clear_policy_number(ctx); - } - PolicycheckAction::InputTextChanged(entity) => { - println!("entry changed: {}", TextBox::text_clone(&ctx.get_widget(entity))); - } - PolicycheckAction::ImportData => { - match self.import_data(ctx) { - Ok(()) => { - trace!(target: "advotracker", import_data = "success"); - } - _ => { - error!("Importing data failed!"); - trace!(target: "advotracker", import_data = "failed"); - } - } - } - PolicycheckAction::NewTicket => { - self.new_ticket(ctx); - } - PolicycheckAction::ParsePolicyNumber(text_box) => { - self.parse_entry(text_box, ctx); - } - PolicycheckAction::RemoveFocus(policy_check_policy_number) => { - ctx.get_widget(policy_check_policy_number).set("enabled", false); - //ctx.EventAdapter(FocusEvent::RemoveFocus(policy_check_policy_number)); - } - PolicycheckAction::RemovePopup(entity) => { - self.remove_popup(entity, ctx); - } - PolicycheckAction::ResetProgress => { - ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 0.); - } - PolicycheckAction::SetEntry(policy_check_policy_number) => { - //self.last_focused = Some(); - self.set_entry(policy_check_policy_number, ctx); - } - PolicycheckAction::SetProgress(value) => { - if value >= 0. || value <= 1. { - ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), value); - } else { - ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 0.); - } } - PolicycheckAction::SetProgressPopup(_entity) => { - self.set_popup_progress(ctx); - } - PolicycheckAction::SetVisibility(_entity) => { - TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); - } - PolicycheckAction::TextChanged(entity, _index) => { - self.set_entry(entity, ctx); - } - PolicycheckAction::UpdatePolicyCode => { - self.update_policy_code(ctx); + for action in actions { + match action { + PolicycheckAction::ClearPolicyNumber => { + println!("clear entry"); + self.clear_policy_number(ctx); + } + PolicycheckAction::InputTextChanged(entity) => { + println!("entry changed: {}", TextBox::text_clone(&ctx.get_widget(entity))); + } + PolicycheckAction::ImportData => { + match self.import_data(ctx) { + Ok(()) => { + trace!(target: "advotracker", import_data = "success"); + } + _ => { + error!("Importing data failed!"); + trace!(target: "advotracker", import_data = "failed"); + } + } + } + PolicycheckAction::NewTicket => { + self.new_ticket(ctx); + } + PolicycheckAction::ParsePolicyNumber(text_box) => { + self.parse_entry(text_box, ctx); + } + PolicycheckAction::RemoveFocus(policy_check_policy_number) => { + ctx.get_widget(policy_check_policy_number).set("enabled", false); + //ctx.EventAdapter(FocusEvent::RemoveFocus(policy_check_policy_number)); + } + PolicycheckAction::RemovePopup(entity) => { + self.remove_popup(entity, ctx); + } + PolicycheckAction::ResetProgress => { + ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 0.); + } + PolicycheckAction::SetEntry(policy_check_policy_number) => { + //self.last_focused = Some(); + self.set_entry(policy_check_policy_number, ctx); + } + PolicycheckAction::SetProgress(value) => { + if value >= 0. || value <= 1. { + ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), value); + } else { + ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 0.); + } } + PolicycheckAction::SetProgressPopup(_entity) => { + self.set_popup_progress(ctx); + } + PolicycheckAction::SetVisibility(_entity) => { + TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); + } + PolicycheckAction::TextChanged(entity, _index) => { + self.set_entry(entity, ctx); + } + PolicycheckAction::UpdatePolicyCode => { + self.update_policy_code(ctx); - //info!("Message send: 'PolicycheckAction::UpdatePolicyNumber({:?}) -> {:?}'", policy_number, self.target); - //let policy_number = (&mut ctx.get_widget(entity).get::("text")); - //let policy_number = ctx.get_widget(ID_POLICY_CHECK_POLICY_NUMBER).get::("text"); - //ctx.send_message(PolicycheckAction::UpdatePolicyCode("AS-1-4711".to_string()), self.target); - //ctx.send_message(PolicycheckAction::UpdatePolicyCode, self.target); + //info!("Message send: 'PolicycheckAction::UpdatePolicyNumber({:?}) -> {:?}'", policy_number, self.target); + //let policy_number = (&mut ctx.get_widget(entity).get::("text")); + //let policy_number = ctx.get_widget(ID_POLICY_CHECK_POLICY_NUMBER).get::("text"); + //ctx.send_message(PolicycheckAction::UpdatePolicyCode("AS-1-4711".to_string()), self.target); + //ctx.send_message(PolicycheckAction::UpdatePolicyCode, self.target); - //let mut widget_container : WidgetContainer = ctx.widget(); - //widget_container.get::("text"); - //let polnum: TextBox = TextBox::get(ctx.child(ID_POLICY_CHECK_POLICY_NUMBER)); - //println!("Policy number: {:?}", polnum); + //let mut widget_container : WidgetContainer = ctx.widget(); + //widget_container.get::("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 = 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::("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); - } - _ => (), - } - } + //let policy_number_string = ctx.get_widget(entity).get::("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); + } + _ => (), + } + } } // /// Update the view after the layout is rendered. @@ -637,51 +634,51 @@ impl State for PolicycheckState { /// Create a progress popup with update status of an onging data import fn create_popup_progress(id: Entity, ctx: &mut BuildContext<'_>) -> Entity { Popup::new() - .id(ID_POLICY_CHECK_POPUP_PROGRESS) - .target(id.0) - .open(true) - .style("popup_progress") - .width(280) - .height(100) - .visibility(Visibility::Visible) - .on_click(move |_ctx, _| { - println!("create_popup_progress: on_click -> remove_popup(popup_progress)"); - //ctx.get_mut::(id) - // .set_action(PolicycheckAction::RemovePopup(id)); - true - }) - .child( - Container::new() - .style("container_progress") - .child( - Stack::new() - .style("stack_progress") - .child( - TextBlock::new() - .id(ID_POLICY_CHECK_PROGRESS_TEXT) - .style("textblock_progress") - .text("Importing data") - .build(ctx) - ) - .child( - ProgressBar::new() - .id(ID_POLICY_CHECK_PROGRESS_BAR) - .style("progress_bar") - .val(0) - //.width(250) - .build(ctx) - ) - .child( - TextBlock::new() - .id(ID_POLICY_CHECK_PROGRESS_TIME) - .style("textblock_progress") - .h_align("end") - .text("Processing time") - .build(ctx) - ) - .build(ctx) - ) - .build(ctx) - ) - .build(ctx) + .id(ID_POLICY_CHECK_POPUP_PROGRESS) + .target(id.0) + .open(true) + .style("popup_progress") + .width(280) + .height(100) + .visibility(Visibility::Visible) + .on_click(move |_ctx, _| { + println!("create_popup_progress: on_click -> remove_popup(popup_progress)"); + //ctx.get_mut::(id) + // .set_action(PolicycheckAction::RemovePopup(id)); + true + }) + .child( + Container::new() + .style("container_progress") + .child( + Stack::new() + .style("stack_progress") + .child( + TextBlock::new() + .id(ID_POLICY_CHECK_PROGRESS_TEXT) + .style("textblock_progress") + .text("Importing data") + .build(ctx) + ) + .child( + ProgressBar::new() + .id(ID_POLICY_CHECK_PROGRESS_BAR) + .style("progress_bar") + .val(0) + //.width(250) + .build(ctx) + ) + .child( + TextBlock::new() + .id(ID_POLICY_CHECK_PROGRESS_TIME) + .style("textblock_progress") + .h_align("end") + .text("Processing time") + .build(ctx) + ) + .build(ctx) + ) + .build(ctx) + ) + .build(ctx) } diff --git a/crates/advotracker_client/src/widgets/ticketdata/ticketdata_state.rs b/crates/advotracker_client/src/widgets/ticketdata/ticketdata_state.rs index b14e847..bf78eb3 100644 --- a/crates/advotracker_client/src/widgets/ticketdata/ticketdata_state.rs +++ b/crates/advotracker_client/src/widgets/ticketdata/ticketdata_state.rs @@ -20,6 +20,7 @@ use crate::{ services::exports::send_ticketdata::sendticketdata, widgets::ticketdata::ticketdata_view::TicketdataView, //widgets::policycheck::policycheck_state::PolicycheckAction, + Lang, }; /// Valid `actions` that are handled as state changes in the `Ticketdata` widget. @@ -47,7 +48,7 @@ struct Environment { pub struct TicketdataState { actions: Vec, button_menu: Entity, - lang: String, + lang: Lang, target: Entity } @@ -113,7 +114,7 @@ impl TicketdataState { } } - pub fn send_form(entity: Entity, ctx: &mut Context<'_>, lang: &str) { + pub fn send_form(entity: Entity, ctx: &mut Context<'_>, _lang: Lang) { info!("TicketdataState: processing entity[{:?}]", entity); let mail_to_index = *TicketdataView::selected_index_ref(&ctx.widget()) as usize; @@ -139,6 +140,7 @@ impl TicketdataState { trace!("eMail fields: {:?}", email); // send email via service + let lang = Lang::De(""); 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")); @@ -178,7 +180,8 @@ impl State for TicketdataState { .expect("TicketState.init: Can't find resource entity 'target'.")); // Get language from environment - self.lang = TicketdataState::get_lang(); + //self.lang = TicketdataState::get_lang(); + //let self.lang = Lang::De(""); 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); @@ -203,7 +206,7 @@ impl State for TicketdataState { TicketdataState::clear_form(ctx.entity(), &id, ctx); } TicketdataAction::SendForm() => { - TicketdataState::send_form(ctx.entity(), ctx, &self.lang); + TicketdataState::send_form(ctx.entity(), ctx, self.lang); } TicketdataAction::UpdatePolicyCode(id) => { TicketdataState::update_policy_code(ctx.entity(), &id, ctx);