advotracker-client: more twine adaptions

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2021-03-22 23:50:15 +01:00
parent dd5d361116
commit 9ed395d04b
9 changed files with 677 additions and 678 deletions

View File

@@ -39,7 +39,8 @@ viperus = { git = "https://github.com/maurocordioli/viperus", features = ["cach
[build-dependencies] [build-dependencies]
winres = { version = "0.1.11" } winres = { version = "0.1.11" }
twine = { version = "~0.3.8", features = ["serde"] } #twine = { version = "0.3.8" }
twine = { path = "../../../twine", features = ["serde"] }
[features] [features]
default = [] default = []

View File

@@ -7,11 +7,11 @@
extern crate winres; extern crate winres;
use twine; use twine::build_translations;
fn main() { fn main() {
println!("cargo:rerun-if-changed=build.rs"); 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") { if cfg!(target_os = "windows") {
let mut res = winres::WindowsResource::new(); let mut res = winres::WindowsResource::new();

View File

@@ -26,6 +26,9 @@
//! WIP: provide a workflow image //! WIP: provide a workflow image
//! //!
// i18n: get the macro (t!) accessing translated strings
include!(concat!(env!("OUT_DIR"), "/i18n.rs"));
// /// The client specific services // /// The client specific services
// pub mod clients; // pub mod clients;

View File

@@ -16,7 +16,6 @@ use std::env;
//use std::process; //use std::process;
use substring::Substring; use substring::Substring;
use tracing::{info, trace, Level}; use tracing::{info, trace, Level};
use twine::t;
use orbtk::{ use orbtk::{
prelude::*, prelude::*,
@@ -30,6 +29,9 @@ use orbtk::theme_fluent::{THEME_FLUENT, THEME_FLUENT_COLORS_DARK, THEME_FLUENT_F
// The Main view // The Main view
use advotracker_client::widgets::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; mod parse_args;
/// define valid environment variables provided via .env files /// define valid environment variables provided via .env files
@@ -37,7 +39,7 @@ mod parse_args;
/// this is primarily used in testing scenarios (eg. debugging) /// this is primarily used in testing scenarios (eg. debugging)
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct Environment { struct Environment {
lang: String, lang: Lang,
test_lang: String, test_lang: String,
rust_log: String, rust_log: String,
} }
@@ -134,17 +136,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// reference: https://tokio.rs/blog/2019-08-tracing/ // reference: https://tokio.rs/blog/2019-08-tracing/
let span = tracing::span!(Level::TRACE, "advotracker"); let span = tracing::span!(Level::TRACE, "advotracker");
let _enter = span.enter(); let _enter = span.enter();
let subscriber = fmt::Subscriber::builder() let collector = fmt::Subscriber::builder()
.with_env_filter(&rust_log) .with_env_filter(&rust_log)
//.with_max_level(tracing::Level::DEBUG) //.with_max_level(tracing::Level::DEBUG)
.finish(); .finish();
tracing::subscriber::with_default(subscriber, || { tracing::subscriber::with_default(collector, || {
// get system environment // get system environment
let lang = get_lang(); //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 state = t!(state_started => lang);
let mut res = t!(parse_environment => lang); let mut res = t!(parse_environment => lang);
@@ -186,7 +186,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// if no dictionary is set for the chosen default language // if no dictionary is set for the chosen default language
// the content of the text property will be drawn. // the content of the text property will be drawn.
let localization = RonLocalization::create() let localization = RonLocalization::create()
.language(&lang) .language("de")
.dictionary("de_DE", ADVOTRACKER_DE_DE) .dictionary("de_DE", ADVOTRACKER_DE_DE)
.build(); .build();

View File

@@ -6,21 +6,19 @@
*/ */
//use chrono::{Local, DateTime}; //use chrono::{Local, DateTime};
use locales::t;
use std::error::Error; use std::error::Error;
use tracing::trace; use tracing::trace;
use crate::Lang;
/// export as csv format /// export as csv format
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html /// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
/// https://blog.burntsushi.net/csv/ /// https://blog.burntsushi.net/csv/
pub fn export(p: &mut String, lang: &str) -> Result<(), Box<dyn Error>> { pub fn export(p: &mut String, lang: &Lang) -> Result<(), Box<dyn Error>> {
use std::fs::File; use std::fs::File;
use std::path::Path; use std::path::Path;
//use std::ffi::OsStr; //use std::ffi::OsStr;
// include localization strings
include!(concat!(env!("OUT_DIR"), "/i18n.rs"));
let mut res = t!(csv_export_started => lang); let mut res = t!(csv_export_started => lang);
let mut state = t!(state_started => lang); let mut state = t!(state_started => lang);
trace!(target: "csv-export", process = ?res, state = ?state); trace!(target: "csv-export", process = ?res, state = ?state);
@@ -33,7 +31,7 @@ pub fn export(p: &mut String, lang: &str) -> Result<(), Box<dyn Error>> {
trace!(target: "csv.export", extension = ?path.extension(), file = ?file); trace!(target: "csv.export", extension = ?path.extension(), file = ?file);
state = t!(state_finished => lang); 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); trace!(target: "csv-export", process = ?res, state = ?state);
Ok(()) Ok(())

View File

@@ -10,19 +10,18 @@ use lettre::{
Message, SmtpTransport, Transport, Message, SmtpTransport, Transport,
transport::smtp::authentication::Credentials, transport::smtp::authentication::Credentials,
}; };
use locales::t;
use maud::html; use maud::html;
use std::error::Error; use std::error::Error;
//use std::process; //use std::process;
use tracing::{info, trace}; use tracing::{info, trace};
use crate::data::structures::Email; use crate::{
data::structures::Email,
Lang,
};
/// send ticket data via eMail /// send ticket data via eMail
pub fn sendticketdata(email: &Email, lang: &str) -> Result<(), Box<dyn Error>> { pub fn sendticketdata(email: &Email, lang: &Lang) -> Result<(), Box<dyn Error>> {
// include localization strings
include!(concat!(env!("OUT_DIR"), "/i18n.rs"));
let mut res = t!(sendticketdata_export_started => lang); let mut res = t!(sendticketdata_export_started => lang);
let mut state = t!(state_started =>lang); let mut state = t!(state_started =>lang);
trace!(target: "sendticketdata", process = ?res, state = ?state); trace!(target: "sendticketdata", process = ?res, state = ?state);

View File

@@ -6,15 +6,16 @@
*/ */
use chrono::{Local, DateTime}; use chrono::{Local, DateTime};
use locales::t;
use std::error::Error; use std::error::Error;
use std::collections::HashMap; use std::collections::HashMap;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
use tracing::trace; use tracing::trace;
//use crate::db::redis; //use crate::db::redis;
use crate::data::structures::{PolicyCode, PolicyDataList, PolicyData}; use crate::{
//use crate::data::structures::PolicyDataList; data::structures::{PolicyCode, PolicyDataList, PolicyData},
Lang,
};
/// import AllianzDirectCall data from a csv delimeted file /// import AllianzDirectCall data from a csv delimeted file
/// save records to redis backend /// save records to redis backend
@@ -22,18 +23,15 @@ use crate::data::structures::{PolicyCode, PolicyDataList, PolicyData};
/// https://blog.burntsushi.net/csv/ /// https://blog.burntsushi.net/csv/
pub fn import(p: &mut String, data_list: &mut PolicyDataList, pub fn import(p: &mut String, data_list: &mut PolicyDataList,
policy_numbers: &mut HashMap<u64, PolicyCode>, policy_numbers: &mut HashMap<u64, PolicyCode>,
policy_data_count: &mut u64, policy_data_count: &mut u64)
lang: &str)
-> Result<(u64, Duration), Box<dyn Error>> { -> Result<(u64, Duration), Box<dyn Error>> {
use std::fs::File; use std::fs::File;
use std::path::Path; use std::path::Path;
use std::ffi::OsStr; use std::ffi::OsStr;
// include localization strings let lang = Lang::De("");
include!(concat!(env!("OUT_DIR"), "/i18n.rs")); let mut res = t!(csv_import_started => lang);
let mut state = t!(state_started => lang);
let mut res = t!("csv.import.started", lang);
let mut state = t!("state.started", lang);
let time_start = SystemTime::now(); let time_start = SystemTime::now();
let datetime: DateTime<Local> = time_start.into(); let datetime: DateTime<Local> = time_start.into();
@@ -93,8 +91,8 @@ pub fn import(p: &mut String, data_list: &mut PolicyDataList,
.expect("Clock may have gone backwards"); .expect("Clock may have gone backwards");
trace!(target: "csv-import", record_count = ?count, duration = ?duration); trace!(target: "csv-import", record_count = ?count, duration = ?duration);
state = t!("state.finished", lang); state = t!(state_finished => lang);
res = t!("csv.import.finished", lang); res = t!(csv_import_finished => lang);
let datetime: DateTime<Local> = time_end.into(); let datetime: DateTime<Local> = time_end.into();
trace!(target: "csv-import", process = ?res, state = ?state, date_stop = ?datetime.to_string()); trace!(target: "csv-import", process = ?res, state = ?state, date_stop = ?datetime.to_string());

View File

@@ -5,7 +5,6 @@
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
use locales::t;
use orbtk::prelude::*; use orbtk::prelude::*;
use serde::Deserialize; use serde::Deserialize;
@@ -19,6 +18,7 @@ use crate::{
structures::{PolicyCode, PolicyDataList, PolicyList}, structures::{PolicyCode, PolicyDataList, PolicyList},
constants::*, constants::*,
}, },
Lang,
//services::imports::allianzdirectcall::import, //services::imports::allianzdirectcall::import,
services::imports::allianzdirectcall, services::imports::allianzdirectcall,
widgets::global_state::GlobalState, widgets::global_state::GlobalState,
@@ -68,7 +68,7 @@ pub struct PolicycheckState {
button_menu: Entity, button_menu: Entity,
duration: Duration, duration: Duration,
label_result: Entity, label_result: Entity,
lang: String, lang: Lang,
policy_data_count: u64, policy_data_count: u64,
//policy_number: Entity, //policy_number: Entity,
policy_numbers: HashMap<u64, PolicyCode>, policy_numbers: HashMap<u64, PolicyCode>,
@@ -92,9 +92,6 @@ impl PolicycheckState {
let policy_list = PolicyList::new("policy list"); let policy_list = PolicyList::new("policy list");
trace!(target: "advotracker", policy_list = ?policy_list); trace!(target: "advotracker", policy_list = ?policy_list);
// include localization strings
include!(concat!(env!("OUTDIR"), "/i18n.rs"));
// create vector to hold imported data // create vector to hold imported data
let res = t!(policy_string_label_policy_data => self.lang); let res = t!(policy_string_label_policy_data => self.lang);
let mut policy_data = PolicyDataList::new(res); let mut policy_data = PolicyDataList::new(res);
@@ -106,8 +103,7 @@ impl PolicycheckState {
//let mut csv_import_path = v.get::<String>("import_file").unwrap(); //let mut csv_import_path = v.get::<String>("import_file").unwrap();
let mut csv_import_path = String::from("POLLFNR_WOECHENTLICH.txt"); let mut csv_import_path = String::from("POLLFNR_WOECHENTLICH.txt");
match allianzdirectcall::import(&mut csv_import_path, &mut policy_data, match allianzdirectcall::import(&mut csv_import_path, &mut policy_data,
&mut policy_numbers, &mut self.policy_data_count, &mut policy_numbers, &mut self.policy_data_count) {
&self.lang) {
Ok((count, duration)) => { Ok((count, duration)) => {
self.policy_data_count = count; self.policy_data_count = count;
self.duration = duration; self.duration = duration;
@@ -450,7 +446,8 @@ impl State for PolicycheckState {
trace!(target: "advotracker", policycheck_state = "init", status = "started"); trace!(target: "advotracker", policycheck_state = "init", status = "started");
// Get language from environment // Get language from environment
self.lang = PolicycheckState::get_lang(); // self.lang = PolicycheckState::get_lang();
self.lang = Lang::De("");
// Initialize required entities // Initialize required entities
self.button_menu = ctx self.button_menu = ctx

View File

@@ -20,6 +20,7 @@ use crate::{
services::exports::send_ticketdata::sendticketdata, services::exports::send_ticketdata::sendticketdata,
widgets::ticketdata::ticketdata_view::TicketdataView, widgets::ticketdata::ticketdata_view::TicketdataView,
//widgets::policycheck::policycheck_state::PolicycheckAction, //widgets::policycheck::policycheck_state::PolicycheckAction,
Lang,
}; };
/// Valid `actions` that are handled as state changes in the `Ticketdata` widget. /// Valid `actions` that are handled as state changes in the `Ticketdata` widget.
@@ -47,7 +48,7 @@ struct Environment {
pub struct TicketdataState { pub struct TicketdataState {
actions: Vec<TicketdataAction>, actions: Vec<TicketdataAction>,
button_menu: Entity, button_menu: Entity,
lang: String, lang: Lang,
target: Entity 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); info!("TicketdataState: processing entity[{:?}]", entity);
let mail_to_index = *TicketdataView::selected_index_ref(&ctx.widget()) as usize; let mail_to_index = *TicketdataView::selected_index_ref(&ctx.widget()) as usize;
@@ -139,6 +140,7 @@ impl TicketdataState {
trace!("eMail fields: {:?}", email); trace!("eMail fields: {:?}", email);
// send email via service // send email via service
let lang = Lang::De("");
if let Err(err) = sendticketdata(&email, &lang) { if let Err(err) = sendticketdata(&email, &lang) {
error!("sendticketdata error: {:?}", err); error!("sendticketdata error: {:?}", err);
Button::icon_brush_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#008000")); 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'.")); .expect("TicketState.init: Can't find resource entity 'target'."));
// Get language from environment // Get language from environment
self.lang = TicketdataState::get_lang(); //self.lang = TicketdataState::get_lang();
//let self.lang = Lang::De("");
Stack::visibility_set(&mut ctx.child(ID_TICKET_DATA_ACTION_STACK), Visibility::Collapsed); 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_CLEAR), material_icons_font::MD_CLEAR);
@@ -203,7 +206,7 @@ impl State for TicketdataState {
TicketdataState::clear_form(ctx.entity(), &id, ctx); TicketdataState::clear_form(ctx.entity(), &id, ctx);
} }
TicketdataAction::SendForm() => { TicketdataAction::SendForm() => {
TicketdataState::send_form(ctx.entity(), ctx, &self.lang); TicketdataState::send_form(ctx.entity(), ctx, self.lang);
} }
TicketdataAction::UpdatePolicyCode(id) => { TicketdataAction::UpdatePolicyCode(id) => {
TicketdataState::update_policy_code(ctx.entity(), &id, ctx); TicketdataState::update_policy_code(ctx.entity(), &id, ctx);