Instead of being called for every row, DisplayProperty() is now called only once and the result is stored in the corresponding column descriptor. This also allows passing extra information such as the column index to Generate{Header,Data}View(). And this allows GenerateList() to iterate only on the properties that are actually being displayed.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- .../lib/ObjectModel/CGI/CollectionBlock.pm | 81 +++++++++++-------- testbot/web/JobDetails.pl | 14 ++-- testbot/web/PatchesList.pl | 6 +- testbot/web/admin/UsersList.pl | 6 +- testbot/web/index.pl | 12 +-- 5 files changed, 68 insertions(+), 51 deletions(-)
diff --git a/testbot/lib/ObjectModel/CGI/CollectionBlock.pm b/testbot/lib/ObjectModel/CGI/CollectionBlock.pm index 03f1d18cd..14e3cfe54 100644 --- a/testbot/lib/ObjectModel/CGI/CollectionBlock.pm +++ b/testbot/lib/ObjectModel/CGI/CollectionBlock.pm @@ -227,6 +227,20 @@ sub GetDetailsLink($$)
Generates an HTML snippet for the column title.
+The Col parameter describes the column to generate the header for. +It contains the following information: +=over 12 +=item Descriptor +The corresponding PropertyDescriptor object. + +=item Display +The value returned by DisplayProperty(), normally "ro". + +=item Index +The index of the column (see $Row->{Cols}). + +=back + The Row parameter contains the following information: =over 12
@@ -234,6 +248,10 @@ The Row parameter contains the following information: The list of item properties, including those that DisplayProperty() says should be hidden.
+=item Cols +The collection block's list of columns. This excludes any hidden property. +The following relation holds: $Row->{Cols}->[$Col->{Index}] == $Col + =item DetailsPage The base link to the item details page if any. See GetDetailsPage().
@@ -253,9 +271,9 @@ The total number of rows (excluding the header).
sub GenerateHeaderView($$$) { - my ($self, $_Row, $PropertyDescriptor) = @_; + my ($self, $_Row, $Col) = @_;
- print $self->escapeHTML($PropertyDescriptor->GetDisplayName()); + print $self->escapeHTML($Col->{Descriptor}->GetDisplayName()); }
=pod @@ -266,8 +284,8 @@ sub GenerateHeaderView($$$) Generates an HTML snippet representing the property value in a user-readable form.
-The Row parameter contains the same information as for GenerateHeaderView() -plus: +See GenerateHeaderView() for a description of the Row and Col parameters. +The Row parameter has the following extra fields: =over 12
=item Row @@ -286,11 +304,11 @@ passing the row to GetDetailsLink().
sub GenerateDataView($$$) { - my ($self, $Row, $PropertyDescriptor) = @_; + my ($self, $Row, $Col) = @_;
- my $PropertyName = $PropertyDescriptor->GetName(); + my $PropertyName = $Col->{Descriptor}->GetName(); my $Value = $Row->{Item}->$PropertyName; - GenerateValueHTML($self, $PropertyDescriptor, $Value); + GenerateValueHTML($self, $Col->{Descriptor}, $Value); }
@@ -317,10 +335,10 @@ sub GenerateFormStart($)
sub GenerateHeaderCell($$$) { - my ($self, $Row, $PropertyDescriptor) = @_; + my ($self, $Row, $Col) = @_;
print "<th>"; - $self->GenerateHeaderView($Row, $PropertyDescriptor); + $self->GenerateHeaderView($Row, $Col); print "</th>\n"; }
@@ -336,12 +354,9 @@ sub GenerateHeaderRow($$) GenerateMasterCheckbox("block$self->{Unique}"); print "</th>\n"; } - foreach my $PropertyDescriptor (@{$Row->{PropertyDescriptors}}) + foreach my $Col (@{$Row->{Cols}}) { - if ($self->DisplayProperty($PropertyDescriptor)) - { - $self->GenerateHeaderCell($Row, $PropertyDescriptor); - } + $self->GenerateHeaderCell($Row, $Col); } print "</tr>\n"; } @@ -356,16 +371,16 @@ sub SelName($$)
sub GenerateDataCell($$$) { - my ($self, $Row, $PropertyDescriptor) = @_; + my ($self, $Row, $Col) = @_;
print "<td>"; my $CloseLink; - if ($Row->{DetailsPage} and $PropertyDescriptor->GetIsKey()) + if ($Row->{DetailsPage} and $Col->{Descriptor}->GetIsKey()) { print "<a href='", $self->escapeHTML($self->GetDetailsLink($Row)), "'>"; $CloseLink = "</a>"; } - $self->GenerateDataView($Row, $PropertyDescriptor); + $self->GenerateDataView($Row, $Col); print "$CloseLink</td>\n"; }
@@ -380,12 +395,9 @@ sub GenerateDataRow($$) print "<td><input name='", $self->SelName($Row->{Item}->GetKey()), "' type='checkbox' cbgroup='block$self->{Unique}'/></td>\n"; } - foreach my $PropertyDescriptor (@{$Row->{PropertyDescriptors}}) + foreach my $Col (@{$Row->{Cols}}) { - if ($self->DisplayProperty($PropertyDescriptor)) - { - $self->GenerateDataCell($Row, $PropertyDescriptor); - } + $self->GenerateDataCell($Row, $Col); } print "</tr>\n"; } @@ -403,18 +415,22 @@ sub GenerateList($) my $Collection = $self->{Collection}; my $PropertyDescriptors = $Collection->GetPropertyDescriptors();
+ my $ColIndex = 0; + my (@Cols, $HasDT); + foreach my $PropertyDescriptor (@$PropertyDescriptors) + { + my $Display = $self->DisplayProperty($PropertyDescriptor); + next if (!$Display); + push @Cols, {Descriptor => $PropertyDescriptor, + Display => $Display, + Index => $ColIndex++}; + $HasDT ||= ($PropertyDescriptor->GetClass() eq "Basic" and + $PropertyDescriptor->GetType() eq "DT"); + } my $Items = $self->{Collection}->GetSortedItems(); - if (@$Items != 0) + if ($HasDT and @$Items != 0) { - foreach my $PropertyDescriptor (@$PropertyDescriptors) - { - if ($PropertyDescriptor->GetClass() eq "Basic" and - $PropertyDescriptor->GetType() eq "DT") - { - $self->{EnclosingPage}->GenerateImportJS(GetDateTimeJSFile()); - last; - } - } + $self->{EnclosingPage}->GenerateImportJS(GetDateTimeJSFile()); }
print "<div class='CollectionBlock'>\n"; @@ -427,6 +443,7 @@ sub GenerateList($) print "<thead>\n"; my $Row = { PropertyDescriptors => $PropertyDescriptors, + Cols => @Cols, DetailsPage => $self->GetDetailsPage(), ItemActions => $self->{RW} ? $self->GetItemActions() : [], Row => 0, # 0 for the header ---> 1 for the first line diff --git a/testbot/web/JobDetails.pl b/testbot/web/JobDetails.pl index e39df41b5..591a47ee9 100644 --- a/testbot/web/JobDetails.pl +++ b/testbot/web/JobDetails.pl @@ -60,9 +60,9 @@ sub DisplayProperty($$)
sub GenerateHeaderView($$$) { - my ($self, $Row, $PropertyDescriptor) = @_; + my ($self, $Row, $Col) = @_;
- my $PropertyName = $PropertyDescriptor->GetName(); + my $PropertyName = $Col->{Descriptor}->GetName(); if ($PropertyName eq "CmdLineArg") { print "Arguments / <span class='MissionHeader'>Missions</span>"; @@ -73,16 +73,16 @@ sub GenerateHeaderView($$$) } else { - $self->SUPER::GenerateHeaderView($Row, $PropertyDescriptor); + $self->SUPER::GenerateHeaderView($Row, $Col); } }
sub GenerateDataView($$$) { - my ($self, $Row, $PropertyDescriptor) = @_; + my ($self, $Row, $Col) = @_;
my $StepTask = $Row->{Item}; - my $PropertyName = $PropertyDescriptor->GetName(); + my $PropertyName = $Col->{Descriptor}->GetName(); if ($PropertyName eq "VM") { print "<a href='#k", $self->escapeHTML($Row->{Item}->GetKey()), "'>"; @@ -103,7 +103,7 @@ sub GenerateDataView($$$) } else { - $self->SUPER::GenerateDataView($Row, $PropertyDescriptor); + $self->SUPER::GenerateDataView($Row, $Col); } } elsif ($PropertyName eq "CmdLineArg") @@ -144,7 +144,7 @@ sub GenerateDataView($$$) } else { - $self->SUPER::GenerateDataView($Row, $PropertyDescriptor); + $self->SUPER::GenerateDataView($Row, $Col); } }
diff --git a/testbot/web/PatchesList.pl b/testbot/web/PatchesList.pl index a1c5171df..30cfc7547 100644 --- a/testbot/web/PatchesList.pl +++ b/testbot/web/PatchesList.pl @@ -46,9 +46,9 @@ sub DisplayProperty($$)
sub GenerateDataView($$$) { - my ($self, $Row, $PropertyDescriptor) = @_; + my ($self, $Row, $Col) = @_;
- if ($PropertyDescriptor->GetName() eq "Disposition" and + if ($Col->{Descriptor}->GetName() eq "Disposition" and $Row->{Item}->Disposition =~ /job ([0-9]+)$/) { my $JobId = $1; @@ -56,7 +56,7 @@ sub GenerateDataView($$$) } else { - $self->SUPER::GenerateDataView($Row, $PropertyDescriptor); + $self->SUPER::GenerateDataView($Row, $Col); } }
diff --git a/testbot/web/admin/UsersList.pl b/testbot/web/admin/UsersList.pl index ec6d2822e..5f9f47b46 100644 --- a/testbot/web/admin/UsersList.pl +++ b/testbot/web/admin/UsersList.pl @@ -47,9 +47,9 @@ sub DisplayProperty($$)
sub GenerateDataView($$$) { - my ($self, $Row, $PropertyDescriptor) = @_; + my ($self, $Row, $Col) = @_;
- if ($PropertyDescriptor->GetName() eq "Status") + if ($Col->{Descriptor}->GetName() eq "Status") { my $User = $Row->{Item}; my $Status = $User->Status; @@ -87,7 +87,7 @@ sub GenerateDataView($$$) } else { - $self->SUPER::GenerateDataView($Row, $PropertyDescriptor); + $self->SUPER::GenerateDataView($Row, $Col); } }
diff --git a/testbot/web/index.pl b/testbot/web/index.pl index 1c506c9b1..331ee85ea 100644 --- a/testbot/web/index.pl +++ b/testbot/web/index.pl @@ -51,9 +51,9 @@ sub DisplayProperty($$)
sub GenerateHeaderView($$$) { - my ($self, $Row, $PropertyDescriptor) = @_; + my ($self, $Row, $Col) = @_;
- my $PropertyName = $PropertyDescriptor->GetName(); + my $PropertyName = $Col->{Descriptor}->GetName(); if ($PropertyName eq "Priority") { print "<a class='title' title='Higher values indicate a lower priority'>Nice</a>"; @@ -64,16 +64,16 @@ sub GenerateHeaderView($$$) } else { - $self->SUPER::GenerateHeaderView($Row, $PropertyDescriptor); + $self->SUPER::GenerateHeaderView($Row, $Col); } }
sub GenerateDataView($$$) { - my ($self, $Row, $PropertyDescriptor) = @_; + my ($self, $Row, $Col) = @_;
my $Job = $Row->{Item}; - my $PropertyName = $PropertyDescriptor->GetName(); + my $PropertyName = $Col->{Descriptor}->GetName(); if ($PropertyName eq "User") { if (defined $Job->Patch and defined $Job->Patch->FromName and @@ -166,7 +166,7 @@ sub GenerateDataView($$$) } else { - $self->SUPER::GenerateDataView($Row, $PropertyDescriptor); + $self->SUPER::GenerateDataView($Row, $Col); } }