ticketdata: code cleanup

This commit is contained in:
2021-03-04 20:24:21 +01:00
parent 6d9d82bb8e
commit 30131ecdb1
2 changed files with 23 additions and 30 deletions

View File

@@ -18,7 +18,8 @@ use crate::{
data::{constants::*, structures::Email},
widgets::global_state::GlobalState,
services::exports::send_ticketdata::sendticketdata,
widgets::policycheck::policycheck_state::{PolicycheckAction, PolicycheckState},
widgets::ticketdata::ticketdata_view::TicketdataView,
widgets::policycheck::policycheck_state::PolicycheckAction,
};
/// Valid `actions` that are handled as state changes in the `Ticketdata` widget.
@@ -28,12 +29,15 @@ pub enum TicketdataAction {
/// Clear text in the form
ClearForm(),
ChangeTheme(),
//ChangeMailCc(),
//ChangeMailTo(),
InputTextChanged(Entity),
ParseEntry(Entity),
RemoveFocus(Entity),
SendForm(),
SetToggleTheme(Entity),
SetEntry(Entity),
SendForm(), SetVisibility(Entity),
SetVisibility(Entity),
TextChanged(Entity, usize),
UpdatePolicyCode(String)
}
@@ -68,7 +72,7 @@ impl TicketdataState {
info!("Widget id: {:?}", ctx.get_widget(entity).get::<String>("id"));
}
// identify the form by its id
// form is identified by its id
if let form_entity = ctx.child(ID_TICKET_DATA_GRID).entity() {
info!("Form id: {:?}", ctx.get_widget(form_entity).get::<String>("id"));
info!("Form node name: {:?}", ctx.get_widget(form_entity).get::<String>("name"));
@@ -81,27 +85,16 @@ impl TicketdataState {
}
}
}
// let Some(count) = ctx.child(ID_TICKET_DATA_GRID).entitry().children_count() {
// for c in 1..=count {
// println!("WIP clear entry of child {:?}", c);
// }
// }
//let mut children = vec![];
//get_all_children(&mut children, entity, ecm.entity_store());
//trace!("Children {:?}: {:?}", children.len(), children);
//println!("Child name: {:?}", ctx.try_child("ticket_data_form"));
//TextBlock::text_set(&mut ctx.child(ID_TICKET_DATA_POLICY_HOLDER), "");
//println!("Number of childs: {:?}", count);
//for c in 1..=count {
// println!("WIP clear entry of child {:?}", c);
// children = get_all_children()
//println!("Child {:?}: Entity: {:?}", c, ctx.child_from_index(c));
//println!("Text: {:?}", ctx.get_widget(entity).entity_of_child(entity));
//TextBlock::text_set(&mut ctx.child(ID_TICKET_DATA_POLICY_HOLDER), "");
//}
//TextBox::text_set(&mut ctx.widget(entity), String::from(""));
}
// pub fn change_mail_cc(&mut self) {
// self.actions.push(TicketdataAction::ChangeMailCc());
// }
// pub fn change_mail_to(&mut self) {
// self.actions.push(TicketdataAction::ChangeMailTo());
// }
pub fn send_form(entity: Entity, ctx: &mut Context<'_>, lang: &str) {
// type conversion (String -> u64)
@@ -135,7 +128,7 @@ impl TicketdataState {
info!("WIP: Sending form to construct eMail to {:?}", email);
// send email via service
if let Err(e) = sendticketdata(&email, &lang) {
if let Err(_e) = sendticketdata(&email, &lang) {
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::icon_set(&mut ctx.child(ID_TICKET_DATA_ACTION_BUTTON_SEND), material_icons_font::MD_CLEAR);
@@ -151,13 +144,14 @@ impl State for TicketdataState {
trace!(target: "advotracker", ticketdata_state = "init", status = "started");
// Initialize required entities
// 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'."));
.expect("TicketState.init: Can't find resource entity 'target'."));
// Get language from environment
self.lang = TicketdataState::get_lang();
@@ -168,6 +162,7 @@ impl State for TicketdataState {
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,
@@ -187,6 +182,7 @@ impl State for TicketdataState {
_ => { println!("messages: action not implemented!"); }
}
}
for message in messages.read::<PolicycheckAction>() {
match message {
PolicycheckAction::UpdatePolicyCode => {
@@ -198,7 +194,7 @@ impl State for TicketdataState {
}
}
fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
let actions: Vec<TicketdataAction> = self.actions.drain(..).collect();
for action in actions {

View File

@@ -5,10 +5,7 @@
* SPDX-License-Identifier: (0BSD or MIT)
*/
use orbtk::{
prelude::*,
//shell::event::Key,
};
use orbtk::prelude::*;
use crate::{
data::constants::*,