frontend: function update

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2020-06-27 22:30:50 +02:00
parent 22ecaaa0fe
commit 267c4faa2c
11 changed files with 972 additions and 691 deletions

View File

@@ -16,8 +16,8 @@ pub trait BaseState {
ctx.get_widget(to).set("visibility", Visibility::Visible); ctx.get_widget(to).set("visibility", Visibility::Visible);
} }
/// Fetches the text of a widget. /// Get the text of a widget.
fn fetch_text(&self, ctx: &mut Context, entity: Entity) -> Option<String> { fn get_text(&self, ctx: &mut Context, entity: Entity) -> Option<String> {
let mut widget = ctx.get_widget(entity); let mut widget = ctx.get_widget(entity);
let entry = widget.get_mut::<String>("text"); let entry = widget.get_mut::<String>("text");
@@ -35,8 +35,8 @@ pub trait BaseState {
registry registry
.get::<Settings>("settings") .get::<Settings>("settings")
.save( .save(
PROP_POLICY_LISTS, PROP_POLICY_LIST,
ctx.widget().get::<PolicyList>(PROP_POLICY_LISTS), ctx.widget().get::<PolicyList>(PROP_POLICY_LIST),
) )
.unwrap(); .unwrap();
} }

View File

@@ -3,8 +3,85 @@ use orbtk::prelude::*;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// An enumeration of valid policy codes
/// right now, only "AS" is used
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum PolicyCode {
AS
}
impl Default for PolicyCode {
fn default() -> Self { PolicyCode::AS }
}
/// Status of a given policy data element (eg: active / inactive)
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum Status {
Active,
Inactive
}
impl Default for Status {
fn default() -> Self { Status::Active }
}
/// A communication type describes possible classifications of customer calls.
/// If not selected, the default will be 'unclassified'.
#[derive(Default, Debug, Clone, Deserialize, Serialize)] #[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct HarmElement { pub struct CommunicationType {
// Unfall, Bußgeldbescheid, Anhörung, Unfallflucht, Kaufvertrag,
// Vodafone, Kündigung, Lohn, Zeugnis, Nachbar, Vermieter, Rente, GdB, Verwaltungsrecht, Unterhalt, Geburt, Hochzeit
pub communication_id: String,
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 {
// policy_code => Versicherungsscheinnummer: "AS1234567890"
// policy_holder => Anrufer: "Vorname, Nachname"
// facts => Sachverhalt: "Kurzschilderung"
// harm_type => Schadensart: "harm_name (harm_id)"
// communication_type => Kommunikationszeichen: "(communication_name)"
// ra_hotline => RA_Hotline: Kanzlei Laqua, Kanzlei Buschbell, Kanzlei DAH, Kanzlei Hiedemann
// ivr_comment => Haftungs-/Deckungskommentar; #IVR (ggf. ergänzt um das Beratungsergebnis)
pub policy_code: String,
pub policy_number: u32,
pub policy_holder: String,
pub facts: String,
pub harm_type: String,
pub communication_name: String,
pub ra_hotline: String, // const "Kanzlei Hiedemann",
pub ivr_comment: String,
}
/// CSV Import
/// The structure elements provided as a comma seperated text list.
/// Referenz: ERG.txt -> 'DION VERS POLLFNR'
/// '1 AS 1515735810'
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct CsvImportRecord {
// dion => Allianz Dion: 1
// policy_code => Policy Typ: "AS"
// policy_number => Versicherungsscheinnummer: "1515735810"
pub dion: String,
pub policy_code: String,
pub policy_number: u32,
}
/// 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 {
pub harm_data: Vec<HarmType>,
//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 {
// Schadenersatz-RS im Verkehrsbereich (RS112) // Schadenersatz-RS im Verkehrsbereich (RS112)
// Ordnungswidrigkeits-RS im Verkehrsbereich (RS122) // Ordnungswidrigkeits-RS im Verkehrsbereich (RS122)
// Straf-RS im Verkehrsbereich (RS121) // Straf-RS im Verkehrsbereich (RS121)
@@ -15,70 +92,50 @@ pub struct HarmElement {
// Sozialgerichts-RS im Privatbereich (RS216) // Sozialgerichts-RS im Privatbereich (RS216)
// Rechtsschutz im Familien- und Erbrecht (RS217) // Rechtsschutz im Familien- und Erbrecht (RS217)
// Wagnis nicht versicherbar / versichert (RS999) // Wagnis nicht versicherbar / versichert (RS999)
pub harm_id: String,
pub harm_name: String,
}
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct HarmType {
pub harm_type: Vec<HarmElement>,
pub name: String,
pub selected: bool
}
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct CommunicationType {
// Unfall, Bußgeldbescheid, Anhörung, Unfallflucht, Kaufvertrag,
// Vodafone, Kündigung, Lohn, Zeugnis, Nachbar, Vermieter, Rente, GdB, Verwaltungsrecht, Unterhalt, Geburt, Hochzeit
pub communication_id: String,
pub communication_name: String,
}
/// CSV Export
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct CSVExport {
// policy_code => Versicherungsscheinnummer: "AS1234567890"
// policy_holder => Anrufer: "Vorname, Nachname"
// facts => Sachverhalt: "Kurzschilderung"
// harm_type => Schadensart: "harm_name (harm_id)"
// communication_type => Kommunikationszeichen: "(communication_name)"
// ra_hotline => RA_Hotline: Kanzlei Laqua, Kanzlei Buschbell, Kanzlei DAH, Kanzlei Hiedemann
// ivr_comment => Haftungs-/Deckungskommentar; #IVR (ggf. ergänzt um das Beratungsergebnis)
pub policy_id: String,
pub policy_number: u32,
pub policy_holder: String,
pub facts: String,
pub harm_type: String, pub harm_type: String,
pub communication_name: String, pub harm_name: String,
pub ra_hotline: String, // const "Kanzlei Hiedemann",
pub ivr_comment: String,
} }
/// Structure used to verify a policy data element. /// Structure used to verify a policy data element.
#[derive(Default, Debug, Clone, Deserialize, Serialize)] #[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct PolicyCheck { pub struct PolicyCheck {
pub policy_id: String, pub policy_check_number: String,
pub policy_number: String, pub policy_number: String,
pub isvalid: bool pub policy_number_valid: bool
} }
// #[derive(Default, Clone, Debug, Serialize, Deserialize)]
// pub struct PolicyCheckList {
// pub title: String,
// pub list: Vec<PolicyCheck>
// }
// impl PolicyCheckList {
// pub fn new(title: impl Into<String>) -> Self {
// PolicyCheckList {
// title: title.into(),
// ..Default::default()
// }
// }
/// Structure collecting policy data elements
#[derive(Default, Clone, Debug, Serialize, Deserialize)] #[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct PolicyList { pub struct PolicyList {
pub policy_list: Vec<PolicyData>, pub name: String,
pub policy_list: Vec<PolicyDataList>,
} }
/// implements helper methods, that manage lists of policy data collections /// implements helper methods, that manage lists of policy data collections
impl PolicyList { impl PolicyList {
pub fn get(&self, index: usize) -> Option<&PolicyData> { pub fn get(&self, index: usize) -> Option<&PolicyDataList> {
self.policy_list.get(index) self.policy_list.get(index)
} }
pub fn get_mut(&mut self, index: usize) -> Option<&mut PolicyData> { pub fn get_mut(&mut self, index: usize) -> Option<&mut PolicyDataList> {
self.policy_list.get_mut(index) self.policy_list.get_mut(index)
} }
pub fn insert_front(&mut self, policy_list: PolicyData) { pub fn insert_front(&mut self, policy_list: PolicyDataList) {
self.policy_list.insert(0, policy_list); self.policy_list.insert(0, policy_list);
} }
@@ -90,50 +147,51 @@ impl PolicyList {
self.policy_list.len() self.policy_list.len()
} }
pub fn push(&mut self, policy_list: PolicyData) { pub fn new(name: impl Into<String>) -> Self {
PolicyList {
name: name.into(),
..Default::default()
}
}
pub fn push(&mut self, policy_list: PolicyDataList) {
self.policy_list.push(policy_list); self.policy_list.push(policy_list);
} }
pub fn remove(&mut self, index: usize) -> PolicyData {
pub fn remove(&mut self, index: usize) -> PolicyDataList {
self.policy_list.remove(index) self.policy_list.remove(index)
} }
} }
// Valid policy codes are represented in this Enumeration /// Structure representing a policy data element
// right now, only "AS" is used
//enum PolicyCode {
// CodeName(String),
//}
/// Structure representing a policy data element.
#[derive(Default, Debug, Clone, Deserialize, Serialize)] #[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct PolicyElement { pub struct PolicyData {
// DION VERS POLLFNR // DION VERS POLLFNR
// 1 AS 1515735810 // 1 AS 1515735810
// DION: Allianz id => len = 1?? // DION: Allianz id => len = 1??
// VERS: policy_code => enum(AS; ??) // VERS: policy_code => enum(AS; ??)
// POLLFNR: policy_number => len = 10 // POLLFNR: policy_number => len = 10
pub date_inserted: Option<NaiveDateTime>,
pub dion: u8, pub dion: u8,
// is String16 a better default-type? // is String16 a better default-type?
pub policy_code: String, pub policy_code: PolicyCode,
pub policy_number: u32, pub policy_number: u32,
pub date_inserted: Option<NaiveDateTime>, pub status: Status
pub isactive: bool
} }
/// Structure grouping valid policy data elements /// Structure collects policy data elements.
#[derive(Default, Debug, Clone, Deserialize, Serialize)] #[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct PolicyData { pub struct PolicyDataList {
pub date_valid_until: Option<NaiveDateTime>, pub date_valid_until: Option<NaiveDateTime>,
pub policy_elements: Vec<PolicyElement>, pub policy_data: Vec<PolicyData>,
pub name: String, pub name: String,
pub selected: bool pub selected: bool
} }
/// implements the helper methods, to manage policy data collections. /// implements the helper methods, to manage policy data collections.
impl PolicyData { impl PolicyDataList {
pub fn new(name: impl Into<String>) -> Self { pub fn new(name: impl Into<String>) -> Self {
// the new inserted element will be active by default // the new inserted element will be active by default
PolicyData { PolicyDataList {
date_valid_until: None, date_valid_until: None,
name: name.into(), name: name.into(),
selected: true, selected: true,
@@ -141,32 +199,32 @@ impl PolicyData {
} }
} }
pub fn push(&mut self, policy_element: PolicyElement) { pub fn push(&mut self, policy_data: PolicyData) {
self.policy_elements.push(policy_element); self.policy_data.push(policy_data);
} }
pub fn insert_front(&mut self, policy_element: PolicyElement) { pub fn insert_front(&mut self, policy_data: PolicyData) {
self.policy_elements.insert(0, policy_element); self.policy_data.insert(0, policy_data);
} }
pub fn remove(&mut self, index: usize) -> PolicyElement { pub fn remove(&mut self, index: usize) -> PolicyData {
self.policy_elements.remove(index) self.policy_data.remove(index)
} }
pub fn get(&self, index: usize) -> Option<&PolicyElement> { pub fn get(&self, index: usize) -> Option<&PolicyData> {
self.policy_elements.get(index) self.policy_data.get(index)
} }
pub fn get_mut(&mut self, index: usize) -> Option<&mut PolicyElement> { pub fn get_mut(&mut self, index: usize) -> Option<&mut PolicyData> {
self.policy_elements.get_mut(index) self.policy_data.get_mut(index)
} }
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.policy_elements.len() self.policy_data.len()
} }
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.policy_elements.is_empty() self.policy_data.is_empty()
} }
} }

