generated from OBJNULL/Dockerized-Rust
App now uses the backend.calculate()
function
This commit is contained in:
parent
845df07b86
commit
a16579802d
1 changed files with 39 additions and 5 deletions
|
@ -1,11 +1,10 @@
|
|||
// Libraries
|
||||
slint::include_modules!();
|
||||
use super::Backend;
|
||||
use slint::{ModelRc, SharedString, VecModel};
|
||||
use std::io::Result;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::Backend;
|
||||
|
||||
// Macros
|
||||
macro_rules! map_err {
|
||||
($expr:expr) => {
|
||||
|
@ -62,16 +61,51 @@ impl App {
|
|||
pub fn start(&self) -> Result<()> {
|
||||
// Creating an Rc of our App
|
||||
let app = Rc::clone(&self.app);
|
||||
let backend = Rc::clone(&self.backend);
|
||||
|
||||
// Setting the on_submit function
|
||||
self.app.on_on_calculate(move || {
|
||||
// Getting the prices of the stuff
|
||||
let current_membership = app.get_current_membership();
|
||||
let new_membership = app.get_new_membership();
|
||||
let last_billing = app.get_last_billing();
|
||||
|
||||
// DEBUG
|
||||
println!("Current Membership: {}", current_membership);
|
||||
println!("New Membership: {}", new_membership);
|
||||
// Are either of these a "Select One..."
|
||||
if current_membership == "Select One..."
|
||||
|| new_membership == "Select One..."
|
||||
|| last_billing == "NULL"
|
||||
{
|
||||
return SharedString::from(
|
||||
"Please fill out all fields before calculating the Prorate.",
|
||||
);
|
||||
}
|
||||
|
||||
// Making the Backend Calculate This
|
||||
let calculation = backend
|
||||
.calculate(
|
||||
current_membership.into(),
|
||||
new_membership.into(),
|
||||
last_billing.into(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Is there no cost difference?
|
||||
if calculation.invalid {
|
||||
return SharedString::from("No price difference, don't change anything.");
|
||||
}
|
||||
|
||||
// Returning the Result
|
||||
if calculation.reversed {
|
||||
SharedString::from(format!(
|
||||
"Retract the billing date to {} (-{}).",
|
||||
calculation.new_date, calculation.days_pushed
|
||||
))
|
||||
} else {
|
||||
SharedString::from(format!(
|
||||
"Extend the billing date to {} (+{}).",
|
||||
calculation.new_date, calculation.days_pushed
|
||||
))
|
||||
}
|
||||
});
|
||||
|
||||
// Starting our application
|
||||
|
|
Loading…
Reference in a new issue