1use crate::action::Action;
2use crate::{Tools, GLOBAL_DATA};
3use crate::PLUGIN_TOOLS;
4use json::{array, object, JsonValue};
5use std::any::type_name;
6pub trait Module {
8 fn _name(&self) -> &'static str {
11 type_name::<Self>().split("::").collect::<Vec<&str>>()[3].to_lowercase().leak()
12 }
13 fn title(&self) -> &'static str;
15 fn description(&self) -> &'static str {
17 ""
18 }
19 fn icon(&self) -> &'static str {
22 ""
23 }
24 fn table(&self) -> bool {
27 false
28 }
29 fn _table_name(&self) -> &'static str {
31 let t = type_name::<Self>().split("::").collect::<Vec<&str>>();
32 format!("{}_{}", t[2], t[3]).leak()
33 }
34 fn table_key(&mut self) -> &'static str {
36 "id"
37 }
38 fn table_unique(&self) -> &'static [&'static str] {
40 &[]
41 }
42 fn table_index(&mut self) -> &'static [&'static [&'static str]] {
44 &[]
45 }
46 fn table_partition(&mut self) -> bool {
48 false
49 }
50 fn table_partition_columns(&mut self) -> JsonValue {
56 array![]
57 }
58 fn action(&mut self, name: &str) -> Result<Box<dyn Action>, String>;
62 fn fields(&mut self) -> JsonValue {
64 object! {}
65 }
66 fn tools(&mut self) -> Tools {
68 let tools = PLUGIN_TOOLS.lock().unwrap();
69 let tools = tools.get("tools").unwrap().clone();
70 tools
71 }
72 fn set_global_data(&mut self, key: &str, value: JsonValue) {
74 GLOBAL_DATA.with(|data| {
75 data.borrow_mut()[key] = value;
76 });
77 }
78 fn get_global_data(&mut self) -> JsonValue {
80 GLOBAL_DATA.with(|data| {
81 data.borrow().clone()
82 })
83 }
84 fn get_global_data_key(&mut self, key: &str) -> JsonValue {
86 GLOBAL_DATA.with(|data| {
87 data.borrow()[key].clone()
88 })
89 }
90}