Flatten create structure
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
206
advotracker_client/src/bin/policycheck.rs
Normal file
206
advotracker_client/src/bin/policycheck.rs
Normal file
@@ -0,0 +1,206 @@
|
||||
use orbtk::prelude::*;
|
||||
|
||||
// fn get_theme() -> ThemeValue {
|
||||
// //ThemeValue::create_from_css(LIGHT_THEME_EXTENSION_CSS)
|
||||
// ThemeValue::create_from_css(DEFAULT_THEME_CSS)
|
||||
// .extension_css(WIDGET_EXT)
|
||||
// .build()
|
||||
// }
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
enum Action {
|
||||
EntryActivated(Entity),
|
||||
EntryChanged(Entity)
|
||||
}
|
||||
|
||||
#[derive(AsAny)]
|
||||
pub struct MainViewState {
|
||||
action: Option<Action>,
|
||||
}
|
||||
|
||||
impl Default for MainViewState {
|
||||
fn default() -> Self {
|
||||
MainViewState { action: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl MainViewState {
|
||||
fn action(&mut self, action: impl Into<Option<Action>>) {
|
||||
self.action = action.into();
|
||||
}
|
||||
}
|
||||
|
||||
impl State for MainViewState {
|
||||
fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
||||
if let Some(action) = self.action {
|
||||
match action {
|
||||
// Action::ClearText => {
|
||||
// ctx.widget().set("policynumber", String16::from(""));
|
||||
// }
|
||||
// Action::ValueOk => {
|
||||
// //let mut text_box = TextBox::get(ctx.get_widget(entity));
|
||||
// //let text = text_box.text_mut();
|
||||
// //ctx.widget().set("policynumber", background("#4d4c4c"));
|
||||
// }
|
||||
// Action::ValueNone => {
|
||||
// //let mut text_box = TextBox::get(ctx.get_widget(entity));
|
||||
// //let text = text_box.text_mut();
|
||||
// //ctx.widget().set("policynumber", background("#5b0f22"));
|
||||
//}
|
||||
Action::EntryActivated(entity) => {
|
||||
//let text = ctx.get_widget(entity).clone::<String>("text");
|
||||
let widget = ctx.get_widget(entity);
|
||||
let text = widget.get::<String>("text");
|
||||
println!("got value policynumber: {}", text);
|
||||
}
|
||||
Action::EntryChanged(entity) => {
|
||||
let widget = ctx.get_widget(entity);
|
||||
let text = widget.get::<String>("text");
|
||||
println!("entry changed: {}", text);
|
||||
}
|
||||
}
|
||||
|
||||
self.action = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_header(ctx: &mut BuildContext, text: &str) -> Entity {
|
||||
TextBlock::new()
|
||||
.text(text)
|
||||
.style("header")
|
||||
.build(ctx)
|
||||
}
|
||||
|
||||
widget!(
|
||||
MainView<MainViewState> {
|
||||
sum_policynumbers: usize,
|
||||
policynumber: String16,
|
||||
result: String16
|
||||
}
|
||||
);
|
||||
|
||||
impl Template for MainView {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
|
||||
self.name("MainView").child(
|
||||
Grid::new()
|
||||
.background("#fafafa")
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push(150.0)
|
||||
.push("*")
|
||||
.push(150.0)
|
||||
.build(),
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
.push("*")
|
||||
.push("*")
|
||||
.build(),
|
||||
)
|
||||
.child(
|
||||
Grid::new()
|
||||
//.element("policyholder_check")
|
||||
.margin((4.0, 24.0, 24.0, 4.0))
|
||||
.min_width(180.0)
|
||||
.min_height(80.0)
|
||||
.attach(Grid::column(1))
|
||||
.attach(Grid::row(0))
|
||||
.child(
|
||||
Stack::new()
|
||||
.spacing(8.0)
|
||||
.orientation("vertical")
|
||||
.h_align("center")
|
||||
//.child(create_header(ctx, "Validation number policyholder"))
|
||||
.child(create_header(ctx, "Validierung Versicherungsnummer"))
|
||||
.child(
|
||||
TextBox::new()
|
||||
.foreground("#9dafbf")
|
||||
.background("#fafafa")
|
||||
.border_brush("#5b0f22")
|
||||
.border_width(5)
|
||||
.border_radius(15)
|
||||
//.name("policynumber")
|
||||
.focused(true)
|
||||
.water_mark("Versicherungs-Nr...")
|
||||
.text(("policynumber", id))
|
||||
.font_size(24.0)
|
||||
.h_align("stretch")
|
||||
.on_activate(move |ctx, entity| {
|
||||
state(id, ctx).action(Action::EntryActivated(entity));
|
||||
})
|
||||
.on_changed("text", move |ctx, entity| {
|
||||
state(id, ctx).action(Action::EntryChanged(entity));
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
//.element("text-block")
|
||||
.id("result")
|
||||
.min_width(80.0)
|
||||
.max_width(180.0)
|
||||
//.text("Result:")
|
||||
.text("Ergebnis:")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx)
|
||||
)
|
||||
.child(
|
||||
Grid::new()
|
||||
//.class("logo_customer")
|
||||
.margin((9.0, 16.0, 16.0, 9.0))
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(1))
|
||||
.v_align("end")
|
||||
.child(
|
||||
ImageWidget::new()
|
||||
.image("assets/images/customer_logo.png")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Grid::new()
|
||||
//.class("logo_vendor")
|
||||
.margin((9.0, 16.0, 16.0, 9.0))
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(1))
|
||||
.v_align("end")
|
||||
.child(
|
||||
ImageWidget::new()
|
||||
.image("assets/images/networkx_logo.png")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
) // MainView
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Application::new()
|
||||
.window(|ctx| {
|
||||
Window::new()
|
||||
//.title("OrbTk - Policyholder checker example")
|
||||
.name("MainWindow")
|
||||
.title("AdvoTracker - Versicherungsnummern")
|
||||
.position((-500.0, -100.0))
|
||||
.size(480.0, 260.0)
|
||||
.min_width(460.0)
|
||||
.min_height(180.0)
|
||||
.resizeable(true)
|
||||
//.theme(get_theme())
|
||||
.child(MainView::new().build(ctx))
|
||||
.build(ctx)
|
||||
})
|
||||
.run();
|
||||
}
|
||||
|
||||
// helper to request MainViewState
|
||||
fn state<'a>(id: Entity, states: &'a mut StatesContext) -> &'a mut MainViewState {
|
||||
states.get_mut(id)
|
||||
}
|
||||
1
advotracker_client/src/bin/resources
Symbolic link
1
advotracker_client/src/bin/resources
Symbolic link
@@ -0,0 +1 @@
|
||||
../../resources
|
||||
169
advotracker_client/src/data/constants.rs
Normal file
169
advotracker_client/src/data/constants.rs
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
// Component Values (Properties)
|
||||
pub static PROP_ADVOTRACKER: &str = "advotracker";
|
||||
|
||||
pub static PROP_MAIL_CC_1: &str = "service@hiedemann.de";
|
||||
pub static PROP_MAIL_CC_2: &str = "info@hiedemann.de";
|
||||
pub static PROP_MAIL_BCC_1: &str = "Networkx Support <support@networkx.de>";
|
||||
pub static PROP_MAIL_BCC_2: &str = "knoche@hiedemann.de";
|
||||
pub static PROP_MAIL_FROM: &str = "Kanzlei Hiedemann <service@hiedemann.de>";
|
||||
pub static PROP_MAIL_REPLY: &str = "Kanzlei Hiedemann <service@hiedemann.de>";
|
||||
pub static PROP_MAIL_SUBJECT: &str = "ZMB Allianz - neues Mandat";
|
||||
pub static PROP_MAIL_TO_1: &str = "allianz@ponschab-partner.com";
|
||||
pub static PROP_MAIL_TO_2: &str = "kontakt@chevalier.law";
|
||||
pub static PROP_MAIL_TO_3: &str = "kontakt@metamedlaw.de";
|
||||
pub static PROP_MAIL_TO_4: &str = "sekretariat@m2-mediation.de";
|
||||
pub static PROP_MAIL_TO_5: &str = "ralf.zerres@networkx.de";
|
||||
|
||||
pub static PROP_POLICY_CHECK: &str = "policy_check";
|
||||
pub static PROP_POLICY_PROGRESS_COUNT: &str = "policy_progress_count";
|
||||
|
||||
pub static PROP_POLICY_DATA_LIST: &str = "policy_data_list";
|
||||
pub static PROP_POLICY_DATA_COUNT: &str = "policy_data_count";
|
||||
|
||||
pub static PROP_POLICY_LIST: &str = "policy_list";
|
||||
pub static PROP_POLICY_LIST_COUNT: &str = "policy_list_count";
|
||||
|
||||
// Styles (RON based theme system)
|
||||
pub static STYLE_BOTTOM_BAR: &str = "bottom_bar";
|
||||
pub static STYLE_BUTTON_MENU: &str = "button_menu";
|
||||
pub static STYLE_BUTTON_ACTION: &str = "button_action";
|
||||
pub static STYLE_CONTAINER_ACTION: &str = "container_action";
|
||||
pub static STYLE_CONTAINER_MAIL: &str = "container_mail";
|
||||
pub static STYLE_HEADER_BAR: &str = "header_bar";
|
||||
pub static STYLE_HEADER_TEXT: &str = "header_text";
|
||||
pub static STYLE_SEPARATOR: &str = "separator";
|
||||
pub static STYLE_MAIL_LABEL: &str = "mail_label";
|
||||
pub static STYLE_MAIL_TO: &str = "mail_to";
|
||||
pub static STYLE_MAIL_CC: &str = "mail_cc";
|
||||
pub static STYLE_MENU: &str = "menu";
|
||||
pub static STYLE_STACK_ACTION: &str = "stack_action";
|
||||
pub static STYLE_STACK_MENU: &str = "stack_menu";
|
||||
|
||||
// Widget IDs (DCES: Entity[id] => [Component1, .. , Component<n>] -> data or state)
|
||||
pub static ID_CONFIGURATION_VIEW: &str = "Configuration";
|
||||
pub static ID_CONFIGURATION_FORM: &str = "configuration_form";
|
||||
pub static ID_CONFIGURATION_HEADER: &str = "configuration_header";
|
||||
pub static ID_CONFIGURATION_LABEL_CONFIG_FILE: &str = "configuration_label_config_file";
|
||||
pub static ID_CONFIGURATION_CONFIG_FILE: &str = "configuration_config_file";
|
||||
pub static ID_CONFIGURATION_LABEL_LANGUAGE_ID: &str = "configuration_label_language_id";
|
||||
pub static ID_CONFIGURATION_LANGUAGE_ID: &str = "configuration_language_id";
|
||||
|
||||
pub static ID_LOCALIZATION_VIEW: &str = "Localization";
|
||||
pub static ID_LOCALIZATION_FORM: &str = "localization_form";
|
||||
pub static ID_LOCALIZATION_HEADER: &str = "localization_header";
|
||||
pub static ID_LOCALIZATION_LANGUAGES: &str = "localization_languages";
|
||||
pub static ID_LOCALIZATION_LABEL_LANGUAGE_NAME: &str = "localization_label_language_name";
|
||||
pub static ID_LOCALIZATION_LANGUAGE_NAME: &str = "localization_language_name";
|
||||
|
||||
pub static ID_MAIN_GRID: &str = "main_grid";
|
||||
pub static ID_MAIN_TABWIDGET: &str = "main_tabwidget";
|
||||
pub static ID_MAIN_BUTTON_MENU: &str = "main_button_menu";
|
||||
|
||||
pub static ID_MENU_VIEW: &str = "menu_view";
|
||||
pub static ID_MENU_POPUP: &str = "menu_popup";
|
||||
pub static ID_MENU_STACK: &str = "menu_stack";
|
||||
pub static ID_MENU_BOTTOM_BAR: &str = "menu_bottom_bar";
|
||||
pub static ID_MENU_BUTTON: &str = "menu_button";
|
||||
pub static ID_MENU_BUTTON_MENU: &str = "menu_button_menu";
|
||||
pub static ID_MENU_GRID: &str = "menu_grid";
|
||||
pub static ID_MENU_HEADER: &str = "menu_header";
|
||||
pub static ID_MENU_HEADER_BAR: &str = "menu_header_bar";
|
||||
pub static ID_MENU_LABEL_ACCOUNT: &str = "menu_label_account";
|
||||
pub static ID_MENU_LABEL_QUIT: &str = "menu_label_quit";
|
||||
pub static ID_MENU_LABEL_TOGGLE_THEME: &str = "menu_label_toggle_theme";
|
||||
pub static ID_MENU_SHORTCUT_QUIT: &str = "menu_shortcut_quit";
|
||||
pub static ID_MENU_TOGGLE_THEME: &str = "menu_toggle_theme";
|
||||
|
||||
pub static ID_POLICY_CHECK_VIEW: &str = "policy_check_view";
|
||||
pub static ID_POLICY_CHECK_ACTION_BUTTON_CLEAR: &str = "policy_check_action_button_clear";
|
||||
pub static ID_POLICY_CHECK_ACTION_BUTTON_CREATE: &str = "policy_check_action_button_create";
|
||||
pub static ID_POLICY_CHECK_ACTION_GRID: &str = "policy_check_action_grid";
|
||||
pub static ID_POLICY_CHECK_ACTION_STACK: &str = "policy_check_action_stack";
|
||||
pub static ID_POLICY_CHECK_BOTTOM_BAR: &str = "policy_check_bottom_bar";
|
||||
pub static ID_POLICY_CHECK_BUTTON_RESULT: &str = "policy_check_button_result";
|
||||
pub static ID_POLICY_CHECK_BUTTON_MENU: &str = "policy_check_button_menu";
|
||||
pub static ID_POLICY_CHECK_DATA_COUNT_BLOCK: &str = "policy_check_data_count_block";
|
||||
pub static ID_POLICY_CHECK_FORM: &str = "policy_check_form";
|
||||
pub static ID_POLICY_CHECK_HEADER: &str = "policy_check_header";
|
||||
pub static ID_POLICY_CHECK_HEADER_BAR: &str = "policy_check_header_bar";
|
||||
pub static ID_POLICY_CHECK_HINT: &str = "policy_check_hint";
|
||||
pub static ID_POLICY_CHECK_ITEMS_WIDGET: &str = "policy_check_items_widget";
|
||||
pub static ID_POLICY_CHECK_LABEL_HINT: &str = "policy_check_label_hint";
|
||||
pub static ID_POLICY_CHECK_LABEL_MENU: &str = "policy_check_label_menu";
|
||||
pub static ID_POLICY_CHECK_LABEL_POLICY_NUMBER: &str = "policy_check_label_policy_number";
|
||||
pub static ID_POLICY_CHECK_LABEL_RESULT: &str = "policy_check_label_result";
|
||||
pub static ID_POLICY_CHECK_POLICY_CODE: &str = "policy_check_policy_code";
|
||||
pub static ID_POLICY_CHECK_POLICY_NUMBER: &str = "policy_number";
|
||||
pub static ID_POLICY_CHECK_POPUP_PROGRESS: &str = "policy_check_popup_progress";
|
||||
pub static ID_POLICY_CHECK_PROGRESS_BAR: &str = "policy_check_progress_bar";
|
||||
pub static ID_POLICY_CHECK_PROGRESS_TIME: &str = "policy_check_progress_time";
|
||||
pub static ID_POLICY_CHECK_PROGRESS_TEXT: &str = "policy_check_progress_text";
|
||||
pub static ID_POLICY_CHECK_RESULT: &str = "policy_check_result";
|
||||
pub static ID_POLICY_CHECK_WIDGET: &str = "policy_check_widget";
|
||||
|
||||
pub static ID_POLICY_DATA_ADD_BUTTON: &str = "policy_data_add_button";
|
||||
pub static ID_POLICY_DATA_COUNT: &str = "policy_data_count";
|
||||
pub static ID_POLICY_DATA_LABEL: &str = "policy_data_label";
|
||||
pub static ID_POLICY_DATA_ITEMS_WIDGET: &str = "policy_data_items_widget";
|
||||
pub static ID_POLICY_DATA_DATE_INSERTED: &str = "policy_data_date_inserted";
|
||||
pub static ID_POLICY_DATA_DION: &str = "policy_data_dion";
|
||||
pub static ID_POLICY_DATA_POLICY_CODE: &str = "policy_data_policy_code";
|
||||
pub static ID_POLICY_DATA_POLICY_NUMBER: &str = "policy_data_policy_number";
|
||||
pub static ID_POLICY_DATA_STACK: &str = "policy_data_stack";
|
||||
pub static ID_POLICY_DATA_STATUS: &str = "policy_data_status";
|
||||
pub static ID_POLICY_DATA_LIST_NAME: &str = "policy_data_list_name";
|
||||
|
||||
pub static ID_POLICY_LIST_ADD_BUTTON: &str = "policy_list_add_button";
|
||||
pub static ID_POLICY_LIST_ITEMS_WIDGET: &str = "policy_list_items_widget";
|
||||
pub static ID_POLICY_LIST_TEXT_BOX: &str = "policy_list_text_box";
|
||||
|
||||
pub static ID_TICKET_DATA_ACTION_BUTTON_CLEAR: &str = "ticket_data_action_button_clear";
|
||||
pub static ID_TICKET_DATA_ACTION_BUTTON_SEND: &str = "ticket_data_action_button_send";
|
||||
pub static ID_TICKET_DATA_ACTION_GRID: &str = "ticket_data_action_grid";
|
||||
pub static ID_TICKET_DATA_ACTION_STACK: &str = "ticket_data_action_stack";
|
||||
pub static ID_TICKET_DATA_BOTTOM_BAR: &str = "ticket_data_bottom_bar";
|
||||
pub static ID_TICKET_DATA_BUTTON_MENU: &str = "ticket_data_button_menu";
|
||||
pub static ID_TICKET_DATA_BUTTON_RESULT: &str = "ticket_data_button_result";
|
||||
pub static ID_TICKET_DATA_CALLBACK_DATE: &str = "ticket_data_label_callback_date";
|
||||
pub static ID_TICKET_DATA_CALLBACK_NUMBER: &str = "ticket_data_callback_number";
|
||||
pub static ID_TICKET_DATA_COMBO_BOX_MAIL_CC: &str = "ticket_data_combo_box_mail_cc";
|
||||
pub static ID_TICKET_DATA_COMBO_BOX_MAIL_TO: &str = "ticket_data_combo_box_mail_to";
|
||||
pub static ID_TICKET_DATA_CONTAINER_MAIL: &str = "ticket_data_container_mail";
|
||||
pub static ID_TICKET_DATA_COUNT_BLOCK: &str = "ticket_data_count_block";
|
||||
pub static ID_TICKET_DATA_DEDUCTIBLE: &str = "ticket_data_deductible";
|
||||
pub static ID_TICKET_DATA_FORM: &str = "ticket_data_form";
|
||||
pub static ID_TICKET_DATA_FORM_GRID: &str = "ticket_data_form_grid";
|
||||
pub static ID_TICKET_DATA_GRID: &str = "ticket_data_grid";
|
||||
pub static ID_TICKET_DATA_GRID_MAIL: &str = "ticket_data_grid_mail";
|
||||
pub static ID_TICKET_DATA_HARM_TYPE: &str = "ticket_data_harm_type";
|
||||
pub static ID_TICKET_DATA_HEADER_BAR: &str = "ticket_data_header_bar";
|
||||
pub static ID_TICKET_DATA_HEADER: &str = "ticket_data_header";
|
||||
pub static ID_TICKET_DATA_HINT: &str = "ticket_data_hint";
|
||||
pub static ID_TICKET_DATA_ITEMS_WIDGET: &str = "ticket_data_items_widget";
|
||||
pub static ID_TICKET_DATA_IVR_COMMENT: &str = "ticket_data_ivr_comment";
|
||||
pub static ID_TICKET_DATA_LABEL_CALLBACK_DATE: &str = "ticket_data_label_callback_data";
|
||||
pub static ID_TICKET_DATA_LABEL_CALLBACK_NUMBER: &str = "ticket_data_label_callback_number";
|
||||
pub static ID_TICKET_DATA_LABEL_DEDUCTIBLE: &str = "ticket_data_label_deductible";
|
||||
pub static ID_TICKET_DATA_LABEL_HARM_TYPE: &str = "ticket_data_label_harm_type";
|
||||
pub static ID_TICKET_DATA_LABEL_HINT: &str = "ticket_data_label_hint";
|
||||
pub static ID_TICKET_DATA_LABEL_IVR_COMMENT: &str = "ticket_data_label_ivr_comment";
|
||||
pub static ID_TICKET_DATA_LABEL_MAIL_CC: &str = "ticket_data_label_mail_cc";
|
||||
pub static ID_TICKET_DATA_LABEL_MAIL_TO: &str = "ticket_data_label_mail_to";
|
||||
pub static ID_TICKET_DATA_LABEL_MENU: &str = "ticket_data_label_menu";
|
||||
pub static ID_TICKET_DATA_LABEL_POLICY_CODE: &str = "ticket_data_label_policy_code";
|
||||
pub static ID_TICKET_DATA_LABEL_POLICY_HOLDER: &str = "ticket_data_label_policy_holder";
|
||||
pub static ID_TICKET_DATA_LOGO_BAR: &str = "ticket_data_logo_bar";
|
||||
pub static ID_TICKET_DATA_MAIL_CC: &str = "ticket_data_mail_cc";
|
||||
pub static ID_TICKET_DATA_MAIL_TO: &str = "ticket_data_mail_to";
|
||||
pub static ID_TICKET_DATA_POLICY_CODE: &str = "ticket_data_policy_code";
|
||||
pub static ID_TICKET_DATA_POLICY_HOLDER: &str = "ticket_data_policy_holder";
|
||||
pub static ID_TICKET_DATA_RESULT: &str = "ticket_data_result";
|
||||
pub static ID_TICKET_DATA_VIEW: &str = "ticket_data_view";
|
||||
pub static ID_TICKET_DATA_WIDGET: &str = "ticket_data_widget";
|
||||
13
advotracker_client/src/data/mod.rs
Normal file
13
advotracker_client/src/data/mod.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
|
||||
/// provides orbtk widgets constants
|
||||
pub mod constants;
|
||||
|
||||
/// structures with implementations
|
||||
pub mod structures;
|
||||
364
advotracker_client/src/data/structures.rs
Normal file
364
advotracker_client/src/data/structures.rs
Normal file
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
use orbtk::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// An enumeration of valid policy codes.
|
||||
/// right now, only "AS" is used.
|
||||
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)]
|
||||
pub enum PolicyCode {
|
||||
/// Allianz Sachversicherung
|
||||
AS
|
||||
}
|
||||
|
||||
impl Default for PolicyCode {
|
||||
fn default() -> Self { PolicyCode::AS }
|
||||
}
|
||||
|
||||
/// Classifier of the Allinaz DirectCall communication type.
|
||||
pub enum CommunicationType {
|
||||
/// Anhörung
|
||||
A,
|
||||
/// Bußgeldbescheid
|
||||
BU,
|
||||
/// Gdb
|
||||
Gdb,
|
||||
/// Geburt
|
||||
GE,
|
||||
/// Hochzeit
|
||||
HO,
|
||||
/// Kündigung
|
||||
KD,
|
||||
/// Kaufvertrag
|
||||
KV,
|
||||
/// Lohn
|
||||
LO,
|
||||
/// Nachbar
|
||||
NA,
|
||||
/// Rente
|
||||
RE,
|
||||
/// Unfallflucht
|
||||
UF,
|
||||
/// Unterhalt
|
||||
UH,
|
||||
/// Unfall
|
||||
UN,
|
||||
/// Vodafone
|
||||
VF,
|
||||
/// Vermieter
|
||||
VM,
|
||||
/// Verwaltungsrecht
|
||||
VW,
|
||||
/// Zeugins
|
||||
ZE,
|
||||
/// Typ is unspecified
|
||||
XX
|
||||
}
|
||||
|
||||
impl Default for CommunicationType {
|
||||
fn default() -> Self { CommunicationType::XX }
|
||||
}
|
||||
|
||||
/// Status of a given policy data element.
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
|
||||
pub enum Status {
|
||||
/// Active -> the policy is active an supported
|
||||
Active,
|
||||
/// Inactive -> the policy is inactive or resigned
|
||||
Inactive
|
||||
}
|
||||
|
||||
impl Default for Status {
|
||||
fn default() -> Self { Status::Active }
|
||||
}
|
||||
|
||||
/// A communication type describes possible classifications of customer calls.
|
||||
/// If the type isn't selected, the default will be 'unclassified -> XX'.
|
||||
#[derive(Default, Deserialize, Serialize)]
|
||||
pub struct CommunicationData {
|
||||
/// pub communication_type: CommunicationType,
|
||||
pub communication_type: String,
|
||||
/// A literal name describing the selected communication type
|
||||
pub communication_name: String
|
||||
}
|
||||
|
||||
/// CSV Export
|
||||
/// The structure elements are required for an export to a comma seperated text list.
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct CsvExportRecord {
|
||||
/// Versicherungsschein Code
|
||||
pub policy_code: String,
|
||||
/// Versicherungsscheinnummer (10-stellig, numerisch)
|
||||
pub policy_number: u64,
|
||||
/// Anrufer: "Vorname, Nachname"
|
||||
pub policy_holder: String,
|
||||
/// Sachverhalt: "Kurzschilderung"
|
||||
pub facts: String,
|
||||
/// Schadensart: "harm_name (harm_id)"
|
||||
pub harm_type: String,
|
||||
/// communication_type => Kommunikationszeichen: "(communication_name)"
|
||||
pub communication_name: String,
|
||||
/// ra_hotline => RA_Hotline: Kanzlei Laqua, Kanzlei Buschbell, Kanzlei DAH, Kanzlei Hiedemann
|
||||
pub ra_hotline: String, // const "Kanzlei Hiedemann",
|
||||
/// ivr_comment => Haftungs-/Deckungskommentar; #IVR (ggf. ergänzt um das Beratungsergebnis)
|
||||
pub ivr_comment: String,
|
||||
}
|
||||
|
||||
/// Handel fields of an Email (header, body)
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Email {
|
||||
/// Recipient address
|
||||
pub mail_to: String,
|
||||
/// Carbon Copy recipient address
|
||||
pub mail_cc: String,
|
||||
/// Blind Carbon Copy recipient address
|
||||
pub mail_bcc: String,
|
||||
/// Sender address
|
||||
pub mail_from: String,
|
||||
/// Replay to given address
|
||||
pub mail_reply: String,
|
||||
/// Mail subject
|
||||
pub subject: String,
|
||||
/// Body policy code
|
||||
pub policy_code: String,
|
||||
/// Body type policy holder
|
||||
pub policy_holder: String,
|
||||
/// Body type deductible
|
||||
pub deductible: String,
|
||||
/// Body callback number
|
||||
pub callback_number: String,
|
||||
/// Body type callback date
|
||||
pub callback_date: String,
|
||||
/// Body type harm type
|
||||
pub harm_type: String,
|
||||
/// Body type ivr comment
|
||||
pub ivr_comment: String
|
||||
}
|
||||
|
||||
impl Email {}
|
||||
|
||||
/// Harm data are list/collections of harm types. You may toggle them to an unselected state.
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct HarmData {
|
||||
/// Liste der Schadensdaten
|
||||
pub harm_data: Vec<HarmType>,
|
||||
/// Status der Schadenliste
|
||||
//pub name: String,
|
||||
pub selected: bool
|
||||
}
|
||||
|
||||
/// Harm types are destincted by a type code.
|
||||
/// The type code represents the unique harm identifier, bound with a literal name.
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct HarmType {
|
||||
/// Kennzeichen des Schadenstyps
|
||||
// Schadenersatz-RS im Verkehrsbereich (RS112)
|
||||
// Ordnungswidrigkeits-RS im Verkehrsbereich (RS122)
|
||||
// Straf-RS im Verkehrsbereich (RS121)
|
||||
// Vertrags-RS im Verkehrsbereich (RS118)
|
||||
// Vertrags-RS im Privatbereich (RS218)
|
||||
// Arbeits-RS im Berufsbereich (RS315)
|
||||
// WuG-RS im Privatbereich (RS220)
|
||||
// Sozialgerichts-RS im Privatbereich (RS216)
|
||||
// Rechtsschutz im Familien- und Erbrecht (RS217)
|
||||
// Wagnis nicht versicherbar / versichert (RS999)
|
||||
pub harm_type: String,
|
||||
/// Beschreibung des Schadenstyps
|
||||
pub harm_name: String,
|
||||
}
|
||||
|
||||
/// Structure used to verify a policy data element.
|
||||
#[derive(Default, Debug, Clone, Deserialize, PartialEq, Serialize)]
|
||||
pub struct PolicyCheck {
|
||||
/// Versicherungsschein-Prüfnummer
|
||||
pub policy_check_number: String,
|
||||
/// Referenz zum Versicherungsschein-Typ
|
||||
pub dion: u8,
|
||||
/// Referenz zum Versicherungsschein-Typ
|
||||
pub policy_code: PolicyCode,
|
||||
/// Referenz zur Versicherungsschein-Nummer
|
||||
pub policy_number: u64,
|
||||
/// Validitätsergebnis
|
||||
pub policy_number_status: Status
|
||||
}
|
||||
|
||||
impl PolicyCheck {}
|
||||
|
||||
/// Structure collecting policy data elements
|
||||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct PolicyList {
|
||||
/// Bescheibung der Versicherungsdatenliste
|
||||
pub name: String,
|
||||
/// Listenelemente der Versicherungsdatendaten
|
||||
pub policy_list: Vec<PolicyDataList>,
|
||||
}
|
||||
|
||||
/// implements helper methods, that manage lists of policy data collections
|
||||
impl PolicyList {
|
||||
/// Index auf Versicherungsliste zurückgeben (unveränderbar)
|
||||
pub fn get(&self, index: usize) -> Option<&PolicyDataList> {
|
||||
self.policy_list.get(index)
|
||||
}
|
||||
|
||||
/// Index auf Versicherungsliste zurückgeben (veränderbar)
|
||||
pub fn get_mut(&mut self, index: usize) -> Option<&mut PolicyDataList> {
|
||||
self.policy_list.get_mut(index)
|
||||
}
|
||||
|
||||
/// Neuer Eintrag am Anfang der Liste einfügen.
|
||||
pub fn insert_front(&mut self, policy_list: PolicyDataList) {
|
||||
self.policy_list.insert(0, policy_list);
|
||||
}
|
||||
|
||||
/// Prüfung ob Versicherungsliste keine Elemente enthält.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.policy_list.is_empty()
|
||||
}
|
||||
|
||||
/// Berechnet die Anzahl der Versicherungslisten Elemente.
|
||||
pub fn len(&self) -> usize {
|
||||
self.policy_list.len()
|
||||
}
|
||||
|
||||
/// Neuen Versicherungslisten-Namen erzeugen
|
||||
pub fn new(name: impl Into<String>) -> Self {
|
||||
PolicyList {
|
||||
name: name.into(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Element der Versicherungsliste anfügen
|
||||
pub fn push(&mut self, policy_list: PolicyDataList) {
|
||||
self.policy_list.push(policy_list);
|
||||
}
|
||||
|
||||
/// Element der Versicherungsliste löschen
|
||||
pub fn remove(&mut self, index: usize) -> PolicyDataList {
|
||||
self.policy_list.remove(index)
|
||||
}
|
||||
}
|
||||
|
||||
/// Structure collects policy data elements.
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct PolicyDataList {
|
||||
/// Verfalldatum des Versicherungslisten Elements
|
||||
pub date_valid_until: Option<NaiveDateTime>,
|
||||
/// Elemente des Versicherungsobjektes
|
||||
pub policy_data: Vec<PolicyData>,
|
||||
/// Name der Versicherungsliste
|
||||
pub name: String,
|
||||
/// Status der Versicherungsliste
|
||||
pub selected: bool
|
||||
}
|
||||
|
||||
/// implements the helper methods, to manage policy data collections.
|
||||
impl PolicyDataList {
|
||||
/// Prüfung auf Versicherungselemente
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.policy_data.is_empty()
|
||||
}
|
||||
|
||||
/// Versicherungselement am Anfang anfügen
|
||||
pub fn insert_front(&mut self, policy_data: PolicyData) {
|
||||
self.policy_data.insert(0, policy_data);
|
||||
}
|
||||
|
||||
/// Index zum Versicherungselement zurückgeben (unveränderbar)
|
||||
pub fn get(&self, index: usize) -> Option<&PolicyData> {
|
||||
self.policy_data.get(index)
|
||||
}
|
||||
|
||||
/// Index zum Versicherungselement zurückgeben (veränderbar)
|
||||
pub fn get_mut(&mut self, index: usize) -> Option<&mut PolicyData> {
|
||||
self.policy_data.get_mut(index)
|
||||
}
|
||||
|
||||
/// Berechnet die Anzahl der Versicherungselemente.
|
||||
pub fn len(&self) -> usize {
|
||||
self.policy_data.len()
|
||||
}
|
||||
|
||||
/// Neues Versicherungselement erstellen.
|
||||
pub fn new(name: impl Into<String>) -> Self {
|
||||
// the new inserted element will be active by default
|
||||
PolicyDataList {
|
||||
date_valid_until: None,
|
||||
name: name.into(),
|
||||
selected: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Versicherungselement anfügen
|
||||
pub fn push(&mut self, policy_data: PolicyData) {
|
||||
self.policy_data.push(policy_data);
|
||||
}
|
||||
|
||||
/// Versicherungselement löschen
|
||||
pub fn remove(&mut self, index: usize) -> PolicyData {
|
||||
self.policy_data.remove(index)
|
||||
}
|
||||
}
|
||||
|
||||
/// Structure representing a policy data element
|
||||
/// This structure groups a set of fields that describes a policy number.
|
||||
/// The data are regularily updated via a data import from a comma seperated
|
||||
/// text file (csv file).
|
||||
/// Since we parse the source record fields to rust types (serde deserialize)
|
||||
/// the field order in our struct must meet the data field order in the source!
|
||||
/// We do use field attribute to precisely rename the source fields (header names)
|
||||
/// to our target rust field names.
|
||||
/// Referenz: POLLFNR_WOECHENTLICH.txt ->
|
||||
/// Header 'DION VERS POLLFNR'
|
||||
/// Record '1 AS 1515735810'
|
||||
// DION: Allianz id => len = 1??
|
||||
// VERS: policy_code => enum(AS; ??)
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct PolicyData {
|
||||
/// Erstellungsdatum
|
||||
pub date_inserted: Option<NaiveDateTime>,
|
||||
/// Allianz Dion
|
||||
#[serde(rename = "DION")]
|
||||
pub dion: u8,
|
||||
/// Kennzeichen des Allianz Versicherungscodes
|
||||
#[serde(rename = "VERS")]
|
||||
pub policy_code: PolicyCode,
|
||||
/// Versicherungsscheinnummer (10stellig, numerisch)
|
||||
#[serde(rename = "POLLFNR")]
|
||||
pub policy_number: u64,
|
||||
/// Status des Versicherungsscheins
|
||||
pub status: Option<Status>
|
||||
}
|
||||
|
||||
/// Policy Number Set
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct AllianzPolicyNumber {
|
||||
/// Allianz Dion
|
||||
#[serde(rename = "DION")]
|
||||
pub dion: u8,
|
||||
/// Kennzeichen des Allianz Versicherungstyps
|
||||
#[serde(rename = "VERS")]
|
||||
pub policy_code: String,
|
||||
/// 10-stellige Versicherungsscheinnummer (numerisch)
|
||||
#[serde(rename = "POLLFNR")]
|
||||
pub policy_number: usize
|
||||
}
|
||||
|
||||
// /// List of Allianz Policy Number records
|
||||
// /// The structure elements are required for an export to a comma seperated text list.
|
||||
// #[derive(Default, Debug, Deserialize)]
|
||||
// pub struct AllianzPolicyNumberList {
|
||||
// records: Vec<AllianzPolicyNumber>
|
||||
// }
|
||||
|
||||
into_property_source!(PolicyCheck);
|
||||
into_property_source!(PolicyDataList);
|
||||
into_property_source!(PolicyList);
|
||||
147
advotracker_client/src/i18n/localization.ini
Normal file
147
advotracker_client/src/i18n/localization.ini
Normal file
@@ -0,0 +1,147 @@
|
||||
[err_lang_not_found]
|
||||
de = Konnte Sprachkode nicht auslesen
|
||||
en = Couldn't read
|
||||
[err_user_not_found]
|
||||
fr = Utilisateur introuvable
|
||||
en = User not found
|
||||
[main_started]
|
||||
de = Programmlogik starten
|
||||
en = Program logic started
|
||||
[main_finished]
|
||||
de = Programmlogik beendet
|
||||
en = Program logic finished
|
||||
[parse_arguments]
|
||||
de = Programmargumente prüfen
|
||||
en = Parsing arguments
|
||||
[parse_environment]
|
||||
de = Umgebungsvariablen prüfen
|
||||
en = Parsing environment
|
||||
[parse_results]
|
||||
de = Ergebnisse der Konfigurationsparameterprüfung
|
||||
en = Config parsing results
|
||||
[config_name]
|
||||
de = Konfigurationswert für
|
||||
en = Config Value for
|
||||
[config_name_lang]
|
||||
de = Sprach-Co
|
||||
en = Language co
|
||||
[config_name_verbositylevel]
|
||||
de = Ausgabe-Ebene
|
||||
en = verbosity level
|
||||
[config_name_environment]
|
||||
de = Umgebungsvariablen
|
||||
en = environment
|
||||
[config_name_configfile]
|
||||
de = Konfigurations-Datei
|
||||
en = config file
|
||||
[config_name_dbdriver]
|
||||
de = Datenbank-Treiber
|
||||
en = database driver
|
||||
[config_name_redis]
|
||||
de = Redis Datenbank
|
||||
en = Redis database
|
||||
[csv_export_started]
|
||||
de = Export in eine CSV Datei starten
|
||||
en = Export to csv file started
|
||||
[csv_export_finished]
|
||||
de = Export in eine CSV Datei beendet
|
||||
en = Export to csv file finished
|
||||
[csv_import_started]
|
||||
de = Import aus einer CSV Datei
|
||||
en = Import from a csv file
|
||||
[csv_import_finished]
|
||||
de = Import aus einer CSV Datei beendet
|
||||
en = Import from a csv file finished
|
||||
[redis_connection_error]
|
||||
de = Es konnte keine Redis Verbindung aufgebaut werden
|
||||
en = Could not establish a redis connection
|
||||
[policy_hashmap_success]
|
||||
de = Hashmap wurde erfolgreich erstellt
|
||||
en = Hashmap creation was successfull
|
||||
[policy_hashmap_failed]
|
||||
de = Hashmap konnte nicht erstellt werden
|
||||
en = Hashmap creation failed
|
||||
[policy_menu_label]
|
||||
de = Menü
|
||||
en = Menu
|
||||
[policy_menu_label_account]
|
||||
de = Aktueller Benutzer
|
||||
en = Active user
|
||||
[policy_menu_label_quit]
|
||||
de = Beenden
|
||||
en = Quit
|
||||
[policy_menu_label_toggle_theme]
|
||||
de = Thema wechseln
|
||||
en = Toggle theme
|
||||
[policy_string_header]
|
||||
de = Validierung Versicherungsnummer
|
||||
en = Policy number validation
|
||||
[policy_string_label_policy_data]
|
||||
de = Importierte Daten
|
||||
en = imported data
|
||||
[policy_string_label_policy_list]
|
||||
de = Versicherungsnummern-Liste
|
||||
en = policy list
|
||||
[policy_string_label_policy_number]
|
||||
de = Versicherungsnummer
|
||||
en = policy number
|
||||
[policy_string_label_result]
|
||||
de = Prüfungsergebnis
|
||||
en = check result
|
||||
[policy_string_data_count]
|
||||
de = Anzahl Prüflistenelemente
|
||||
en = Number of checklist elements
|
||||
[policy_string_import_data]
|
||||
de = Importieren der Prüflisten-Elemente
|
||||
en = Import checklist elements
|
||||
[policy_string_progress_time]
|
||||
de = Bearbeitungszeit
|
||||
en = processing time
|
||||
[policy_string_progress_text]
|
||||
de = Importiere Daten
|
||||
en = Importing data
|
||||
[policy_validation_button_failed]
|
||||
de = ungültig
|
||||
en = invalid
|
||||
[policy_validation_button_success]
|
||||
de = gültig
|
||||
en = valid
|
||||
[policy_validation_failed]
|
||||
de = Die Versicherungsscheinnummber ist ungültig
|
||||
en = The given policy number is invalid
|
||||
[policy_validation_new]
|
||||
de = Neue Prüfung
|
||||
en = New validation
|
||||
[policy_validation_success]
|
||||
de = Die Versicherungsscheinnummber ist gültig
|
||||
en = The given policy number is valid
|
||||
[policy_validation_started]
|
||||
de = Die Prüfung der Versicherungsscheinnummber wurde gestartet
|
||||
en = Validation of the policy number started
|
||||
[policy_validation_finished]
|
||||
de = Die Prüfung der Versicherungsscheinnummber wurde beendet
|
||||
en = Validation of the policy number finished
|
||||
[policy_validation_invalid_input]
|
||||
de = Nur Nummer sind zulässig
|
||||
en = Only numbers are valid
|
||||
[policy_validation_not_found]
|
||||
de = Nummer ist nicht aktiviert
|
||||
en = number isn't marked active
|
||||
[policy_validation_to_long]
|
||||
de = Die Nummer ist zu lang
|
||||
en = Policy number is to long
|
||||
[policy_validation_to_short]
|
||||
de = Die Nummer ist zu kurz
|
||||
en = Policy number is to short
|
||||
[sendticketdata_export_started]
|
||||
de = Versenden von ticket daten via eMail gestartet
|
||||
en = Send ticket data via eMail started
|
||||
[sendticketdata_export_finished]
|
||||
de = Versenden von ticket daten via eMail beendet
|
||||
en = Send ticket data via eMail finished
|
||||
[state_started]
|
||||
de = gestartet
|
||||
en = started
|
||||
[state_finished]
|
||||
de = beended
|
||||
en = finished
|
||||
46
advotracker_client/src/lib.rs
Normal file
46
advotracker_client/src/lib.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: 0BSD, MIT
|
||||
*/
|
||||
|
||||
#![crate_name = "advotracker_client"]
|
||||
#![crate_type = "lib"]
|
||||
|
||||
//#![warn(missing_docs, rust_2018_idioms, rust_2018_compatibility)]
|
||||
#![warn(rust_2018_idioms, rust_2018_compatibility)]
|
||||
|
||||
//! advotracker
|
||||
//! Supports lawyers to capture relevant data encountered during an
|
||||
//! online legal advice.
|
||||
//! This is the frontend componet that communicates to the backend `advotrackerd`.
|
||||
//!
|
||||
//! The crate is called `advotracker` and you can depend on it via cargo:
|
||||
//!
|
||||
//! ```ini
|
||||
//! [dependencies]
|
||||
//! advotracker = { version = "~0.1" }
|
||||
//! ```
|
||||
//!
|
||||
//! 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;
|
||||
|
||||
/// provides data definitions
|
||||
pub mod data;
|
||||
|
||||
/// provides orbtk widgets (handling views and states)
|
||||
pub mod widgets;
|
||||
|
||||
/// provides services
|
||||
pub mod services;
|
||||
|
||||
// /// Provide test data
|
||||
// #[cfg!Test]
|
||||
// pub mod data;
|
||||
223
advotracker_client/src/main.rs
Normal file
223
advotracker_client/src/main.rs
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
// suppress creation of a new console window on window
|
||||
#![windows_subsystem = "windows"]
|
||||
|
||||
//use chrono::{Local, DateTime};
|
||||
use dotenv::dotenv;
|
||||
use cfg_if::cfg_if;
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
//use std::process;
|
||||
use substring::Substring;
|
||||
use tracing::{info, trace, Level};
|
||||
|
||||
use orbtk::{
|
||||
prelude::*,
|
||||
theme_default::{THEME_DEFAULT, THEME_DEFAULT_COLORS_DARK, THEME_DEFAULT_FONTS},
|
||||
theming::config::ThemeConfig,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use orbtk::theme_fluent::{THEME_FLUENT, THEME_FLUENT_COLORS_DARK, THEME_FLUENT_FONTS};
|
||||
|
||||
// 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
|
||||
/// located in the current call directory
|
||||
/// this is primarily used in testing scenarios (eg. debugging)
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Environment {
|
||||
lang: Lang,
|
||||
test_lang: String,
|
||||
rust_log: String,
|
||||
}
|
||||
|
||||
// Style extension
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
// German localization file.
|
||||
static ADVOTRACKER_DE_DE: &str = include_str!("../assets/advotracker/advotracker_de_DE.ron");
|
||||
|
||||
/// Get the active language environment.
|
||||
fn get_lang() -> String {
|
||||
// get system environment
|
||||
let mut lang = env::var("LANG").unwrap_or_else(|_| "en".to_string());
|
||||
lang = lang.substring(0,2).to_string(); // "de_DE.UTF-8" -> "de"
|
||||
info!("GUI-Language: preset to {:?}", lang);
|
||||
|
||||
// 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) => { info!(target: "advotracker", "{}", e) }
|
||||
}
|
||||
trace!(target: "advotracker", lang = ?lang);
|
||||
|
||||
// return the active language
|
||||
lang
|
||||
}
|
||||
|
||||
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)),
|
||||
}
|
||||
} 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)),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
use parse_args::parse_args;
|
||||
use tracing_subscriber::fmt;
|
||||
use viperus::Viperus;
|
||||
|
||||
let machine_kind = if cfg!(unix) {
|
||||
"unix"
|
||||
} else if cfg!(windows) {
|
||||
"windows"
|
||||
} else {
|
||||
"unknown/unsupported"
|
||||
};
|
||||
|
||||
// respect dotenv environment (e.g for testing)
|
||||
// -> overwrites the preset default values
|
||||
let rust_log = dotenv::var("RUST_LOG").unwrap_or_else(|_| String::from("None"));
|
||||
|
||||
// initialize the tracing subsystem
|
||||
// a drop in replacement for classical logging
|
||||
// reference: https://tokio.rs/blog/2019-08-tracing/
|
||||
let span = tracing::span!(Level::TRACE, "advotracker");
|
||||
let _enter = span.enter();
|
||||
let collector = fmt::Subscriber::builder()
|
||||
.with_env_filter(&rust_log)
|
||||
//.with_max_level(tracing::Level::DEBUG)
|
||||
.finish();
|
||||
|
||||
tracing::subscriber::with_default(collector, || {
|
||||
// get system environment
|
||||
//let lang = get_lang();
|
||||
let lang = Lang::De("de");
|
||||
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
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::<String>("test_policy_number").unwrap().parse::<u64>().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);
|
||||
|
||||
// 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();
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
213
advotracker_client/src/parse_args.rs
Normal file
213
advotracker_client/src/parse_args.rs
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
// parse CLI commandline arguments with clap
|
||||
use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg};
|
||||
|
||||
//use log::{debug, info, trace, warn};
|
||||
use std::env;
|
||||
use tracing::trace;
|
||||
use viperus::Viperus;
|
||||
|
||||
/// Parse the commandline arguments and preset default values
|
||||
/// Precedence: defaults -> config-file -> environment -> commandline
|
||||
pub fn parse_args(viperus: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if cfg!(feature = "global") {
|
||||
trace!(target: "Viperus", "Viperus feature 'global' enabled.");
|
||||
println!("Lasy static: 'VIPERUS' is accessible globaly");
|
||||
}
|
||||
|
||||
if cfg!(feature = "fmt-clap") {
|
||||
trace!(target: "Viperus", "Viperus feature 'fmt-clap' enabled.");
|
||||
println!("Using feature fmt-clap");
|
||||
}
|
||||
|
||||
// preset default key/value pairs (lowest priority)
|
||||
viperus.add_default("config_file", String::from("csv_import.ron"));
|
||||
viperus.add_default("import_file", String::from("POLLFNR_WOECHENTLICH.txt"));
|
||||
viperus.add_default("export_file", String::from(""));
|
||||
viperus.add_default("test_policy_number", String::from("9999999992"));
|
||||
viperus.add_default("to_email_address_file", String::from("Allianz RA-Hotline <smr-rahotline@allianz.de>"));
|
||||
viperus.add_default("from_email_address_file", String::from("Allianz-Hotline RA-Hiedemann <azhotline@hiedemann.de>"));
|
||||
//viperus.add_default("username", String::from("nctalkbot"));
|
||||
//viperus.add_default("password", String::from("botpassword"));
|
||||
viperus.add_default("verbose", 0);
|
||||
|
||||
// CLI arguments are defined inline
|
||||
let matches = App::new("advotracker")
|
||||
.name(crate_name!())
|
||||
.version(crate_version!())
|
||||
.author(crate_authors!())
|
||||
.about(crate_description!())
|
||||
.after_help("
|
||||
Testprogramm: Allianz Online-Beratung Im/Export CSV-Daten
|
||||
Direct-Call via IVR-System (Interactive Voice Response)
|
||||
SMR Deckungssummen-Prüfung: 089 92529 60211
|
||||
SMR Unerledigt: 089 92529 60222")
|
||||
.template(
|
||||
"\
|
||||
{bin} v{version}
|
||||
{about}
|
||||
|
||||
{all-args}
|
||||
|
||||
(C) 2020 {author}
|
||||
{after-help}",
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("configFile")
|
||||
.short("c")
|
||||
.long("configFile")
|
||||
.value_name("FILE")
|
||||
.help("Select a config file")
|
||||
.default_value("csv_import.ron")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("importFile")
|
||||
.short("i")
|
||||
.long("importFile")
|
||||
.help("Select source file for the csv-import")
|
||||
.default_value("POLLFNR_WOECHENTLICH.txt")
|
||||
//.default_value("POLLFNR_MINI.txt")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("exportFile")
|
||||
.short("e")
|
||||
.long("exportFile")
|
||||
.help("Select target file for the csv-export")
|
||||
.default_value("RA-Hiedemann_DirectCall.txt")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("fromEmailAddress")
|
||||
.short("f")
|
||||
.long("fromEmailAddress")
|
||||
.help("Select the sender email-address (From:)")
|
||||
.default_value("Allianz-Hotline RA-Hiedemann <azhotline@hiedemann.de>")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("toEmailAddress")
|
||||
.short("t")
|
||||
.long("toEmailAddress")
|
||||
.help("Select the target email-address (To:)")
|
||||
.default_value("Allianz RA-Hotline <smr-rahotline@allianz.de>")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("testPolicyNumber")
|
||||
.short("p")
|
||||
.long("testPolicyNumber")
|
||||
.help("Test validity of given policy number")
|
||||
//.default_value("")
|
||||
.takes_value(true),
|
||||
)
|
||||
// .arg(
|
||||
// Arg::with_name("username")
|
||||
// .short("u")
|
||||
// .long("username")
|
||||
// .help("Sets username")
|
||||
// .takes_value(true),
|
||||
// )
|
||||
// .arg(
|
||||
// Arg::with_name("password")
|
||||
// .short("P")
|
||||
// .long("password")
|
||||
// .help("Sets password")
|
||||
// .takes_value(true),
|
||||
// )
|
||||
.arg(
|
||||
Arg::with_name("verbose")
|
||||
.short("v")
|
||||
.long("verbose")
|
||||
.help("Sets verbosity level")
|
||||
.multiple(true),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
if matches.occurrences_of("verbose") > 0 {
|
||||
// clap is using i64, viperus i32
|
||||
let n = matches.occurrences_of("verbose") as i32;
|
||||
viperus.add("verbose", n);
|
||||
}
|
||||
|
||||
// preset the prefix for relevant environment variables ("ADVOTRACKER_")
|
||||
let mut env_prefix: String = crate_name!().to_uppercase();
|
||||
env_prefix.push('_');
|
||||
viperus.set_env_prefix(&env_prefix);
|
||||
|
||||
// enable caching and automatic update of environment values
|
||||
viperus.cache(true);
|
||||
viperus.automatic_env(true);
|
||||
|
||||
// load user selected call arguments
|
||||
// -> overwrites values given via environment variables
|
||||
viperus.load_clap(matches)?;
|
||||
|
||||
// bond the clap names to camel_case rust variable names
|
||||
viperus.bond_clap("configFile", "config_file");
|
||||
viperus.bond_clap("importFile", "import_file");
|
||||
viperus.bond_clap("exportFile", "export_file");
|
||||
viperus.bond_clap("toEmailAddress", "to_email_address");
|
||||
viperus.bond_clap("fromEmailAddress", "from_email_address");
|
||||
viperus.bond_clap("testPolicyNumber", "test_policy_number");
|
||||
//viperus.bond_clap("username", "username");
|
||||
//viperus.bond_clap("password", "password");
|
||||
viperus.bond_clap("verbose", "verbose");
|
||||
|
||||
trace!("verbose {:?}", viperus.get::<i32>("verbose").unwrap());
|
||||
if viperus.get::<i32>("verbose").unwrap() > 0 {
|
||||
println!(
|
||||
"config_file: {:?}",
|
||||
viperus.get::<String>("config_file").unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"import_file: {:?}",
|
||||
viperus.get::<String>("import_file").unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"export_file: {:?}",
|
||||
viperus.get::<String>("export_file").unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"to_email_address: {:?}",
|
||||
viperus.get::<String>("to_email_address").unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"from_email_address: {:?}",
|
||||
viperus.get::<String>("from_email_address").unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"test_policy_number: {:?}",
|
||||
viperus.get::<i32>("test_policy_number").unwrap_or_default()
|
||||
);
|
||||
// println!(
|
||||
// "username: {:?}",
|
||||
// viperus.get::<String>("username").unwrap_or_default()
|
||||
// );
|
||||
// println!(
|
||||
// "password: {:?}",
|
||||
// viperus.get::<String>("password").unwrap_or_default()
|
||||
// ); // only for testing now
|
||||
|
||||
println!(
|
||||
"verbosity level: {:?}",
|
||||
viperus.get::<i32>("verbose").unwrap_or_default()
|
||||
);
|
||||
}
|
||||
|
||||
if viperus.get::<i32>("verbose").unwrap() > 1 {
|
||||
println!("\nEnvironment:");
|
||||
for (key, value) in env::vars() {
|
||||
println!("{}={}", key, value);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
127
advotracker_client/src/services/exports/#send_ticketdata.rs#
Normal file
127
advotracker_client/src/services/exports/#send_ticketdata.rs#
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use lettre::{
|
||||
message::{header, MultiPart, SinglePart},
|
||||
Message, SmtpTransport, Transport,
|
||||
transport::smtp::authentication::Credentials,
|
||||
};
|
||||
use maud::html;
|
||||
use std::error::Error;
|
||||
//use std::process;
|
||||
use tracing::{info, trace};
|
||||
|
||||
use crate::data::structures::Email;
|
||||
use self::t;
|
||||
|
||||
// include localization strings
|
||||
include!(concat!(env!("OUT_DIR"), "/i18n.rs"));
|
||||
|
||||
/// send ticket data via eMail
|
||||
pub fn sendticketdata(email: &Email, language: &str) -> Result<(), Box<dyn Error>> {
|
||||
use self.t;
|
||||
|
||||
let mut res = t!(sendticketdata_export_started => lang);
|
||||
let mut state = t!(state_started => lang);
|
||||
trace!(target: "sendticketdata", process = ?res, state = ?state);
|
||||
|
||||
// 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) }
|
||||
}
|
||||
};
|
||||
|
||||
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";
|
||||
|
||||
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");
|
||||
|
||||
|
||||
info!("message: {:?}", message);
|
||||
|
||||
// Create credential for remote authentication (username, password)
|
||||
// WIP: get credentials from config file / cli
|
||||
let credentials = Credentials::new("service@hiedemann.de".to_string(), "88service99$".to_string());
|
||||
|
||||
// standard smtp client connection
|
||||
//let mailer = SmtpTransport::starttls_relay("hiedemannsbs.kanzlei.hiedemann.de")
|
||||
|
||||
// Open a remote connection to relay server (port 2525)
|
||||
// WIP: get relay address from config file / cli
|
||||
//let relay = "hiedemannsbs.kanzlei.hiedemann.de"
|
||||
let relay = "smtp.strato.de";
|
||||
|
||||
let mailer = SmtpTransport::relay(relay)
|
||||
.unwrap()
|
||||
.credentials(credentials)
|
||||
.build();
|
||||
|
||||
trace!(target: "sendticketdata", email = ?email);
|
||||
|
||||
// Send the email and catch the error if it isn't successfully
|
||||
let _result = mailer.send(&message)?;
|
||||
|
||||
state = t!(state_finished => lang);
|
||||
res = t!(sendticketdata_export_finished => lang);
|
||||
trace!(target: "sendticketdata", process = ?res, state = ?state);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
38
advotracker_client/src/services/exports/allianzdirectcall.rs
Normal file
38
advotracker_client/src/services/exports/allianzdirectcall.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
//use chrono::{Local, DateTime};
|
||||
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: &Lang) -> Result<(), Box<dyn Error>> {
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
//use std::ffi::OsStr;
|
||||
|
||||
let mut res = t!(csv_export_started => lang);
|
||||
let mut state = t!(state_started => lang);
|
||||
trace!(target: "csv-export", process = ?res, state = ?state);
|
||||
|
||||
// Note: slash syntax also works on Windows!
|
||||
let path = Path::new(p);
|
||||
|
||||
// open the file
|
||||
let file = File::open(path)?;
|
||||
|
||||
trace!(target: "csv.export", extension = ?path.extension(), file = ?file);
|
||||
state = t!(state_finished => lang);
|
||||
res = t!(csv_export_finished => lang);
|
||||
trace!(target: "csv-export", process = ?res, state = ?state);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
12
advotracker_client/src/services/exports/mod.rs
Normal file
12
advotracker_client/src/services/exports/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// Send ticketdata via email
|
||||
pub mod send_ticketdata;
|
||||
|
||||
/// Exporting Allianz DirecCall data
|
||||
pub mod allianzdirectcall;
|
||||
124
advotracker_client/src/services/exports/send_ticketdata.rs
Normal file
124
advotracker_client/src/services/exports/send_ticketdata.rs
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use lettre::{
|
||||
message::{header, MultiPart, SinglePart},
|
||||
Message, SmtpTransport, Transport,
|
||||
transport::smtp::authentication::Credentials,
|
||||
};
|
||||
use maud::html;
|
||||
use std::error::Error;
|
||||
//use std::process;
|
||||
use tracing::{info, trace};
|
||||
|
||||
use crate::{
|
||||
data::structures::Email,
|
||||
Lang,
|
||||
};
|
||||
|
||||
/// send ticket data via eMail
|
||||
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);
|
||||
|
||||
// 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) }
|
||||
}
|
||||
};
|
||||
|
||||
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";
|
||||
|
||||
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");
|
||||
|
||||
|
||||
info!("message: {:?}", message);
|
||||
|
||||
// Create credential for remote authentication (username, password)
|
||||
// WIP: get credentials from config file / cli
|
||||
let credentials = Credentials::new("service@hiedemann.de".to_string(), "88service99$".to_string());
|
||||
|
||||
// standard smtp client connection
|
||||
//let mailer = SmtpTransport::starttls_relay("hiedemannsbs.kanzlei.hiedemann.de")
|
||||
|
||||
// Open a remote connection to relay server (port 2525)
|
||||
// WIP: get relay address from config file / cli
|
||||
//let relay = "hiedemannsbs.kanzlei.hiedemann.de"
|
||||
let relay = "smtp.strato.de";
|
||||
|
||||
let mailer = SmtpTransport::relay(relay)
|
||||
.unwrap()
|
||||
.credentials(credentials)
|
||||
.build();
|
||||
|
||||
trace!(target: "sendticketdata", email = ?email);
|
||||
|
||||
// Send the email and catch the error if it isn't successfully
|
||||
let _result = mailer.send(&message)?;
|
||||
|
||||
state = t!(state_finished => lang);
|
||||
res = t!(sendticketdata_export_finished => lang);
|
||||
trace!(target: "sendticketdata", process = ?res, state = ?state);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
134
advotracker_client/src/services/imports/allianzdirectcall.rs
Normal file
134
advotracker_client/src/services/imports/allianzdirectcall.rs
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use chrono::{Local, DateTime};
|
||||
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},
|
||||
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<u64, PolicyCode>,
|
||||
policy_data_count: &mut u64)
|
||||
-> Result<(u64, Duration), Box<dyn Error>> {
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use std::ffi::OsStr;
|
||||
|
||||
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();
|
||||
|
||||
trace!(target: "csv-import", process = ?res, state = ?state, date_start = ?datetime.to_string());
|
||||
|
||||
// Note: slash syntax also works on Windows!
|
||||
let path = Path::new(p);
|
||||
|
||||
// must be a readable file
|
||||
trace!(target: "csv-import", path = ?path);
|
||||
assert_eq!(path.is_file(), true);
|
||||
|
||||
// only accept files with '.txt' extensions
|
||||
let extension = path.extension();
|
||||
assert_eq!(extension, Some(OsStr::new("txt")));
|
||||
|
||||
// open the file
|
||||
let file = File::open(path)?;
|
||||
trace!(target: "csv-import", extension = ?extension, file = ?file);
|
||||
|
||||
// Build the CSV reader
|
||||
let mut csv_reader = csv::ReaderBuilder::new()
|
||||
.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);
|
||||
}
|
||||
|
||||
// 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<StringRecord, Error>, 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);
|
||||
|
||||
// push record as new vector elements
|
||||
data_list.push(record);
|
||||
|
||||
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");
|
||||
trace!(target: "csv-import", record_count = ?count, duration = ?duration);
|
||||
|
||||
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());
|
||||
|
||||
Ok((count, duration))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_import() {
|
||||
// Takes a reference and returns Option<&V>
|
||||
let my_policy_numbers : [u64; 2] = [1511111111, 9999999993];
|
||||
assert_eq!(my_policy_numbers, [1511111111, 9999999993]);
|
||||
|
||||
let mut csv_import_path = String::from("data/POLLFNR_TEST.txt");
|
||||
let mut policy_data = PolicyDataList::new("PolicyDataList");
|
||||
let mut policy_numbers : HashMap<u64, PolicyCode> = HashMap::new();
|
||||
let mut policy_data_count: u64 = 0;
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
30
advotracker_client/src/services/imports/csv-test.rs
Normal file
30
advotracker_client/src/services/imports/csv-test.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
use std::process;
|
||||
|
||||
/// Testing: import from csv format (Standard in)
|
||||
fn import() -> Result<(), Box<dyn Error>> {
|
||||
// Build the CSV reader and iterate over each record.
|
||||
let mut csv_reader = csv::Reader::from_reader(io::stdin());
|
||||
for result in csv_reader.records() {
|
||||
// The iterator yields Result<StringRecord, Error>, so we check the
|
||||
// error here.
|
||||
let record = result?;
|
||||
println!("{:?}", record);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let Err(err) = import() {
|
||||
println!("import error: {}", err);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
9
advotracker_client/src/services/imports/mod.rs
Normal file
9
advotracker_client/src/services/imports/mod.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// Importing Allianz DirecCall data
|
||||
pub mod allianzdirectcall;
|
||||
12
advotracker_client/src/services/mod.rs
Normal file
12
advotracker_client/src/services/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// advotracker import modules
|
||||
pub mod imports;
|
||||
|
||||
/// advotracker export modules
|
||||
pub mod exports;
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::widgets::configuration::configuration_view::ConfigurationView;
|
||||
|
||||
/// Valid `actions` that are handled as state changes in the `Configuration` widget.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ConfigurationAction {
|
||||
SaveConfiguration,
|
||||
LoadConfiguration,
|
||||
}
|
||||
|
||||
/// Define valid configuration data.
|
||||
/// This structure is serialized and saved inside the OS dependent settings file.
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
struct ConfigurationData(
|
||||
pub String,
|
||||
pub String
|
||||
);
|
||||
|
||||
/// Valid `structures` that are handled inside the state of the `Configuration` widget.
|
||||
#[derive(Debug, Default, AsAny)]
|
||||
pub struct ConfigurationState {}
|
||||
|
||||
impl State for ConfigurationState {
|
||||
fn messages(
|
||||
&mut self,
|
||||
mut messages: MessageReader,
|
||||
registry: &mut Registry,
|
||||
ctx: &mut Context<'_>,
|
||||
) {
|
||||
for message in messages.read::<ConfigurationAction>() {
|
||||
match message {
|
||||
ConfigurationAction::LoadConfiguration => {
|
||||
registry
|
||||
.get::<Settings>("settings")
|
||||
.load_async::<ConfigurationData>(
|
||||
"configuration_data".to_string(), ctx.entity()
|
||||
);
|
||||
}
|
||||
ConfigurationAction::SaveConfiguration => {
|
||||
let configuration_file: String = ConfigurationView::configuration_file_clone(&ctx.widget());
|
||||
let language_id: String = ConfigurationView::language_id_clone(&ctx.widget());
|
||||
registry
|
||||
.get::<Settings>("settings")
|
||||
.save_async(
|
||||
"configuration_data".to_string(),
|
||||
ConfigurationData(
|
||||
configuration_file,
|
||||
language_id
|
||||
),
|
||||
ctx.entity(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// save the result
|
||||
for message in messages.read::<SettingsResult<()>>() {
|
||||
println!("Result {:?}", message);
|
||||
}
|
||||
|
||||
// load result
|
||||
for message in messages.read::<SettingsResult<ConfigurationData>>() {
|
||||
if let Ok(data) = message {
|
||||
ConfigurationView::configuration_file_set(&mut ctx.widget(), data.0);
|
||||
ConfigurationView::language_id_set(&mut ctx.widget(), data.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
data::constants::*,
|
||||
widgets::configuration::configuration_state::{ConfigurationAction, ConfigurationState},
|
||||
};
|
||||
|
||||
// Macro that initializes the widget structures/variables for our view
|
||||
widget!(
|
||||
ConfigurationView<ConfigurationState> {
|
||||
configuration_file: String,
|
||||
language_id: String
|
||||
}
|
||||
);
|
||||
|
||||
/// The template implementation of the configuration view
|
||||
/// All GUI elements are styled using the "style" attribute referencing to a ron based css
|
||||
impl Template for ConfigurationView {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
self.child(
|
||||
Grid::new()
|
||||
.id(ID_CONFIGURATION_FORM)
|
||||
.style("configuration_form")
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push(120)
|
||||
.push(12)
|
||||
.push("auto")
|
||||
)
|
||||
.rows(Rows::create()
|
||||
.push("auto") // Header_Bar
|
||||
.push(4) // Seperator
|
||||
.push("auto") // Configuartion_File
|
||||
.push(4) // Seperator
|
||||
.push("auto") // Language_ID
|
||||
.push(12) // Seperator
|
||||
.push("auto"), // Action
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_CONFIGURATION_HEADER)
|
||||
.h_align("start")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.text("Configuration settings")
|
||||
.style("header")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_CONFIGURATION_LABEL_CONFIG_FILE)
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(2))
|
||||
.v_align("center")
|
||||
.h_align("end")
|
||||
.text("Configuration file")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_CONFIGURATION_CONFIG_FILE)
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(2))
|
||||
.text(("configuration_file", id))
|
||||
.water_mark("Filename...")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_CONFIGURATION_LABEL_LANGUAGE_ID)
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(4))
|
||||
.v_align("center")
|
||||
.h_align("end")
|
||||
.text("Language Id")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_CONFIGURATION_LANGUAGE_ID)
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(4))
|
||||
.text(("language_id", id))
|
||||
.water_mark("Locale Identifier...")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Grid::new()
|
||||
.h_align("center")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(6))
|
||||
.attach(Grid::column_span(3))
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push("auto")
|
||||
.push(8)
|
||||
.push("auto")
|
||||
)
|
||||
.rows(Rows::create()
|
||||
.push("auto")
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.style("button_single_content")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(0))
|
||||
.text("Load")
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.send_message(ConfigurationAction::LoadConfiguration, id);
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.text("Save")
|
||||
.style("button_single_content")
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(0))
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.send_message(ConfigurationAction::SaveConfiguration, id);
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
12
advotracker_client/src/widgets/configuration/mod.rs
Normal file
12
advotracker_client/src/widgets/configuration/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// The configuration state
|
||||
pub mod configuration_state;
|
||||
|
||||
/// The configuration view
|
||||
pub mod configuration_view;
|
||||
93
advotracker_client/src/widgets/global_state.rs
Normal file
93
advotracker_client/src/widgets/global_state.rs
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use dotenv::dotenv;
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
use substring::Substring;
|
||||
use tracing::{info, trace};
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
data::constants::*,
|
||||
data::structures::PolicyList
|
||||
};
|
||||
|
||||
/// define valid environment variables provided via .env files
|
||||
/// located in the current call directory
|
||||
/// this is primarily used in testing scenarios (eg. debugging)
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Environment {
|
||||
test_lang: String,
|
||||
rust_log: String,
|
||||
}
|
||||
|
||||
/// Provides generic methods to handle states of datatypes.
|
||||
pub trait GlobalState {
|
||||
fn get_lang() -> String {
|
||||
// get system environment
|
||||
let mut lang = env::var("LANG").unwrap_or_else(|_| "C".to_string());
|
||||
lang = lang.substring(0,5).to_string(); // "de_DE.UTF-8" -> "de_DE"
|
||||
info!("GUI-Language: preset to {:?}", lang);
|
||||
|
||||
// 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) => { info!(target: "advotracker", "{}", e) }
|
||||
}
|
||||
trace!(target: "advotracker", lang = ?lang);
|
||||
|
||||
// return the active language
|
||||
lang
|
||||
}
|
||||
|
||||
/// Get the text of a widget.
|
||||
fn get_text(&self, ctx: &mut Context<'_>, entity: Entity) -> Option<String> {
|
||||
let text = TextBox::text_clone(&ctx.get_widget(entity));
|
||||
|
||||
if text.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
TextBox::text_set(&mut ctx.get_widget(entity), String::default());
|
||||
Some(text)
|
||||
}
|
||||
|
||||
// /// Navigates to the given entity.
|
||||
// fn navigate(&self, to: Entity, ctx: &mut Context<'_>) {
|
||||
// if let Some(old_focused_element) = *Window::focus_state_ref(&ctx.window()).focused_entity() {
|
||||
// ctx.push_event_by_window(FocusEvent::RemoveFocus(old_focused_element));
|
||||
// }
|
||||
// ctx.widget().set("visibility", Visibility::Collapsed);
|
||||
// ctx.get_widget(to).set("visibility", Visibility::Visible);
|
||||
// }
|
||||
|
||||
/// Save the our data structure and convert it to `ron` file format.
|
||||
/// The cargo package identifier (here: 'nwx.advotracker') is taken to create the app directory.
|
||||
/// in users 'settings directory'. The directory location is OS dependant
|
||||
/// (Windows: AppData, Unix: XDG_CONFIG_HOME, MacOS: $HOME/Library/Preferences).
|
||||
/// The data is stored in filename PROP_ADVOTRACKER (here: `advotracker.ron`)
|
||||
fn save(&self, registry: &mut Registry, ctx: &mut Context<'_>) {
|
||||
registry
|
||||
.get::<Settings>("settings")
|
||||
.save(
|
||||
PROP_ADVOTRACKER,
|
||||
ctx.widget().get::<PolicyList>(PROP_ADVOTRACKER),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// #[test]
|
||||
// assert_eq!(2 + 2, 4);
|
||||
// }
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
use tracing::info;
|
||||
|
||||
use crate::widgets::localization::localization_view::LocalizationView;
|
||||
|
||||
#[derive(AsAny, Debug, Default)]
|
||||
pub struct LocalizationState {
|
||||
change_language: bool,
|
||||
}
|
||||
|
||||
impl LocalizationState {
|
||||
pub fn change_language(&mut self) {
|
||||
self.change_language = true;
|
||||
}
|
||||
}
|
||||
|
||||
impl State for LocalizationState {
|
||||
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
|
||||
if !self.change_language {
|
||||
return;
|
||||
}
|
||||
|
||||
// get value of activ selected combo_box item
|
||||
let index = *LocalizationView::selected_index_ref(&ctx.widget()) as usize;
|
||||
let selected_language = LocalizationView::languages_ref(&ctx.widget())[index].clone();
|
||||
info!("New selected language item: {:?}", selected_language);
|
||||
|
||||
match selected_language.as_str() {
|
||||
"English" => ctx.set_language("en_US"),
|
||||
"German" => ctx.set_language("de_DE"),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.change_language = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
data::constants::*,
|
||||
widgets::localization::localization_state::LocalizationState,
|
||||
};
|
||||
|
||||
type List = Vec<String>;
|
||||
|
||||
// Macro that initializes the widget structures/variables for our view
|
||||
widget!(LocalizationView<LocalizationState> {
|
||||
languages: List,
|
||||
selected_index: i32 }
|
||||
);
|
||||
|
||||
/// The template implementation of the localization view
|
||||
/// All GUI elements are styled using the "style" attribute referencing to a ron based css
|
||||
impl Template for LocalizationView {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
let languages = vec!["English".to_string(), "German".to_string()];
|
||||
let count = languages.len();
|
||||
|
||||
self.languages(languages)
|
||||
.selected_index(1)
|
||||
.child(
|
||||
Grid::new()
|
||||
.id(ID_LOCALIZATION_FORM)
|
||||
.margin(4)
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push(120)
|
||||
.push(12)
|
||||
.push(150)
|
||||
)
|
||||
.rows(Rows::create()
|
||||
.push("auto")
|
||||
.push(4)
|
||||
.push("auto")
|
||||
.push(4)
|
||||
.push("auto")
|
||||
.push(12)
|
||||
.push("auto"),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_LOCALIZATION_HEADER)
|
||||
.h_align("start")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.text("Localization dialog")
|
||||
.style("header")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_LOCALIZATION_LABEL_LANGUAGE_NAME)
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(2))
|
||||
.v_align("center")
|
||||
.h_align("end")
|
||||
.text("Language ID")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
ComboBox::new()
|
||||
.id(ID_LOCALIZATION_LANGUAGES)
|
||||
.count(count)
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(2))
|
||||
.items_builder(move |bc, index| {
|
||||
let text = bc.get_widget(id)
|
||||
.get::<Vec<String>>("languages")[index]
|
||||
.clone();
|
||||
TextBlock::new()
|
||||
.id(ID_LOCALIZATION_LANGUAGE_NAME)
|
||||
.v_align("center")
|
||||
.text(text)
|
||||
.build(bc)
|
||||
})
|
||||
.on_changed("selected_index", move |states, _| {
|
||||
states.get_mut::<LocalizationState>(id).change_language();
|
||||
})
|
||||
.selected_index(id)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
12
advotracker_client/src/widgets/localization/mod.rs
Normal file
12
advotracker_client/src/widgets/localization/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// The localization state
|
||||
pub mod localization_state;
|
||||
|
||||
/// The localizatin view
|
||||
pub mod localization_view;
|
||||
127
advotracker_client/src/widgets/login/loginform_view.rs
Normal file
127
advotracker_client/src/widgets/login/loginform_view.rs
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
data::constants::*,
|
||||
callbacks::loginform_state::LoginFormState,
|
||||
};
|
||||
|
||||
// Macro that initializes the widget structures/variables for our view
|
||||
widget!(
|
||||
/// Dialog to authenticate a username.
|
||||
/// This identifier is checked agains database-entries of valid user id's.
|
||||
LoginFormView<LoginFormState> {
|
||||
lang: String,
|
||||
//login: Login,
|
||||
login_title: String16,
|
||||
policycheck: u32
|
||||
}
|
||||
);
|
||||
|
||||
/// The template implementation of the policy check view
|
||||
/// All GUI elements are styled using the "style" attribute referencing to a ron based css
|
||||
impl Template for LoginFormView {
|
||||
//fn template(self, policycheck_view: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
let login_form_header_bar = Container::new()
|
||||
.style(STYLE_HEADER_BAR)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(1))
|
||||
.attach(Grid::column_span(2))
|
||||
.child(
|
||||
Grid::new()
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.style("header")
|
||||
//.id(ID_LOGIN_FORM_HEADER)
|
||||
.id("login_from_header")
|
||||
.v_align("center")
|
||||
.h_align("left")
|
||||
.text("Login validation")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
self.name("LoginForm").child(
|
||||
Grid::new()
|
||||
.columns(Columns::create().push(64.0).push(64.0))
|
||||
.rows(Rows::create().push(48.0).push(48.0).push(48.0).push(48.0))
|
||||
.v_align("start")
|
||||
.h_align("center")
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.text("Please login to continue !")
|
||||
.font_size(18.0)
|
||||
.v_align("center")
|
||||
.h_align("start")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column_span(2))
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
//.text("Username:")
|
||||
.v_align("center")
|
||||
.h_align("start")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(1))
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
//.text("Password:")
|
||||
.v_align("center")
|
||||
.h_align("start")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(2))
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_LOGIN_FORM_LABEL_USERNAME)
|
||||
//.water_mark("Username")
|
||||
.v_align("center")
|
||||
.h_align("start")
|
||||
.attach(Grid::column(1))
|
||||
.attach(Grid::row(1))
|
||||
.max_width(128.0)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
PasswordBox::new()
|
||||
.id(ID_LOGIN_FORM_LABEL_PASSWORD)
|
||||
//.water_mark("Password")
|
||||
.v_align("center")
|
||||
.h_align("start")
|
||||
.attach(Grid::column(1))
|
||||
.attach(Grid::row(2))
|
||||
.max_width(128.0)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.text("Login")
|
||||
.v_align("center")
|
||||
.h_align("end")
|
||||
.attach(Grid::column(1))
|
||||
.attach(Grid::row(3))
|
||||
// send a new Authenticate action to LoginFormState
|
||||
.on_click(move |states, _| -> bool {
|
||||
states.get_mut::<LoginFormState>(id).authenticate();
|
||||
false
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
143
advotracker_client/src/widgets/login/loginlist_view.rs
Normal file
143
advotracker_client/src/widgets/login/loginlist_view.rs
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
data::constants::*,
|
||||
callbacks::loginlist_state::LoginListState,
|
||||
};
|
||||
|
||||
// Macro that initializes the widget structures/variables for our view
|
||||
widget!(
|
||||
/// Dialog to authenticate a username.
|
||||
/// This identifier is checked agains database-entries of valid user id's.
|
||||
LoginListView<LoginListState> {
|
||||
lang: String,
|
||||
//login: Login,
|
||||
login_title: String16,
|
||||
policycheck: u32
|
||||
}
|
||||
);
|
||||
|
||||
/// The template implementation of the policy check view
|
||||
/// All GUI elements are styled using the "style" attribute referencing to a ron based css
|
||||
impl Template for LoginListView {
|
||||
//fn template(self, policycheck_view: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
let login_form_header_bar = Container::new()
|
||||
.style(STYLE_HEADER_BAR)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(1))
|
||||
.attach(Grid::column_span(2))
|
||||
.child(
|
||||
Grid::new()
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.style("header")
|
||||
//.id(ID_LOGIN_FORM_HEADER)
|
||||
.id("login_from_header")
|
||||
.v_align("center")
|
||||
.h_align("left")
|
||||
.text("Login validation")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
self.name("LoginList")
|
||||
.combo_box_user_list(vec![
|
||||
"UserID 1".to_string(),
|
||||
"UserID 2".to_string(),
|
||||
"UserID 3".to_string(),
|
||||
"UserID 4".to_string(),
|
||||
"UserID 5".to_string(),
|
||||
"UserID 6".to_string(),
|
||||
"UserID 7".to_string(),
|
||||
"UserID 8".to_string(),
|
||||
"UserID 9".to_string(),
|
||||
"UserID 10".to_string(),
|
||||
])
|
||||
.combo_box_list_count(10)
|
||||
.child(
|
||||
Grid::new()
|
||||
.columns(Columns::create().push("*").push(4).push("*"))
|
||||
.rows(Rows::create().push(auto).push(32.0))
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(0))
|
||||
.v_align("start")
|
||||
.h_align("center")
|
||||
// row 0: User ComboBox
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_LOGIN_VIEW_LABEL_USERNAMES)
|
||||
//.text("User List")
|
||||
.font_size(18.0)
|
||||
.v_align("center")
|
||||
.h_align("start")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column_span(1))
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
ComboBox::new()
|
||||
.items_builder(move |builder_combobox, index| {
|
||||
let text = builder_combobox
|
||||
.get_widget(id)
|
||||
.get::<Vec<String>>("combo_box_user_list")[index]
|
||||
.clone();
|
||||
TextBlock::new()
|
||||
.style("small_text")
|
||||
.margin((0, 0, 0, 2))
|
||||
.v_align("center")
|
||||
.text(text)
|
||||
.build(builder_combobox)
|
||||
})
|
||||
.selected_index(0)
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.attach(Grid::row(0))
|
||||
.margin((0, 8, 0, 0))
|
||||
.count(("combo_box_list_count", id))
|
||||
.build(ctx),
|
||||
)
|
||||
// row 1: Task Buttons
|
||||
.child(
|
||||
Button::new()
|
||||
.style("button_single_content")
|
||||
.id("login-user-change")
|
||||
.text("Username")
|
||||
.icon(material_icons_font::MD_360)
|
||||
// .on_click(move |states, _| {
|
||||
// state(id, states).action(Action::SelectItem);
|
||||
// true
|
||||
// })
|
||||
.min_width(0)
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(1))
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.style("button_single_content")
|
||||
.id("login-user-clear")
|
||||
.icon(material_icons_font::MD_CLEAR)
|
||||
// .on_click(move |states, _| {
|
||||
// state(id, states).action(Action::ClearItem);
|
||||
// true
|
||||
// })
|
||||
.min_width(0)
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(1))
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
76
advotracker_client/src/widgets/main_view.rs
Normal file
76
advotracker_client/src/widgets/main_view.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
data::{
|
||||
constants::*,
|
||||
structures::PolicyCheck,
|
||||
},
|
||||
widgets::configuration::configuration_view::ConfigurationView,
|
||||
widgets::policycheck::policycheck_view::PolicycheckView,
|
||||
widgets::localization::localization_view::LocalizationView,
|
||||
//widgets::menu::menu_view::MenuView,
|
||||
widgets::ticketdata::ticketdata_view::TicketdataView,
|
||||
};
|
||||
|
||||
// [START] views
|
||||
|
||||
widget!(MainView {
|
||||
// policy_list: PolicyList,
|
||||
// policy_data_list: PolicyDataList,
|
||||
// policylist_view: u32,
|
||||
// policydata_view: u32,
|
||||
policycheck_view: PolicyCheck
|
||||
//ticketdata_view: TicketData
|
||||
});
|
||||
|
||||
impl Template for MainView {
|
||||
fn template(self, _id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
let ticketdata_view = TicketdataView::new()
|
||||
.build(ctx);
|
||||
|
||||
let policycheck_view = PolicycheckView::new()
|
||||
.target(ticketdata_view.0)
|
||||
//.policy_number_count(0)
|
||||
//.policylist_view(id)
|
||||
.build(ctx);
|
||||
|
||||
// let policylist_view = PolicyListView::new()
|
||||
// .back_entity(policycheck_view.0)
|
||||
// .policydata_view(id)
|
||||
// .policylist_view(id)
|
||||
// .policy_list_count(id)
|
||||
// .build(ctx);
|
||||
|
||||
// let policydata_view = PolicyDataView::new()
|
||||
// .back_entity(policylist_view.0)
|
||||
// .policylist_view(id)
|
||||
// .visibility("collapsed")
|
||||
// .build(ctx);
|
||||
|
||||
self.name("MainView")
|
||||
//.policycheck_view(PolicyCheck::default())
|
||||
// //.policycheck_view(0)
|
||||
// .policydata_view(policydata_view.0)
|
||||
// //.policylist_view(PolicyList::default())
|
||||
// .policylist_view(policylist_view.0)
|
||||
// .child(policydata_view)
|
||||
// .child(policylist_view)
|
||||
.child(
|
||||
TabWidget::new()
|
||||
.tab(ID_POLICY_CHECK_VIEW, policycheck_view)
|
||||
.tab(ID_TICKET_DATA_VIEW, ticketdata_view)
|
||||
.tab(ID_LOCALIZATION_VIEW, LocalizationView::new().build(ctx))
|
||||
.tab(ID_CONFIGURATION_VIEW, ConfigurationView::new().build(ctx))
|
||||
//.tab(ID_MENU_VIEW, MenuView::new().build(ctx))
|
||||
.build(ctx),
|
||||
)
|
||||
//.child(policycheck_view)
|
||||
}
|
||||
}
|
||||
427
advotracker_client/src/widgets/menu/menu_state.rs
Normal file
427
advotracker_client/src/widgets/menu/menu_state.rs
Normal file
@@ -0,0 +1,427 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use orbtk::prelude::*;
|
||||
use orbtk::shell::event::Key;
|
||||
use tracing::{info, trace};
|
||||
|
||||
use std::process;
|
||||
|
||||
use crate::{
|
||||
data::constants::*,
|
||||
widgets::menu::menu_view::MenuView,
|
||||
//widgets::policycheck::policycheck_view::PolicycheckView,
|
||||
};
|
||||
|
||||
/// Valid `actions` that are handled as state changes in the `Menu` widget.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum MenuAction {
|
||||
CreateMenu,
|
||||
CreateMenuToggleTheme,
|
||||
RemoveMenu,
|
||||
RemoveMenuToggleTheme,
|
||||
SetTheme,
|
||||
UpdateMenuRelativePosition
|
||||
}
|
||||
|
||||
/// Valid `structures` that are handled inside the state of the `Menu` widget.
|
||||
#[derive(AsAny, Default)]
|
||||
pub struct MenuState {
|
||||
action: Option<MenuAction>,
|
||||
menu: Option<Entity>,
|
||||
//menu_toggle_theme: Option<Entity>
|
||||
menu_toggle_theme: Entity
|
||||
}
|
||||
|
||||
/// Method definitions, that react on any given state change inside the `Menu` widget.
|
||||
impl MenuState {
|
||||
/// Create a toggle_theme menu as a child of the given parent
|
||||
/// Select the active theme from a `ComboBox` offering a list of valid `themes`
|
||||
fn _create_menu_toggle_theme(&mut self, _ctx: &mut Context<'_>) {
|
||||
self.action = Some(MenuAction::CreateMenuToggleTheme);
|
||||
}
|
||||
|
||||
/// Remove the menu popup box
|
||||
fn remove_menu(&mut self, ctx: &mut Context<'_>) {
|
||||
self.action = Some(MenuAction::RemoveMenu);
|
||||
ctx.remove_child(ctx.entity());
|
||||
println!("Popup {:?} removed.", ctx.entity());
|
||||
}
|
||||
|
||||
/// Remove the menu popup box
|
||||
fn _remove_menu_toggle_theme(&mut self, _ctx: &mut Context<'_>) {
|
||||
self.action = Some(MenuAction::RemoveMenuToggleTheme);
|
||||
}
|
||||
|
||||
/// Sets a new action.
|
||||
pub fn set_action(&mut self, action: MenuAction) {
|
||||
self.action = action.into();
|
||||
}
|
||||
|
||||
/// Update the relative position of the menu overlay
|
||||
fn _update_menu_relative_position(&mut self) {
|
||||
println!("TODO: Update relative position of menu {}.", ID_MENU_POPUP);
|
||||
//self.action = Some(MenuAction::UpdateRelativePosition);
|
||||
}
|
||||
}
|
||||
|
||||
/// Supported methods handled inside the `MenuState`
|
||||
impl State for MenuState {
|
||||
// /// Initialize the state of widgets inside `MenuState`
|
||||
// fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
||||
// }
|
||||
|
||||
/// Handle messages for the `MenuState`
|
||||
fn messages(
|
||||
&mut self,
|
||||
mut messages: MessageReader,
|
||||
_registry: &mut Registry,
|
||||
ctx: &mut Context<'_>,
|
||||
) {
|
||||
for message in messages.read::<MenuAction>() {
|
||||
match message {
|
||||
MenuAction::CreateMenu => {
|
||||
info!("WIP: create a menu popup in MenuState");
|
||||
|
||||
// assign parent entity
|
||||
let parent = ctx.entity();
|
||||
trace!(parent = ?parent);
|
||||
//let parent_name = ctx.get_widget().get::<String16>("text");
|
||||
//trace!(parent = ?parent, parent_name = ?parent_name);
|
||||
|
||||
// assign target -> search for a child of parent with given id
|
||||
let target = ctx
|
||||
.entity_of_child(ID_MENU_BUTTON_MENU)
|
||||
.expect("MenuState: Can't find entity of resource 'ID_MENU_BUTTON_MENU'.");
|
||||
|
||||
trace!(target = ?target.0, entity_of_child = ?ID_MENU_BUTTON_MENU);
|
||||
|
||||
// create the target entity as child of parent
|
||||
let menu_popup = create_menu_popup(parent, &mut ctx.build_context());
|
||||
//let menu_popup = create_popup(target, "Testmenu Popup", &mut ctx.build_context());
|
||||
|
||||
// append the child to target (overlay stays on top of the main tree)
|
||||
ctx.build_context()
|
||||
.append_child_to_overlay(menu_popup)
|
||||
.expect("Failed create an overlay that consumes popup `menu` as its child.");
|
||||
self.menu = Some(menu_popup);
|
||||
|
||||
trace!(menu = ?self.menu);
|
||||
|
||||
// open: is the default
|
||||
//ctx.get_widget(menu).set("open", true);
|
||||
|
||||
info!("CreateMenu: parent {:?}, target: {:?}, popup: {:?}", parent, target, self.menu);
|
||||
}
|
||||
|
||||
MenuAction::SetTheme => {
|
||||
let theme_index = *MenuView::selected_index_ref(&ctx.widget());
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
match theme_index {
|
||||
0 => ctx.switch_theme(theme_default_dark()),
|
||||
1 => ctx.switch_theme(theme_default_light()),
|
||||
2 => ctx.switch_theme(theme_redox()),
|
||||
3 => ctx.switch_theme(theme_fluent_dark()),
|
||||
4 => ctx.switch_theme(theme_fluent_light()),
|
||||
_ => {}
|
||||
}
|
||||
} else {
|
||||
match theme_index {
|
||||
0 => ctx.switch_theme(theme_default_dark()),
|
||||
1 => ctx.switch_theme(theme_default_light()),
|
||||
2 => ctx.switch_theme(theme_redox()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the state of widgets inside the `Menu` view.
|
||||
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
|
||||
if let Some(action) = self.action {
|
||||
match action {
|
||||
MenuAction::CreateMenuToggleTheme => {
|
||||
let menu_target = ctx
|
||||
.entity_of_child(ID_MENU_LABEL_TOGGLE_THEME)
|
||||
.expect("MenuState: Can't find entity of resource 'ID_MENU_LABEL_TOGGLE_THEME'.");
|
||||
let current_entity = ctx.entity();
|
||||
let build_context = &mut ctx.build_context();
|
||||
|
||||
// create a new menu popup
|
||||
self.menu_toggle_theme = create_menu_toggle_theme_popup(current_entity, build_context);
|
||||
|
||||
// create a menu_popup widget as a child of entity "ID_POPUP_MENU"
|
||||
build_context.append_child(menu_target, self.menu_toggle_theme);
|
||||
|
||||
ctx.get_widget(self.menu_toggle_theme).clone::<Visibility>("visibility");
|
||||
|
||||
println!("Popup Menu Toggle Theme created: {:?}", self.menu_toggle_theme);
|
||||
}
|
||||
MenuAction::RemoveMenu => {
|
||||
self.remove_menu(ctx);
|
||||
}
|
||||
MenuAction::RemoveMenuToggleTheme => {
|
||||
ctx.remove_child(self.menu_toggle_theme);
|
||||
println!("Popup {:?} removed.", ctx.entity());
|
||||
}
|
||||
MenuAction::UpdateMenuRelativePosition => {
|
||||
if let Some(menu) = self.menu {
|
||||
// let theme_combo_box = ctx.entity_of_child(ID_MENU_TOGGLE_THEME).unwrap();
|
||||
// let selected_index: i32 = ctx.get_widget(theme_combo_box).clone("selected_index");
|
||||
// // let relative_position: RelativePosition =
|
||||
// // ctx.get_widget(ID_MENU_POPUP).clone_or_default("relative_position");
|
||||
// match selected_index {
|
||||
// 0 => {
|
||||
// RelativePosition::relative_position_mut(&mut ctx.widget()).into_bottom();
|
||||
// //RelativePosition::get_mut::<MenuState>("relative_position").into_bottom();
|
||||
// // ctx
|
||||
// // .get_widget(self.ID_MENU_POPUP.unwrap())
|
||||
// // .set("relative_position", relative_position.into_bottom());
|
||||
// },
|
||||
// 1 => RelativePosition::relative_position_mut(&mut ctx.widget()).into_top(),
|
||||
// 2 => RelativePosition::relative_position_mut(&mut ctx.widget()).into_left(),
|
||||
// 3 => RelativePosition::relative_position_mut(&mut ctx.widget()).into_right(),
|
||||
// _ => panic!(),
|
||||
// }
|
||||
println!("Relative position of menu {:?} updated.", menu);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new popup presenting the menu components
|
||||
fn create_menu_popup(target: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
Popup::new()
|
||||
.id(ID_MENU_POPUP)
|
||||
.name(ID_MENU_POPUP)
|
||||
.target(target.0)
|
||||
.open(true)
|
||||
// WIP: this requires orbtk-develop with PR #304 (new_popup)
|
||||
// Specify the popup position relative to the target
|
||||
//.relative_position(RelativePosition::Bottom(5.0))
|
||||
// Reference target from given Point
|
||||
//.target(Point::new(100.0,100.0))
|
||||
//.style("popup_menu")
|
||||
.width(300.0)
|
||||
.height(100.0)
|
||||
|
||||
.on_key_down(move | ctx, key_event | {
|
||||
match key_event.key {
|
||||
Key::Q(..) => {
|
||||
//if is_ctrl_home_down(ctx)
|
||||
println!("KeyHandler: got Ctrl+Q");
|
||||
process::exit(0);
|
||||
//}
|
||||
},
|
||||
Key::Escape => {
|
||||
println!("KeyHandler: got Escape");
|
||||
ctx.get_mut::<MenuState>(target)
|
||||
.set_action(MenuAction::RemoveMenu);
|
||||
},
|
||||
_ => {
|
||||
println!("KeyHandler: got {:?}", key_event.key);
|
||||
},
|
||||
};
|
||||
true
|
||||
})
|
||||
.child(
|
||||
Container::new()
|
||||
.child(
|
||||
TextBlock::new()
|
||||
//.style("popup_text_block")
|
||||
.h_align("center")
|
||||
.v_align("enter")
|
||||
.text(ID_MENU_POPUP)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Grid::new()
|
||||
.id(ID_MENU_GRID)
|
||||
.name(ID_MENU_GRID)
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push("180") // Menu Button
|
||||
.push("1") // Seperator
|
||||
.push("auto") // Keyboard Shortcut
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
.push("auto")
|
||||
.push("auto")
|
||||
.push("auto")
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.id(ID_MENU_LABEL_ACCOUNT)
|
||||
.name(ID_MENU_LABEL_ACCOUNT)
|
||||
.style("button_menu")
|
||||
//.h_align("start")
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(0))
|
||||
//.attach(Grid::column_span(2))
|
||||
.icon(material_icons_font::MD_PERSON)
|
||||
.text("Account")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.id(ID_MENU_LABEL_TOGGLE_THEME)
|
||||
.name(ID_MENU_LABEL_TOGGLE_THEME)
|
||||
.style("button_menu")
|
||||
//.h_align("start")
|
||||
.attach(Grid::row(1))
|
||||
.attach(Grid::column(0))
|
||||
//.attach(Grid::column_span(2))
|
||||
.icon(material_icons_font::MD_EDIT)
|
||||
.text("Toggle theme")
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.get_mut::<MenuState>(target)
|
||||
.set_action(MenuAction::CreateMenuToggleTheme);
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.id(ID_MENU_LABEL_QUIT)
|
||||
.name(ID_MENU_LABEL_QUIT)
|
||||
.style("button_menu")
|
||||
//.h_align("start")
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(0))
|
||||
//.attach(Grid::column_span(2))
|
||||
.icon(material_icons_font::MD_SETTINGS_POWER)
|
||||
.text("Quit")
|
||||
.on_mouse_down(move |_states, _| {
|
||||
process::exit(0);
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_MENU_SHORTCUT_QUIT)
|
||||
.name(ID_MENU_SHORTCUT_QUIT)
|
||||
//.style("button_menu")
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(2))
|
||||
.margin((0, 0, 16, 0))
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.text("CTRL+Q")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx)
|
||||
}
|
||||
|
||||
|
||||
fn _create_popup(target: Entity, text: &str, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
Popup::new()
|
||||
.id("test_popup")
|
||||
.name("Test Popup")
|
||||
// Reference target from given Entity
|
||||
.target(target.0)
|
||||
// Reference target from given Point
|
||||
//.target(Point::new(0.0, 5.0))
|
||||
// Specify the popup position relative to the target (the button in this case)
|
||||
//.relative_position(RelativePosition::Bottom(5.0))
|
||||
.open(true)
|
||||
.style("popup_form")
|
||||
.width(350.0)
|
||||
.height(100.0)
|
||||
.child(
|
||||
Container::new()
|
||||
.child(
|
||||
TextBlock::new()
|
||||
//.style("popup_text_block")
|
||||
.h_align("center")
|
||||
.text(text)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Create a new popup submenu to toogle the active theme
|
||||
fn create_menu_toggle_theme_popup(id: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
// define the list of supported themes
|
||||
let themes = vec![
|
||||
"default_dark".to_string(),
|
||||
"default_light".to_string(),
|
||||
"redox".to_string(),
|
||||
"fluent_dark".to_string(),
|
||||
"fluent_light".to_string()
|
||||
];
|
||||
} else {
|
||||
// define the list of supported themes
|
||||
let themes = vec![
|
||||
"default_dark".to_string(),
|
||||
"default_light".to_string(),
|
||||
"redox".to_string(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
let themes_count = themes.len();
|
||||
|
||||
Popup::new()
|
||||
.id(ID_MENU_TOGGLE_THEME)
|
||||
.target(id.0)
|
||||
.style("container_menu")
|
||||
.width(280)
|
||||
.height(140)
|
||||
.on_key_down(move | _ctx, key_event | {
|
||||
match key_event.key {
|
||||
Key::Escape => {
|
||||
println!("KeyHandler: got Escape");
|
||||
//ctx.get_mut::<MenuState>(id)
|
||||
// .set_action(MenuAction::RemoveMenuToggleTheme);
|
||||
},
|
||||
_ => {
|
||||
println!("KeyHandler: got {:?}", key_event.key);
|
||||
},
|
||||
};
|
||||
true
|
||||
})
|
||||
.child(
|
||||
ComboBox::new()
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(6))
|
||||
.count(themes_count)
|
||||
.style("combo_box_form")
|
||||
.items_builder(move |ctx, index| {
|
||||
let theme_name =
|
||||
MenuView::themes_ref(&ctx.get_widget(id))[index].clone();
|
||||
TextBlock::new().v_align("center").text(theme_name).build(ctx)
|
||||
})
|
||||
.on_changed("selected_index", move |states, _entity| {
|
||||
states.send_message(MenuAction::SetTheme, id);
|
||||
println!("changed theme.");
|
||||
})
|
||||
.selected_index(id)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx)
|
||||
}
|
||||
127
advotracker_client/src/widgets/menu/menu_view.rs
Normal file
127
advotracker_client/src/widgets/menu/menu_view.rs
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::data::constants::*;
|
||||
use crate::widgets::menu::menu_state::{MenuAction, MenuState};
|
||||
|
||||
type List = Vec<String>;
|
||||
|
||||
// Macro that initializes the widget structures/variables for the menu view
|
||||
widget!(
|
||||
MenuView<MenuState> {
|
||||
//menu_stack: Entity,
|
||||
//button_menu: Entity,
|
||||
selected_index: i32,
|
||||
themes: List
|
||||
}
|
||||
);
|
||||
|
||||
/// The template implementation of the menu view
|
||||
/// All GUI elements are styled using the "style" attribute referencing to a ron based css
|
||||
impl Template for MenuView {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
let menu_bottom_bar = Container::new()
|
||||
.id(ID_MENU_BOTTOM_BAR)
|
||||
.style(STYLE_BOTTOM_BAR)
|
||||
.attach(Grid::row(3))
|
||||
.attach(Grid::column(1))
|
||||
.attach(Grid::column_span(2))
|
||||
.v_align("end")
|
||||
.child(
|
||||
Container::new()
|
||||
.child( Container::new()
|
||||
.margin((0, 16, 16, 0))
|
||||
.v_align("center")
|
||||
.child(
|
||||
ImageWidget::new()
|
||||
.image("assets/advotracker/hiedemann_logo.png")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Container::new()
|
||||
.attach(Grid::column(1))
|
||||
.h_align("end")
|
||||
.v_align("end")
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.margin((0, 9, 48, 0))
|
||||
.text("©Networkx GmbH")
|
||||
.build(ctx)
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let menu_button_menu = Button::new()
|
||||
.id(ID_MENU_BUTTON_MENU)
|
||||
.name(ID_MENU_BUTTON_MENU)
|
||||
.style("button_single_content")
|
||||
.icon(material_icons_font::MD_MENU)
|
||||
.attach(Grid::column(2))
|
||||
//.min_size(16, 16)
|
||||
//.h_align("end")
|
||||
.h_align("start")
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.send_message(MenuAction::CreateMenu, id);
|
||||
true
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
let menu_header_bar = Container::new()
|
||||
.id(ID_MENU_HEADER_BAR)
|
||||
.style(STYLE_HEADER_BAR)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(1))
|
||||
.attach(Grid::column_span(2))
|
||||
.child(
|
||||
Grid::new()
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.style("header")
|
||||
.id(ID_MENU_HEADER)
|
||||
.v_align("center")
|
||||
.h_align("left")
|
||||
.text("Ticket Data")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(menu_button_menu)
|
||||
.build(ctx);
|
||||
|
||||
//self.themes(themes).child(MenuState::create_menu(ID_MENU_POPUP, ctx))
|
||||
self.name("MenuView")
|
||||
.child(
|
||||
Grid::new()
|
||||
.id(ID_MENU_VIEW)
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push(50) // Left margin
|
||||
.push("*") // Content
|
||||
.push(50) // Right margin
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
.push("auto") // Header_Bar
|
||||
.push(28) // Seperator
|
||||
.push("*") // InputForm
|
||||
.push("auto") // Bottom_Bar
|
||||
)
|
||||
|
||||
.child(menu_header_bar) // Row 0
|
||||
.child(menu_bottom_bar) // Row 3
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
12
advotracker_client/src/widgets/menu/mod.rs
Normal file
12
advotracker_client/src/widgets/menu/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// The menu view
|
||||
pub mod menu_view;
|
||||
|
||||
/// The menu state
|
||||
pub mod menu_state;
|
||||
33
advotracker_client/src/widgets/mod.rs
Normal file
33
advotracker_client/src/widgets/mod.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// Configuration widget.
|
||||
pub mod configuration;
|
||||
|
||||
/// Global helper functions.
|
||||
pub mod global_state;
|
||||
|
||||
/// Localization widget.
|
||||
pub mod localization;
|
||||
|
||||
/// The starting point (Main View).
|
||||
pub mod main_view;
|
||||
|
||||
/// Menu widget.
|
||||
pub mod menu;
|
||||
|
||||
/// Policycheck wigdet.
|
||||
pub mod policycheck;
|
||||
|
||||
// /// Policydata widget.
|
||||
// pub mod policydata;
|
||||
|
||||
// /// Policylists widget.
|
||||
// pub mod policylist;
|
||||
|
||||
/// Ticketdata wigdet.
|
||||
pub mod ticketdata;
|
||||
12
advotracker_client/src/widgets/policycheck/mod.rs
Normal file
12
advotracker_client/src/widgets/policycheck/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// The policy check state
|
||||
pub mod policycheck_state;
|
||||
|
||||
/// The policy check view
|
||||
pub mod policycheck_view;
|
||||
684
advotracker_client/src/widgets/policycheck/policycheck_state.rs
Normal file
684
advotracker_client/src/widgets/policycheck/policycheck_state.rs
Normal file
@@ -0,0 +1,684 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::process;
|
||||
use std::collections::HashMap;
|
||||
use std::time::{Duration, SystemTime};
|
||||
use tracing::{error, info, trace};
|
||||
|
||||
use crate::{
|
||||
data::{
|
||||
structures::{PolicyCode, PolicyDataList, PolicyList},
|
||||
constants::*,
|
||||
},
|
||||
Lang,
|
||||
//services::imports::allianzdirectcall::import,
|
||||
services::imports::allianzdirectcall,
|
||||
widgets::global_state::GlobalState,
|
||||
//widgets::menu::menu_view::MenuView,
|
||||
//widgets::policycheck::policycheck_view::PolicycheckView,
|
||||
//widgets::ticketdata::ticketdata_state::TicketdataAction,
|
||||
};
|
||||
|
||||
/// Enumeration of valid `action variants` that need to be handled as
|
||||
/// state changes for the `PolicycheckView` widget.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PolicycheckAction {
|
||||
ClearPolicyNumber,
|
||||
ChangeTheme(),
|
||||
SendPolicynumber(),
|
||||
InputTextChanged(Entity),
|
||||
ImportData,
|
||||
NewTicket,
|
||||
ParsePolicyNumber(Entity),
|
||||
RemoveFocus(Entity),
|
||||
RemovePopup(Entity),
|
||||
ResetProgress,
|
||||
GetProgress,
|
||||
SetProgress(f64),
|
||||
SetProgressPopup(Entity),
|
||||
SetToggleTheme(Entity),
|
||||
SetEntry(Entity),
|
||||
SetVisibility(Entity),
|
||||
TextChanged(Entity, usize),
|
||||
UpdatePolicyCode,
|
||||
UpdateProgress(f64)
|
||||
}
|
||||
|
||||
/// Define valid environment variables provided via .env files
|
||||
/// located in the current call directory.
|
||||
/// This is primarily used in testing scenarios (eg. debugging).
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Environment {
|
||||
test_lang: String,
|
||||
rust_log: String,
|
||||
}
|
||||
|
||||
/// Valid `structures` that are handled inside the state of the `Policycheck` widget.
|
||||
#[derive(AsAny, Default)]
|
||||
pub struct PolicycheckState {
|
||||
actions: Vec<PolicycheckAction>,
|
||||
button_menu: Entity,
|
||||
duration: Duration,
|
||||
label_result: Entity,
|
||||
lang: Lang,
|
||||
policy_data_count: u64,
|
||||
//policy_number: Entity,
|
||||
policy_numbers: HashMap<u64, PolicyCode>,
|
||||
progress_bar: Entity,
|
||||
progress_count: f64,
|
||||
progress_popup: Entity,
|
||||
// target that recieves messages
|
||||
target: Entity,
|
||||
ticketdata_view: Entity
|
||||
}
|
||||
|
||||
impl GlobalState for PolicycheckState {}
|
||||
|
||||
/// Method definitions, that react on any given state change inside the `Policycheck` widget.
|
||||
impl PolicycheckState {
|
||||
/// Create a hashmap (key: policy number, value: policy type).
|
||||
pub fn create_hashmap(&mut self, _ctx: &mut Context<'_>)
|
||||
-> Result<(), Box<dyn std::error::Error>> {
|
||||
trace!(target: "advotracker", create_hashmap = "started");
|
||||
|
||||
let policy_list = PolicyList::new("policy list");
|
||||
trace!(target: "advotracker", policy_list = ?policy_list);
|
||||
|
||||
// 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<u64, PolicyCode> = HashMap::new();
|
||||
|
||||
// Wip: use cli parameter stored in viperus ...
|
||||
//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) {
|
||||
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;
|
||||
|
||||
trace!(target: "advotracker", create_hashmap = "finished");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// Import policy numbers into hashmap
|
||||
fn import_data(&mut self, ctx: &mut Context<'_>)
|
||||
-> Result<(), Box<dyn std::error::Error>> {
|
||||
// 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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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::<TicketdataView>(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");
|
||||
|
||||
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));
|
||||
},
|
||||
|
||||
Err(e) => trace!(target: "advotracker", policycheck_state = "init", import_data = ?e),
|
||||
}
|
||||
}
|
||||
|
||||
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"));
|
||||
|
||||
if policy_number_length == 10 {
|
||||
// cast policy_number_sting to <u64>
|
||||
match policy_number_string.parse::<u64>() {
|
||||
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);
|
||||
|
||||
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"));
|
||||
|
||||
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);
|
||||
|
||||
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"));
|
||||
|
||||
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);
|
||||
|
||||
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"));
|
||||
|
||||
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");
|
||||
|
||||
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"));
|
||||
|
||||
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");
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
trace!(target: "advotracker", parse_entry = "finished");
|
||||
}
|
||||
|
||||
/// parse message 'ParseEntry'
|
||||
pub fn parse_policy_number(&mut self, entity: 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);
|
||||
}
|
||||
|
||||
// /// If TextBox 'policy_check_policy_number' is empty, disable button "clear"
|
||||
// /// otherwise enabled it.
|
||||
// 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() {
|
||||
// ctx.get_widget(self.policy_check_clear_button).set("enabled", false);
|
||||
// } else {
|
||||
// ctx.get_widget(self.policy_check_clear_button).set("enabled", true);
|
||||
// }
|
||||
|
||||
// ctx.get_widget(self.policy_check_policy_number).update_theme_by_state(true);
|
||||
// }
|
||||
|
||||
/// 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::<String>("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::<String16>("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 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);
|
||||
|
||||
// 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::<String16>("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::<PolicyDataList>(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);
|
||||
|
||||
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::<f64>("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::<PolicycheckState>(ID_POLICY_CHECK_POLICY_CODE);
|
||||
//ctx.widget().set(PROP_POLICY_DATA_COUNT, policy_code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Supported methods handled inside the `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();
|
||||
|
||||
trace!(target: "advotracker", policycheck_state = "init", status = "started");
|
||||
|
||||
// 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'.");
|
||||
|
||||
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);
|
||||
|
||||
Stack::visibility_set(&mut ctx.child(ID_POLICY_CHECK_ACTION_STACK), Visibility::Collapsed);
|
||||
|
||||
|
||||
//self.policy_number = Entity::from(ctx.widget().try_clone::<u32>(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::<u32>("target")
|
||||
.expect("PolicycheckState::init(): Can't find resource entity 'target'."));
|
||||
|
||||
//self.ticketdata_view = (*ctx.widget().get::<u32>("ticketdata_view")).into();
|
||||
//self.ticketdata = Entity::from(ctx.widget().try_clone::<u32>(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>("settings")
|
||||
// .load::<PolicyDataList>(PROP_ADVOTRACKER)
|
||||
// {
|
||||
// ctx.widget().set(PROP_ADVOTRACKER, policy_data);
|
||||
// }
|
||||
|
||||
let time_end = SystemTime::now();
|
||||
let duration = time_end.duration_since(time_start);
|
||||
|
||||
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<'_>,
|
||||
) {
|
||||
for message in messages.read::<PolicycheckAction>() {
|
||||
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!"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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>("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<PolicycheckAction> = 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);
|
||||
|
||||
//info!("Message send: 'PolicycheckAction::UpdatePolicyNumber({:?}) -> {:?}'", policy_number, self.target);
|
||||
//let policy_number = (&mut ctx.get_widget(entity).get::<String>("text"));
|
||||
//let policy_number = ctx.get_widget(ID_POLICY_CHECK_POLICY_NUMBER).get::<text>("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::<String16>("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_string = ctx.get_widget(entity).get::<String16>("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.
|
||||
// fn update_post_layout(&mut self, _: &mut Registry, _ctx: &mut Context<'_>) {
|
||||
// }
|
||||
}
|
||||
|
||||
/// 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::<PolicycheckState>(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)
|
||||
}
|
||||
331
advotracker_client/src/widgets/policycheck/policycheck_view.rs
Normal file
331
advotracker_client/src/widgets/policycheck/policycheck_view.rs
Normal file
@@ -0,0 +1,331 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
use orbtk::shell::event::Key;
|
||||
|
||||
use crate::{
|
||||
data::{
|
||||
constants::*,
|
||||
structures::PolicyCheck,
|
||||
},
|
||||
//widgets::menu::menu_state::{MenuAction, MenuState},
|
||||
widgets::policycheck::policycheck_state::{PolicycheckAction, PolicycheckState},
|
||||
};
|
||||
|
||||
// Macro that initializes the widget structures/variables for the policy check view
|
||||
widget!(
|
||||
/// Dialog to enter a policy identifier/number.
|
||||
/// This identifier is checked agains a map of valid policy codes.
|
||||
// PolicycheckView<PolicycheckState>: KeyDownHandler {
|
||||
PolicycheckView<PolicycheckState> {
|
||||
// holds the language code
|
||||
lang: String,
|
||||
// provides a struct with `PolicyCheck` members
|
||||
policy_check: PolicyCheck,
|
||||
// holds number of imported data
|
||||
policy_data_count: u32,
|
||||
// holds the title string
|
||||
policy_check_title: String,
|
||||
// widget entity that will receive the message
|
||||
target: u32
|
||||
}
|
||||
);
|
||||
|
||||
/// The template implementation of the policy check view
|
||||
/// All GUI elements are styled using the "style" attribute referencing to a ron based css
|
||||
impl Template for PolicycheckView {
|
||||
//fn template(self, policycheck_view: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
let tenent_logo = Container::new()
|
||||
.margin((16, 16, 0, 0))
|
||||
.attach(Grid::column(0))
|
||||
.v_align("center")
|
||||
.child(
|
||||
ImageWidget::new()
|
||||
.image("assets/advotracker/hiedemann_logo.png")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let policy_check_bottom_bar = Container::new()
|
||||
.id(ID_POLICY_CHECK_BOTTOM_BAR)
|
||||
//.style(STYLE_BOTTOM_BAR)
|
||||
.padding(14)
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(1))
|
||||
.attach(Grid::column_span(2))
|
||||
.v_align("end")
|
||||
.child(
|
||||
Container::new()
|
||||
.attach(Grid::column(1))
|
||||
.h_align("end")
|
||||
.v_align("end")
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.margin((0, 9, 48, 0))
|
||||
.text("©Networkx GmbH")
|
||||
.build(ctx)
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let policy_check_button_menu = Button::new()
|
||||
.id(ID_POLICY_CHECK_BUTTON_MENU)
|
||||
.style("button_single_content")
|
||||
.icon(material_icons_font::MD_MENU)
|
||||
.attach(Grid::column(2))
|
||||
//.min_size(16, 16)
|
||||
.h_align("end")
|
||||
.on_click(move |_ctx, _| {
|
||||
println!("WIP: open menu popup from MenuView");
|
||||
// ctx.get_mut::<MenuState>(id)
|
||||
// .set_action(MenuAction::CreateMenu(ID_MENU_STACK));
|
||||
true
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
let policy_check_button_result = Button::new()
|
||||
.id(ID_POLICY_CHECK_BUTTON_RESULT)
|
||||
.style("button_single_content")
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(3))
|
||||
.h_align("start")
|
||||
.v_align("center")
|
||||
.visibility(Visibility::Collapsed)
|
||||
.enabled(false)
|
||||
.build(ctx);
|
||||
|
||||
let policy_check_header_text = TextBlock::new()
|
||||
.id(ID_POLICY_CHECK_HEADER)
|
||||
.attach(Grid::column(0))
|
||||
.style(STYLE_HEADER_TEXT)
|
||||
.text("Validation policy number")
|
||||
.build(ctx);
|
||||
|
||||
let policy_check_header_bar = Container::new()
|
||||
.id(ID_POLICY_CHECK_HEADER_BAR)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.style(STYLE_HEADER_BAR)
|
||||
.child(tenent_logo)
|
||||
.child(policy_check_header_text)
|
||||
.child(policy_check_button_menu)
|
||||
.build(ctx);
|
||||
|
||||
let policy_check_policy_code = TextBlock::new()
|
||||
.id(ID_POLICY_CHECK_POLICY_CODE)
|
||||
.style("body")
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(2))
|
||||
.build(ctx);
|
||||
|
||||
let policy_check_form_action = Container::new()
|
||||
.id(ID_POLICY_CHECK_ACTION_GRID)
|
||||
.attach(Grid::row(3))
|
||||
.attach(Grid::column(1))
|
||||
//.style(STYLE_CONTAINER_ACTION)
|
||||
.padding(14)
|
||||
.h_align("center")
|
||||
.child(
|
||||
Stack::new()
|
||||
.id(ID_POLICY_CHECK_ACTION_STACK)
|
||||
//.style(STYLE_STACK_ACTION)
|
||||
.orientation("horizontal")
|
||||
.spacing(50)
|
||||
.child(
|
||||
Button::new()
|
||||
.id(ID_POLICY_CHECK_ACTION_BUTTON_CLEAR)
|
||||
.style(STYLE_BUTTON_ACTION)
|
||||
.text("Clear")
|
||||
.on_click(move |states, _entity| {
|
||||
states.send_message(PolicycheckAction::ClearPolicyNumber, id);
|
||||
false
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.id(ID_POLICY_CHECK_ACTION_BUTTON_CREATE)
|
||||
.style(STYLE_BUTTON_ACTION)
|
||||
.text("Create ticket")
|
||||
.on_click(move |states, _entity| {
|
||||
states.send_message(PolicycheckAction::UpdatePolicyCode, id);
|
||||
states.send_message(PolicycheckAction::NewTicket, id);
|
||||
false
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let policy_check_form = Container::new()
|
||||
.id(ID_POLICY_CHECK_FORM)
|
||||
.name(ID_POLICY_CHECK_FORM)
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(1))
|
||||
.style("container_form")
|
||||
.child(
|
||||
Grid::new()
|
||||
.id(ID_POLICY_CHECK_FORM)
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push("auto") // Label
|
||||
.push("16") // Delimiter
|
||||
.push("200") // Data
|
||||
.push("16") // Delimiter
|
||||
.push("32") // Result-Button
|
||||
.push("4") // Delimeter
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
.push("auto") // Row 0
|
||||
.push("14") // Seperator
|
||||
.push("auto") // Row 2
|
||||
.push("14") // Seperator
|
||||
.push("auto") // Row 3
|
||||
)
|
||||
|
||||
//.child(policy_check_form_row_0)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_POLICY_CHECK_LABEL_POLICY_NUMBER)
|
||||
.style("body")
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(0))
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.text("Policy number")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_POLICY_CHECK_POLICY_NUMBER)
|
||||
//.style("body")
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(2))
|
||||
//.lose_focus_on_activation(false)
|
||||
//WIP: localization for water_mark
|
||||
.water_mark("10-stellig")
|
||||
.on_activate(move |states, entity| {
|
||||
// Entity is entered/activated via Mouse/Keyboard
|
||||
states.get_mut::<PolicycheckState>(id).parse_policy_number(entity);
|
||||
})
|
||||
.on_key_down(move |_, key_event| {
|
||||
if key_event.key == Key::A(true) {
|
||||
println!("A key down");
|
||||
}
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .set_action(Action::ImportData);
|
||||
true
|
||||
})
|
||||
.build(ctx)
|
||||
)
|
||||
.child(policy_check_button_result)
|
||||
|
||||
//.child(policy_check_form_row_2)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_POLICY_CHECK_LABEL_RESULT)
|
||||
.style("body")
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(0))
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.text("Policy code")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(policy_check_policy_code)
|
||||
|
||||
//.child(policy_check_form_row_2)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_POLICY_CHECK_LABEL_HINT)
|
||||
.style("hint")
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(0))
|
||||
//.margin((0, 0, 16, 0))
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.text("Error:")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_POLICY_CHECK_HINT)
|
||||
.style("hint")
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(2))
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
|
||||
// row3: only shown, if we read in `policy numbers` in
|
||||
// a hashmap as values
|
||||
let policy_data_stack = Stack::new()
|
||||
.id(ID_POLICY_DATA_STACK)
|
||||
.attach(Grid::row(3))
|
||||
.attach(Grid::column(1))
|
||||
.h_align("end")
|
||||
.v_align("top")
|
||||
.orientation("horizontal")
|
||||
.visibility(Visibility::Collapsed)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_POLICY_DATA_LABEL)
|
||||
.margin((0, 4, 0, 0))
|
||||
.enabled(true)
|
||||
.text("Checklist elements: ")
|
||||
.build(ctx)
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_POLICY_DATA_COUNT)
|
||||
.margin((0, 4, 0, 0))
|
||||
.enabled(true)
|
||||
.text("0")
|
||||
.build(ctx)
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
// Starter page: check policy numbers
|
||||
self.name("PolicycheckView")
|
||||
// initialize struct (derived default macro)
|
||||
.policy_check(PolicyCheck::default())
|
||||
.child(
|
||||
Grid::new()
|
||||
.id(ID_POLICY_CHECK_WIDGET)
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push(50) // Left margin
|
||||
.push("*") // Content
|
||||
.push(50) // Right margin
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
.push("auto") // Header_Bar
|
||||
.push(28) // Seperator
|
||||
.push("*") // InputForm
|
||||
.push("auto") // Data_Result
|
||||
.push("auto") // Bottom_Bar
|
||||
)
|
||||
|
||||
.child(policy_check_header_bar) // row 0
|
||||
.child(policy_check_form) // row 2
|
||||
.child(policy_data_stack) // row 3
|
||||
.child(policy_check_form_action) // row 4
|
||||
.child(policy_check_bottom_bar) // row 5
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
12
advotracker_client/src/widgets/policydata/mod.rs
Normal file
12
advotracker_client/src/widgets/policydata/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// The policy check state
|
||||
pub mod policycheck_state;
|
||||
|
||||
/// The policy check view
|
||||
pub mod policycheck_view;
|
||||
290
advotracker_client/src/widgets/policydata/policydata_state.rs
Normal file
290
advotracker_client/src/widgets/policydata/policydata_state.rs
Normal file
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
callbacks::global_state::GlobalState,
|
||||
data::constants::*,
|
||||
data::{PolicyCode, PolicyData, PolicyList, Status},
|
||||
};
|
||||
use chrono::{Utc, NaiveDateTime};
|
||||
|
||||
/// Actions that can execute on the task view.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Action {
|
||||
InputTextChanged(Entity),
|
||||
NavigateBack(),
|
||||
NewEntry(Entity),
|
||||
RemoveFocus(Entity),
|
||||
RemoveEntry(usize),
|
||||
SetDateInserted(Entity),
|
||||
SetDion(Entity),
|
||||
SetPolicyCode(Entity),
|
||||
SetPolicyNumber(Entity),
|
||||
StatusChanged(Entity, usize),
|
||||
TextChanged(Entity, usize),
|
||||
}
|
||||
|
||||
/// Handles the requests of the `PolicyDataListView`.
|
||||
#[derive(Debug, Default, AsAny)]
|
||||
pub struct PolicyDataState {
|
||||
action:Option<Action>,
|
||||
back_entity: Entity,
|
||||
last_focused: Option<Entity>,
|
||||
policy_data_add_button: Entity,
|
||||
pub policy_data_date_inserted: Entity,
|
||||
pub policy_data_dion: Entity,
|
||||
pub policy_data_policy_code: Entity,
|
||||
pub policy_data_policy_number: Entity,
|
||||
open: bool,
|
||||
}
|
||||
|
||||
/// implement of the BaseState trait for our PolicyDataState type
|
||||
impl GlobalState for PolicyDataState {}
|
||||
|
||||
/// implement the PolicyDateState type itself
|
||||
impl PolicyDataState {
|
||||
/// Sets a new action.
|
||||
pub fn action(&mut self, action: Action) {
|
||||
self.action = action.into();
|
||||
}
|
||||
|
||||
/// update number of available policy data entries.
|
||||
fn adjust_count(&self, ctx: &mut Context) {
|
||||
if let Some(index) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
if let Some(policy_list) = ctx
|
||||
.widget()
|
||||
.clone::<PolicyList>("policy_list")
|
||||
.get(index)
|
||||
{
|
||||
ctx.widget().set("policy_data_count", policy_list.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If policy data element 'name' is empty, disable the add button
|
||||
/// otherwise otherwise enabled it.
|
||||
fn adjust_add_button_enabled(&self, text_box: Entity, ctx: &mut Context) {
|
||||
if ctx.get_widget(text_box).get::<String16>("name").is_empty() {
|
||||
ctx.get_widget(self.policy_data_add_button).set("enabled", false);
|
||||
} else {
|
||||
ctx.get_widget(self.policy_data_add_button).set("enabled", true);
|
||||
}
|
||||
|
||||
ctx.get_widget(self.policy_data_add_button).update_theme_by_state(true);
|
||||
}
|
||||
|
||||
/// Change status of given text box to edit mode.
|
||||
fn edit_entry(&self, text_box: Entity, ctx: &mut Context) {
|
||||
if *ctx.get_widget(text_box).get::<bool>("focused") {
|
||||
ctx.get_widget(text_box).set("enabled", false);
|
||||
ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box));
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(old_focused_element) = ctx.window().get::<Global>("global").focused_widget {
|
||||
ctx.push_event_by_window(FocusEvent::RemoveFocus(old_focused_element));
|
||||
}
|
||||
|
||||
ctx.get_widget(text_box).set("enabled", true);
|
||||
|
||||
// select all
|
||||
ctx.get_widget(text_box)
|
||||
.get_mut::<TextSelection>("text_selection")
|
||||
.start_index = 0;
|
||||
ctx.get_widget(text_box)
|
||||
.get_mut::<TextSelection>("text_selection")
|
||||
.length = ctx.get_widget(text_box).get::<String16>("name").len();
|
||||
ctx.push_event_by_window(FocusEvent::RequestFocus(text_box));
|
||||
}
|
||||
|
||||
/// navigate to previous policy data entry.
|
||||
fn navigate_back(&mut self, ctx: &mut Context) {
|
||||
ctx.get_widget(self.text_box)
|
||||
.set("name", String16::from(""));
|
||||
self.open = false;
|
||||
ctx.widget().set::<Option<usize>>("list_index", None);
|
||||
ctx.widget().set("policy_data_count", 0 as usize);
|
||||
self.navigate(self.back_entity, ctx);
|
||||
}
|
||||
|
||||
/// create a new policy data member
|
||||
fn new_entry(&self, policy_number: u32, registry: &mut Registry, ctx: &mut Context) {
|
||||
let index = ctx.widget().clone::<Option<usize>>("list_index");
|
||||
|
||||
if let Some(index) = index {
|
||||
if let Some(policy_data) = ctx
|
||||
.widget()
|
||||
.get_mut::<PolicyList>("policy_list")
|
||||
.get_mut(index)
|
||||
{
|
||||
policy_data.push(PolicyData {
|
||||
date_inserted: Some(Utc::now().naive_utc()),
|
||||
dion: 1,
|
||||
policy_code: PolicyCode::AS,
|
||||
policy_number,
|
||||
status: Status::Active,
|
||||
});
|
||||
}
|
||||
|
||||
self.adjust_count(ctx);
|
||||
}
|
||||
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
|
||||
pub fn open(&mut self, ctx: &mut Context) {
|
||||
if let Some(index) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
let mut name: String16 = "".into();
|
||||
let mut policy_data_count = 0;
|
||||
if let Some(policy_list) = ctx.widget().get::<PolicyList>("policy_list").get(index) {
|
||||
name = String16::from(policy_list.name.as_str());
|
||||
policy_data_count = policy_list.len();
|
||||
}
|
||||
ctx.widget().set("name", name);
|
||||
ctx.widget().set("policy_data_count", policy_data_count);
|
||||
self.open = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_entry(&self, index: usize, registry: &mut Registry, ctx: &mut Context) {
|
||||
if let Some(idx) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
if let Some(policy_list) = ctx
|
||||
.widget()
|
||||
.get_mut::<PolicyList>("policy_list")
|
||||
.get_mut(idx)
|
||||
{
|
||||
policy_list.remove(index);
|
||||
}
|
||||
}
|
||||
self.adjust_count(ctx);
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
|
||||
/// Toggle the selection state of the given policy number element
|
||||
fn toggle_status(
|
||||
&self,
|
||||
entry: Entity,
|
||||
index: usize,
|
||||
registry: &mut Registry,
|
||||
ctx: &mut Context,
|
||||
) {
|
||||
let invalid: bool = *ctx.get_widget(entry).get("status");
|
||||
|
||||
if let Some(idx) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
if let Some(policy_data) = ctx
|
||||
.widget()
|
||||
.get_mut::<PolicyList>("policy_list")
|
||||
.get_mut(idx)
|
||||
{
|
||||
if let Some(policy_data) = policy_data.get_mut(index) {
|
||||
policy_data.status = Status::Active;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
|
||||
fn update_entry(
|
||||
&self,
|
||||
policy_data_date_inserted: Entity,
|
||||
policy_data_dion: Entity,
|
||||
policy_data_policy_code: Entity,
|
||||
policy_data_policy_number: Entity,
|
||||
index: usize,
|
||||
registry: &mut Registry,
|
||||
ctx: &mut Context,
|
||||
) {
|
||||
let date_inserted: Option<NaiveDateTime> = ctx.get_widget(policy_data_date_inserted).clone("date_inserted");
|
||||
let dion: u8 = ctx.get_widget(policy_data_dion).clone("dion");
|
||||
let policy_code: PolicyCode = ctx.get_widget(policy_data_policy_code).clone("policy_code");
|
||||
let policy_number: u32 = ctx.get_widget(policy_data_policy_number).clone("policy_number");
|
||||
|
||||
// get the index from the active widgets 'list_index' member
|
||||
if let Some(idx) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
// get view record from the active widgets 'policy_list' member
|
||||
if let Some(policy_list) = ctx
|
||||
.widget()
|
||||
.get_mut::<PolicyList>("policy_list")
|
||||
.get_mut(idx)
|
||||
{
|
||||
// update the record data using the view values of the active policy_list member
|
||||
if let Some(policy_data) = policy_list.get_mut(index) {
|
||||
policy_data.date_inserted = date_inserted;
|
||||
policy_data.dion = dion;
|
||||
policy_data.policy_code = policy_code;
|
||||
policy_data.policy_number = policy_number;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
impl State for PolicyDataState {
|
||||
fn init(&mut self, _: &mut Registry, ctx: &mut Context) {
|
||||
self.back_entity = (*ctx.widget().get::<u32>("back_entity")).into();
|
||||
self.policy_data_add_button = ctx
|
||||
.entity_of_child(ID_POLICY_DATA_ADD_BUTTON)
|
||||
.expect("PolicyState.init: Can't find child 'Add button'.");
|
||||
self.policy_data_policy_number = ctx
|
||||
.entity_of_child(ID_POLICY_DATA_POLICY_NUMBER)
|
||||
.expect("PolicyState.init: Can't find child 'Policy Number'.");
|
||||
}
|
||||
|
||||
fn update(&mut self, registry: &mut Registry, ctx: &mut Context) {
|
||||
if !self.open {
|
||||
self.open(ctx);
|
||||
}
|
||||
if let Some(action) = self.action {
|
||||
match action {
|
||||
Action::InputTextChanged(text_box) => {
|
||||
self.adjust_add_button_enabled(text_box, ctx);
|
||||
}
|
||||
Action::NewEntry(entity) => {
|
||||
if let Some(text) = self.fetch_text(ctx, entity) {
|
||||
self.new_entry(text, registry, ctx);
|
||||
}
|
||||
}
|
||||
Action::RemoveEntry(index) => {
|
||||
self.remove_entry(index, registry, ctx);
|
||||
}
|
||||
Action::SelectionChanged(entity, index) => {
|
||||
self.toggle_selection(entity, index, registry, ctx);
|
||||
}
|
||||
Action::TextChanged(entity, index) => {
|
||||
self.update_entry(entity, index, registry, ctx);
|
||||
}
|
||||
Action::SetDateInserted(policy_data_date_inserted) => {
|
||||
self.last_focused = Some(policy_data_date_inserted);
|
||||
self.edit_entry(policy_data_date_inserted, ctx);
|
||||
}
|
||||
Action::SetDion(policy_data_dion) => {
|
||||
self.last_focused = Some(policy_data_dion);
|
||||
self.edit_entry(policy_data_policy_dion);
|
||||
}
|
||||
Action::SetPolicyCode(policy_data_policy_code) => {
|
||||
self.last_focused = Some(policy_data_policy_code);
|
||||
self.edit_entry(policy_data_policy_code, ctx);
|
||||
}
|
||||
Action::SetPolicyNumber(policy_data_policy_number) => {
|
||||
self.last_focused = Some(policy_data_policy_number);
|
||||
self.edit_entry(policy_data_policy_number, ctx);
|
||||
}
|
||||
Action::RemoveFocus(text_box) => {
|
||||
ctx.get_widget(text_box).set("enabled", false);
|
||||
ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box));
|
||||
}
|
||||
Action::NavigateBack() => {
|
||||
self.navigate_back(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.action = None;
|
||||
}
|
||||
}
|
||||
394
advotracker_client/src/widgets/policydata/policydata_view.rs
Normal file
394
advotracker_client/src/widgets/policydata/policydata_view.rs
Normal file
@@ -0,0 +1,394 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
constants::*,
|
||||
data::{PolicyList, Status},
|
||||
policydata_state::{Action, PolicyDataState},
|
||||
};
|
||||
use chrono::NaiveDateTime;
|
||||
|
||||
type ListIndex = Option<usize>;
|
||||
|
||||
// Dialog to manage policy identifiers.
|
||||
// The elements may be toggled to be deactivated. The optional value 'data_valid_until'
|
||||
// will render this value unvalid after the given date.
|
||||
widget!(
|
||||
PolicyDataView<PolicyDataState> {
|
||||
back_entity: u32,
|
||||
policy_list_count: usize,
|
||||
policylist_view: u32,
|
||||
list_index: ListIndex,
|
||||
date_valid_until: NaiveDateTime,
|
||||
policy_list: PolicyList
|
||||
});
|
||||
|
||||
impl Template for PolicyDataView {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
|
||||
// listing the policy elements
|
||||
let items_widget = ItemsWidget::new()
|
||||
.id(ID_POLICY_DATA_ITEMS_WIDGET)
|
||||
.v_align("start")
|
||||
.items_builder(move |ctx, index| {
|
||||
let mut date_inserted = None;
|
||||
let mut dion = 1;
|
||||
let mut policy_code = "".to_string();
|
||||
let mut policy_number = None;
|
||||
let mut status = false; // Status::<Active, Inactive>;
|
||||
|
||||
if let Some(list_index) = ctx.get_widget(id).clone::<ListIndex>("list_index") {
|
||||
if let Some(policy_data) = ctx
|
||||
.get_widget(id)
|
||||
.get::<PolicyList>(PROP_POLICY_LIST)
|
||||
.get(list_index)
|
||||
{
|
||||
if let Some(policy_data) = policy_data.get(index) {
|
||||
date_inserted = policy_data.date_inserted.clone();
|
||||
dion = policy_data.dion.clone();
|
||||
policy_code = policy_data.policy_code.clone();
|
||||
policy_number = policy_data.policy_number.clone();
|
||||
status = policy_data.status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let policy_data_status = CheckBox::new()
|
||||
.attach(Grid::column(1))
|
||||
.v_align("center")
|
||||
// status: true -> State::Active false -> State::Inactive
|
||||
.enabled(status)
|
||||
.on_changed(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::StatusChanged(entity, index));
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
let policy_data_dion = TextBox::new()
|
||||
.id(ID_POLICY_DATA_DION)
|
||||
.attach(Grid::row(3))
|
||||
.v_align("center")
|
||||
.margin((4.0, 0.0, 0.0, 0.0))
|
||||
.text(dion)
|
||||
.lost_focus_on_activation(false)
|
||||
.on_activate(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::CreateEntry(entity));
|
||||
})
|
||||
.on_changed(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::InputTextChanged(entity));
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
let policy_data_dion = TextBox::new()
|
||||
.id(ID_POLICY_DATA_DION)
|
||||
.attach(Grid::row(5))
|
||||
.v_align("center")
|
||||
.margin((4.0, 0.0, 0.0, 0.0))
|
||||
.text(policy_code)
|
||||
.lost_focus_on_activation(false)
|
||||
.on_activate(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::TextChanged(entity));
|
||||
})
|
||||
.on_changed(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::RemoveFocus(entity));
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
let policy_data_policy_code = TextBox::new()
|
||||
.id(ID_POLICY_DATA_POLICY_CODE)
|
||||
.attach(Grid::row(7))
|
||||
.v_align("center")
|
||||
.margin((4.0, 0.0, 0.0, 0.0))
|
||||
.text(policy_code)
|
||||
.lost_focus_on_activation(false)
|
||||
.on_activate(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::TextChanged(entity));
|
||||
})
|
||||
.on_changed(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::RemoveFocus(entity));
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
|
||||
let policy_data_policy_number = TextBox::new()
|
||||
.id(ID_POLICY_DATA_POLICY_NUMBER)
|
||||
.attach(Grid::column(9))
|
||||
.text(policy_number)
|
||||
.enabled(false)
|
||||
.v_align("center")
|
||||
.water_mark("Insert the new policy number ...")
|
||||
.class("inplace")
|
||||
.on_activate(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::TextChanged(entity));
|
||||
})
|
||||
.on_changed(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::RemoveFocus(entity));
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
let policy_data_date_inserted = TextBlock::new()
|
||||
.id(ID_POLICY_DATA_DATE_INSERTED)
|
||||
.attach(Grid::column(9))
|
||||
.text(date_inserted)
|
||||
.v_align("start")
|
||||
.on_activate(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::TextChanged(entity));
|
||||
})
|
||||
.on_changed(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::RemoveFocus(entity));
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
Grid::new()
|
||||
.height(48.0)
|
||||
.columns(
|
||||
Columns::new()
|
||||
.add(10.0)
|
||||
.add(24.0)
|
||||
.add(8.0)
|
||||
.add(24.0)
|
||||
.add(8.0)
|
||||
.add(24.0)
|
||||
.add(8.0)
|
||||
.add("auto")
|
||||
.add(8.0)
|
||||
.add("auto")
|
||||
.add(8.0)
|
||||
.add(32.0)
|
||||
.add(4.0)
|
||||
.add(32.0)
|
||||
.add(8.0)
|
||||
.build(),
|
||||
)
|
||||
.child(policy_data_status)
|
||||
.child(policy_data_dion)
|
||||
.child(policy_data_policy_code)
|
||||
.child(policy_data_policy_number)
|
||||
.child(policy_data_date_inserted)
|
||||
.child(
|
||||
// edit active policy data element
|
||||
Button::new()
|
||||
.class(CLASS_ICON_ONLY)
|
||||
.attach(Grid::column(11))
|
||||
.min_size(32.0, 32.0)
|
||||
.v_align("center")
|
||||
.icon(material_icons_font_ttf::MD_EDIT)
|
||||
//.icon("")
|
||||
.on_mouse_down(|_, _| true)
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::EditEntry(text_box));
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
// delete active policy data element
|
||||
Button::new()
|
||||
.class("icon_only")
|
||||
.attach(Grid::column(13))
|
||||
.min_size(32.0, 32.0)
|
||||
.v_align("center")
|
||||
.icon(material_icons_font_ttf::MD_DELETE)
|
||||
//.icon("")
|
||||
.on_mouse_down(|_, _| true)
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::RemoveEntry(index));
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx)
|
||||
})
|
||||
.policy_data_count(PROP_POLICY_DATA_COUNT, id)
|
||||
.build(ctx);
|
||||
|
||||
let scroll_viewer = ScrollViewer::new()
|
||||
.scroll_viewer_mode(("disabled", "auto"))
|
||||
.child(items_widget)
|
||||
.build(ctx);
|
||||
|
||||
let policy_data_list_name = TextBox::new()
|
||||
.id(ID_POLICY_DATA_LIST_NAME)
|
||||
.attach(Grid::row(4))
|
||||
.v_align("center")
|
||||
.margin((4.0, 0.0, 0.0, 0.0))
|
||||
.lost_focus_on_activation(false)
|
||||
.on_activate(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::CreateEntry(entity));
|
||||
})
|
||||
.on_changed(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::InputTextChanged(entity));
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
// Child page: list available policy data elements
|
||||
self.name("PolicyDataListView").child(
|
||||
Grid::new()
|
||||
.rows(
|
||||
Rows::new()
|
||||
.add(52.0)
|
||||
.add(1.0)
|
||||
.add("*")
|
||||
.add(1.0)
|
||||
.add("auto")
|
||||
.build(),
|
||||
)
|
||||
.columns(
|
||||
Columns::new()
|
||||
.add("*")
|
||||
.add(4.0)
|
||||
.add(36.0)
|
||||
.build(),
|
||||
)
|
||||
// Top Bar
|
||||
.child(
|
||||
Container::new()
|
||||
.class(CLASS_TOP_BAR)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.child(
|
||||
Grid::new()
|
||||
.columns(
|
||||
Columns::new()
|
||||
.add(32.0)
|
||||
.add(4.0)
|
||||
.add("*")
|
||||
.add(4.0)
|
||||
.add(32.0)
|
||||
.build(),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.height(32.0)
|
||||
.icon(material_icons_font_ttf::MD_ARROW_LEFT)
|
||||
//.icon("")
|
||||
.class(CLASS_ICON_ONLY)
|
||||
.v_align("center")
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::NavigateBack());
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.class(CLASS_HEADER)
|
||||
.attach(Grid::column(2))
|
||||
.v_align("center")
|
||||
.h_align("center")
|
||||
.text(("name", id))
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Stack::new()
|
||||
.class(CLASS_HEADER)
|
||||
.attach(Grid::column(3))
|
||||
.h_align("start")
|
||||
.orientation("horizontal")
|
||||
.child(
|
||||
TextBox::new()
|
||||
.class(CLASS_HEADER)
|
||||
//.v_align("center")
|
||||
.h_align("start")
|
||||
.text(("Anzahl:", id))
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.class(CLASS_HEADER)
|
||||
.id(PROP_POLICY_DATA_COUNT)
|
||||
.attach(Grid::column(3))
|
||||
//.v_align("center")
|
||||
.h_align("end")
|
||||
.text("policy_data_count")
|
||||
.build(ctx),
|
||||
)
|
||||
.build,
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Container::new()
|
||||
.class("separator")
|
||||
.attach(Grid::row(1))
|
||||
.attach(Grid::column_span(3))
|
||||
.build(ctx),
|
||||
)
|
||||
// Content
|
||||
.child(
|
||||
Container::new()
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.child(scroll_viewer)
|
||||
.child(
|
||||
ScrollIndicator::new()
|
||||
.padding((0.0, 4.0, 0.0, 0.0))
|
||||
.content_id(items_widget.0)
|
||||
.scroll_offset(scroll_viewer)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Container::new()
|
||||
.class("separator")
|
||||
.attach(Grid::row(3))
|
||||
.attach(Grid::column_span(3))
|
||||
.build(ctx),
|
||||
)
|
||||
// Bottom bar
|
||||
.child(
|
||||
Container::new()
|
||||
.class(CLASS_BOTTOM_BAR)
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.build(ctx),
|
||||
)
|
||||
.child(policy_data_list_name)
|
||||
.child(
|
||||
Button::new()
|
||||
.id(ID_POLICY_DATA_ADD_BUTTON)
|
||||
.class(CLASS_ICON_ONLY)
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(2))
|
||||
.margin((0.0, 0.0, 4.0, 0.0))
|
||||
.enabled(false)
|
||||
.min_size(32.0, 32.0)
|
||||
.v_align("center")
|
||||
.icon(material_icons_font_ttf::MD_ADD_CIRCLE)
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::CreateEntry(policy_data_list_name));
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
12
advotracker_client/src/widgets/policylist/mod.rs
Normal file
12
advotracker_client/src/widgets/policylist/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// The policy check state
|
||||
pub mod policylist_state;
|
||||
|
||||
/// The policy check view
|
||||
pub mod policylist_view;
|
||||
203
advotracker_client/src/widgets/policylist/policylist_state.rs
Normal file
203
advotracker_client/src/widgets/policylist/policylist_state.rs
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
base_state::BaseState,
|
||||
constants::*,
|
||||
data::{PolicyDataList, PolicyList},
|
||||
};
|
||||
|
||||
/// Actions that can execute on the task view.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Action {
|
||||
InputTextChanged(Entity),
|
||||
NewEntry(Entity),
|
||||
RemoveFocus(Entity),
|
||||
RemoveEntry(usize),
|
||||
OpenPolicyList(usize),
|
||||
SetEntry(Entity),
|
||||
TextChanged(Entity, usize),
|
||||
}
|
||||
|
||||
/// Handles the requests of the `PolicyListView`.
|
||||
#[derive(Default, AsAny)]
|
||||
pub struct PolicyListState {
|
||||
action:Option<Action>,
|
||||
add_button: Entity,
|
||||
items_widget: Entity,
|
||||
policydata_view: Entity,
|
||||
last_focused: Option<Entity>,
|
||||
text_box: Entity,
|
||||
}
|
||||
|
||||
impl BaseState for PolicyListState {}
|
||||
|
||||
impl PolicyListState {
|
||||
/// Sets a new action.
|
||||
pub fn action(&mut self, action: Action) {
|
||||
self.action = action.into();
|
||||
}
|
||||
|
||||
/// If policy data element 'name' is empty, disable the add button
|
||||
/// otherwise otherwise enabled it.
|
||||
fn adjust_add_button_enabled(&self, text_box: Entity, ctx: &mut Context) {
|
||||
/* Old syntax
|
||||
if ctx.get_widget(text_box).get::<String>("name").is_empty() {
|
||||
ctx.get_widget(self.add_button).set("enabled", false);
|
||||
} else {
|
||||
ctx.get_widget(self.add_button).set("enabled", true);
|
||||
}
|
||||
ctx.get_widget(self.add_button).update_theme_by_state(true);
|
||||
*/
|
||||
|
||||
if TextBox::get(ctx.get_widget(text_box)).text().is_empty() {
|
||||
Button::get(ctx.child("add_button")).set_enabled(false);
|
||||
} else {
|
||||
Button::get(ctx.child("add_button")).set_enabled(true);
|
||||
}
|
||||
// new syntax not implemented yet
|
||||
ctx.get_widget(self.add_button).update_theme_by_state(true);
|
||||
}
|
||||
|
||||
/// update number of available policy list entries.
|
||||
fn adjust_count(&self, ctx: &mut Context) {
|
||||
let policy_list_count = ctx.widget().get::<PolicyList>(PROP_POLICY_LIST).len();
|
||||
ctx.widget().set(PROP_POLICY_LIST_COUNT, policy_list_count);
|
||||
}
|
||||
|
||||
// Creates a new policy data list.
|
||||
fn new_entry(&self, name: String, registry: &mut Registry, ctx: &mut Context) {
|
||||
ctx.widget()
|
||||
.get_mut::<PolicyList>(PROP_POLICY_LIST)
|
||||
.push(PolicyList::new(name));
|
||||
self.adjust_count(ctx);
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
|
||||
// opens a given policy list name.
|
||||
fn open_policy_list(&self, index: usize, ctx: &mut Context) {
|
||||
ctx.get_widget(self.text_box)
|
||||
.set("text", String16::from(""));
|
||||
ctx.get_widget(self.policydata_view)
|
||||
.set("list_index", Some(index));
|
||||
self.navigate(self.policydata_view, ctx);
|
||||
}
|
||||
|
||||
// removes a policy list.
|
||||
fn remove_entry(&self, index: usize, registry: &mut Registry, ctx: &mut Context) {
|
||||
ctx.widget()
|
||||
.get_mut::<PolicyList>(PROP_POLICY_LIST)
|
||||
.remove(index);
|
||||
self.adjust_count(ctx);
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
|
||||
/// Change status of given text box to edit mode.
|
||||
fn set_entry(&self, text_box: Entity, ctx: &mut Context) {
|
||||
if *ctx.get_widget(text_box).get::<bool>("focused") {
|
||||
ctx.get_widget(text_box).set("enabled", false);
|
||||
ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box));
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(old_focused_element) = ctx.window().get::<Global>("global").focused_widget {
|
||||
ctx.push_event_by_window(FocusEvent::RemoveFocus(old_focused_element));
|
||||
}
|
||||
|
||||
ctx.get_widget(text_box).set("enabled", true);
|
||||
|
||||
// select all
|
||||
ctx.get_widget(text_box)
|
||||
.get_mut::<TextSelection>("text_selection")
|
||||
.start_index = 0;
|
||||
ctx.get_widget(text_box)
|
||||
.get_mut::<TextSelection>("text_selection")
|
||||
.length = ctx.get_widget(text_box).get::<String16>("name").len();
|
||||
ctx.push_event_by_window(FocusEvent::RequestFocus(text_box));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl State for PolicyListState {
|
||||
fn init(&mut self, registry: &mut Registry, ctx: &mut Context) {
|
||||
self.text_box = ctx
|
||||
.entity_of_child(ID_POLICY_LIST_TEXT_BOX)
|
||||
.expect("PolicyListState.init: Child 'Text box' not found.");
|
||||
self.add_button = ctx
|
||||
.entity_of_child(ID_POLICY_LIST_ADD_BUTTON)
|
||||
.expect("PolicyListState.init: Child 'Add button' not found.");
|
||||
self.items_widget = ctx
|
||||
.entity_of_child(ID_POLICY_LIST_ITEMS_WIDGET)
|
||||
.expect("PolicyListState.init: Child 'Items widget' not found.");
|
||||
self.policydata_view = (*ctx.widget()
|
||||
.get::<u32>("policy_list_view")).into();
|
||||
|
||||
if let Ok(policy_list_name) = registry
|
||||
.get::<Settings>("settings")
|
||||
.load::<PolicyList>(PROP_POLICY_LIST)
|
||||
{
|
||||
ctx.widget().set(PROP_POLICY_LIST, policy_list_name);
|
||||
}
|
||||
|
||||
self.adjust_count(ctx);
|
||||
}
|
||||
|
||||
fn update(&mut self, registry: &mut Registry, ctx: &mut Context) {
|
||||
// clear focus on focus moved
|
||||
if self.last_focused != ctx.window().get::<Global>("global").focused_widget {
|
||||
if let Some(last_focused) = self.last_focused {
|
||||
ctx.get_widget(last_focused).set("focused", false);
|
||||
ctx.get_widget(last_focused)
|
||||
.set("visibility", Visibility::Collapsed);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(action) = self.action {
|
||||
match action {
|
||||
Action::InputTextChanged(text_box) => {
|
||||
self.adjust_add_button_enabled(text_box, ctx);
|
||||
}
|
||||
Action::NewEntry(entity) => {
|
||||
if let Some(name) = self.fetch_text(ctx, entity) {
|
||||
self.new_entry(name, registry, ctx);
|
||||
}
|
||||
}
|
||||
Action::RemoveEntry(index) => {
|
||||
self.remove_entry(index, registry, ctx);
|
||||
}
|
||||
Action::TextChanged(entity, index) => {
|
||||
let text: String16 = ctx.get_widget(entity).clone("text");
|
||||
|
||||
if let Some(header) = ctx
|
||||
.widget()
|
||||
.get_mut::<PolicyList>("policy_list")
|
||||
.get_mut(index)
|
||||
{
|
||||
header.name = text.to_string();
|
||||
}
|
||||
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
Action::SetEntry(text_box) => {
|
||||
self.last_focused = Some(text_box);
|
||||
self.set_entry(text_box, ctx);
|
||||
}
|
||||
Action::RemoveFocus(text_box) => {
|
||||
self.last_focused = None;
|
||||
ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box));
|
||||
}
|
||||
Action::OpenPolicyList(index) => {
|
||||
self.open_policy_list(index, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.action = None;
|
||||
}
|
||||
}
|
||||
289
advotracker_client/src/widgets/policylist/policylist_view.rs
Normal file
289
advotracker_client/src/widgets/policylist/policylist_view.rs
Normal file
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
constants::*,
|
||||
data::PolicyList,
|
||||
//policylist_state::{Action, PolicyListState},
|
||||
policylist_state::*,
|
||||
};
|
||||
|
||||
//type ListIndex = Option<usize>;
|
||||
|
||||
widget!(
|
||||
/// Dialog selecting a list of policy identifiers.
|
||||
/// The lists groups a collection of policy codes.
|
||||
PolicyListView<PolicyListState> {
|
||||
back_entity: u32,
|
||||
policy_list: PolicyList,
|
||||
policy_list_count: usize,
|
||||
policydata_view: u32
|
||||
}
|
||||
);
|
||||
|
||||
impl Template for PolicyListView {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
|
||||
// collect the DCES elements of our 'policy lists' view
|
||||
let items_widget = ItemsWidget::new()
|
||||
.id(ID_POLICY_LIST_ITEMS_WIDGET)
|
||||
.v_align("start")
|
||||
.items_builder(move |ctx, index| {
|
||||
let mut name = "".to_string();
|
||||
|
||||
if let Some(policy_list) = ctx
|
||||
.get_widget(id)
|
||||
.get::<PolicyList>(PROP_POLICY_LIST)
|
||||
.get(index)
|
||||
{
|
||||
name = policy_list.name.clone();
|
||||
}
|
||||
|
||||
// plus button: open new policy
|
||||
let new_list_button = Button::new()
|
||||
.min_height(48.0)
|
||||
.class(CLASS_ITEM_BUTTON)
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column_span(1))
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.get_mut::<PolicyListState>(id)
|
||||
.action(Action::OpenPolicyList(index));
|
||||
true
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
let text_block = TextBlock::new()
|
||||
.foreground(new_list_button)
|
||||
.margin((14.0, 0.0, 0.0, 0.0))
|
||||
.v_align("center")
|
||||
.attach(Grid::column(0))
|
||||
.text(name)
|
||||
.element("text-box")
|
||||
.build(ctx);
|
||||
|
||||
let text_box = TextBox::new()
|
||||
.margin((8.0, 0.0, 0.0, 0.0))
|
||||
.visibility("collapsed")
|
||||
.v_align("center")
|
||||
.water_mark("Insert name of a new policy collection ...")
|
||||
.attach(Grid::column(0))
|
||||
.text(text_block)
|
||||
.on_changed(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyListState>(id)
|
||||
.action(Action::TextChanged(entity, index));
|
||||
})
|
||||
.on_activate(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyListState>(id)
|
||||
.action(Action::RemoveFocus(entity));
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
Grid::new()
|
||||
.height(48.0)
|
||||
.columns(
|
||||
Columns::new()
|
||||
.add("*")
|
||||
.add(8.0)
|
||||
.add(32.0)
|
||||
.add(4.0)
|
||||
.add(32.0)
|
||||
.add(8.0)
|
||||
.build(),
|
||||
)
|
||||
.child(new_list_button)
|
||||
.child(text_box)
|
||||
.child(text_block)
|
||||
.child(
|
||||
// toggle if text_box is focused
|
||||
ToggleButton::new()
|
||||
.selected(("focused", text_box))
|
||||
.class(CLASS_ICON_ONLY)
|
||||
.attach(Grid::column(2))
|
||||
.min_size(32.0, 32.0)
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
// .selected(("focused", text_box))
|
||||
.class(CLASS_ICON_ONLY)
|
||||
.attach(Grid::column(2))
|
||||
.min_size(32.0, 32.0)
|
||||
.v_align("center")
|
||||
.icon(material_icons_font_ttf::MD_ADD)
|
||||
//.icon(material_icons_font_ttf::MD_EDIT)
|
||||
//.icon("")
|
||||
.on_mouse_down(|_, _| true)
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.get_mut::<PolicyListState>(id)
|
||||
.action(Action::SetEntry(text_box));
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.class("icon_only")
|
||||
.attach(Grid::column(4))
|
||||
.min_size(32.0, 32.0)
|
||||
.v_align("center")
|
||||
.icon(material_icons_font_ttf::MD_DELETE)
|
||||
//.icon("")
|
||||
.on_mouse_down(|_, _| true)
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.get_mut::<PolicyListState>(id)
|
||||
.action(Action::RemoveEntry(index));
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx)
|
||||
})
|
||||
.count((PROP_POLICY_LIST_COUNT, id))
|
||||
.build(ctx);
|
||||
|
||||
// create new policy list element
|
||||
let policy_list_text_box = TextBox::new()
|
||||
.id(ID_POLICY_LIST_TEXT_BOX)
|
||||
.attach(Grid::row(4))
|
||||
.v_align("center")
|
||||
.margin((4.0, 0.0, 0.0, 2.0))
|
||||
.lost_focus_on_activation(false)
|
||||
.on_activate(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyListState>(id)
|
||||
.action(Action::NewEntry(entity));
|
||||
})
|
||||
.on_changed(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyListState>(id)
|
||||
.action(Action::InputTextChanged(entity));
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
let scroll_viewer = ScrollViewer::new()
|
||||
.scroll_viewer_mode(("disabled", "auto"))
|
||||
.child(items_widget)
|
||||
.build(ctx);
|
||||
|
||||
// Child page: list available policy lists
|
||||
self.name("PolicyListView")
|
||||
.policy_list(PolicyList::default())
|
||||
.policy_list_count(0)
|
||||
.child(
|
||||
Grid::new()
|
||||
.rows(
|
||||
Rows::new()
|
||||
.add(52.0)
|
||||
.add(1.0)
|
||||
.add("*")
|
||||
.add(1.0)
|
||||
.add(40.0)
|
||||
.build(),
|
||||
)
|
||||
.columns(
|
||||
Columns::new()
|
||||
.add("*")
|
||||
.add(4.0)
|
||||
.add(36.0)
|
||||
.build(),
|
||||
)
|
||||
// Content
|
||||
.child(
|
||||
Container::new()
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.child(scroll_viewer)
|
||||
.child(
|
||||
ScrollIndicator::new()
|
||||
.padding((0.0, 4.0, 0.0, 0.0))
|
||||
.content_id(items_widget.0)
|
||||
.scroll_offset(scroll_viewer)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
// Top Bar
|
||||
.child(
|
||||
Container::new()
|
||||
.class(CLASS_TOP_BAR)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.child(
|
||||
Grid::new()
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.class(CLASS_HEADER)
|
||||
.v_align("center")
|
||||
.h_align("center")
|
||||
.text("Lists of policy data collections")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Container::new()
|
||||
.class("separator")
|
||||
.attach(Grid::row(1))
|
||||
.attach(Grid::column_span(3))
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Container::new()
|
||||
.class("separator")
|
||||
.attach(Grid::row(3))
|
||||
.attach(Grid::column_span(3))
|
||||
.build(ctx),
|
||||
)
|
||||
// Bottom bar
|
||||
.child(
|
||||
Container::new()
|
||||
.class(CLASS_BOTTOM_BAR)
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
// workaround, todo fix scroll viewer mouse behavior in OrbTk
|
||||
Button::new()
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.on_mouse_down(|_, _| true)
|
||||
.on_mouse_up(|_, _| true)
|
||||
.on_click(|_, _| true)
|
||||
.class(CLASS_TRANSPARENT)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(policy_list_text_box)
|
||||
.child(
|
||||
Button::new()
|
||||
.id(ID_POLICY_LIST_ADD_BUTTON)
|
||||
.class(CLASS_ICON_ONLY)
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(2))
|
||||
.margin((0.0, 0.0, 4.0, 0.0))
|
||||
.enabled(false)
|
||||
.min_size(32.0, 32.0)
|
||||
.v_align("center")
|
||||
.icon(material_icons_font_ttf::MD_ADD)
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.get_mut::<PolicyListState>(id)
|
||||
.action(Action::NewEntry(policy_list_text_box));
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
12
advotracker_client/src/widgets/ticketdata/mod.rs
Normal file
12
advotracker_client/src/widgets/ticketdata/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// The ticket data state
|
||||
pub mod ticketdata_state;
|
||||
|
||||
/// The tckicket data view
|
||||
pub mod ticketdata_view;
|
||||
235
advotracker_client/src/widgets/ticketdata/ticketdata_state.rs
Normal file
235
advotracker_client/src/widgets/ticketdata/ticketdata_state.rs
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
//use locales::t;
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use serde::Deserialize;
|
||||
//use std::process;
|
||||
//use std::collections::HashMap;
|
||||
use std::time::SystemTime;
|
||||
use tracing::{error, info, trace};
|
||||
|
||||
use crate::{
|
||||
data::{constants::*, structures::Email},
|
||||
widgets::global_state::GlobalState,
|
||||
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.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TicketdataAction {
|
||||
/// Clear text in the form
|
||||
ClearForm(String),
|
||||
ParseEntry(Entity),
|
||||
SendForm(),
|
||||
UpdatePolicyCode(String)
|
||||
|
||||
}
|
||||
|
||||
/// Define valid environment variables provided via .env files
|
||||
/// located in the current call directory.
|
||||
/// This is primarily used in testing scenarios (eg. debugging).
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Environment {
|
||||
test_lang: String,
|
||||
rust_log: String,
|
||||
}
|
||||
|
||||
/// Valid `structures` that are handled inside the state of the `Ticket` widget.
|
||||
#[derive(AsAny, Default)]
|
||||
pub struct TicketdataState {
|
||||
actions: Vec<TicketdataAction>,
|
||||
button_menu: Entity,
|
||||
lang: Lang,
|
||||
target: Entity
|
||||
}
|
||||
|
||||
impl GlobalState for TicketdataState {}
|
||||
|
||||
/// Method definitions, that react on any given state change inside the `Ticketdata` widget.
|
||||
impl TicketdataState {
|
||||
/// Clear the text property of all children of the given form entity
|
||||
pub fn clear_form(entity: Entity, id: &str, ctx: &mut Context<'_>) {
|
||||
// form is identified by its id
|
||||
if ctx.entity_of_child(id).is_some() {
|
||||
let form_entity = ctx.entity_of_child(ID_TICKET_DATA_FORM_GRID).unwrap();
|
||||
|
||||
let form_container: WidgetContainer<'_> = ctx.get_widget(form_entity);
|
||||
// BUG: Why does name defer from id, they are using the same constant?
|
||||
info!("Form id: {:?}", form_container.get::<String>("id"));
|
||||
info!("Form name: {:?}", form_container.get::<String>("name"));
|
||||
|
||||
//ctx.clear_children_of(form_entity); // complete form is cleared!
|
||||
|
||||
// switch into the context of the form_container
|
||||
ctx.change_into(form_entity);
|
||||
|
||||
if let Some(count) = ctx.widget().children_count() {
|
||||
for i in 0..count {
|
||||
if let Some(child) = &mut ctx.try_child_from_index(i) {
|
||||
let child_name: &str = child.get::<String>("name");
|
||||
info!("child({:?}) name: {:?}",
|
||||
i, child_name);
|
||||
let child_id: &str = child.get::<String>("id");
|
||||
info!("child({:?}) name: {:?}",
|
||||
i, child_id);
|
||||
|
||||
// TODO: check the orbtk type
|
||||
// if let child_type: bool = child.get::<String>("id") = std::any::type_name::<TextBox>().to_string() {
|
||||
match child_name {
|
||||
"TextBox" => TextBox::text_set(child, ""),
|
||||
"ticket_data_policy_code" => TextBox::text_set(child, ""),
|
||||
_ => info!("don't act on types other than 'TextBox'"),
|
||||
}
|
||||
|
||||
// match child_id {
|
||||
// "ticket_data_policy_code" => TextBox::text_set(child, ""),
|
||||
// "ticket_data_policy_holder" => TextBox::text_set(child, ""),
|
||||
// "ticket_data_policy_deductible" => TextBox::text_set(child, ""),
|
||||
// "ticket_data_policy_callback_number" => TextBox::text_set(child, ""),
|
||||
// "ticket_data_policy_callback_date" => TextBox::text_set(child, ""),
|
||||
// "ticket_data_policy_callback_harm_type" => TextBox::text_set(child, ""),
|
||||
// "ticket_data_policy_callback_ivr_comment" => TextBox::text_set(child, ""),
|
||||
// _ => info!("don't act on child_id '{:?}", child_id),
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// switch back to parent entity
|
||||
ctx.change_into(entity);
|
||||
|
||||
Stack::visibility_set(&mut ctx.child(ID_TICKET_DATA_ACTION_STACK), Visibility::Collapsed);
|
||||
Button::background_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#008000"));
|
||||
Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_SEND);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
let mail_to_item = TicketdataView::mail_to_ref(&ctx.widget())[mail_to_index].clone();
|
||||
info!("mail_to item[{:?}]: {:?}]", mail_to_index, mail_to_item);
|
||||
|
||||
// create Email structures
|
||||
let email = Email {
|
||||
mail_to: mail_to_item.to_string(),
|
||||
mail_cc: PROP_MAIL_CC_1.to_string(),
|
||||
mail_bcc: PROP_MAIL_BCC_1.to_string(),
|
||||
mail_from: PROP_MAIL_FROM.to_string(),
|
||||
mail_reply: PROP_MAIL_REPLY.to_string(),
|
||||
subject: PROP_MAIL_SUBJECT.to_string(),
|
||||
policy_code: ctx.child(ID_TICKET_DATA_POLICY_CODE).get::<String>("text").to_string(),
|
||||
policy_holder: ctx.child(ID_TICKET_DATA_POLICY_HOLDER).get::<String>("text").to_string(),
|
||||
deductible: ctx.child(ID_TICKET_DATA_DEDUCTIBLE).get::<String>("text").to_string(),
|
||||
callback_number: ctx.child(ID_TICKET_DATA_CALLBACK_NUMBER).get::<String>("text").to_string(),
|
||||
callback_date: ctx.child(ID_TICKET_DATA_CALLBACK_DATE).get::<String>("text").to_string(),
|
||||
harm_type: ctx.child(ID_TICKET_DATA_HARM_TYPE).get::<String>("text").to_string(),
|
||||
ivr_comment: ctx.child(ID_TICKET_DATA_IVR_COMMENT).get::<String>("text").to_string(),
|
||||
};
|
||||
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"));
|
||||
//Button::foreground_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#CC000000"));
|
||||
Button::background_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#CC000000"));
|
||||
Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_THUMB_DOWN);
|
||||
//Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_ERROR);
|
||||
} else {
|
||||
Button::icon_brush_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#FF0000"));
|
||||
//Button::foreground_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#FF0000"));
|
||||
Button::background_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), String::from("#FF0000"));
|
||||
Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_THUMB_UP);
|
||||
};
|
||||
}
|
||||
|
||||
pub fn update_policy_code(_entity: Entity, _id: &str, ctx: &mut Context<'_>) {
|
||||
Stack::visibility_set(&mut ctx.child(ID_TICKET_DATA_ACTION_STACK), Visibility::Visible);
|
||||
//self.actions.push(TicketdataAction::UpdatePolicyCode(entity));
|
||||
}
|
||||
}
|
||||
|
||||
/// Supported methods handled inside the `TicketState`
|
||||
impl State for TicketdataState {
|
||||
/// Initialize the state of widgets inside `TicketState`
|
||||
fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
||||
let time_start= SystemTime::now();
|
||||
|
||||
trace!(target: "advotracker", ticketdata_state = "init", status = "started");
|
||||
|
||||
// Initialize required menu button entity
|
||||
self.button_menu = ctx
|
||||
.entity_of_child(ID_TICKET_DATA_BUTTON_MENU)
|
||||
.expect("TicketState.init: Can't find resource entity 'ID_TICKET_DATA_BUTTON_MENU'.");
|
||||
|
||||
// initialize the entity object, that will receive messages
|
||||
self.target = Entity::from(ctx.widget().try_clone::<u32>("target")
|
||||
.expect("TicketState.init: Can't find resource entity 'target'."));
|
||||
|
||||
// Get language from environment
|
||||
//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);
|
||||
Button::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_SEND);
|
||||
|
||||
let time_end = SystemTime::now();
|
||||
let duration = time_end.duration_since(time_start);
|
||||
|
||||
trace!(target: "advotracker", ticketdata_state = "init", status = "finished", duration = ?duration);
|
||||
}
|
||||
|
||||
/// The reader component of the message system handing `TicketdataState``
|
||||
fn messages(
|
||||
&mut self,
|
||||
mut messages: MessageReader,
|
||||
_registry: &mut Registry,
|
||||
ctx: &mut Context<'_>,
|
||||
) {
|
||||
for message in messages.read::<TicketdataAction>() {
|
||||
match message {
|
||||
TicketdataAction::ClearForm(id) => {
|
||||
TicketdataState::clear_form(ctx.entity(), &id, ctx);
|
||||
}
|
||||
TicketdataAction::SendForm() => {
|
||||
TicketdataState::send_form(ctx.entity(), ctx, self.lang);
|
||||
}
|
||||
TicketdataAction::UpdatePolicyCode(id) => {
|
||||
TicketdataState::update_policy_code(ctx.entity(), &id, ctx);
|
||||
}
|
||||
_ => { println!("messages: action not implemented!"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
|
||||
let actions: Vec<TicketdataAction> = self.actions.drain(..).collect();
|
||||
|
||||
for action in actions {
|
||||
match action {
|
||||
TicketdataAction::ClearForm(ref id) => {
|
||||
ctx.send_message(TicketdataAction::ClearForm(id.to_string()), self.target);
|
||||
}
|
||||
// TicketdataAction::SendForm() => {
|
||||
// //ctx.send_message(TicketdataAction::SendForm(), self.ID_TICKETDATA_FORM);
|
||||
// info!("update: got send_message {:?}", action);
|
||||
// }
|
||||
_ => { println!("TicketdataAction: action not implemented!"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
480
advotracker_client/src/widgets/ticketdata/ticketdata_view.rs
Normal file
480
advotracker_client/src/widgets/ticketdata/ticketdata_view.rs
Normal file
@@ -0,0 +1,480 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
data::constants::*,
|
||||
widgets::ticketdata::ticketdata_state::{TicketdataAction, TicketdataState},
|
||||
};
|
||||
|
||||
// Used to define ComboBox list members
|
||||
type List = Vec<String>;
|
||||
|
||||
// Macro that initializes the widget structures/variables for the policy check view
|
||||
widget!(
|
||||
/// Form to enter data of a ticket record
|
||||
TicketdataView<TicketdataState> {
|
||||
// language used inside the widget
|
||||
lang: String,
|
||||
// mail recipients (mail_to) saved in a vector
|
||||
mail_to: List,
|
||||
// carbo copy recipients (mail_to) saved in a vector
|
||||
mail_cc: List,
|
||||
// active seleced index of combo box
|
||||
selected_index: i32,
|
||||
// title used in the header
|
||||
ticket_data_title: String,
|
||||
// entity id that will receive the messages
|
||||
target: u32
|
||||
}
|
||||
);
|
||||
|
||||
/// The template implementation of the ticket view
|
||||
/// All GUI elements are styled using the "style" attribute referencing to a ron based css
|
||||
impl Template for TicketdataView {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
// vector with valid strings of mail recipients addresses (mail_to)
|
||||
let mail_to = vec![
|
||||
PROP_MAIL_TO_1.to_string(),
|
||||
PROP_MAIL_TO_2.to_string(),
|
||||
PROP_MAIL_TO_3.to_string(),
|
||||
PROP_MAIL_TO_4.to_string(),
|
||||
PROP_MAIL_TO_5.to_string(),
|
||||
];
|
||||
let count_mail_to = mail_to.len();
|
||||
|
||||
// vector with valid carbon copy recipients addresses (mail_to)
|
||||
let mail_cc = vec![
|
||||
PROP_MAIL_CC_1.to_string(),
|
||||
PROP_MAIL_CC_2.to_string(),
|
||||
];
|
||||
let _count_mail_cc = mail_cc.len();
|
||||
|
||||
let tenent_logo = Container::new()
|
||||
.margin((16, 16, 0, 0))
|
||||
.attach(Grid::column(0))
|
||||
.v_align("center")
|
||||
.child(
|
||||
ImageWidget::new()
|
||||
.image("assets/advotracker/hiedemann_logo.png")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let ticket_data_bottom_bar = Container::new()
|
||||
.id(ID_TICKET_DATA_BOTTOM_BAR)
|
||||
.style(STYLE_BOTTOM_BAR)
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(1))
|
||||
.attach(Grid::column_span(2))
|
||||
.v_align("end")
|
||||
.child(
|
||||
Container::new()
|
||||
.attach(Grid::column(1))
|
||||
.h_align("end")
|
||||
.v_align("end")
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.margin((0, 9, 48, 0))
|
||||
.text("©Networkx GmbH")
|
||||
.build(ctx)
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let ticket_data_button_menu = Button::new()
|
||||
.id(ID_TICKET_DATA_BUTTON_MENU)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(2))
|
||||
.h_align("end")
|
||||
.icon(material_icons_font::MD_MENU)
|
||||
//.style("button_single_content")
|
||||
.style(STYLE_BUTTON_MENU)
|
||||
.on_click(move |_ctx, _| {
|
||||
println!("WIP: open menu popup from MenuView");
|
||||
// ctx.get_mut::<MenuState>(id)
|
||||
// .set_action(MenuAction::CreateMenu(ID_MENU_STACK));
|
||||
true
|
||||
})
|
||||
.build(ctx);
|
||||
|
||||
let ticket_data_form = Container::new()
|
||||
.id(ID_TICKET_DATA_FORM)
|
||||
.name(ID_TICKET_DATA_FORM)
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(1))
|
||||
.style("container_form")
|
||||
.child(
|
||||
Grid::new()
|
||||
.id(ID_TICKET_DATA_FORM_GRID)
|
||||
.name(ID_TICKET_DATA_FORM_GRID)
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push("auto") // Label
|
||||
.push(16) // Delimiter
|
||||
.push("*") // Data
|
||||
.push(32) // Delimiter (2x margin)
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
.push("auto") // Row 0
|
||||
.push(14) // Seperator
|
||||
.push("auto") // Row 2
|
||||
.push(14) // Seperator
|
||||
.push("auto") // Row 4
|
||||
.push(14) // Seperator
|
||||
.push("auto") // Row 6
|
||||
.push(14) // Seperator
|
||||
.push("auto") // Row 8
|
||||
.push(14) // Seperator
|
||||
.push("auto") // Row 10
|
||||
.push(14) // Seperator
|
||||
.push("auto") // Row 12
|
||||
.push(14) // Seperator
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_TICKET_DATA_LABEL_POLICY_CODE)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(0))
|
||||
.text("Policy code")
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_TICKET_DATA_POLICY_CODE)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(2))
|
||||
.text("")
|
||||
.v_align("center")
|
||||
.water_mark("ID, bzw. Nummer")
|
||||
.on_activate(move |states, _entity| {
|
||||
states.send_message(TicketdataAction::UpdatePolicyCode(ID_TICKET_DATA_POLICY_CODE.to_string()), id);
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_TICKET_DATA_LABEL_POLICY_HOLDER)
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(0))
|
||||
.text("Policy holder")
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_TICKET_DATA_POLICY_HOLDER)
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(2))
|
||||
.text("")
|
||||
.water_mark("Name des Versicherungsnehmers")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_TICKET_DATA_LABEL_DEDUCTIBLE)
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(0))
|
||||
.text("Deductible")
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_TICKET_DATA_DEDUCTIBLE)
|
||||
.attach(Grid::row(4))
|
||||
.attach(Grid::column(2))
|
||||
.text("")
|
||||
.water_mark("im Beratungsgespräch erfragen")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_TICKET_DATA_LABEL_CALLBACK_NUMBER)
|
||||
.attach(Grid::row(6))
|
||||
.attach(Grid::column(0))
|
||||
.text("Callback number")
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_TICKET_DATA_CALLBACK_NUMBER)
|
||||
.attach(Grid::row(6))
|
||||
.attach(Grid::column(2))
|
||||
.text("")
|
||||
.water_mark("wie zu erreichen")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_TICKET_DATA_LABEL_CALLBACK_DATE)
|
||||
.attach(Grid::row(8))
|
||||
.attach(Grid::column(0))
|
||||
.text("Callback date")
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_TICKET_DATA_CALLBACK_DATE)
|
||||
.attach(Grid::row(8))
|
||||
.attach(Grid::column(2))
|
||||
.text("")
|
||||
.water_mark("Rückruf gewünscht um")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_TICKET_DATA_LABEL_HARM_TYPE)
|
||||
.attach(Grid::row(10))
|
||||
.attach(Grid::column(0))
|
||||
.text("Harm type")
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_TICKET_DATA_HARM_TYPE)
|
||||
.name(ID_TICKET_DATA_HARM_TYPE)
|
||||
.attach(Grid::row(10))
|
||||
.attach(Grid::column(2))
|
||||
.text("")
|
||||
.water_mark("Schadenstyp")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_TICKET_DATA_LABEL_IVR_COMMENT)
|
||||
.attach(Grid::row(12))
|
||||
.attach(Grid::column(0))
|
||||
.text("IVR comment")
|
||||
.h_align("end")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.id(ID_TICKET_DATA_IVR_COMMENT)
|
||||
.attach(Grid::row(12))
|
||||
.attach(Grid::column(2))
|
||||
.text("")
|
||||
.water_mark("Kommentar zur Haftung, bzw. zur Deckung")
|
||||
//.height(48.0)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let ticket_data_form_action = Container::new()
|
||||
.id(ID_TICKET_DATA_ACTION_GRID)
|
||||
.attach(Grid::row(3))
|
||||
.attach(Grid::column(1))
|
||||
//.style(STYLE_CONTAINER_ACTION)
|
||||
.padding(14)
|
||||
.h_align("center")
|
||||
.child(
|
||||
Stack::new()
|
||||
.id(ID_TICKET_DATA_ACTION_STACK)
|
||||
//.style(STYLE_STACK_ACTION)
|
||||
.orientation("horizontal")
|
||||
.spacing(50)
|
||||
.child(
|
||||
Button::new()
|
||||
.id(ID_TICKET_DATA_ACTION_BUTTON_CLEAR)
|
||||
.style(STYLE_BUTTON_ACTION)
|
||||
.text("Clear")
|
||||
.on_click(move |states, _entity| {
|
||||
states.send_message(TicketdataAction::ClearForm(ID_TICKET_DATA_FORM_GRID.to_string()), id);
|
||||
false
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.id(ID_TICKET_DATA_ACTION_BUTTON_SEND)
|
||||
.style(STYLE_BUTTON_ACTION)
|
||||
.text("Send")
|
||||
.on_click(move |states, _entity| {
|
||||
states.send_message(TicketdataAction::SendForm(), id);
|
||||
false
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let ticket_data_form_mail = Container::new()
|
||||
.id(ID_TICKET_DATA_CONTAINER_MAIL)
|
||||
|
||||
.name(ID_TICKET_DATA_CONTAINER_MAIL)
|
||||
.attach(Grid::row(1))
|
||||
.attach(Grid::column(1))
|
||||
.style(STYLE_CONTAINER_MAIL)
|
||||
.child(
|
||||
|
||||
Grid::new()
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push(16) // Delimiter
|
||||
.push("stretch") // Label
|
||||
.push(16) // Delimiter
|
||||
.push("auto") // MailAddress
|
||||
.push("32") // Delimiter (2x margin)
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
.push("auto") // Row 0
|
||||
.push(2) // Seperator
|
||||
.push("auto") // Row 2
|
||||
.push(2) // Seperator
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_TICKET_DATA_LABEL_MAIL_TO)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(1))
|
||||
.style(STYLE_MAIL_LABEL)
|
||||
.text("Recipient (To)")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
ComboBox::new()
|
||||
.id(ID_TICKET_DATA_COMBO_BOX_MAIL_TO)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column(3))
|
||||
.style(STYLE_MAIL_TO)
|
||||
.count(count_mail_to)
|
||||
// create the items builder context (ibc) for the `mail_to` vector-items
|
||||
.selected_index(id)
|
||||
.items_builder(move |ibc, index| {
|
||||
let text = TicketdataView::mail_to_ref(&ibc.get_widget(id))[index].clone();
|
||||
TextBlock::new()
|
||||
.name(ID_TICKET_DATA_MAIL_TO)
|
||||
.v_align("center")
|
||||
.text(text)
|
||||
.build(ibc)
|
||||
})
|
||||
//.on_changed("selected_index", move |states, _entity| {
|
||||
// states.send_message(TicketdataAction::UpdateSelectedIndex(ID_TICKET_DATA_COMBO_BOX_MAIL_TO.to_string()), id);
|
||||
//})
|
||||
.build(ctx)
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_TICKET_DATA_LABEL_MAIL_CC)
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(1))
|
||||
.style(STYLE_MAIL_LABEL)
|
||||
.text("Copie (CC)")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_TICKET_DATA_COMBO_BOX_MAIL_CC)
|
||||
.attach(Grid::row(2))
|
||||
.attach(Grid::column(3))
|
||||
.name(ID_TICKET_DATA_MAIL_CC)
|
||||
.margin((12, 0, 0, 0))
|
||||
.text("service@hiedemann.de")
|
||||
.build(ctx)
|
||||
)
|
||||
// .child(
|
||||
// ComboBox::new()
|
||||
// .id(ID_TICKET_DATA_COMBO_BOX_MAIL_CC)
|
||||
// .attach(Grid::row(2))
|
||||
// .attach(Grid::column(3))
|
||||
// .style(STYLE_MAIL_CC)
|
||||
// .count(count_mail_cc)
|
||||
// // create the items builder context (ibc) for the `mail_cc` vector-items
|
||||
// .items_builder(move |ibc, index| {
|
||||
// // let text = ibc.get_widget(id)
|
||||
// // .get::<Vec<String>>("mail_cc")[index]
|
||||
// // .clone();
|
||||
// let text = TicketdataView::mail_cc_ref(&ibc.get_widget(id))[index].clone();
|
||||
// TextBlock::new()
|
||||
// .name(ID_TICKET_DATA_MAIL_CC)
|
||||
// .text(text)
|
||||
// .v_align("center")
|
||||
// .build(ibc)
|
||||
// })
|
||||
// .selected_index(id)
|
||||
// .on_changed("selected_index", move |states, _entity| {
|
||||
// states.send_message(TicketdataAction::UpdateSelectedIndex(ID_TICKET_DATA_COMBO_BOX_MAIL_CC.to_string()), id);
|
||||
// })
|
||||
// .build(ctx)
|
||||
// )
|
||||
.build(ctx)
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let ticket_data_header_text = TextBlock::new()
|
||||
.id(ID_TICKET_DATA_HEADER)
|
||||
.attach(Grid::column(0))
|
||||
.style(STYLE_HEADER_TEXT)
|
||||
.text("Ticket Data")
|
||||
.build(ctx);
|
||||
|
||||
let ticket_data_header_bar = Container::new()
|
||||
.id(ID_TICKET_DATA_HEADER_BAR)
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.style(STYLE_HEADER_BAR)
|
||||
.child(tenent_logo)
|
||||
.child(ticket_data_header_text)
|
||||
.child(ticket_data_button_menu)
|
||||
.build(ctx);
|
||||
|
||||
// Widget: Ticket data view
|
||||
self.id(ID_TICKET_DATA_VIEW)
|
||||
.name(ID_TICKET_DATA_VIEW)
|
||||
.mail_to(mail_to)
|
||||
.mail_cc(mail_cc)
|
||||
.selected_index(0)
|
||||
//.selected_index_mail_to(0)
|
||||
//.selected_index_mail_cc(0)
|
||||
.min_height(410.0)
|
||||
.child(
|
||||
Grid::new()
|
||||
.id(ID_TICKET_DATA_GRID)
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push(50) // Left margin
|
||||
.push("*") // Content
|
||||
.push(50) // Right margin
|
||||
)
|
||||
.rows(
|
||||
Rows::create()
|
||||
.push("auto") // Header_Bar
|
||||
.push("auto") // Mail_Form
|
||||
.push("*") // Input_Form
|
||||
.push("auto") // Action
|
||||
.push("auto") // Bottom_Bar
|
||||
)
|
||||
|
||||
.child(ticket_data_header_bar) // row 0
|
||||
.child(ticket_data_form_mail) // row 1
|
||||
.child(ticket_data_form) // row 2
|
||||
.child(ticket_data_form_action) // row 3
|
||||
.child(ticket_data_bottom_bar) // row 4
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user