Merge #484: gui: check rescan start date
458075357a0d66422161e20cd812d9eb970121e0 gui: check rescan start date (edouard)
Pull request description:
ACKs for top commit:
edouardparis:
Self-ACK 458075357a0d66422161e20cd812d9eb970121e0
Tree-SHA512: 73a245fe8dd2fa6c739d0a802aa97238f401d8a024d3c97198382fc811ba1e07dafa13cb2774d8d2672ae016bf8df4381c7f9e98455139e146a3cf63e5fdda35
This commit is contained in:
commit
80c5a5f518
@ -251,6 +251,7 @@ pub struct RescanSetting {
|
||||
year: form::Value<String>,
|
||||
month: form::Value<String>,
|
||||
day: form::Value<String>,
|
||||
invalid_date: bool,
|
||||
}
|
||||
|
||||
impl From<RescanSetting> for Box<dyn Setting> {
|
||||
@ -292,6 +293,7 @@ impl Setting for RescanSetting {
|
||||
}
|
||||
}
|
||||
view::SettingsEditMessage::FieldEdited(field, value) => {
|
||||
self.invalid_date = false;
|
||||
if !self.processing && (value.is_empty() || u32::from_str(&value).is_ok()) {
|
||||
match field {
|
||||
"rescan_year" => self.year.value = value,
|
||||
@ -302,12 +304,22 @@ impl Setting for RescanSetting {
|
||||
}
|
||||
}
|
||||
view::SettingsEditMessage::Confirm => {
|
||||
let date_time = NaiveDate::from_ymd_opt(
|
||||
let date_time = if let Some(date) = NaiveDate::from_ymd_opt(
|
||||
i32::from_str(&self.year.value).unwrap_or(1),
|
||||
u32::from_str(&self.month.value).unwrap_or(1),
|
||||
u32::from_str(&self.day.value).unwrap_or(1),
|
||||
)
|
||||
.unwrap();
|
||||
) {
|
||||
if date < NaiveDate::from_str("2009-01-03").unwrap() {
|
||||
self.invalid_date = true;
|
||||
return Command::none();
|
||||
} else {
|
||||
self.invalid_date = false;
|
||||
date
|
||||
}
|
||||
} else {
|
||||
self.invalid_date = true;
|
||||
return Command::none();
|
||||
};
|
||||
let t = date_time.and_hms_opt(0, 0, 0).unwrap().timestamp() as u32;
|
||||
self.processing = true;
|
||||
info!("Asking deamon to rescan with timestamp: {}", t);
|
||||
@ -329,6 +341,7 @@ impl Setting for RescanSetting {
|
||||
self.success,
|
||||
self.processing,
|
||||
can_edit,
|
||||
self.invalid_date,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -414,6 +414,7 @@ pub fn is_running_label<'a, T: 'a>(is_running: Option<bool>) -> Container<'a, T>
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn rescan<'a>(
|
||||
year: &form::Value<String>,
|
||||
month: &form::Value<String>,
|
||||
@ -422,6 +423,7 @@ pub fn rescan<'a>(
|
||||
success: bool,
|
||||
processing: bool,
|
||||
can_edit: bool,
|
||||
invalid_date: bool,
|
||||
) -> Element<'a, SettingsEditMessage> {
|
||||
card::simple(Container::new(
|
||||
Column::new()
|
||||
@ -479,8 +481,17 @@ pub fn rescan<'a>(
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(10),
|
||||
)
|
||||
.push_maybe(if invalid_date {
|
||||
Some(
|
||||
p1_regular("Provided date is either invalid or anterior to the genesis block's timestamp.")
|
||||
.style(color::RED),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
.push(
|
||||
if can_edit
|
||||
&& !invalid_date
|
||||
&& !processing
|
||||
&& (is_ok_and(&u32::from_str(&year.value), |&v| v > 0)
|
||||
&& is_ok_and(&u32::from_str(&month.value), |&v| {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user