advotracker: change localization handling
* main: adapt resource path for localization information * data/constants: Stings used in policycheck state/view * widgets/policycheck_view: change the used localization strings * callbacks/policycheck_state: change child ID'S to use constants and localization strings Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
//use chrono::{Local, DateTime, Duration};
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use locales::t;
|
use locales::t;
|
||||||
use orbtk::{
|
use orbtk::{
|
||||||
@@ -18,7 +17,7 @@ use serde::Deserialize;
|
|||||||
use std::{env, process};
|
use std::{env, process};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
use tracing::{debug, error, info, trace};
|
use tracing::{error, info, trace};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
callbacks::global_state::GlobalState,
|
callbacks::global_state::GlobalState,
|
||||||
@@ -94,8 +93,7 @@ impl PolicyCheckState {
|
|||||||
pub fn create_hashmap(&mut self, _ctx: &mut Context<'_>) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn create_hashmap(&mut self, _ctx: &mut Context<'_>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
trace!(target: "advotracker", create_hashmap = "started");
|
trace!(target: "advotracker", create_hashmap = "started");
|
||||||
|
|
||||||
let res = t!("policy.string.label_policy_list", self.lang);
|
let policy_list = PolicyList::new("policy list");
|
||||||
let policy_list = PolicyList::new(res);
|
|
||||||
trace!(target: "advotracker", policy_list = ?policy_list);
|
trace!(target: "advotracker", policy_list = ?policy_list);
|
||||||
|
|
||||||
// create vector to hold imported data
|
// create vector to hold imported data
|
||||||
@@ -139,13 +137,14 @@ impl PolicyCheckState {
|
|||||||
/// Get the active language environment.
|
/// Get the active language environment.
|
||||||
pub fn get_lang() -> String {
|
pub fn get_lang() -> String {
|
||||||
// get system environment
|
// get system environment
|
||||||
let mut lang = env::var("LANG").unwrap_or("en".to_string());
|
let mut lang = env::var("LANG").unwrap_or("C".to_string());
|
||||||
|
|
||||||
// testing environment: read from .env file
|
// testing environment: read from .env file
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
match envy::from_env::<Environment>() {
|
match envy::from_env::<Environment>() {
|
||||||
Ok(environment) => {
|
Ok(environment) => {
|
||||||
if environment.test_lang != lang { lang = environment.test_lang; }
|
if environment.test_lang != lang { lang = environment.test_lang; }
|
||||||
|
trace!(target: "advotracker", lang = ?lang);
|
||||||
},
|
},
|
||||||
Err(e) => { info!(target: "advotracker", "{}", e) }
|
Err(e) => { info!(target: "advotracker", "{}", e) }
|
||||||
}
|
}
|
||||||
@@ -157,7 +156,7 @@ impl PolicyCheckState {
|
|||||||
-> Result<(), Box<dyn std::error::Error>> {
|
-> Result<(), Box<dyn std::error::Error>> {
|
||||||
// WIP: for now, only import once per session
|
// WIP: for now, only import once per session
|
||||||
if self.policy_data_count == 0 {
|
if self.policy_data_count == 0 {
|
||||||
TextBlock::enabled_set(&mut ctx.child("policy_check_result"), true);
|
TextBlock::enabled_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), true);
|
||||||
|
|
||||||
if self.policy_numbers.len() == 0 {
|
if self.policy_numbers.len() == 0 {
|
||||||
// initialize popup widget
|
// initialize popup widget
|
||||||
@@ -216,25 +215,21 @@ impl PolicyCheckState {
|
|||||||
ctx: &mut Context<'_>) {
|
ctx: &mut Context<'_>) {
|
||||||
trace!(target: "advotracker", parse_entry = "started");
|
trace!(target: "advotracker", parse_entry = "started");
|
||||||
|
|
||||||
//let policy_number_string = ctx.get_widget(policy_check_policy_number).get::<String16>("text").as_string();
|
|
||||||
let policy_number_string = TextBox::text_clone(&mut ctx.get_widget(policy_check_policy_number));
|
let policy_number_string = TextBox::text_clone(&mut ctx.get_widget(policy_check_policy_number));
|
||||||
let policy_number_length = policy_number_string.len();
|
let policy_number_length = policy_number_string.len();
|
||||||
|
|
||||||
// // WIP: redundant lang selection (already in main!)
|
if self.policy_data_count == 0 {
|
||||||
// let mut lang = env::var("lang").unwrap_or("en".to_string());
|
// Load data into hashmap
|
||||||
// // testing environment: read from .env file
|
match self.import_data(ctx) {
|
||||||
// dotenv().ok();
|
Ok(()) => {
|
||||||
// match envy::from_env::<Environment>() {
|
trace!(target: "advotracker", policycheck_state = "init", import_data = "success");
|
||||||
// Ok(environment) => {
|
Stack::visibility_set(&mut ctx.child(ID_POLICY_DATA_STACK), Visibility::Visible);
|
||||||
// if environment.test_lang != lang { lang = environment.test_lang; }
|
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) => { debug!(target: "advotracker", "{}", e); }
|
},
|
||||||
// }
|
|
||||||
|
|
||||||
// Load data into hashmap
|
Err(e) => trace!(target: "advotracker", policycheck_state = "init", import_data = ?e),
|
||||||
match self.import_data(ctx) {
|
}
|
||||||
Ok(()) => trace!(target: "advotracker", policycheck_state = "init", import_data = "success"),
|
|
||||||
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);
|
||||||
@@ -242,15 +237,15 @@ impl PolicyCheckState {
|
|||||||
// Parse policy code: "AS-123456789"
|
// Parse policy code: "AS-123456789"
|
||||||
// DION VERS POLLFNR
|
// DION VERS POLLFNR
|
||||||
// 1 AS 1515735810
|
// 1 AS 1515735810
|
||||||
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
||||||
Button::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Visible);
|
Button::background_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("transparent"));
|
||||||
Button::background_set(&mut ctx.child("policy_check_button_result"), String::from("transparent"));
|
Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Collapsed);
|
||||||
|
|
||||||
if policy_number_length == 10 {
|
if policy_number_length == 10 {
|
||||||
// cast policy_number_sting to <u64>
|
// cast policy_number_sting to <u64>
|
||||||
match policy_number_string.parse::<u64>() {
|
match policy_number_string.parse::<u64>() {
|
||||||
Ok(p) => {
|
Ok(p) => {
|
||||||
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(""));
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), String::from(""));
|
||||||
|
|
||||||
// match hashmap's key
|
// match hashmap's key
|
||||||
match self.policy_numbers.get(&p) {
|
match self.policy_numbers.get(&p) {
|
||||||
@@ -260,60 +255,58 @@ impl PolicyCheckState {
|
|||||||
policy_number = ?p, policy_code = ?policy_code);
|
policy_number = ?p, policy_code = ?policy_code);
|
||||||
let string_result = format!("1-{:?}-{}",
|
let string_result = format!("1-{:?}-{}",
|
||||||
policy_code, p);
|
policy_code, p);
|
||||||
TextBlock::enabled_set(&mut ctx.child("policy_check_result"), true);
|
TextBlock::enabled_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), true);
|
||||||
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(string_result));
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), String::from(string_result));
|
||||||
|
|
||||||
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Visible);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible);
|
||||||
let res = t!("policy.validation.button_success", self.lang);
|
Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#008000"));
|
||||||
Button::text_set(&mut ctx.child("policy_check_button_result"), String::from(res));
|
Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#008000"));
|
||||||
Button::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Visible);
|
Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CHECK);
|
||||||
Button::icon_set(&mut ctx.child("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("policy_check_button_result"), String::from("#008000"));
|
|
||||||
Button::foreground_set(&mut ctx.child("policy_check_button_result"), String::from("#008000"));
|
|
||||||
Button::background_set(&mut ctx.child("policy_check_button_result"), String::from("transparent"));
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// no matching key
|
// no matching key
|
||||||
let res = t!("policy.validation.failed", self.lang);
|
let res = t!("policy.validation.failed", self.lang);
|
||||||
trace!(target: "advotracker", state = ?res, policy_number = ?p);
|
trace!(target: "advotracker", state = ?res, policy_number = ?p);
|
||||||
|
|
||||||
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Visible);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible);
|
||||||
let res = t!("policy.validation.button_failed", self.lang);
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), String::from("The given policy number is invalid"));
|
||||||
Button::text_set(&mut ctx.child("policy_check_button_result"), String::from(res));
|
Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000"));
|
||||||
Button::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Visible);
|
Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000"));
|
||||||
Button::icon_set(&mut ctx.child("policy_check_button_result"), material_icons_font::MD_CLEAR);
|
Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CLEAR);
|
||||||
Button::icon_brush_set(&mut ctx.child("policy_check_button_result"), String::from("#FF0000"));
|
Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible);
|
||||||
Button::foreground_set(&mut ctx.child("policy_check_button_result"), String::from("#FF0000"));
|
|
||||||
let res = t!("policy.validation.not_found", self.lang);
|
|
||||||
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(res));
|
|
||||||
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Visible);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace!(target: "advotracker", state = "error", error_type = "invalid type", error = ?e);
|
trace!(target: "advotracker", state = "error", error_type = "invalid type", error = ?e);
|
||||||
|
|
||||||
Button::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Visible);
|
TextBlock::enabled_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), true);
|
||||||
Button::icon_set(&mut ctx.child("policy_check_button_result"), material_icons_font::MD_CLEAR);
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), String::from("Only numbers are valid"));
|
||||||
Button::icon_brush_set(&mut ctx.child("policy_check_button_result"), String::from("#FF0000"));
|
Button::icon_brush_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000"));
|
||||||
Button::foreground_set(&mut ctx.child("policy_check_button_result"), String::from("#FF0000"));
|
Button::foreground_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), String::from("#FF0000"));
|
||||||
let res = t!("policy.validation.invalid_input", self.lang);
|
Button::icon_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), material_icons_font::MD_CLEAR);
|
||||||
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(res));
|
Button::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible);
|
||||||
TextBlock::enabled_set(&mut ctx.child("policy_check_result"), true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if policy_number_length < 10 {
|
if policy_number_length < 10 {
|
||||||
let res = t!("policy.validation.to_short", self.lang);
|
TextBlock::enabled_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), true);
|
||||||
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(res));
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), String::from("Policy number is to short"));
|
||||||
TextBlock::enabled_set(&mut ctx.child("policy_check_result"), true);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible);
|
||||||
TextBlock::visibility_set(&mut ctx.child("policy_check_label_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);
|
||||||
}
|
}
|
||||||
if policy_number_length > 10 {
|
if policy_number_length > 10 {
|
||||||
let res = t!("policy.validation.to_long", self.lang);
|
TextBlock::enabled_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), true);
|
||||||
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(res));
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_RESULT), String::from("Policy number is to long"));
|
||||||
TextBlock::enabled_set(&mut ctx.child("policy_check_result"), true);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible);
|
||||||
TextBlock::visibility_set(&mut ctx.child("policy_check_label_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
trace!(target: "advotracker", parse_entry = "finished");
|
trace!(target: "advotracker", parse_entry = "finished");
|
||||||
@@ -342,11 +335,11 @@ impl PolicyCheckState {
|
|||||||
/// Change status of given text box to edit mode.
|
/// Change status of given text box to edit mode.
|
||||||
fn set_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
fn set_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
||||||
if ctx.get_widget(text_box).get::<String16>("text").is_empty() {
|
if ctx.get_widget(text_box).get::<String16>("text").is_empty() {
|
||||||
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
||||||
TextBlock::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Collapsed);
|
||||||
} else {
|
} else {
|
||||||
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Visible);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible);
|
||||||
TextBlock::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Visible);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,13 +352,6 @@ impl PolicyCheckState {
|
|||||||
self.menu = create_menu(current_entity, build_context);
|
self.menu = create_menu(current_entity, build_context);
|
||||||
let _menu = build_context.append_child_to_overlay(self.menu)
|
let _menu = build_context.append_child_to_overlay(self.menu)
|
||||||
.expect("PolicyCheckState: Can't create overlay as child of entity");
|
.expect("PolicyCheckState: Can't create overlay as child of entity");
|
||||||
|
|
||||||
let label_account = t!("policy.menu.label_account", self.lang);
|
|
||||||
Button::text_set(&mut ctx.child(ID_POLICY_CHECK_MENU_LABEL_ACCOUNT), String::from(label_account));
|
|
||||||
let label_quit = t!("policy.menu.label_quit", self.lang);
|
|
||||||
Button::text_set(&mut ctx.child(ID_POLICY_CHECK_MENU_LABEL_QUIT), String::from(label_quit));
|
|
||||||
let label_toggle_theme = t!("policy.menu.label_toggle_theme", self.lang);
|
|
||||||
Button::text_set(&mut ctx.child(ID_POLICY_CHECK_MENU_LABEL_TOGGLE_THEME), String::from(label_toggle_theme));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a progress popup that updates the import status in a progress bar
|
/// Set a progress popup that updates the import status in a progress bar
|
||||||
@@ -377,8 +363,7 @@ impl PolicyCheckState {
|
|||||||
let current_entity = ctx.entity;
|
let current_entity = ctx.entity;
|
||||||
let build_context = &mut ctx.build_context();
|
let build_context = &mut ctx.build_context();
|
||||||
|
|
||||||
let res = t!("policy.string.progress_text", self.lang);
|
self.progress_popup = create_popup_progress(current_entity, build_context);
|
||||||
self.progress_popup = create_popup_progress(current_entity, &res, build_context);
|
|
||||||
|
|
||||||
// create a progress_popup widget as a child of entity "ID_POLICY_CHECK_POLICY_NUMBER"
|
// create a progress_popup widget as a child of entity "ID_POLICY_CHECK_POLICY_NUMBER"
|
||||||
build_context.append_child(stack, self.progress_popup);
|
build_context.append_child(stack, self.progress_popup);
|
||||||
@@ -460,30 +445,12 @@ impl State for PolicyCheckState {
|
|||||||
.entity_of_child(ID_POLICY_CHECK_LABEL_RESULT)
|
.entity_of_child(ID_POLICY_CHECK_LABEL_RESULT)
|
||||||
.expect("PolicyCheckState.init: Can't find resource entity 'ID_POLICY_CHECK_LABEL_RESULT'.");
|
.expect("PolicyCheckState.init: Can't find resource entity 'ID_POLICY_CHECK_LABEL_RESULT'.");
|
||||||
|
|
||||||
// WIP: redundant lang selection (already in main!)
|
|
||||||
let mut lang = env::var("lang").unwrap_or("en".to_string());
|
|
||||||
// testing environment: read from .env file
|
|
||||||
dotenv().ok();
|
|
||||||
match envy::from_env::<Environment>() {
|
|
||||||
Ok(environment) => {
|
|
||||||
if environment.test_lang != lang { lang = environment.test_lang; }
|
|
||||||
},
|
|
||||||
Err(e) => { debug!(target: "advotracker", "{}", e); }
|
|
||||||
}
|
|
||||||
self.lang = lang;
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
let res = t!("policy.string.header", self.lang);
|
|
||||||
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_HEADER), String::from(res));
|
|
||||||
|
|
||||||
let res = t!("policy.string.label_policy_number", self.lang);
|
|
||||||
let string_label_policy_number = format!("{}:", res);
|
|
||||||
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_POLICY_NUMBER), String::from(string_label_policy_number));
|
|
||||||
|
|
||||||
let res = t!("policy.string.label_result", self.lang);
|
|
||||||
let string_label_result = format!("{}:", res);
|
|
||||||
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), String::from(string_label_result));
|
|
||||||
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
||||||
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
||||||
|
|
||||||
|
// Preset localization with given environment lang
|
||||||
|
self.lang = PolicyCheckState::get_lang();
|
||||||
|
ctx.set_language(&self.lang);
|
||||||
|
|
||||||
// // Load the saved data from a file in 'ron' format into our data structure.
|
// // 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
|
// // The cargo package identifier (default: 'nwx.advotracker') is used as the
|
||||||
@@ -605,23 +572,9 @@ impl State for PolicyCheckState {
|
|||||||
self.action = None;
|
self.action = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the view after the layout is rendered.
|
// /// Update the view after the layout is rendered.
|
||||||
fn update_post_layout(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
// fn update_post_layout(&mut self, _: &mut Registry, _ctx: &mut Context<'_>) {
|
||||||
// WIP: redundant lang selection (already in main!)
|
// }
|
||||||
let mut lang = env::var("lang").unwrap_or("en".to_string());
|
|
||||||
// testing environment: read from .env file
|
|
||||||
dotenv().ok();
|
|
||||||
match envy::from_env::<Environment>() {
|
|
||||||
Ok(environment) => {
|
|
||||||
if environment.test_lang != lang { lang = environment.test_lang; }
|
|
||||||
},
|
|
||||||
Err(e) => { debug!(target: "advotracker", "{}", e); }
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = t!("policy.string.data_count", lang);
|
|
||||||
let string_data_count = format!("{}: {:?}", res, self.policy_numbers.len());
|
|
||||||
TextBlock::text_set(&mut ctx.child(ID_POLICY_DATA_COUNT_BLOCK), String::from(string_data_count));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a menu popup
|
/// Create a menu popup
|
||||||
@@ -708,7 +661,7 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a progress popup with update status of an onging data import
|
/// Create a progress popup with update status of an onging data import
|
||||||
fn create_popup_progress(target: Entity, text: &str, ctx: &mut BuildContext<'_>) -> Entity {
|
fn create_popup_progress(target: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||||
Popup::new()
|
Popup::new()
|
||||||
.id(ID_POLICY_CHECK_POPUP_PROGRESS)
|
.id(ID_POLICY_CHECK_POPUP_PROGRESS)
|
||||||
.target(target)
|
.target(target)
|
||||||
@@ -725,14 +678,15 @@ fn create_popup_progress(target: Entity, text: &str, ctx: &mut BuildContext<'_>)
|
|||||||
.child(
|
.child(
|
||||||
Container::new()
|
Container::new()
|
||||||
.style("container_progress")
|
.style("container_progress")
|
||||||
.child( Stack::new()
|
.child(
|
||||||
|
Stack::new()
|
||||||
.style("stack_progress")
|
.style("stack_progress")
|
||||||
.child(
|
.child(
|
||||||
TextBlock::new()
|
TextBlock::new()
|
||||||
.id(ID_POLICY_CHECK_PROGRESS_TEXT)
|
.id(ID_POLICY_CHECK_PROGRESS_TEXT)
|
||||||
//.style("textblock_progress")
|
//.style("textblock_progress")
|
||||||
.font_size(12)
|
.font_size(12)
|
||||||
.text(text)
|
.text("Importing data")
|
||||||
.build(ctx)
|
.build(ctx)
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -748,6 +702,7 @@ fn create_popup_progress(target: Entity, text: &str, ctx: &mut BuildContext<'_>)
|
|||||||
//.style("textblock_progress")
|
//.style("textblock_progress")
|
||||||
.h_align("end")
|
.h_align("end")
|
||||||
.font_size(12)
|
.font_size(12)
|
||||||
|
.text("Processing time")
|
||||||
.build(ctx)
|
.build(ctx)
|
||||||
)
|
)
|
||||||
.build(ctx)
|
.build(ctx)
|
||||||
|
|||||||
@@ -39,12 +39,14 @@ pub static ID_POLICY_CHECK_RESULT: &'static str = "policy_check_result";
|
|||||||
pub static ID_POLICY_CHECK_WIDGET: &'static str = "policy_check_widget";
|
pub static ID_POLICY_CHECK_WIDGET: &'static str = "policy_check_widget";
|
||||||
|
|
||||||
pub static ID_POLICY_DATA_ADD_BUTTON: &'static str = "policy_data_add_button";
|
pub static ID_POLICY_DATA_ADD_BUTTON: &'static str = "policy_data_add_button";
|
||||||
pub static ID_POLICY_DATA_COUNT_BLOCK: &'static str = "policy_data_count_block";
|
pub static ID_POLICY_DATA_COUNT: &'static str = "policy_data_count";
|
||||||
|
pub static ID_POLICY_DATA_LABEL: &'static str = "policy_data_label";
|
||||||
pub static ID_POLICY_DATA_ITEMS_WIDGET: &'static str = "policy_data_items_widget";
|
pub static ID_POLICY_DATA_ITEMS_WIDGET: &'static str = "policy_data_items_widget";
|
||||||
pub static ID_POLICY_DATA_DATE_INSERTED: &'static str = "policy_data_date_inserted";
|
pub static ID_POLICY_DATA_DATE_INSERTED: &'static str = "policy_data_date_inserted";
|
||||||
pub static ID_POLICY_DATA_DION: &'static str = "policy_data_dion";
|
pub static ID_POLICY_DATA_DION: &'static str = "policy_data_dion";
|
||||||
pub static ID_POLICY_DATA_POLICY_CODE: &'static str = "policy_data_policy_code";
|
pub static ID_POLICY_DATA_POLICY_CODE: &'static str = "policy_data_policy_code";
|
||||||
pub static ID_POLICY_DATA_POLICY_NUMBER: &'static str = "policy_data_policy_number";
|
pub static ID_POLICY_DATA_POLICY_NUMBER: &'static str = "policy_data_policy_number";
|
||||||
|
pub static ID_POLICY_DATA_STACK: &'static str = "policy_data_stack";
|
||||||
pub static ID_POLICY_DATA_STATUS: &'static str = "policy_data_status";
|
pub static ID_POLICY_DATA_STATUS: &'static str = "policy_data_status";
|
||||||
pub static ID_POLICY_DATA_LIST_NAME: &'static str = "policy_data_list_name";
|
pub static ID_POLICY_DATA_LIST_NAME: &'static str = "policy_data_list_name";
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ struct Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// German localization file.
|
// German localization file.
|
||||||
static ADVOTRACKER_DE_DE: &str = include_str!("../locales/advotracker_de_DE.ron");
|
static ADVOTRACKER_DE_DE: &str = include_str!("../resources/advotracker/advotracker_de_DE.ron");
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
use parse_args::parse_args;
|
use parse_args::parse_args;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ impl Template for PolicyCheckView {
|
|||||||
.v_align("center")
|
.v_align("center")
|
||||||
.child(
|
.child(
|
||||||
ImageWidget::new()
|
ImageWidget::new()
|
||||||
.image("resources/images/hiedemann_logo.png")
|
.image("resources/advotracker/hiedemann_logo.png")
|
||||||
.v_align("center")
|
.v_align("center")
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
@@ -111,7 +111,7 @@ impl Template for PolicyCheckView {
|
|||||||
.id(ID_POLICY_CHECK_HEADER)
|
.id(ID_POLICY_CHECK_HEADER)
|
||||||
.v_align("center")
|
.v_align("center")
|
||||||
.h_align("left")
|
.h_align("left")
|
||||||
.text("Validierung Versicherungsnummer")
|
.text("Policy number validation")
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
@@ -134,7 +134,7 @@ impl Template for PolicyCheckView {
|
|||||||
.margin((0, 0, 16, 0))
|
.margin((0, 0, 16, 0))
|
||||||
.h_align("end")
|
.h_align("end")
|
||||||
.v_align("center")
|
.v_align("center")
|
||||||
.text("Versicherungsnummer:")
|
.text("Policy number")
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -144,6 +144,7 @@ impl Template for PolicyCheckView {
|
|||||||
.id(ID_POLICY_CHECK_POLICY_NUMBER)
|
.id(ID_POLICY_CHECK_POLICY_NUMBER)
|
||||||
.h_align("start")
|
.h_align("start")
|
||||||
.lost_focus_on_activation(false)
|
.lost_focus_on_activation(false)
|
||||||
|
//WIP: localization for water_mark
|
||||||
.water_mark("10-stellig")
|
.water_mark("10-stellig")
|
||||||
.on_activate(move |ctx, entity| {
|
.on_activate(move |ctx, entity| {
|
||||||
// Entity is entered/activated via Mouse/Keyboard
|
// Entity is entered/activated via Mouse/Keyboard
|
||||||
@@ -185,6 +186,7 @@ impl Template for PolicyCheckView {
|
|||||||
.attach(Grid::column(0))
|
.attach(Grid::column(0))
|
||||||
.attach(Grid::column_span(5))
|
.attach(Grid::column_span(5))
|
||||||
.orientation("horizontal")
|
.orientation("horizontal")
|
||||||
|
//.visibility(Visibility::Collapsed)
|
||||||
.v_align("center")
|
.v_align("center")
|
||||||
.child(
|
.child(
|
||||||
TextBlock::new()
|
TextBlock::new()
|
||||||
@@ -197,7 +199,7 @@ impl Template for PolicyCheckView {
|
|||||||
.v_align("center")
|
.v_align("center")
|
||||||
.width(250)
|
.width(250)
|
||||||
.min_width(250)
|
.min_width(250)
|
||||||
.visibility(Visibility::Visible)
|
.text("Check result")
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -267,14 +269,33 @@ impl Template for PolicyCheckView {
|
|||||||
//})
|
//})
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
|
|
||||||
let policy_data_count_block = TextBlock::new()
|
let policy_data_stack = Stack::new()
|
||||||
.id(ID_POLICY_DATA_COUNT_BLOCK)
|
.id(ID_POLICY_DATA_STACK)
|
||||||
.attach(Grid::row(3))
|
.attach(Grid::row(3))
|
||||||
.attach(Grid::column(1))
|
.attach(Grid::column(1))
|
||||||
.margin((0, 4, 0, 0))
|
|
||||||
.h_align("end")
|
.h_align("end")
|
||||||
.v_align("top")
|
.v_align("top")
|
||||||
.enabled(true)
|
.orientation("horizontal")
|
||||||
|
.visibility(Visibility::Collapsed)
|
||||||
|
//.spacing("4")
|
||||||
|
.child(
|
||||||
|
TextBlock::new()
|
||||||
|
.id(ID_POLICY_DATA_LABEL)
|
||||||
|
.margin((0, 4, 0, 0))
|
||||||
|
.enabled(true)
|
||||||
|
.text("Checklist elements: ")
|
||||||
|
//.visibility(Visibility::Collapsed)
|
||||||
|
.build(ctx)
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
TextBlock::new()
|
||||||
|
.id(ID_POLICY_DATA_COUNT)
|
||||||
|
.margin((0, 4, 0, 0))
|
||||||
|
.enabled(true)
|
||||||
|
.text("0")
|
||||||
|
//.visibility(Visibility::Collapsed)
|
||||||
|
.build(ctx)
|
||||||
|
)
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
|
|
||||||
// Starter page: check policy numbers
|
// Starter page: check policy numbers
|
||||||
@@ -310,7 +331,7 @@ impl Template for PolicyCheckView {
|
|||||||
.child(policy_check_form)
|
.child(policy_check_form)
|
||||||
|
|
||||||
// row 3: Sum HashMap elements
|
// row 3: Sum HashMap elements
|
||||||
.child(policy_data_count_block)
|
.child(policy_data_stack)
|
||||||
|
|
||||||
// row 4: Policy Check Bottom
|
// row 4: Policy Check Bottom
|
||||||
.child(policy_check_bottom_bar)
|
.child(policy_check_bottom_bar)
|
||||||
|
|||||||
Reference in New Issue
Block a user