1use crate::action::Action;
2use crate::{Tools, GLOBAL_DATA};
3use crate::PLUGIN_TOOLS;
4use json::{array, object, JsonValue};
5use std::any::type_name;
6
7pub trait Module {
9 fn _name(&self) -> &'static str {
12 type_name::<Self>().split("::").collect::<Vec<&str>>()[3].to_lowercase().leak()
13 }
14 fn title(&self) -> &'static str;
16 fn description(&self) -> &'static str {
18 ""
19 }
20 fn icon(&self) -> &'static str {
23 ""
24 }
25 fn table(&self) -> bool {
28 false
29 }
30 fn _table_name(&self) -> &'static str {
32 let mut it = type_name::<Self>().rsplitn(4, "::");
33 let _ = it.next().unwrap_or(""); let t2 = it.next().unwrap_or("");
35 let t3 = it.next().unwrap_or("");
36
37 let s = format!("{t3}_{t2}").to_lowercase();
38 Box::leak(s.into_boxed_str())
39 }
40 fn table_key(&self) -> &'static str {
42 "id"
43 }
44 fn table_unique(&self) -> &'static [&'static str] {
46 &[]
47 }
48 fn table_index(&self) -> &'static [&'static [&'static str]] {
50 &[]
51 }
52 fn table_partition(&self) -> bool {
54 false
55 }
56 fn table_partition_columns(&self) -> JsonValue {
62 array![]
63 }
64 fn action(&mut self, name: &str) -> Result<Box<dyn Action>, String>;
68 fn fields(&mut self) -> JsonValue {
70 object! {}
71 }
72 fn tools(&mut self) -> Tools {
74 let tools = PLUGIN_TOOLS.lock().unwrap();
75 let tools = tools.get("tools").unwrap().clone();
76 tools
77 }
78 fn set_global_data(&mut self, key: &str, value: JsonValue) {
80 GLOBAL_DATA.with(|data| {
81 data.borrow_mut()[key] = value;
82 });
83 }
84 fn get_global_data(&mut self) -> JsonValue {
86 GLOBAL_DATA.with(|data| {
87 data.borrow().clone()
88 })
89 }
90 fn get_global_data_key(&mut self, key: &str) -> JsonValue {
92 GLOBAL_DATA.with(|data| {
93 data.borrow()[key].clone()
94 })
95 }
96}