Files
advotracker/advotracker_client/src/widgets/policycheck/policycheck_view.rs
2021-07-15 01:15:07 +02:00

331 lines
13 KiB
Rust

// SPDX-License-Identifier: (0BSD or MIT)
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
*/
use orbtk::{prelude::*, shell::*, widgets::themes::* };
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_CONTAINER)
.name(ID_POLICY_CHECK_FORM_CONTAINER)
.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),
)
}
}