Set the FormPage property descriptors list. This allows FormPage::Validate() to do most of the validation work. Treat "00" the same as "0".
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/web/Activity.pl | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/testbot/web/Activity.pl b/testbot/web/Activity.pl index 9444779433..272215f958 100644 --- a/testbot/web/Activity.pl +++ b/testbot/web/Activity.pl @@ -27,28 +27,35 @@ our @ISA = qw(ObjectModel::CGI::FreeFormPage); use POSIX qw(strftime); use URI::Escape;
+use ObjectModel::BasicPropertyDescriptor; use WineTestBot::Config; use WineTestBot::Activity; use WineTestBot::Log; # For Elapsed() use WineTestBot::Utils; use WineTestBot::VMs;
- my $HOURS_DEFAULT = 12;
+ sub _initialize($$$) { my ($self, $Request, $RequiredRole) = @_;
$self->{start} = Time(); - $self->{hours} = $self->GetParam("Hours"); - if (!defined $self->{hours} or $self->{hours} !~ /^\d{1,3}$/) - { - $self->{hours} = $HOURS_DEFAULT; - } - + my @PropertyDescriptors = ( + CreateBasicPropertyDescriptor("Hours", "Hours", !1, 1, "N", 3), + ); $self->SUPER::_initialize($Request, $RequiredRole); $self->{Method} = "get"; + + if (!$self->GetParam("Hours") or !$self->Validate() or + !int($self->GetParam("Hours"))) # 00 case! + { + # This page always needs a valid value to calculate the cutoff. So just + # replace invalid values with the default (no error message is shown + # either). + $self->SetParam("Hours", $HOURS_DEFAULT); + } }
sub GetPageTitle($$) @@ -61,7 +68,8 @@ sub GetPageTitle($$) sub GeneratePage($) { my ($self) = @_; - if ($self->{hours} and $self->{hours} <= $HOURS_DEFAULT) + + if ($self->GetParam("Hours") <= $HOURS_DEFAULT) { $self->{Request}->headers_out->add("Refresh", "60"); } @@ -101,7 +109,7 @@ sub GenerateBody($)
# Generate a custom form to let the user specify the Hours field. $self->GenerateFormStart(); - print "<div class='ItemProperty'><label>Analyze the activity of the past <div class='ItemValue'><input type='text' name='Hours' maxlength='3' size='3' value='$self->{hours}'/></div> hours.</label></div>\n"; + print "<div class='ItemProperty'><label>Analyze the activity of the past <div class='ItemValue'><input type='text' name='Hours' maxlength='3' size='3' value='", $self->GetParam("Hours"), "'/></div> hours.</label></div>\n"; $self->GenerateFormEnd();
print "<h1>${ProjectName} Test Bot activity</h1>\n"; @@ -148,7 +156,7 @@ EOF ### Generate the HTML table with the newest record first
print "<tbody>\n"; - my ($Activity, $_Counters) = GetActivity($VMs, $self->{hours} * 3600); + my ($Activity, $_Counters) = GetActivity($VMs, $self->GetParam("Hours") * 3600); for (my $Index = @$Activity; $Index--; ) { my $Group = $Activity->[$Index];