View File

@@ -14,28 +14,38 @@ pub static CLASS_TOP_BAR: &str = "top_bar";
pub static CLASS_TRANSPARENT: &str = "transparent"; pub static CLASS_TRANSPARENT: &str = "transparent";
pub static CLASS_SEPERATOR: &str = "seperator"; pub static CLASS_SEPERATOR: &str = "seperator";
// DCES: Entity[id] => [Component1, .. , Component<n>] -> data or state // Widget IDs (DCES: Entity[id] => [Component1, .. , Component<n>] -> data or state)
pub static ID_POLICY_CHECK_FORM: &str = "policy_check_form"; 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: &str = "policy_check_header";
//pub static ID_POLICY_CHECK_ITEMS_WIDGET: &str = "policy_check_items_widget";
pub static ID_POLICY_CHECK_LABEL_POLICY_NUMBER: &str = "policy_check_label_policy_number"; 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_LABEL_RESULT: &str = "policy_check_label_result";
pub static ID_POLICY_CHECK_MENU_BUTTON: &str = "policy_check_menu_button"; pub static ID_POLICY_CHECK_MENU_BUTTON: &str = "policy_check_menu_button";
pub static ID_POLICY_CHECK_MENU_CONTAINER: &str = "policy_check_menu_container"; pub static ID_POLICY_CHECK_MENU_TEXT_BLOCK: &str = "policy_check_menu_text_block";
pub static ID_POLICY_CHECK_RESULT: &str = "policy_check_result"; pub static ID_POLICY_CHECK_RESULT: &str = "policy_check_result";
pub static ID_POLICY_CHECK_POLICY_NUMBER: &str = "policy_check_policy_number"; pub static ID_POLICY_CHECK_POLICY_NUMBER: &str = "policy_check_policy_number";
pub static ID_POLICY_CHECK_WIDGET: &str = "policy_check_widget"; 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_ADD_BUTTON: &str = "policy_data_add_button";
pub static ID_POLICY_DATA_ITEMS_WIDGET: &str = "policy_data_items_widget"; pub static ID_POLICY_DATA_ITEMS_WIDGET: &str = "policy_data_items_widget";
pub static ID_POLICY_DATA_TEXT_BOX: &str = "policy_data_text_box"; //pub static ID_POLICY_DATA_TEXT_BOX: &str = "policy_data_text_box";
pub static ID_POLICY_LISTS_ADD_BUTTON: &str = "policy_lists_add_button"; pub static ID_POLICY_DATA_DATE_INSERTED: &str = "policy_data_date_inserted";
pub static ID_POLICY_LISTS_ITEMS_WIDGET: &str = "policy_lists_items_widget"; pub static ID_POLICY_DATA_DION: &str = "policy_data_dion";
pub static ID_POLICY_LISTS_TEXT_BOX: &str = "policy_list_text_box"; 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_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";
// Component Values (Properties) // Component Values (Properties)
pub static PROP_POLICY_CHECK: &str = "policy_check"; pub static PROP_POLICY_CHECK: &str = "policy_check";
pub static PROP_POLICY_CODE: &str = "policy_code"; pub static PROP_POLICY_CHECK_LIST: &str = "policy_check_list";
pub static PROP_POLICY_ELEMENT: &str = "policy_element";
pub static PROP_POLICY_LISTS: &str = "policy_lists"; pub static PROP_POLICY_DATA_LIST: &str = "policy_data_list";
pub static PROP_POLICY_DATA: &str = "policy_data";
pub static PROP_POLICY_LISTS_COUNT: &str = "policy_lists_count";
pub static PROP_POLICY_DATA_COUNT: &str = "policy_data_count"; 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";

