помогите
parent
d48a1f6cf7
commit
44451de6d9
|
|
@ -0,0 +1,112 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use egui::mutex::RwLock;
|
||||||
|
use egui_extras::Column;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
database::DBOperator,
|
||||||
|
misc,
|
||||||
|
models::Order,
|
||||||
|
tab::{TABS_CAN_BE_WINDOWS, Tab, TabTypes},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct OrderTabViewer {
|
||||||
|
db_oper: DBOperator,
|
||||||
|
rt: tokio::runtime::Runtime,
|
||||||
|
|
||||||
|
incoming_orders: Arc<RwLock<Vec<Order>>>,
|
||||||
|
outcoming_orders: Arc<RwLock<Vec<Order>>>,
|
||||||
|
incoming_order_page: i32,
|
||||||
|
outcoming_order_page: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OrderTabViewer {
|
||||||
|
pub fn show_orders(&mut self, ui: &mut egui::Ui, incoming_orders: bool) {
|
||||||
|
let orders = if incoming_orders {
|
||||||
|
&self.incoming_orders
|
||||||
|
} else {
|
||||||
|
&self.outcoming_orders
|
||||||
|
};
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if ui.button("Добавить").clicked() {}
|
||||||
|
if ui.button("<-").clicked() {}
|
||||||
|
ui.monospace(if incoming_orders {
|
||||||
|
self.incoming_order_page.to_string()
|
||||||
|
} else {
|
||||||
|
self.outcoming_order_page.to_string()
|
||||||
|
});
|
||||||
|
if ui.button("->").clicked() {}
|
||||||
|
});
|
||||||
|
|
||||||
|
egui_extras::TableBuilder::new(ui)
|
||||||
|
.columns(Column::auto(), 5)
|
||||||
|
.striped(true)
|
||||||
|
.vscroll(true)
|
||||||
|
.header(25.0, |mut heading| {
|
||||||
|
heading.col(|ui| {
|
||||||
|
ui.heading(if incoming_orders {
|
||||||
|
"Заказчик"
|
||||||
|
} else {
|
||||||
|
"Клиент"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
heading.col(|ui| {
|
||||||
|
ui.heading("Состав");
|
||||||
|
});
|
||||||
|
heading.col(|ui| {
|
||||||
|
ui.heading("Стоимость");
|
||||||
|
});
|
||||||
|
heading.col(|ui| {
|
||||||
|
ui.heading("Дата создания");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl egui_dock::TabViewer for OrderTabViewer {
|
||||||
|
type Tab = Tab;
|
||||||
|
|
||||||
|
fn title(&mut self, tab: &mut Self::Tab) -> egui::WidgetText {
|
||||||
|
tab.title.clone().into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ui(&mut self, ui: &mut egui::Ui, tab: &mut Self::Tab) {
|
||||||
|
match tab.tab_type {
|
||||||
|
TabTypes::IncomingOrderList => {
|
||||||
|
self.show_orders(ui, true);
|
||||||
|
}
|
||||||
|
TabTypes::OutcomingOrderList => {
|
||||||
|
self.show_orders(ui, false);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
ui.label("Nope");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn allowed_in_windows(&self, _tab: &mut Self::Tab) -> bool {
|
||||||
|
TABS_CAN_BE_WINDOWS
|
||||||
|
}
|
||||||
|
fn is_closeable(&self, _tab: &Self::Tab) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Default for OrderTabViewer {
|
||||||
|
fn default() -> Self {
|
||||||
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
|
let db_oper = rt.block_on(async { DBOperator::new().await });
|
||||||
|
|
||||||
|
Self {
|
||||||
|
incoming_orders: Arc::new(RwLock::new(
|
||||||
|
rt.block_on(async { db_oper.get_orders(0, misc::ELEMENTS_PER_PAGE, true).await }),
|
||||||
|
)),
|
||||||
|
outcoming_orders: Arc::new(RwLock::new(
|
||||||
|
rt.block_on(async { db_oper.get_orders(0, misc::ELEMENTS_PER_PAGE, false).await }),
|
||||||
|
)),
|
||||||
|
|
||||||
|
incoming_order_page: 0,
|
||||||
|
outcoming_order_page: 0,
|
||||||
|
db_oper,
|
||||||
|
rt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue