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
|
// Libraries
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
use super::Backend;
|
||||||
use slint::{ModelRc, SharedString, VecModel};
|
use slint::{ModelRc, SharedString, VecModel};
|
||||||
use std::io::Result;
|
use std::io::Result;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::Backend;
|
|
||||||
|
|
||||||
// Macros
|
// Macros
|
||||||
macro_rules! map_err {
|
macro_rules! map_err {
|
||||||
($expr:expr) => {
|
($expr:expr) => {
|
||||||
|
@ -62,16 +61,51 @@ impl App {
|
||||||
pub fn start(&self) -> Result<()> {
|
pub fn start(&self) -> Result<()> {
|
||||||
// Creating an Rc of our App
|
// Creating an Rc of our App
|
||||||
let app = Rc::clone(&self.app);
|
let app = Rc::clone(&self.app);
|
||||||
|
let backend = Rc::clone(&self.backend);
|
||||||
|
|
||||||
// Setting the on_submit function
|
// Setting the on_submit function
|
||||||
self.app.on_on_calculate(move || {
|
self.app.on_on_calculate(move || {
|
||||||
// Getting the prices of the stuff
|
// Getting the prices of the stuff
|
||||||
let current_membership = app.get_current_membership();
|
let current_membership = app.get_current_membership();
|
||||||
let new_membership = app.get_new_membership();
|
let new_membership = app.get_new_membership();
|
||||||
|
let last_billing = app.get_last_billing();
|
||||||
|
|
||||||
// DEBUG
|
// Are either of these a "Select One..."
|
||||||
println!("Current Membership: {}", current_membership);
|
if current_membership == "Select One..."
|
||||||
println!("New Membership: {}", new_membership);
|
|| 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
|
// Starting our application
|
||||||
|
|
Loading…
Reference in a new issue