View File

@@ -19,6 +19,10 @@ pub mod policycheck_menu;
pub mod policylist_view; pub mod policylist_view;
pub mod policylist_state; pub mod policylist_state;
// manage policy data elements
pub mod policydata_view;
pub mod policydata_state;
//#[cfg(feature = "light-theme")] //#[cfg(feature = "light-theme")]
static STYLESHEET: &'static str = include_str!("../resources/stylesheets/advotracker.css"); static STYLESHEET: &'static str = include_str!("../resources/stylesheets/advotracker.css");

View File

@@ -1,41 +1,59 @@
use orbtk::prelude::*; use orbtk::prelude::*;
use crate::policycheck_view::PolicyCheckView; use crate::{
//data::PolicyList, data::{PolicyCheck, PolicyList, PolicyDataList},
//policylist_view::PolicyListView, policycheck_view::PolicyCheckView,
//policy_view::PolicyDataView policylist_view::PolicyListView,
policydata_view::PolicyDataView
};
// use crate::{
// data::{PolicyList, PolicyData},
// //policycheck_view::*,
// //PolicyCheckView,
// //policylist_view::*,
// //PolicyListView,
// //policydata_view::*,
// //PolicyDataList
// };
widget!(MainView { widget!(MainView {
policy_list_count: usize, policy_list_count: usize,
policy_list: PolicyList,
policy_data_list: PolicyDataList,
policycheck_view: u32,
policylist_view: u32, policylist_view: u32,
policy_view: u32 policydata_view: u32
}); });
impl Template for MainView { impl Template for MainView {
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
let policycheck_view = PolicyCheckView::new() let policycheck_view = PolicyCheckView::new()
//.policylist_view(id)
//.policylist_count(id)
.build(ctx);
/* let policylist_view = PolicyList::new()
.back_entity(policycheck_view.0)
.policydata_view(id)
.policy_list_count(id)
.policylist_view(id) .policylist_view(id)
.build(ctx); .build(ctx);
*/
/* let policylist_view = PolicyListView::new()
let policydata_view = TaskView::new() .back_entity(policycheck_view.0)
.back_entity(policy_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) .policylist_view(id)
.visibility("collapsed") .visibility("collapsed")
.build(ctx); .build(ctx);
*/
self.name("MainView") self.name("MainView")
//.policy_list(policy_list.0) .policy_list_count(0)
//.policylist_view(PolicyList:default()) .policycheck_view(PolicyCheck::default())
//.policy_list_count(0) //.policycheck_view(0)
.policydata_view(policydata_view.0)
//.policylist_view(PolicyList::default())
.policylist_view(policylist_view.0)
.child(policydata_view)
.child(policylist_view)
.child(policycheck_view) .child(policycheck_view)
} }
} }

View File

