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]
winres = { version = "0.1.11" }
twine = { version = "~0.3.8", features = ["serde"] }
#twine = { version = "0.3.8" }
twine = { path = "../../../twine", features = ["serde"] }
[features]
default = []

View File

@@ -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();

View File

@@ -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;

View File

@@ -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,
}
@@ -134,17 +136,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// reference: https://tokio.rs/blog/2019-08-tracing/
let span = tracing::span!(Level::TRACE, "advotracker");
let _enter = span.enter();
let subscriber = fmt::Subscriber::builder()
let collector = fmt::Subscriber::builder()
.with_env_filter(&rust_log)
//.with_max_level(tracing::Level::DEBUG)
.finish();
tracing::subscriber::with_default(subscriber, || {
tracing::subscriber::with_default(collector, || {
// get system environment
let lang = get_lang();
// include localization strings
include!(concat!(env!("OUTDIR"), "/i18n.rs"));
//let lang = get_lang();
let lang = Lang::De("de");
let mut state = t!(state_started => 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
// the content of the text property will be drawn.
let localization = RonLocalization::create()
.language(&lang)
.language("de")
.dictionary("de_DE", ADVOTRACKER_DE_DE)
.build();

View File

@@ -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<dyn Error>> {
pub fn export(p: &mut String, lang: &Lang) -> Result<(), Box<dyn Error>> {
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<dyn Error>> {
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(())

View File

@@ -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<dyn Error>> {
// include localization strings
include!(concat!(env!("OUT_DIR"), "/i18n.rs"));
pub fn sendticketdata(email: &Email, lang: &Lang) -> Result<(), Box<dyn Error>> {
let mut res = t!(sendticketdata_export_started => lang);
let mut state = t!(state_started =>lang);
trace!(target: "sendticketdata", process = ?res, state = ?state);

View File

@@ -6,15 +6,16 @@
*/
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
@@ -22,18 +23,15 @@ use crate::data::structures::{PolicyCode, PolicyDataList, PolicyData};
/// https://blog.burntsushi.net/csv/
pub fn import(p: &mut String, data_list: &mut PolicyDataList,
policy_numbers: &mut HashMap<u64, PolicyCode>,
policy_data_count: &mut u64,
lang: &str)
policy_data_count: &mut u64)
-> Result<(u64, Duration), Box<dyn Error>> {
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<Local> = time_start.into();
@@ -93,8 +91,8 @@ pub fn import(p: &mut String, data_list: &mut PolicyDataList,
.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<Local> = time_end.into();
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)
*/
use locales::t;
use orbtk::prelude::*;
use serde::Deserialize;
@@ -19,6 +18,7 @@ use crate::{
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<u64, PolicyCode>,
@@ -92,9 +92,6 @@ impl PolicycheckState {
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);
@@ -106,8 +103,7 @@ impl PolicycheckState {
//let mut csv_import_path = v.get::<String>("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) {
&mut policy_numbers, &mut self.policy_data_count) {
Ok((count, duration)) => {
self.policy_data_count = count;
self.duration = duration;
@@ -450,7 +446,8 @@ impl State for PolicycheckState {
trace!(target: "advotracker", policycheck_state = "init", status = "started");
// Get language from environment
self.lang = PolicycheckState::get_lang();
// self.lang = PolicycheckState::get_lang();
self.lang = Lang::De("");
// Initialize required entities
self.button_menu = ctx

View File

@@ -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<TicketdataAction>,
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);