callbacks: progressing I18n handling
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -176,8 +176,10 @@ impl PolicyCheckState {
|
|||||||
/// Parse validity of the given policy number.
|
/// Parse validity of the given policy number.
|
||||||
fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
||||||
ctx: &mut Context<'_>) {
|
ctx: &mut Context<'_>) {
|
||||||
let policy_string = ctx.get_widget(policy_check_policy_number).get::<String16>("text").as_string();
|
trace!(target: "advotracker", parse_entry = "started");
|
||||||
let policy_number_length = policy_string.len();
|
|
||||||
|
let policy_number_string = ctx.get_widget(policy_check_policy_number).get::<String16>("text").as_string();
|
||||||
|
let policy_number_length = policy_number_string.len();
|
||||||
|
|
||||||
// WIP: redundant lang selection (already in main!)
|
// WIP: redundant lang selection (already in main!)
|
||||||
let mut lang = env::var("lang").unwrap_or("en".to_string());
|
let mut lang = env::var("lang").unwrap_or("en".to_string());
|
||||||
@@ -216,20 +218,18 @@ impl PolicyCheckState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trace!(target: "advotracker", state = "parsing", policy_number = ?policy_number_string);
|
||||||
trace!(target: "advotracker", state = "parsing", policy_number = ?policy_string);
|
|
||||||
|
|
||||||
// Parse policy code: "AS-123456789"
|
// Parse policy code: "AS-123456789"
|
||||||
// DION VERS POLLFNR
|
// DION VERS POLLFNR
|
||||||
// 1 AS 1515735810
|
// 1 AS 1515735810
|
||||||
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Collapsed);
|
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Collapsed);
|
||||||
text_block(ctx.child("policy_check_label_result")).set_text("Prüfungsergebnis:");
|
|
||||||
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Collapsed);
|
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Collapsed);
|
||||||
button(ctx.child("policy_check_button_result")).set_background("transparent");
|
button(ctx.child("policy_check_button_result")).set_background("transparent");
|
||||||
|
|
||||||
if policy_number_length == 10 {
|
if policy_number_length == 10 {
|
||||||
// cast policy_string to <usize>
|
// cast policy_number_sting to <usize>
|
||||||
match policy_string.parse::<usize>() {
|
match policy_number_string.parse::<usize>() {
|
||||||
Ok(p) => {
|
Ok(p) => {
|
||||||
let mut result_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
let mut result_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
||||||
result_wrapper.set_text("");
|
result_wrapper.set_text("");
|
||||||
@@ -245,7 +245,8 @@ impl PolicyCheckState {
|
|||||||
result_wrapper.set_text(string_result);
|
result_wrapper.set_text(string_result);
|
||||||
button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CHECK);
|
button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CHECK);
|
||||||
button(ctx.child("policy_check_button_result")).set_icon_brush("#008000");
|
button(ctx.child("policy_check_button_result")).set_icon_brush("#008000");
|
||||||
button(ctx.child("policy_check_button_result")).set_text("gültig!");
|
let res = t!("policy.validation.button_success", lang);
|
||||||
|
button(ctx.child("policy_check_button_result")).set_text(res);
|
||||||
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
|
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
|
||||||
button(ctx.child("policy_check_button_result")).set_foreground("#008000");
|
button(ctx.child("policy_check_button_result")).set_foreground("#008000");
|
||||||
button(ctx.child("policy_check_button_result")).set_background("transparent");
|
button(ctx.child("policy_check_button_result")).set_background("transparent");
|
||||||
@@ -257,7 +258,8 @@ impl PolicyCheckState {
|
|||||||
trace!(target: "advotracker", state = ?res, policy_number = ?p);
|
trace!(target: "advotracker", state = ?res, policy_number = ?p);
|
||||||
button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CLEAR);
|
button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CLEAR);
|
||||||
button(ctx.child("policy_check_button_result")).set_icon_brush("#FF0000");
|
button(ctx.child("policy_check_button_result")).set_icon_brush("#FF0000");
|
||||||
button(ctx.child("policy_check_button_result")).set_text("ungültig!");
|
let res = t!("policy.validation.button_failed", lang);
|
||||||
|
button(ctx.child("policy_check_button_result")).set_text(res);
|
||||||
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
|
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
|
||||||
button(ctx.child("policy_check_button_result")).set_foreground("#FF0000");
|
button(ctx.child("policy_check_button_result")).set_foreground("#FF0000");
|
||||||
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
||||||
@@ -271,7 +273,6 @@ impl PolicyCheckState {
|
|||||||
trace!(target: "advotracker", state = "error", error_type = "invalid type", error = ?e);
|
trace!(target: "advotracker", state = "error", error_type = "invalid type", error = ?e);
|
||||||
button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CLEAR);
|
button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CLEAR);
|
||||||
button(ctx.child("policy_check_button_result")).set_icon_brush("#FF0000");
|
button(ctx.child("policy_check_button_result")).set_icon_brush("#FF0000");
|
||||||
button(ctx.child("policy_check_button_result")).set_text("ungültig!");
|
|
||||||
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
|
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
|
||||||
button(ctx.child("policy_check_button_result")).set_foreground("#FF0000");
|
button(ctx.child("policy_check_button_result")).set_foreground("#FF0000");
|
||||||
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Visible);
|
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Visible);
|
||||||
@@ -279,7 +280,6 @@ impl PolicyCheckState {
|
|||||||
let res = t!("policy.validation.invalid_input", lang);
|
let res = t!("policy.validation.invalid_input", lang);
|
||||||
text_block_wrapper.set_text(res);
|
text_block_wrapper.set_text(res);
|
||||||
text_block_wrapper.set_enabled(true);
|
text_block_wrapper.set_enabled(true);
|
||||||
text_block_wrapper.set_text("Nur Nummern sind zulässig!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -299,21 +299,25 @@ impl PolicyCheckState {
|
|||||||
let res = t!("policy.validation.to_long", lang);
|
let res = t!("policy.validation.to_long", lang);
|
||||||
text_block_wrapper.set_text(res);
|
text_block_wrapper.set_text(res);
|
||||||
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Visible);
|
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Visible);
|
||||||
//self.set_visibility(policy_check_policy_number, ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trace!(target: "advotracker", parse_entry = "finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove a popup box showing the data import status in a progress bar
|
/// Remove a popup box showing the data import status in a progress bar
|
||||||
fn remove_progress_box(&mut self, ctx: &mut Context<'_>) {
|
fn remove_progress_popup(&mut self, ctx: &mut Context<'_>) {
|
||||||
if let Some(progress_box) = self.progress_box {
|
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Collapsed);
|
||||||
ctx.remove_child(progress_box);
|
//text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Visible);
|
||||||
println!("ProgressBox removed !");
|
//if let progress_box = self.progress_box {
|
||||||
}
|
// ctx.remove_child(progress_box);
|
||||||
|
// println!("ProgressPopup removed !");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If TextBox 'policy_check_policy_number' is empty, disable button "clear"
|
// /// If TextBox 'policy_check_policy_number' is empty, disable button "clear"
|
||||||
/// otherwise enabled it.
|
// /// otherwise enabled it.
|
||||||
// fn set_policy_check_clear_button(&self, policy_check_policy_number: Entity, ctx: &mut Context<' >) {
|
// fn set_policy_check_clear(&mut self, policy_check_policy_number: Entity, ctx: &mut Context<'_>) {
|
||||||
|
// button(&self, policy_check_policy_number: Entity, ctx: &mut Context<' >) {
|
||||||
// if ctx.get_widget(clear_button).get::<String>("policy_check_policy_number").is_empty() {
|
// if ctx.get_widget(clear_button).get::<String>("policy_check_policy_number").is_empty() {
|
||||||
// ctx.get_widget(self.policy_check_clear_button).set("enabled", false);
|
// ctx.get_widget(self.policy_check_clear_button).set("enabled", false);
|
||||||
// } else {
|
// } else {
|
||||||
@@ -389,21 +393,56 @@ impl State for PolicyCheckState {
|
|||||||
|
|
||||||
trace!(target: "advotracker", policycheck_state = "init", status = "started");
|
trace!(target: "advotracker", policycheck_state = "init", status = "started");
|
||||||
|
|
||||||
|
// Entities
|
||||||
self.menu_button = ctx
|
self.menu_button = ctx
|
||||||
.entity_of_child(ID_POLICY_CHECK_BUTTON_MENU)
|
.entity_of_child(ID_POLICY_CHECK_BUTTON_MENU)
|
||||||
.expect("PolicyCheckState.init: Can't find entity of resource 'ID_POLICY_CHECK_BUTTON_MENU'.");
|
.expect("PolicyCheckState.init: Can't find resource entity 'ID_POLICY_CHECK_BUTTON_MENU'.");
|
||||||
|
|
||||||
self.label_result = ctx
|
self.label_result = ctx
|
||||||
.entity_of_child(ID_POLICY_CHECK_LABEL_RESULT)
|
.entity_of_child(ID_POLICY_CHECK_LABEL_RESULT)
|
||||||
.expect("PolicyCheckState.init: Can't find entity of resource 'ID_POLICY_CHECK_LABEL_RESULT'.");
|
.expect("PolicyCheckState.init: Can't find resource entity 'ID_POLICY_CHECK_LABEL_RESULT'.");
|
||||||
|
|
||||||
let string_result = "Prüfungsergebnis:".to_string();
|
// self.progress_bar = ctx
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_text(string_result);
|
// .entity_of_child(ID_POLICY_CHECK_PROGRESS_BAR)
|
||||||
|
// .expect("PolicyCheckState.init: Can't find resource entity 'ID_POLICY_CHECK_PROGRESS_BAR'.");
|
||||||
|
|
||||||
|
// self.progress_popup = ctx
|
||||||
|
// .entity_of_child(ID_POLICY_CHECK_PROGRESS_POPUP)
|
||||||
|
// .expect("PolicyCheckState.init: Can't find resource entity 'ID_POLICY_CHECK_PROGRESS_POPUP'.");
|
||||||
|
|
||||||
|
// 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); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
let res = t!("policy.string.header", lang);
|
||||||
|
text_block(ctx.child(ID_POLICY_CHECK_HEADER)).set_text(res);
|
||||||
|
|
||||||
|
let res = t!("policy.string.label_policy_number", lang);
|
||||||
|
let string_label_policy_number = format!("{}:", res);
|
||||||
|
text_block(ctx.child(ID_POLICY_CHECK_LABEL_POLICY_NUMBER)).set_text(string_label_policy_number);
|
||||||
|
|
||||||
|
let res = t!("policy.string.label_result", lang);
|
||||||
|
let string_label_result = format!("{}:", res);
|
||||||
|
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_text(string_label_result);
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Collapsed);
|
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Collapsed);
|
||||||
|
|
||||||
// self.progress_box = ctx
|
let res = t!("policy.string.progress_text", lang);
|
||||||
// .entity_of_child(ID_POLICY_CHECK_PROGRESS_BOX)
|
let string_progress_text = format!("{}: {:?}", res, self.policy_numbers.len());
|
||||||
// .expect("PolicyCheckState.init: Can't find entity of resource 'ID_POLICY_CHECK_PROGRESS_BOX'.");
|
//text_block(ctx.child(ID_POLICY_CHECK_PROGRESS_TEXT)).set_text(string_progress_text);
|
||||||
|
|
||||||
|
let string_pro_text = format!("{}: {:?}", res, self.policy_numbers.len());
|
||||||
|
|
||||||
|
// self.progress_popup = ctx
|
||||||
|
// .entity_of_child(ID_POLICY_CHECK_PROGRESS_POPUP)
|
||||||
|
// .expect("PolicyCheckState.init: Can't find entity of resource 'ID_POLICY_CHECK_PROGRESS_POPUP'.");
|
||||||
|
|
||||||
// // 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
|
||||||
@@ -516,21 +555,32 @@ impl State for PolicyCheckState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Reset action
|
||||||
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<'_>) {
|
||||||
let mut string_data_count = "Prüflisten-Elemente:".to_string();
|
// WIP: redundant lang selection (already in main!)
|
||||||
string_data_count = format!("{} {:?}", string_data_count, self.policy_numbers.len());
|
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());
|
||||||
text_block(ctx.child(ID_POLICY_DATA_COUNT_BLOCK)).set_text(string_data_count);
|
text_block(ctx.child(ID_POLICY_DATA_COUNT_BLOCK)).set_text(string_data_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_progress_box(target: Entity, text: &str, ctx: &mut BuildContext<'_>) -> Entity {
|
fn new_progress_popup(target: Entity, text: &str, ctx: &mut BuildContext<'_>) -> Entity {
|
||||||
Popup::new()
|
Popup::new()
|
||||||
.id(ID_POLICY_CHECK_PROGRESS_BOX)
|
.id(ID_POLICY_CHECK_PROGRESS_POPUP)
|
||||||
.target(target)
|
.target(target)
|
||||||
.open(true)
|
.open(true)
|
||||||
.width(280.0)
|
.width(280.0)
|
||||||
|
|||||||
Reference in New Issue
Block a user