mirror of
https://github.com/creating2morrow/neveko.git
synced 2024-12-22 19:49:24 +00:00
gui market integration initial commit
This commit is contained in:
parent
8f85277194
commit
dcde30b350
4 changed files with 249 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
use crate::{
|
||||
args,
|
||||
contact,
|
||||
db,
|
||||
gpg,
|
||||
i2p,
|
||||
|
@ -657,6 +658,20 @@ pub async fn can_transfer(invoice: u128) -> bool {
|
|||
balance.result.unlocked_balance > (fee + invoice)
|
||||
}
|
||||
|
||||
/// Gui toggle for vendor mode
|
||||
pub fn toggle_vendor_enabled() {
|
||||
let off: &str = "0";
|
||||
let on: &str = "1";
|
||||
let vendor_env = std::env::var(contact::NEVEKO_VENDOR_ENABLED).unwrap_or(String::from(off));
|
||||
if vendor_env == off {
|
||||
info!("neveko vendor mode enabled");
|
||||
std::env::set_var(contact::NEVEKO_VENDOR_ENABLED, on);
|
||||
} else {
|
||||
info!("neveko vendor mode disabled");
|
||||
std::env::set_var(contact::NEVEKO_VENDOR_ENABLED, off);
|
||||
}
|
||||
}
|
||||
|
||||
// Tests
|
||||
//-------------------------------------------------------------------------------
|
||||
|
||||
|
|
224
neveko-gui/src/apps/market.rs
Normal file
224
neveko-gui/src/apps/market.rs
Normal file
|
@ -0,0 +1,224 @@
|
|||
use neveko_core::*;
|
||||
use std::sync::mpsc::{
|
||||
Receiver,
|
||||
Sender,
|
||||
};
|
||||
|
||||
pub struct MarketApp {
|
||||
is_showing_products: bool,
|
||||
is_showing_orders: bool,
|
||||
orders: Vec<models::Order>,
|
||||
products: Vec<models::Product>,
|
||||
new_product_name: String,
|
||||
new_product_desc: String,
|
||||
new_product_price: String,
|
||||
new_product_qty: String,
|
||||
_refresh_on_delete_product_tx: Sender<bool>,
|
||||
_refresh_on_delete_product_rx: Receiver<bool>,
|
||||
}
|
||||
|
||||
impl Default for MarketApp {
|
||||
fn default() -> Self {
|
||||
let (_refresh_on_delete_product_tx, _refresh_on_delete_product_rx) =
|
||||
std::sync::mpsc::channel();
|
||||
MarketApp {
|
||||
is_showing_orders: false,
|
||||
is_showing_products: false,
|
||||
orders: Vec::new(),
|
||||
products: Vec::new(),
|
||||
new_product_name: utils::empty_string(),
|
||||
new_product_desc: utils::empty_string(),
|
||||
new_product_price: utils::empty_string(),
|
||||
new_product_qty: utils::empty_string(),
|
||||
_refresh_on_delete_product_tx,
|
||||
_refresh_on_delete_product_rx,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for MarketApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
// Hook into async channel threads
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
// Products window
|
||||
//-----------------------------------------------------------------------------------
|
||||
let mut is_showing_products = self.is_showing_products;
|
||||
let mut is_showing_orders = self.is_showing_orders;
|
||||
egui::Window::new("Products")
|
||||
.open(&mut is_showing_products)
|
||||
.vscroll(true)
|
||||
.show(&ctx, |ui| {
|
||||
use egui_extras::{
|
||||
Column,
|
||||
TableBuilder,
|
||||
};
|
||||
|
||||
let table = TableBuilder::new(ui)
|
||||
.striped(true)
|
||||
.resizable(true)
|
||||
.cell_layout(egui::Layout::left_to_right(egui::Align::Center))
|
||||
.column(Column::auto())
|
||||
.column(Column::initial(100.0).at_least(40.0).clip(true))
|
||||
.column(Column::initial(100.0).at_least(40.0).clip(true))
|
||||
.column(Column::initial(100.0).at_least(40.0).clip(true))
|
||||
.column(Column::remainder())
|
||||
.min_scrolled_height(0.0);
|
||||
|
||||
table
|
||||
.header(20.0, |mut header| {
|
||||
header.col(|ui| {
|
||||
ui.strong("Name");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("Description");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("Price");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("Quantity");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("");
|
||||
});
|
||||
})
|
||||
.body(|mut body| {
|
||||
for p in &self.products {
|
||||
let row_height = 200.0;
|
||||
body.row(row_height, |mut row| {
|
||||
row.col(|ui| {
|
||||
ui.label(format!("{}", p.name));
|
||||
});
|
||||
row.col(|ui| {
|
||||
ui.label(format!("{}", p.description));
|
||||
});
|
||||
row.col(|ui| {
|
||||
ui.label(format!("{}", p.price));
|
||||
});
|
||||
row.col(|ui| {
|
||||
ui.label(format!("{}", p.qty));
|
||||
});
|
||||
row.col(|ui| {
|
||||
ui.style_mut().wrap = Some(false);
|
||||
ui.horizontal(|_ui| {
|
||||
// update button
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
egui::Window::new("Orders")
|
||||
.open(&mut is_showing_orders)
|
||||
.vscroll(true)
|
||||
.show(&ctx, |ui| {
|
||||
use egui_extras::{
|
||||
Column,
|
||||
TableBuilder,
|
||||
};
|
||||
|
||||
let table = TableBuilder::new(ui)
|
||||
.striped(true)
|
||||
.resizable(true)
|
||||
.cell_layout(egui::Layout::left_to_right(egui::Align::Center))
|
||||
.column(Column::auto())
|
||||
.column(Column::initial(100.0).at_least(40.0).clip(true))
|
||||
.column(Column::initial(100.0).at_least(40.0).clip(true))
|
||||
.column(Column::initial(100.0).at_least(40.0).clip(true))
|
||||
.column(Column::remainder())
|
||||
.min_scrolled_height(0.0);
|
||||
|
||||
table
|
||||
.header(20.0, |mut header| {
|
||||
header.col(|ui| {
|
||||
ui.strong("Name");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("Description");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("Price");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("Quantity");
|
||||
});
|
||||
header.col(|ui| {
|
||||
ui.strong("");
|
||||
});
|
||||
})
|
||||
.body(|mut body| {
|
||||
for o in &self.orders {
|
||||
let row_height = 200.0;
|
||||
body.row(row_height, |mut row| {
|
||||
row.col(|ui| {
|
||||
ui.label(format!("{}", o.cid));
|
||||
});
|
||||
row.col(|ui| {
|
||||
ui.label(format!("{}", o.status));
|
||||
});
|
||||
row.col(|ui| {
|
||||
ui.label(format!("{}", o.date));
|
||||
});
|
||||
row.col(|ui| {
|
||||
ui.label(format!("{}", o.subaddress));
|
||||
});
|
||||
row.col(|ui| {
|
||||
ui.style_mut().wrap = Some(false);
|
||||
ui.horizontal(|_ui| {
|
||||
// update button
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
if ui.button("Refresh").clicked() {
|
||||
self.products = product::find_all();
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("vendor mode: \t");
|
||||
if ui.button("toggle").clicked() {
|
||||
utils::toggle_vendor_enabled();
|
||||
}
|
||||
});
|
||||
ui.label("\n");
|
||||
ui.heading("Add Product");
|
||||
ui.label(
|
||||
"____________________________________________________________________________\n",
|
||||
);
|
||||
ui.horizontal(|ui| {
|
||||
let product_name = ui.label("name: \t\t\t");
|
||||
ui.text_edit_singleline(&mut self.new_product_name)
|
||||
.labelled_by(product_name.id);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
let product_desc = ui.label("description: \t");
|
||||
ui.text_edit_singleline(&mut self.new_product_desc)
|
||||
.labelled_by(product_desc.id);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
let product_price = ui.label("price: \t\t\t");
|
||||
ui.text_edit_singleline(&mut self.new_product_price)
|
||||
.labelled_by(product_price.id);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
let product_qty = ui.label("quantity: \t\t");
|
||||
ui.text_edit_singleline(&mut self.new_product_qty)
|
||||
.labelled_by(product_qty.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn _refresh_on_delete_product_req(tx: Sender<bool>, ctx: egui::Context) {
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||
log::error!("refreshing products....");
|
||||
let _ = tx.send(true);
|
||||
ctx.request_repaint();
|
||||
});
|
||||
}
|
|
@ -2,6 +2,7 @@ mod address_book;
|
|||
mod home;
|
||||
mod lock_screen;
|
||||
mod mailbox;
|
||||
mod market;
|
||||
mod settings;
|
||||
mod wallet;
|
||||
|
||||
|
@ -9,5 +10,6 @@ pub use address_book::AddressBookApp;
|
|||
pub use home::HomeApp;
|
||||
pub use lock_screen::LockScreenApp;
|
||||
pub use mailbox::MailBoxApp;
|
||||
pub use market::MarketApp;
|
||||
pub use settings::SettingsApp;
|
||||
pub use wallet::WalletApp;
|
||||
|
|
|
@ -7,8 +7,6 @@ use std::sync::mpsc::{
|
|||
Sender,
|
||||
};
|
||||
|
||||
// TODO(c2m): gui marketplace integration
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
|
@ -18,6 +16,7 @@ enum Anchor {
|
|||
Home,
|
||||
AddressBook,
|
||||
MailBox,
|
||||
Market,
|
||||
Settings,
|
||||
Wallet,
|
||||
}
|
||||
|
@ -57,6 +56,7 @@ pub struct State {
|
|||
lock_timer: u64,
|
||||
login: crate::login::LoginApp,
|
||||
mailbox: crate::apps::MailBoxApp,
|
||||
market: crate::apps::MarketApp,
|
||||
selected_anchor: Anchor,
|
||||
settings: crate::apps::SettingsApp,
|
||||
wallet: crate::apps::WalletApp,
|
||||
|
@ -89,6 +89,7 @@ impl Default for State {
|
|||
lock_timer_tx,
|
||||
login: Default::default(),
|
||||
mailbox: Default::default(),
|
||||
market: Default::default(),
|
||||
selected_anchor: Default::default(),
|
||||
settings: Default::default(),
|
||||
wallet: Default::default(),
|
||||
|
@ -132,6 +133,11 @@ impl WrapApp {
|
|||
Anchor::MailBox,
|
||||
&mut self.state.mailbox as &mut dyn eframe::App,
|
||||
),
|
||||
(
|
||||
"Market",
|
||||
Anchor::Market,
|
||||
&mut self.state.market as &mut dyn eframe::App,
|
||||
),
|
||||
(
|
||||
"Wallet",
|
||||
Anchor::Wallet,
|
||||
|
|
Loading…
Reference in a new issue