From ad6352d1eb91a23e0c2e3d0f334389eaa5bac60f Mon Sep 17 00:00:00 2001 From: Yung Han Khoe Date: Tue, 21 Apr 2009 17:28:05 +0000 Subject: [PATCH] fixed #10158: Matrix 2.0 - Screenshots rendering poorly --- docs/changelog/7.x.x.txt | 1 + docs/upgrades/upgrade_7.7.3-7.7.4.pl | 11 +++++++++ lib/WebGUI/Asset/MatrixListing.pm | 31 +++++++++++++++++++++++++ lib/WebGUI/Asset/Wobject/Matrix.pm | 14 +++++++++++ lib/WebGUI/i18n/English/Asset_Matrix.pm | 20 ++++++++++++++++ 5 files changed, 77 insertions(+) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 8e85e5170..ecd78bb55 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -35,6 +35,7 @@ - fixed: #10109: Matrix 2.0 - Updates to product listing by maintainer account require admin approval - fixed #10146: Thingy duplicate errors - Added Survey back button + - fixed #10158: Matrix 2.0 - Screenshots rendering poorly 7.7.3 - fixed #10094: double explanation in thread help diff --git a/docs/upgrades/upgrade_7.7.3-7.7.4.pl b/docs/upgrades/upgrade_7.7.3-7.7.4.pl index d915c26f9..4b3296e96 100644 --- a/docs/upgrades/upgrade_7.7.3-7.7.4.pl +++ b/docs/upgrades/upgrade_7.7.3-7.7.4.pl @@ -37,10 +37,21 @@ allMaintenanceSingleton($session); unsetPackageFlags($session); installThingyRecord( $session ); installPluggableTax( $session ); +addMatrixMaxScreenshotWidthHeight($session); addSurveyBackButtonColumn( $session ); finish($session); # this line required +#---------------------------------------------------------------------------- +sub addMatrixMaxScreenshotWidthHeight { + my $session = shift; + print "\tAdding maximum screenshot width and height property to the Matrix." unless $quiet; + $session->db->write("alter table Matrix add maxScreenshotWidth int(11), add maxScreenshotHeight int(11);"); + $session->db->write("update Matrix set maxScreenshotWidth = 800, maxScreenshotHeight = 600;"); + print "DONE!\n" unless $quiet; +} + + #---------------------------------------------------------------------------- sub unsetPackageFlags { my $session = shift; diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm index 1f49e603b..0eed343b9 100644 --- a/lib/WebGUI/Asset/MatrixListing.pm +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -509,6 +509,34 @@ sub processPropertiesFromFormPost { } $self->update({score => $score}); + if ( $self->get('screenshots') ) { + my $fileObject = WebGUI::Form::File->new($self->session,{ value=>$self->get('screenshots') }); + my $storage = $fileObject->getStorageLocation; + my @files; + @files = @{ $storage->getFiles } if (defined $storage); + foreach my $file (@files) { + unless ($file =~ m/^thumb-/){ + my ($resizeWidth,$resizeHeight); + my ($width, $height) = $storage->getSizeInPixels($file); + my $maxWidth = $self->getParent->get('maxScreenshotWidth'); + my $maxHeight = $self->getParent->get('maxScreenshotHeight'); + if ($width > $maxWidth){ + my $newHeight = $height * ($maxWidth / $width); + if ($newHeight > $maxHeight){ + # Heigth requires more resizing so use maxHeight + $storage->resize($file, 0, $maxHeight); + } + else{ + $storage->resize($file, $maxWidth); + } + } + elsif($height > $maxHeight){ + $storage->resize($file, 0, $maxHeight); + } + } + } + } + $self->requestAutoCommit; return undef; } @@ -979,6 +1007,7 @@ sub www_getScreenshots { @files = @{ $storage->getFiles } if (defined $storage); foreach my $file (@files) { unless ($file =~ m/^thumb-/){ + my ($width, $height) = $storage->getSizeInPixels($file); my $thumb = 'thumb-'.$file; $xml .= " @@ -987,6 +1016,8 @@ sub www_getScreenshots { ".$storage->getUrl($file)." 5 ".$storage->getUrl($thumb)." + ".$width." + ".$height." "; } diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index 99d66dc60..eeb8d2ad7 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -194,6 +194,20 @@ sub definition { hoverHelp =>$i18n->get('compare color yes description'), label =>$i18n->get('compare color yes label'), }, + maxScreenshotWidth=>{ + fieldType =>"integer", + tab =>"display", + defaultValue =>"800", + hoverHelp =>$i18n->get('max screenshot width description'), + label =>$i18n->get('max screenshot width label'), + }, + maxScreenshotHeight=>{ + fieldType =>"integer", + tab =>"display", + defaultValue =>"600", + hoverHelp =>$i18n->get('max screenshot height description'), + label =>$i18n->get('max screenshot height label'), + }, categories=>{ fieldType =>"textarea", tab =>"properties", diff --git a/lib/WebGUI/i18n/English/Asset_Matrix.pm b/lib/WebGUI/i18n/English/Asset_Matrix.pm index 4386e0412..3746c3cf1 100644 --- a/lib/WebGUI/i18n/English/Asset_Matrix.pm +++ b/lib/WebGUI/i18n/English/Asset_Matrix.pm @@ -387,6 +387,16 @@ listing,|, lastUpdated => 0, }, + 'max screenshot width description' => { + message => q|Select the maximum width of the screenshots in this matrix. Screenshots that are larger will be resized.|, + lastUpdated => 0, + }, + + 'max screenshot height description' => { + message => q|Select the maximum height of the screenshots in this matrix. Screenshots that are larger will be resized.|, + lastUpdated => 0, + }, + 'compare color no description' => { message => q|Select the color for compare result 'No' in the compare display.|, lastUpdated => 0, @@ -528,6 +538,16 @@ to increase performance. How long should we cache them?|, lastUpdated => 0, }, + 'max screenshot height label' => { + message => q|Maximum Screenshot Height|, + lastUpdated => 0, + }, + + 'max screenshot width label' => { + message => q|Maximum Screenshot Width|, + lastUpdated => 0, + }, + 'sort by score label' => { message => q|Score|, lastUpdated => 0,