update project structure
* assets: all resources are bundled in this subdirectory * widgets: use subdirs to group them by function the subdir hold their callbacks (state handling) and views * theming: update to new theming syntax * fonts: remove fonts that are provovided by default in OrbTK Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// global helper functions
|
||||
pub mod global_state;
|
||||
|
||||
/// policycheck helper functions
|
||||
pub mod policycheck_state;
|
||||
|
||||
// /// policylist helper functions
|
||||
// pub mod policylist_state;
|
||||
|
||||
// /// policydata helper functions
|
||||
// pub mod policydata_state;
|
||||
|
||||
/// policy verification methods
|
||||
pub mod policy_check;
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use chrono::{Local, DateTime};
|
||||
use locales::t;
|
||||
use std::collections::HashMap;
|
||||
use tracing::{info, trace};
|
||||
|
||||
use crate::data::structures::{PolicyCode, PolicyDataList};
|
||||
|
||||
/// validate a given policy number
|
||||
/// result will return true or false
|
||||
pub fn is_valid(policy_number: &usize, policy_list: &PolicyDataList,
|
||||
policy_numbers: &mut HashMap<usize, PolicyCode>, lang: &String)
|
||||
-> Result<bool, Box<dyn std::error::Error>> {
|
||||
|
||||
let mut res = t!("policy.validation.started", lang);
|
||||
let mut state = t!("state.started", lang);
|
||||
let dt_start: DateTime<Local> = Local::now();
|
||||
|
||||
trace!(target: "advotracker",
|
||||
process = ?res,
|
||||
state = ?state,
|
||||
policy_number = ?policy_number,
|
||||
policy_list = ?policy_list.name,
|
||||
elements = ?policy_list.policy_data.len(),
|
||||
date_start = ?dt_start.to_string());
|
||||
|
||||
let mut result = false;
|
||||
match policy_numbers.get(&policy_number) {
|
||||
Some(&policy_code) => {
|
||||
let res = t!("policy.validation.success", lang);
|
||||
info!("{} => {} ({:?})", res, policy_number, policy_code);
|
||||
result = true;
|
||||
trace!(target: "advotracker",
|
||||
policy_number = ?policy_number,
|
||||
validation = ?res,
|
||||
policy_code = ?policy_code);
|
||||
},
|
||||
_ => {
|
||||
let res = t!("policy.validation.failed", lang);
|
||||
info!("{} => {}", res, policy_number);
|
||||
trace!(target: "advotracker",
|
||||
policy_number = ?policy_number,
|
||||
validation = ?res);
|
||||
},
|
||||
}
|
||||
|
||||
let dt_end: DateTime<Local> = Local::now();
|
||||
let duration = dt_end.signed_duration_since(dt_start);
|
||||
|
||||
res = t!("policy.validation.finished", lang);
|
||||
state = t!("state.finished", lang);
|
||||
trace!(target: "advotracker",
|
||||
process = ?res,
|
||||
state = ?state,
|
||||
date_stop = ?dt_end.to_string(),
|
||||
duration = ?duration);
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
@@ -26,13 +26,10 @@
|
||||
// /// The client specific services
|
||||
// pub mod clients;
|
||||
|
||||
/// provides helper functions to manage orbtk callbacks
|
||||
pub mod callbacks;
|
||||
|
||||
/// provides data definitions
|
||||
pub mod data;
|
||||
|
||||
/// provides orbtk widget structures
|
||||
/// provides orbtk widgets (handling views and states)
|
||||
pub mod widgets;
|
||||
|
||||
/// provides services
|
||||
|
||||
@@ -129,7 +129,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.build();
|
||||
|
||||
Application::from_name("nwx.advotracker")
|
||||
.theme(PolicyCheckState::theme())
|
||||
.localization(localization)
|
||||
.window(|ctx| {
|
||||
Window::new()
|
||||
|
||||
@@ -9,7 +9,7 @@ use orbtk::prelude::*;
|
||||
|
||||
use crate::{
|
||||
data::structures::PolicyCheck,
|
||||
widgets::policycheck_view::PolicyCheckView,
|
||||
widgets::policycheck::policycheck_view::PolicyCheckView,
|
||||
};
|
||||
|
||||
type List = Vec<String>;
|
||||
|
||||
@@ -5,11 +5,17 @@
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
/// global helper functions
|
||||
pub mod global_state;
|
||||
|
||||
/// The starting point (Main View)
|
||||
pub mod main_view;
|
||||
|
||||
/// The policy check wigdet
|
||||
pub mod policycheck_view;
|
||||
pub mod policycheck;
|
||||
|
||||
// /// The policy data widget
|
||||
// pub mod policydata;
|
||||
|
||||
// /// The policy lists widget
|
||||
// pub mod policylist_view;
|
||||
// pub mod policylist;
|
||||
|
||||
12
advotracker/src/widgets/policycheck/mod.rs
Normal file
12
advotracker/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;
|
||||
@@ -1,16 +1,5 @@
|
||||
use locales::t;
|
||||
use orbtk::{
|
||||
prelude::*,
|
||||
shell::WindowRequest,
|
||||
theme::{COLORS_RON, FONTS_RON},
|
||||
theming::config::ThemeConfig,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "light"))]
|
||||
use orbtk::theme::DARK_THEME_RON;
|
||||
|
||||
#[cfg(feature = "light")]
|
||||
use orbtk::theme::LIGHT_THEME_RON;
|
||||
use orbtk::prelude::*;
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::process;
|
||||
@@ -19,7 +8,7 @@ use std::time::{Duration, SystemTime};
|
||||
use tracing::{error, info, trace};
|
||||
|
||||
use crate::{
|
||||
callbacks::global_state::GlobalState,
|
||||
widgets::global_state::GlobalState,
|
||||
data::structures::{PolicyCode, PolicyDataList, PolicyList},
|
||||
data::constants::*,
|
||||
services::imports::allianzdirectcall::import,
|
||||
@@ -39,6 +28,7 @@ pub enum Action {
|
||||
SetProgress(f64),
|
||||
SetProgressPopup(Entity),
|
||||
RemoveFocus(Entity),
|
||||
RemoveMenu(Entity),
|
||||
RemovePopup(Entity),
|
||||
SetEntry(Entity),
|
||||
SetVisibility(Entity),
|
||||
@@ -73,12 +63,6 @@ pub struct PolicyCheckState {
|
||||
theme_name: String
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "light"))]
|
||||
static DARK_EXT: &'static str = include_str!("../../resources/stylesheets/advotracker_dark.ron");
|
||||
|
||||
#[cfg(feature = "light")]
|
||||
static LIGHT_EXT: &'static str = include_str!("../../resources/stylesheets/advotracker_light.ron");
|
||||
|
||||
impl GlobalState for PolicyCheckState {}
|
||||
|
||||
/// method definitions, that react on any given state change inside the view
|
||||
@@ -142,11 +126,11 @@ impl PolicyCheckState {
|
||||
|
||||
if self.policy_numbers.len() == 0 {
|
||||
// initialize popup widget
|
||||
let sender = ctx.window_sender();
|
||||
//let sender = ctx.send_window_request();
|
||||
self.set_popup_progress(ctx);
|
||||
self.progress_count += 0.33;
|
||||
self.update_progress_bar(ctx);
|
||||
sender.send(WindowRequest::Redraw).unwrap();
|
||||
//sender.send(WindowRequest::Redraw).unwrap();
|
||||
|
||||
// for _ in 1..4 {
|
||||
// self.progress_count += 0.33;
|
||||
@@ -166,7 +150,7 @@ impl PolicyCheckState {
|
||||
self.progress_count = 1.;
|
||||
self.update_progress_bar(ctx);
|
||||
|
||||
sender.send(WindowRequest::Redraw).unwrap();
|
||||
//sender.send(WindowRequest::Redraw).unwrap();
|
||||
}
|
||||
_ => {
|
||||
let res = t!("policy.hashmap.failed", self.lang);
|
||||
@@ -332,8 +316,13 @@ impl PolicyCheckState {
|
||||
}
|
||||
|
||||
/// Remove the menu popup box
|
||||
fn remove_popup(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
||||
fn remove_menu(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
||||
ctx.remove_child(self.menu);
|
||||
println!("Popup {:?} removed !", id);
|
||||
}
|
||||
|
||||
/// Remove the menu popup box
|
||||
fn remove_popup(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
||||
ctx.remove_child(self.progress_popup);
|
||||
println!("Popup {:?} removed !", id);
|
||||
}
|
||||
@@ -364,13 +353,21 @@ impl PolicyCheckState {
|
||||
|
||||
/// Set a menu
|
||||
fn set_menu(&mut self, ctx: &mut Context<'_>) {
|
||||
let current_entity = ctx.entity;
|
||||
let stack = ctx
|
||||
.entity_of_child(ID_POLICY_CHECK_BUTTON_MENU)
|
||||
.expect("PolicyCheckState: Can't find entity of resource 'ID_POLICY_CHECK_BUTTON_MENU'.");
|
||||
let current_entity = ctx.entity();
|
||||
let build_context = &mut ctx.build_context();
|
||||
|
||||
// create a menu overlay
|
||||
self.menu = create_menu(current_entity, build_context);
|
||||
let _menu = build_context.append_child_to_overlay(self.menu)
|
||||
.expect("PolicyCheckState: Can't create overlay as child of entity");
|
||||
|
||||
// create a menu_popup widget as a child of entity "ID_POLICY_CHECK_POLICY_NUMBER"
|
||||
build_context.append_child(stack, self.menu);
|
||||
//.expect("PolicyCheckState: Can't find entity of resource 'ID_POLICY_CHECK_MENU'");
|
||||
//.expect("PolicyCheckState: Can't create overlay as child of entity");
|
||||
|
||||
println!("Popup Menu created: {:?}", self.menu);
|
||||
}
|
||||
|
||||
/// Set a progress popup that updates the import status in a progress bar
|
||||
@@ -379,7 +376,7 @@ impl PolicyCheckState {
|
||||
let stack = ctx
|
||||
.entity_of_child(ID_POLICY_CHECK_RESULT)
|
||||
.expect("PolicyCheckState: Can't find entity of resource 'ID_POLICY_CHECK_RESULT'.");
|
||||
let current_entity = ctx.entity;
|
||||
let current_entity = ctx.entity();
|
||||
let build_context = &mut ctx.build_context();
|
||||
|
||||
self.progress_popup = create_popup_progress(current_entity, build_context);
|
||||
@@ -407,29 +404,6 @@ impl PolicyCheckState {
|
||||
//ctx.get_widget(self.label_result).update_theme_by_state(true);
|
||||
}
|
||||
|
||||
|
||||
/// Set and activate the theme attributes.
|
||||
#[cfg(not(feature = "light"))]
|
||||
pub fn theme() -> Theme {
|
||||
Theme::from_config(
|
||||
// sourcing: crates/theme/assets/dark/dark.ron
|
||||
ThemeConfig::from(DARK_THEME_RON)
|
||||
.extend(ThemeConfig::from(DARK_EXT))
|
||||
.extend(ThemeConfig::from(COLORS_RON))
|
||||
.extend(ThemeConfig::from(FONTS_RON)),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "light")]
|
||||
pub fn theme() -> Theme {
|
||||
Theme::from_config(
|
||||
ThemeConfig::from(LIGHT_THEME_RON)
|
||||
.extend(ThemeConfig::from(LIGHT_EXT))
|
||||
.extend(ThemeConfig::from(COLORS_RON))
|
||||
.extend(ThemeConfig::from(FONTS_RON)),
|
||||
)
|
||||
}
|
||||
|
||||
/// 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();
|
||||
@@ -543,7 +517,10 @@ impl State for PolicyCheckState {
|
||||
}
|
||||
Action::RemoveFocus(policy_check_policy_number) => {
|
||||
ctx.get_widget(policy_check_policy_number).set("enabled", false);
|
||||
ctx.push_event_by_window(FocusEvent::RemoveFocus(policy_check_policy_number));
|
||||
//ctx.EventAdapter(FocusEvent::RemoveFocus(policy_check_policy_number));
|
||||
}
|
||||
Action::RemoveMenu(entity) => {
|
||||
self.remove_menu(entity, ctx);
|
||||
}
|
||||
Action::RemovePopup(entity) => {
|
||||
self.remove_popup(entity, ctx);
|
||||
@@ -574,18 +551,6 @@ impl State for PolicyCheckState {
|
||||
self.set_entry(entity, ctx);
|
||||
}
|
||||
Action::ToggleTheme(_entity) => {
|
||||
if self.theme_name == "light" {
|
||||
let theme = dark_theme();
|
||||
self.theme_name = "dark".to_string();
|
||||
ctx.switch_theme(theme);
|
||||
}
|
||||
|
||||
if self.theme_name == "dark" {
|
||||
let theme = light_theme();
|
||||
self.theme_name = "light".to_string();
|
||||
ctx.switch_theme(theme);
|
||||
};
|
||||
|
||||
println!{"Switch theme to {:?}", self.theme_name};
|
||||
}
|
||||
}
|
||||
@@ -602,11 +567,19 @@ impl State for PolicyCheckState {
|
||||
|
||||
/// Create a menu popup
|
||||
fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
Container::new()
|
||||
Popup::new()
|
||||
.id(ID_POLICY_CHECK_POPUP_MENU)
|
||||
.style("container_menu")
|
||||
.width(280.0)
|
||||
.height(140.0)
|
||||
.position((100.0, 100.0))
|
||||
.target(menu)
|
||||
.open(true)
|
||||
.width(280)
|
||||
.height(140)
|
||||
.on_mouse_down(move |ctx, _| {
|
||||
println!("on_click -> remove_menu()");
|
||||
ctx.get_mut::<PolicyCheckState>(menu)
|
||||
.action(Action::RemoveMenu(menu));
|
||||
true
|
||||
})
|
||||
.child(
|
||||
Grid::new()
|
||||
.id(ID_POLICY_CHECK_MENU)
|
||||
@@ -10,7 +10,7 @@ use orbtk::prelude::*;
|
||||
use crate::{
|
||||
data::constants::*,
|
||||
data::structures::PolicyCheck,
|
||||
callbacks::policycheck_state::*,
|
||||
widgets::policycheck::policycheck_state::*,
|
||||
};
|
||||
|
||||
// Macro that initializes the widget structures/variables for our view
|
||||
@@ -43,7 +43,7 @@ impl Template for PolicyCheckView {
|
||||
.v_align("center")
|
||||
.child(
|
||||
ImageWidget::new()
|
||||
.image("resources/advotracker/hiedemann_logo.png")
|
||||
.image("assets/advotracker/hiedemann_logo.png")
|
||||
.v_align("center")
|
||||
.build(ctx),
|
||||
)
|
||||
12
advotracker/src/widgets/policydata/mod.rs
Normal file
12
advotracker/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;
|
||||
12
advotracker/src/widgets/policylist/mod.rs
Normal file
12
advotracker/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;
|
||||
Reference in New Issue
Block a user