metis_docs_tui/app/actions/
ui_actions.rs1use crate::app::state::ConfirmationType;
2use crate::app::App;
3use crate::models::{AppState, BoardType};
4
5impl App {
6 pub fn add_success_message(&mut self, message: String) {
8 self.ui_state.message_state.add_success(message);
9 }
10
11 pub fn add_error_message(&mut self, message: String) {
12 self.ui_state.message_state.add_error(message);
13 }
14
15 pub fn add_warning_message(&mut self, message: String) {
16 self.ui_state.message_state.add_warning(message);
17 }
18
19 pub fn add_info_message(&mut self, message: String) {
20 self.ui_state.message_state.add_info(message);
21 }
22
23 pub fn clear_messages(&mut self) {
24 self.ui_state.message_state.clear_message();
25 }
26
27 pub fn clear_expired_messages(&mut self) {
28 self.ui_state.message_state.clear_expired_messages();
29 }
30
31 pub fn start_document_creation(&mut self) {
33 self.ui_state.set_app_state(AppState::CreatingDocument);
34 self.ui_state.reset_input();
35 }
36
37 pub fn start_smart_document_creation(&mut self) {
38 match self.ui_state.current_board {
39 BoardType::Strategy => {
41 if self.core_state.flight_config.strategies_enabled {
42 self.ui_state.set_app_state(AppState::CreatingDocument);
44 } else {
45 self.ui_state.set_app_state(AppState::CreatingChildDocument);
47 }
48 self.ui_state.reset_input();
49 }
50 BoardType::Initiative => {
52 if !self.core_state.flight_config.strategies_enabled
53 && self.core_state.flight_config.initiatives_enabled
54 {
55 self.ui_state.set_app_state(AppState::CreatingDocument);
57 } else {
58 self.ui_state.set_app_state(AppState::CreatingChildDocument);
60 }
61 self.ui_state.reset_input();
62 }
63 BoardType::Task => {
65 if !self.core_state.flight_config.strategies_enabled
66 && !self.core_state.flight_config.initiatives_enabled
67 {
68 self.ui_state.set_app_state(AppState::CreatingDocument);
70 self.ui_state.reset_input();
71 } else {
72 self.add_error_message("Tasks are created from the Initiative board (with parent) or Backlog board (standalone)".to_string());
74 }
75 }
76 BoardType::Adr => {
78 self.ui_state.set_app_state(AppState::CreatingAdr);
79 self.ui_state.reset_input();
80 }
81 BoardType::Backlog => {
83 self.ui_state
84 .set_app_state(AppState::SelectingBacklogCategory);
85 self.ui_state.reset_input();
86 }
87 }
88 }
89
90 pub fn start_child_document_creation(&mut self) {
91 self.ui_state.set_app_state(AppState::CreatingChildDocument);
92 self.ui_state.reset_input();
93 }
94
95 pub fn start_adr_creation(&mut self) {
96 self.ui_state.set_app_state(AppState::CreatingAdr);
97 self.ui_state.reset_input();
98 }
99
100 pub fn cancel_document_creation(&mut self) {
101 self.ui_state.set_app_state(AppState::Normal);
102 self.ui_state.reset_input();
103 }
104
105 pub fn start_delete_confirmation(&mut self) {
107 self.ui_state.confirmation_type = Some(ConfirmationType::Delete);
108 self.ui_state.set_app_state(AppState::Confirming);
109 }
110
111 pub fn start_transition_confirmation(&mut self) {
112 self.ui_state.confirmation_type = Some(ConfirmationType::Transition);
113 self.ui_state.set_app_state(AppState::Confirming);
114 }
115
116 pub fn cancel_confirmation(&mut self) {
117 self.ui_state.confirmation_type = None;
118 self.ui_state.set_app_state(AppState::Normal);
119 }
120}