@@ -2,7 +2,7 @@ use orbtk::prelude::*;
use crate::{ use crate::{
base_state::BaseState, base_state::BaseState,
//data::{PolicyData, PolicyList}, data::{PolicyData, PolicyDataList},
keys::*, keys::*,
}; };
@@ -11,13 +11,14 @@ use crate::{
pub enum Action { pub enum Action {
ClearEntry(Entity), ClearEntry(Entity),
InputTextChanged(Entity), InputTextChanged(Entity),
OpenMenu(Entity),
ParseEntry(Entity), ParseEntry(Entity),
RemoveFocus(Entity), RemoveFocus(Entity),
SetEntry(Entity), SetEntry(Entity),
TextChanged(Entity, usize), TextChanged(Entity, usize),
} }
/// Handles the requests of the `OverviewView`. /// Handles the requests of the `PolicyCheckView`.
#[derive(Default, AsAny)] #[derive(Default, AsAny)]
pub struct PolicyCheckState { pub struct PolicyCheckState {
action:Option<Action>, action:Option<Action>,
@@ -42,9 +43,13 @@ impl PolicyCheckState {
println!("reset {}", text); println!("reset {}", text);
} }
/// Open menu.
pub fn open_menu(&mut self, text_block: Entity, ctx: &mut Context) {
let mut text_block = TextBlock::get(ctx.get_widget(text_block));
let text = text_block.text_mut();
println!("Menu text: {}", text);
}
/// Parse and verify given policy code to match a valid policy data element.
//fn parse_entry(&self, text_box: Entity, ctx: &mut Context) -> Result<(), Box<dyn std::error::Error>> {
fn parse_entry(&self, text_box: Entity, ctx: &mut Context) { fn parse_entry(&self, text_box: Entity, ctx: &mut Context) {
// Old style // Old style
//let length = ctx.get_widget(text_box).get::<String>("policy_number").len(); //let length = ctx.get_widget(text_box).get::<String>("policy_number").len();
@@ -125,10 +130,10 @@ impl State for PolicyCheckState {
fn init(&mut self, _: &mut Registry, ctx: &mut Context) { fn init(&mut self, _: &mut Registry, ctx: &mut Context) {
self.menu_button = ctx self.menu_button = ctx
.entity_of_child(ID_POLICY_CHECK_MENU_BUTTON) .entity_of_child(ID_POLICY_CHECK_MENU_BUTTON)
.expect("PolicyState.init: Can't find child 'Menu button'."); .expect("PolicyCheckState.init: Can't find child 'Menu button'.");
self.text_box = ctx self.text_box = ctx
.entity_of_child(ID_POLICY_CHECK_POLICY_NUMBER) .entity_of_child(ID_POLICY_CHECK_POLICY_NUMBER)
.expect("PolicyState.init: Can't find child 'Text Box'."); .expect("PolicyCheckState.init: Can't find child 'Text Box'.");
} }
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context) { fn update(&mut self, _registry: &mut Registry, ctx: &mut Context) {
@@ -149,6 +154,9 @@ impl State for PolicyCheckState {
Action::InputTextChanged(text_box) => { Action::InputTextChanged(text_box) => {
self.set_check_button(text_box, ctx); self.set_check_button(text_box, ctx);
} }
Action::OpenMenu(text_block) => {
self.open_menu(text_block, ctx);
}
Action::ParseEntry(text_box) => { Action::ParseEntry(text_box) => {
self.parse_entry(text_box, ctx); self.parse_entry(text_box, ctx);
} }

View File

@@ -1,26 +1,79 @@
use orbtk::prelude::*; use orbtk::prelude::*;
use orbtk::theme::vector_graphics::material_icons_font; //use orbtk::theme::vector_graphics::material_icons_font_ttf;
use crate::{ use crate::{
//data::PolicyList, data::PolicyCheck,
keys::*, keys::*,
policycheck_state::*,
//policycheck_state::{Action, PolicyCheckState}, //policycheck_state::{Action, PolicyCheckState},
}; };
widget!(PolicyCheckView); widget!(
// widget!( /// Dialog to enter a policy identifier/number.
// /// Starter page that offers the dialog to enter an identifier of a policy. /// This identifier is checked agains a map of valid policy codes.
// /// This identifier is checked agains a map of valid policy codes. PolicyCheckView<PolicyCheckState> {
// PolicyCheckView<PolicyCheckState> { policy_check: PolicyCheck,
// //is_valid: bool, //policy_check_list: PolicyCheckList,
// title: String, policy_check_title: String,
// policy_check_text_box: String policy_check_number: String,
// } policy_check_number_valid: bool,
// ); policy_check_text_box: String,
policy_data_count: u32,
policylist_view: u32,
title: String
}
);
impl Template for PolicyCheckView { impl Template for PolicyCheckView {
fn template(self, id: Entity, ctx: &mut BuildContext)-> Self { fn template(self, id: Entity, ctx: &mut BuildContext)-> Self {
// collect the DCES elements of our 'policy check' view
// let items_widget = ItemsWidget::new()
// .id(ID_POLICY_CHECK_ITEMS_WIDGET)
// .v_align("start")
// .items_builder(move |ctx, index| {
// let mut title = "".to_string();
// if let Some(policy_check) = ctx
// .get_widget(id)
// .get::<PolicyCheckList>(PROP_POLICY_CHECK_LIST)
// .get(index)
// {
// title = policy_check.title.clone();
// }
// })
// .count((PROP_POLICY_DATA_COUNT, id))
// .build(ctx);
let policycheck_menu_text_block = TextBlock::new()
.foreground("#3b434a")
.text("Help Menu")
.v_align("center")
.h_align("center")
.build(ctx);
let policy_check_menu_button = Button::new()
.margin((0.0, 0.0, 12.0, 12.0))
.icon(material_icons_font_ttf::MD_MENU)
//.class(CLASS_ICON_ONLY)
//.attach(Grid::row(0))
.attach(Grid::column(2))
.margin((8.0, 0.0, 2.0, 0.0))
.text("Menu Button")
//.min_size(8.0, 8.0)
//.min_size(16.0, 16.0)
//.h_align("end")
//.v_align("center")
//.enabled(true)
//.on_mouse_down(|_, _| true)
//.child(policycheck_menu_container)
//.on_click(move |ctx, _| {
// ctx.get_mut::<PolicyCheckState>(id)
// .action(Action::OpenMenu(policy_check_menu_text_block));
// true
//})
.build(ctx);
// let policy_check_text_box = TextBox::new() // let policy_check_text_box = TextBox::new()
// .id(ID_POLICY_CHECK_TEXT_BOX) // .id(ID_POLICY_CHECK_TEXT_BOX)
// .attach(Grid::row(4)) // .attach(Grid::row(4))
@@ -56,35 +109,20 @@ impl Template for PolicyCheckView {
// }) // })
// .build(ctx); // .build(ctx);
let policy_check_menu_button = Button::new() // let policycheck_menu_container = Container::new()
.id(ID_POLICY_CHECK_MENU_BUTTON) // .id(ID_POLICY_CHECK_MENU_CONTAINER)
//.class(CLASS_ICON_ONLY) // .background("#dfebf5")
//.attach(Grid::row(0)) // .width(200.0)
.attach(Grid::column(2)) // .height(200.0)
//.margin((0.0, 0.0, 12.0, 12.0)) // .child(
//.min_size(8.0, 8.0)
.min_size(16.0, 16.0)
.h_align("end")
.v_align("center")
.enabled(true)
//.icon(material_icons_font::MENU_FONT_ICON)
//.icon(material_icons_font_ttf::EDIT_FONT_ICON)
//.icon("")
//.icon("")
.on_mouse_down(|_, _| true)
//.child(policycheck_menu)
// .on_click(move |ctx, _| {
// //ctx.get_mut::<PolicyCheckState>(id)
// // .action(Action::NewEntry(policy_check_menu_container));
// true
//})
.build(ctx);
// The menu implemented as an overlay // The menu implemented as an overlay
//ctx.append_child_to_overlay(policy_check_menu_button).unwrap(); //ctx.append_child_to_overlay(policy_check_menu_button).unwrap();
// Check policy identifier page // Starter page: check for valid policy number
self.name("Policy check").child( self.name("PolicyCheckView")
.policy_check(PolicyCheck::default())
.child(
Grid::new() Grid::new()
.id(ID_POLICY_CHECK_WIDGET) .id(ID_POLICY_CHECK_WIDGET)
//.v_align("start") //.v_align("start")
@@ -133,7 +171,7 @@ impl Template for PolicyCheckView {
) )
.build(ctx), .build(ctx),
) )
.child(policy_check_menu_button) //.child(policy_check_menu_button)
.build(ctx), .build(ctx),
) )
.child( .child(
@@ -294,10 +332,15 @@ impl Template for PolicyCheckView {
.build(ctx), .build(ctx),
) )
.build(ctx), .build(ctx),
//ctx.append_child_to_overlay(policycheck_menu_text_block).unwrap()
) )
.build(ctx), .build(ctx),
) )
.build(ctx), .build(ctx),
) )
} }

View File

@@ -2,11 +2,10 @@ use orbtk::prelude::*;
use crate::{ use crate::{
base_state::BaseState, base_state::BaseState,
data::{PolicyData, PolicyList}, data::{PolicyCode, PolicyData, PolicyList, Status},
keys::*, keys::*,
}; };
use chrono::{Local, NaiveDateTime}; use chrono::{Utc, NaiveDateTime};
//use chrono::{DateTime, Local, TimeZone, NaiveDateTime, Utc};
/// Actions that can execute on the task view. /// Actions that can execute on the task view.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
@@ -16,19 +15,25 @@ pub enum Action {
NewEntry(Entity), NewEntry(Entity),
RemoveFocus(Entity), RemoveFocus(Entity),
RemoveEntry(usize), RemoveEntry(usize),
SetEntry(Entity), SetDateInserted(Entity),
SetDion(Entity),
SetPolicyCode(Entity),
SetPolicyNumber(Entity),
StatusChanged(Entity, usize), StatusChanged(Entity, usize),
TextChanged(Entity, usize), TextChanged(Entity, usize),
} }
/// Handles the requests of the `OverviewView`. /// Handles the requests of the `PolicyDataListView`.
#[derive(Default, AsAny)] #[derive(Debug, Default, AsAny)]
pub struct PolicyDataState { pub struct PolicyDataState {
action:Option<Action>, action:Option<Action>,
add_button: Entity,
back_entity: Entity, back_entity: Entity,
last_focused: Option<Entity>, last_focused: Option<Entity>,
pub text_box: 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, open: bool,
} }
@@ -59,12 +64,12 @@ impl PolicyDataState {
/// otherwise otherwise enabled it. /// otherwise otherwise enabled it.
fn adjust_add_button_enabled(&self, text_box: Entity, ctx: &mut Context) { fn adjust_add_button_enabled(&self, text_box: Entity, ctx: &mut Context) {
if ctx.get_widget(text_box).get::<String16>("name").is_empty() { if ctx.get_widget(text_box).get::<String16>("name").is_empty() {
ctx.get_widget(self.add_button).set("enabled", false); ctx.get_widget(self.policy_data_add_button).set("enabled", false);
} else { } else {
ctx.get_widget(self.add_button).set("enabled", true); ctx.get_widget(self.policy_data_add_button).set("enabled", true);
} }
ctx.get_widget(self.add_button).update_theme_by_state(true); ctx.get_widget(self.policy_data_add_button).update_theme_by_state(true);
} }
/// Change status of given text box to edit mode. /// Change status of given text box to edit mode.
@@ -102,19 +107,21 @@ impl PolicyDataState {
} }
/// create a new policy data member /// create a new policy data member
fn new_entry(&self, name: String, registry: &mut Registry, ctx: &mut Context) { fn new_entry(&self, policy_number: u32, registry: &mut Registry, ctx: &mut Context) {
let index = ctx.widget().clone::<Option<usize>>("list_index"); let index = ctx.widget().clone::<Option<usize>>("list_index");
if let Some(index) = index { if let Some(index) = index {
if let Some(policy_elements) = ctx if let Some(policy_data) = ctx
.widget() .widget()
.get_mut::<PolicyData>("policy_elements") .get_mut::<PolicyList>("policy_list")
.get_mut(index) .get_mut(index)
{ {
policy_list.push(PolicyData { policy_data.push(PolicyData {
policy_code, date_inserted: Some(Utc::now().naive_utc()),
date_valid_until, dion: 1,
selected: true, policy_code: PolicyCode::AS,
policy_number,
status: Status::Active,
}); });
} }
@@ -132,8 +139,8 @@ impl PolicyDataState {
name = String16::from(policy_list.name.as_str()); name = String16::from(policy_list.name.as_str());
policy_data_count = policy_list.len(); policy_data_count = policy_list.len();
} }
ctx.widget().set("name", title); ctx.widget().set("name", name);
ctx.widget().set("policy_data_count", policy_count); ctx.widget().set("policy_data_count", policy_data_count);
self.open = true; self.open = true;
} }
} }
@@ -152,24 +159,24 @@ impl PolicyDataState {
self.save(registry, ctx); self.save(registry, ctx);
} }
/// Toggle the invalid element of the given policy data entry /// Toggle the selection state of the given policy number element
fn toggle_invalid( fn toggle_status(
&self, &self,
entry: Entity, entry: Entity,
index: usize, index: usize,
registry: &mut Registry, registry: &mut Registry,
ctx: &mut Context, ctx: &mut Context,
) { ) {
let invalid: bool = *ctx.get_widget(entry).get("invalid"); let invalid: bool = *ctx.get_widget(entry).get("status");
if let Some(idx) = ctx.widget().clone::<Option<usize>>("list_index") { if let Some(idx) = ctx.widget().clone::<Option<usize>>("list_index") {
if let Some(policy_list) = ctx if let Some(policy_data) = ctx
.widget() .widget()
.get_mut::<PolicyData>("policy_list") .get_mut::<PolicyList>("policy_list")
.get_mut(idx) .get_mut(idx)
{ {
if let Some(task) = policy_list.get_mut(index) { if let Some(policy_data) = policy_data.get_mut(index) {
policy.selected = selected; policy_data.status = Status::Active;
} }
} }
} }
@@ -178,21 +185,33 @@ impl PolicyDataState {
fn update_entry( fn update_entry(
&self, &self,
text_box: Entity, policy_data_date_inserted: Entity,
policy_data_dion: Entity,
policy_data_policy_code: Entity,
policy_data_policy_number: Entity,
index: usize, index: usize,
registry: &mut Registry, registry: &mut Registry,
ctx: &mut Context, ctx: &mut Context,
) { ) {
let text: String16 = ctx.get_widget(text_box).clone("text"); 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") { 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 if let Some(policy_list) = ctx
.widget() .widget()
.get_mut::<PolicyList>("policy_list") .get_mut::<PolicyList>("policy_list")
.get_mut(idx) .get_mut(idx)
{ {
if let Some(task) = policy_list.get_mut(index) { // update the record data using the view values of the active policy_list member
task.text = text.to_string(); 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;
} }
} }
} }
@@ -200,15 +219,15 @@ impl PolicyDataState {
} }
} }
impl State for PolicyState { impl State for PolicyDataState {
fn init(&mut self, _: &mut Registry, ctx: &mut Context) { fn init(&mut self, _: &mut Registry, ctx: &mut Context) {
self.back_entity = (*ctx.widget().get::<u32>("back_entity")).into(); self.back_entity = (*ctx.widget().get::<u32>("back_entity")).into();
self.add_button = ctx self.policy_data_add_button = ctx
.entity_of_child(ID_POLICY_ADD_BUTTON) .entity_of_child(ID_POLICY_DATA_ADD_BUTTON)
.expect("PolicyState.init: Can't find child 'Add button'."); .expect("PolicyState.init: Can't find child 'Add button'.");
self.text_box = ctx self.policy_data_policy_number = ctx
.entity_of_child(ID_POLICY_TEXT_BOX) .entity_of_child(ID_POLICY_DATA_POLICY_NUMBER)
.expect("PolicyState.init: Can't find child 'Text Box'."); .expect("PolicyState.init: Can't find child 'Policy Number'.");
} }
fn update(&mut self, registry: &mut Registry, ctx: &mut Context) { fn update(&mut self, registry: &mut Registry, ctx: &mut Context) {
@@ -220,9 +239,9 @@ impl State for PolicyState {
Action::InputTextChanged(text_box) => { Action::InputTextChanged(text_box) => {
self.adjust_add_button_enabled(text_box, ctx); self.adjust_add_button_enabled(text_box, ctx);
} }
Action::CreateEntry(entity) => { Action::NewEntry(entity) => {
if let Some(text) = self.fetch_text(ctx, entity) { if let Some(text) = self.fetch_text(ctx, entity) {
self.create_entry(name, registry, ctx); self.new_entry(text, registry, ctx);
} }
} }
Action::RemoveEntry(index) => { Action::RemoveEntry(index) => {
@@ -234,9 +253,21 @@ impl State for PolicyState {
Action::TextChanged(entity, index) => { Action::TextChanged(entity, index) => {
self.update_entry(entity, index, registry, ctx); self.update_entry(entity, index, registry, ctx);
} }
Action::EditEntry(text_box) => { Action::SetDateInserted(policy_data_date_inserted) => {
self.last_focused = Some(text_box); self.last_focused = Some(policy_data_date_inserted);
self.edit_entry(text_box, ctx); 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) => { Action::RemoveFocus(text_box) => {
ctx.get_widget(text_box).set("enabled", false); ctx.get_widget(text_box).set("enabled", false);

View File

@@ -1,59 +1,148 @@
use orbtk::prelude::*; use orbtk::prelude::*;
use crate::{ use crate::{
data::PolicyData, data::{PolicyList, Status},
keys::*, keys::*,
policy_state::{Action, PolicyState}, policydata_state::{Action, PolicyDataState},
}; };
use chrono::NaiveDateTime;
type ListIndex = Option<usize>; type ListIndex = Option<usize>;
widget!(PolicyData<PolicyDataState> { // 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, back_entity: u32,
policy_list_count: usize,
policylist_view: u32,
list_index: ListIndex, list_index: ListIndex,
name: String16 date_valid_until: NaiveDateTime,
policy_data: PolicyData, policy_list: PolicyList
policy_data_count: usize,
}); });
impl Template for PolicyData { impl Template for PolicyDataView {
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
// listing the policy elements // listing the policy elements
let items_widget = ItemsWidget::new() let items_widget = ItemsWidget::new()
.id(ID_POLICY_DATA_ITEMS_WIDGET) .id(ID_POLICY_DATA_ITEMS_WIDGET)
.v_align("start") .v_align("start")
.items_builder(move |ctx, index| { .items_builder(move |ctx, index| {
let mut policy_code = "".to_string();
let mut date_inserted = None; let mut date_inserted = None;
let mut isactive = false; 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(list_index) = ctx.get_widget(id).clone::<ListIndex>("list_index") {
if let Some(policy_data) = ctx if let Some(policy_data) = ctx
.get_widget(id) .get_widget(id)
.get::<PolicyData(PROP_POLICY_DATA) .get::<PolicyList>(PROP_POLICY_LIST)
.get(list_index) .get(list_index)
{ {
if let Some(policy_data) = policy_data.get(index) { if let Some(policy_data) = policy_data.get(index) {
policy_code = policy_data.policy_code.clone();
date_inserted = policy_data.date_inserted.clone(); date_inserted = policy_data.date_inserted.clone();
isactive = policy_data.isactive; dion = policy_data.dion.clone();
policy_code = policy_data.policy_code.clone();
policy_number = policy_data.policy_number.clone();
status = policy_data.status;
} }
} }
} }
let text_box = TextBox::new() let policy_data_status = CheckBox::new()
.text(name) .attach(Grid::column(1))
.enabled(false)
.v_align("center") .v_align("center")
.water_mark("Insert the new policy collection name ...") // status: true -> State::Active false -> State::Inactive
.class("inplace") .enabled(status)
.attach(Grid::column(3))
.on_changed(move |ctx, entity| { .on_changed(move |ctx, entity| {
ctx.get_mut::<PolicyDataState>(id) ctx.get_mut::<PolicyDataState>(id)
.action(Action::TextChanged(entity, index)); .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| { .on_activate(move |ctx, entity| {
ctx.get_mut::<PolicyState>(id) 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)); .action(Action::RemoveFocus(entity));
}) })
.build(ctx); .build(ctx);
@@ -65,7 +154,13 @@ impl Template for PolicyData {
.add(10.0) .add(10.0)
.add(24.0) .add(24.0)
.add(8.0) .add(8.0)
.add("*") .add(24.0)
.add(8.0)
.add(24.0)
.add(8.0)
.add("auto")
.add(8.0)
.add("auto")
.add(8.0) .add(8.0)
.add(32.0) .add(32.0)
.add(4.0) .add(4.0)
@@ -73,56 +168,40 @@ impl Template for PolicyData {
.add(8.0) .add(8.0)
.build(), .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( .child(
CheckBox::new() // edit active policy data element
.attach(Grid::column(1))
.v_align("center")
.invalid(invalid)
.on_changed(move |ctx, entity| {
ctx.get_mut::<PolicyState>(id)
.action(Action::StatusChanged(entity, index));
})
.build(ctx),
)
.child(text_box)
.child(
ToggleButton::new()
.selected(("focused", text_box))
.class(CLASS_ICON_ONLY)
.attach(Grid::column(5))
.min_size(32.0, 32.0)
.v_align("center")
.build(ctx),
)
.child(
Button::new() Button::new()
.class(CLASS_ICON_ONLY) .class(CLASS_ICON_ONLY)
.attach(Grid::column(5)) .attach(Grid::column(11))
.min_size(32.0, 32.0) .min_size(32.0, 32.0)
.v_align("center") .v_align("center")
// todo use remove from icons .icon(material_icons_font_ttf::MD_EDIT)
// .icon(material_font_icons::DELETE_FONT_ICON) //.icon("")
.icon("")
.on_mouse_down(|_, _| true) .on_mouse_down(|_, _| true)
.on_click(move |ctx, _| { .on_click(move |ctx, _| {
ctx.get_mut::<PolicyState>(id) ctx.get_mut::<PolicyDataState>(id)
.action(Action::EditEntry(text_box)); .action(Action::EditEntry(text_box));
true true
}) })
.build(ctx), .build(ctx),
) )
.child( .child(
// delete active policy data element
Button::new() Button::new()
.class("icon_only") .class("icon_only")
.attach(Grid::column(7)) .attach(Grid::column(13))
.min_size(32.0, 32.0) .min_size(32.0, 32.0)
.v_align("center") .v_align("center")
// todo use remove from icons .icon(material_icons_font_ttf::MD_DELETE)
// .icon(material_font_icons::DELETE_FONT_ICON) //.icon("")
.icon("")
.on_mouse_down(|_, _| true) .on_mouse_down(|_, _| true)
.on_click(move |ctx, _| { .on_click(move |ctx, _| {
ctx.get_mut::<PolicyState>(id) ctx.get_mut::<PolicyDataState>(id)
.action(Action::RemoveEntry(index)); .action(Action::RemoveEntry(index));
true true
}) })
@@ -130,7 +209,7 @@ impl Template for PolicyData {
) )
.build(ctx) .build(ctx)
}) })
.policy_data_count(PROP_POLICY_COUNT, id) .policy_data_count(PROP_POLICY_DATA_COUNT, id)
.build(ctx); .build(ctx);
let scroll_viewer = ScrollViewer::new() let scroll_viewer = ScrollViewer::new()
@@ -138,23 +217,24 @@ impl Template for PolicyData {
.child(items_widget) .child(items_widget)
.build(ctx); .build(ctx);
let task_text_box = TextBox::new() let policy_data_list_name = TextBox::new()
.id(ID_POLICY_TEXT_BOX) .id(ID_POLICY_DATA_LIST_NAME)
.attach(Grid::row(4)) .attach(Grid::row(4))
.v_align("center") .v_align("center")
.margin((4.0, 0.0, 0.0, 0.0)) .margin((4.0, 0.0, 0.0, 0.0))
.lost_focus_on_activation(false) .lost_focus_on_activation(false)
.on_activate(move |ctx, entity| { .on_activate(move |ctx, entity| {
ctx.get_mut::<PolicyState>(id) ctx.get_mut::<PolicyDataState>(id)
.action(Action::CreateEntry(entity)); .action(Action::CreateEntry(entity));
}) })
.on_changed(move |ctx, entity| { .on_changed(move |ctx, entity| {
ctx.get_mut::<PolicyState>(id) ctx.get_mut::<PolicyDataState>(id)
.action(Action::InputTextChanged(entity)); .action(Action::InputTextChanged(entity));
}) })
.build(ctx); .build(ctx);
self.name("PolicyList").child( // Child page: list available policy data elements
self.name("PolicyDataListView").child(
Grid::new() Grid::new()
.rows( .rows(
Rows::new() Rows::new()
@@ -172,22 +252,6 @@ impl Template for PolicyData {
.add(36.0) .add(36.0)
.build(), .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 // Top Bar
.child( .child(
Container::new() Container::new()
@@ -209,11 +273,12 @@ impl Template for PolicyData {
.child( .child(
Button::new() Button::new()
.height(32.0) .height(32.0)
.icon("") .icon(material_icons_font_ttf::MD_ARROW_LEFT)
//.icon("")
.class(CLASS_ICON_ONLY) .class(CLASS_ICON_ONLY)
.v_align("center") .v_align("center")
.on_click(move |ctx, _| { .on_click(move |ctx, _| {
ctx.get_mut::<PolicyState>(id) ctx.get_mut::<PolicyDataState>(id)
.action(Action::NavigateBack()); .action(Action::NavigateBack());
true true
}) })
@@ -228,6 +293,32 @@ impl Template for PolicyData {
.text(("name", id)) .text(("name", id))
.build(ctx), .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),
) )
.build(ctx), .build(ctx),
@@ -239,6 +330,22 @@ impl Template for PolicyData {
.attach(Grid::column_span(3)) .attach(Grid::column_span(3))
.build(ctx), .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( .child(
Container::new() Container::new()
.class("separator") .class("separator")
@@ -255,10 +362,10 @@ impl Template for PolicyData {
.attach(Grid::column_span(3)) .attach(Grid::column_span(3))
.build(ctx), .build(ctx),
) )
.child(task_text_box) .child(policy_data_list_name)
.child( .child(
Button::new() Button::new()
.id(ID_POLICY_ADD_BUTTON) .id(ID_POLICY_DATA_ADD_BUTTON)
.class(CLASS_ICON_ONLY) .class(CLASS_ICON_ONLY)
.attach(Grid::row(4)) .attach(Grid::row(4))
.attach(Grid::column(2)) .attach(Grid::column(2))
@@ -266,10 +373,10 @@ impl Template for PolicyData {
.enabled(false) .enabled(false)
.min_size(32.0, 32.0) .min_size(32.0, 32.0)
.v_align("center") .v_align("center")
.icon(material_font_icons::ADD_FONT_ICON) .icon(material_icons_font_ttf::MD_ADD_CIRCLE)
.on_click(move |ctx, _| { .on_click(move |ctx, _| {
ctx.get_mut::<PolicyState>(id) ctx.get_mut::<PolicyDataState>(id)
.action(Action::CreateEntry(task_text_box)); .action(Action::CreateEntry(policy_data_list_name));
true true
}) })
.build(ctx), .build(ctx),

View File

@@ -2,7 +2,7 @@ use orbtk::prelude::*;
use crate::{ use crate::{
base_state::BaseState, base_state::BaseState,
data::{PolicyData, PolicyList}, data::{PolicyDataList, PolicyList},
keys::*, keys::*,
}; };
@@ -18,7 +18,7 @@ pub enum Action {
TextChanged(Entity, usize), TextChanged(Entity, usize),
} }
/// Handles the requests of the `OverviewView`. /// Handles the requests of the `PolicyListView`.
#[derive(Default, AsAny)] #[derive(Default, AsAny)]
pub struct PolicyListState { pub struct PolicyListState {
action:Option<Action>, action:Option<Action>,
@@ -60,21 +60,21 @@ impl PolicyListState {
/// update number of available policy list entries. /// update number of available policy list entries.
fn adjust_count(&self, ctx: &mut Context) { fn adjust_count(&self, ctx: &mut Context) {
let policy_lists_count = ctx.widget().get::<PolicyList>(PROP_POLICY_LISTS).len(); let policy_list_count = ctx.widget().get::<PolicyList>(PROP_POLICY_LIST).len();
ctx.widget().set(PROP_POLICY_LISTS_COUNT, policy_lists_count); ctx.widget().set(PROP_POLICY_LIST_COUNT, policy_list_count);
} }
// Creates a new policy list. // Creates a new policy data list.
fn new_entry(&self, name: String, registry: &mut Registry, ctx: &mut Context) { fn new_entry(&self, name: String, registry: &mut Registry, ctx: &mut Context) {
ctx.widget() ctx.widget()
.get_mut::<PolicyList>(PROP_POLICY_LISTS) .get_mut::<PolicyList>(PROP_POLICY_LIST)
.push(PolicyData::new(name)); .push(PolicyList::new(name));
self.adjust_count(ctx); self.adjust_count(ctx);
self.save(registry, ctx); self.save(registry, ctx);
} }
// opens a given policy list name. // opens a given policy list name.
fn open_policy_lists(&self, index: usize, ctx: &mut Context) { fn open_policy_list(&self, index: usize, ctx: &mut Context) {
ctx.get_widget(self.text_box) ctx.get_widget(self.text_box)
.set("text", String16::from("")); .set("text", String16::from(""));
ctx.get_widget(self.policydata_view) ctx.get_widget(self.policydata_view)
@@ -85,7 +85,7 @@ impl PolicyListState {
// removes a policy list. // removes a policy list.
fn remove_entry(&self, index: usize, registry: &mut Registry, ctx: &mut Context) { fn remove_entry(&self, index: usize, registry: &mut Registry, ctx: &mut Context) {
ctx.widget() ctx.widget()
.get_mut::<PolicyList>(PROP_POLICY_LISTS) .get_mut::<PolicyList>(PROP_POLICY_LIST)
.remove(index); .remove(index);
self.adjust_count(ctx); self.adjust_count(ctx);
self.save(registry, ctx); self.save(registry, ctx);
@@ -120,22 +120,22 @@ impl PolicyListState {
impl State for PolicyListState { impl State for PolicyListState {
fn init(&mut self, registry: &mut Registry, ctx: &mut Context) { fn init(&mut self, registry: &mut Registry, ctx: &mut Context) {
self.text_box = ctx self.text_box = ctx
.entity_of_child(ID_POLICY_LISTS_TEXT_BOX) .entity_of_child(ID_POLICY_LIST_TEXT_BOX)
.expect("PolicyListState.init: Child 'Text box' not found."); .expect("PolicyListState.init: Child 'Text box' not found.");
self.add_button = ctx self.add_button = ctx
.entity_of_child(ID_POLICY_LISTS_ADD_BUTTON) .entity_of_child(ID_POLICY_LIST_ADD_BUTTON)
.expect("PolicyListState.init: Child 'Add button' not found."); .expect("PolicyListState.init: Child 'Add button' not found.");
self.items_widget = ctx self.items_widget = ctx
.entity_of_child(ID_POLICY_LISTS_ITEMS_WIDGET) .entity_of_child(ID_POLICY_LIST_ITEMS_WIDGET)
.expect("PolicyListState.init: Child 'Items widget' not found."); .expect("PolicyListState.init: Child 'Items widget' not found.");
self.policydata_view = (*ctx.widget() self.policydata_view = (*ctx.widget()
.get::<u32>("policy_lists_view")).into(); .get::<u32>("policy_list_view")).into();
if let Ok(tasks) = registry if let Ok(policy_list_name) = registry
.get::<Settings>("settings") .get::<Settings>("settings")
.load::<PolicyList>(PROP_POLICY_LISTS) .load::<PolicyList>(PROP_POLICY_LIST)
{ {
ctx.widget().set(PROP_POLICY_LISTS, tasks); ctx.widget().set(PROP_POLICY_LIST, policy_list_name);
} }
self.adjust_count(ctx); self.adjust_count(ctx);
@@ -157,8 +157,8 @@ impl State for PolicyListState {
self.adjust_add_button_enabled(text_box, ctx); self.adjust_add_button_enabled(text_box, ctx);
} }
Action::NewEntry(entity) => { Action::NewEntry(entity) => {
if let Some(text) = self.fetch_text(ctx, entity) { if let Some(name) = self.fetch_text(ctx, entity) {
self.new_entry(text, registry, ctx); self.new_entry(name, registry, ctx);
} }
} }
Action::RemoveEntry(index) => { Action::RemoveEntry(index) => {
@@ -169,7 +169,7 @@ impl State for PolicyListState {
if let Some(header) = ctx if let Some(header) = ctx
.widget() .widget()
.get_mut::<PolicyList>("policy_lists") .get_mut::<PolicyList>("policy_list")
.get_mut(index) .get_mut(index)
{ {
header.name = text.to_string(); header.name = text.to_string();
@@ -186,7 +186,7 @@ impl State for PolicyListState {
ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box)); ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box));
} }
Action::OpenPolicyList(index) => { Action::OpenPolicyList(index) => {
self.open_policy_lists(index, ctx); self.open_policy_list(index, ctx);
} }
} }
} }

View File

@@ -10,34 +10,35 @@ use crate::{
//type ListIndex = Option<usize>; //type ListIndex = Option<usize>;
widget!( widget!(
/// Starter page that offers the dialog to enter an identifier of a policy. /// Dialog selecting a list of policy identifiers.
/// This identifier is checked agains a map of valid policy codes. /// The lists groups a collection of policy codes.
PolicyListView<PolicyListState> { PolicyListView<PolicyListState> {
policy_lists: PolicyList, back_entity: u32,
policy_lists_count: usize, policy_list: PolicyList,
policy_data: u32 policy_list_count: usize,
policydata_view: u32
} }
); );
impl Template for PolicyListView { impl Template for PolicyListView {
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
// all items of our policy lists // collect the DCES elements of our 'policy lists' view
let items_widget = ItemsWidget::new() let items_widget = ItemsWidget::new()
.id(ID_POLICY_LISTS_ITEMS_WIDGET) .id(ID_POLICY_LIST_ITEMS_WIDGET)
.v_align("start") .v_align("start")
.items_builder(move |ctx, index| { .items_builder(move |ctx, index| {
let mut name = "".to_string(); let mut name = "".to_string();
//let mut selected = false;
if let Some(policy_lists) = ctx if let Some(policy_list) = ctx
.get_widget(id) .get_widget(id)
.get::<PolicyList>(PROP_POLICY_LISTS) .get::<PolicyList>(PROP_POLICY_LIST)
.get(index) { .get(index)
name = policy_lists.name.clone(); {
name = policy_list.name.clone();
} }
// plus button: open new policy // plus button: open new policy
let helper_button = Button::new() let new_list_button = Button::new()
.min_height(48.0) .min_height(48.0)
.class(CLASS_ITEM_BUTTON) .class(CLASS_ITEM_BUTTON)
.attach(Grid::column(0)) .attach(Grid::column(0))
@@ -51,7 +52,7 @@ impl Template for PolicyListView {
.build(ctx); .build(ctx);
let text_block = TextBlock::new() let text_block = TextBlock::new()
.foreground(helper_button) .foreground(new_list_button)
.margin((14.0, 0.0, 0.0, 0.0)) .margin((14.0, 0.0, 0.0, 0.0))
.v_align("center") .v_align("center")
.attach(Grid::column(0)) .attach(Grid::column(0))
@@ -63,7 +64,7 @@ impl Template for PolicyListView {
.margin((8.0, 0.0, 0.0, 0.0)) .margin((8.0, 0.0, 0.0, 0.0))
.visibility("collapsed") .visibility("collapsed")
.v_align("center") .v_align("center")
.water_mark("Insert name of a new policy list...") .water_mark("Insert name of a new policy collection ...")
.attach(Grid::column(0)) .attach(Grid::column(0))
.text(text_block) .text(text_block)
.on_changed(move |ctx, entity| { .on_changed(move |ctx, entity| {
@@ -88,10 +89,11 @@ impl Template for PolicyListView {
.add(8.0) .add(8.0)
.build(), .build(),
) )
.child(helper_button) .child(new_list_button)
.child(text_box) .child(text_box)
.child(text_block) .child(text_block)
.child( .child(
// toggle if text_box is focused
ToggleButton::new() ToggleButton::new()
.selected(("focused", text_box)) .selected(("focused", text_box))
.class(CLASS_ICON_ONLY) .class(CLASS_ICON_ONLY)
@@ -107,9 +109,9 @@ impl Template for PolicyListView {
.attach(Grid::column(2)) .attach(Grid::column(2))
.min_size(32.0, 32.0) .min_size(32.0, 32.0)
.v_align("center") .v_align("center")
// todo use remove from icons .icon(material_icons_font_ttf::MD_ADD)
// .icon(material_font_icons::DELETE_FONT_ICON) //.icon(material_icons_font_ttf::MD_EDIT)
.icon("") //.icon("")
.on_mouse_down(|_, _| true) .on_mouse_down(|_, _| true)
.on_click(move |ctx, _| { .on_click(move |ctx, _| {
ctx.get_mut::<PolicyListState>(id) ctx.get_mut::<PolicyListState>(id)
@@ -124,9 +126,8 @@ impl Template for PolicyListView {
.attach(Grid::column(4)) .attach(Grid::column(4))
.min_size(32.0, 32.0) .min_size(32.0, 32.0)
.v_align("center") .v_align("center")
// todo use Tray icon for action remove .icon(material_icons_font_ttf::MD_DELETE)
// .icon(material_font_icons::DELETE_FONT_ICON) //.icon("")
.icon("")
.on_mouse_down(|_, _| true) .on_mouse_down(|_, _| true)
.on_click(move |ctx, _| { .on_click(move |ctx, _| {
ctx.get_mut::<PolicyListState>(id) ctx.get_mut::<PolicyListState>(id)
@@ -137,12 +138,12 @@ impl Template for PolicyListView {
) )
.build(ctx) .build(ctx)
}) })
.count((PROP_POLICY_LISTS_COUNT, id)) .count((PROP_POLICY_LIST_COUNT, id))
.build(ctx); .build(ctx);
// create new policy list element // create new policy list element
let policy_lists_text_box = TextBox::new() let policy_list_text_box = TextBox::new()
.id(ID_POLICY_LISTS_TEXT_BOX) .id(ID_POLICY_LIST_TEXT_BOX)
.attach(Grid::row(4)) .attach(Grid::row(4))
.v_align("center") .v_align("center")
.margin((4.0, 0.0, 0.0, 2.0)) .margin((4.0, 0.0, 0.0, 2.0))
@@ -162,9 +163,10 @@ impl Template for PolicyListView {
.child(items_widget) .child(items_widget)
.build(ctx); .build(ctx);
self.name("Policy Lists") // Child page: list available policy lists
.policy_lists(PolicyList::default()) self.name("PolicyListView")
.policy_lists_count(0) .policy_list(PolicyList::default())
.policy_list_count(0)
.child( .child(
Grid::new() Grid::new()
.rows( .rows(
@@ -213,7 +215,7 @@ impl Template for PolicyListView {
.class(CLASS_HEADER) .class(CLASS_HEADER)
.v_align("center") .v_align("center")
.h_align("center") .h_align("center")
.text("Lists with policy data collections") .text("Lists of policy data collections")
.build(ctx), .build(ctx),
) )
.build(ctx), .build(ctx),
@@ -255,10 +257,10 @@ impl Template for PolicyListView {
.class(CLASS_TRANSPARENT) .class(CLASS_TRANSPARENT)
.build(ctx), .build(ctx),
) )
.child(policy_lists_text_box) .child(policy_list_text_box)
.child( .child(
Button::new() Button::new()
.id(ID_POLICY_LISTS_ADD_BUTTON) .id(ID_POLICY_LIST_ADD_BUTTON)
.class(CLASS_ICON_ONLY) .class(CLASS_ICON_ONLY)
.attach(Grid::row(4)) .attach(Grid::row(4))
.attach(Grid::column(2)) .attach(Grid::column(2))
@@ -266,10 +268,10 @@ impl Template for PolicyListView {
.enabled(false) .enabled(false)
.min_size(32.0, 32.0) .min_size(32.0, 32.0)
.v_align("center") .v_align("center")
.icon(material_icons_font::ADD_FONT_ICON) .icon(material_icons_font_ttf::MD_ADD)
.on_click(move |ctx, _| { .on_click(move |ctx, _| {
ctx.get_mut::<PolicyListState>(id) ctx.get_mut::<PolicyListState>(id)
.action(Action::NewEntry(policy_lists_text_box)); .action(Action::NewEntry(policy_list_text_box));
true true
}) })
.build(ctx), .build(ctx),