Added buttons to the GalleryAlbum edit view so users can rotate photos by 90 deg (RFE 620).

This commit is contained in:
kimd 2010-04-19 22:24:09 +02:00
parent 1df580f13f
commit dd72159db0
10 changed files with 338 additions and 16 deletions

View file

@ -1,3 +1,6 @@
7.9.3
- added #620: Add buttons to the GalleryAlbum edit view so users can rotate photos by 90 deg
7.9.2
- fixed #11507: Spectre Reports Wrong Workflow Count
- added #11412: Additional navigation in Gallery Photo View

View file

@ -390,6 +390,29 @@ sub processPropertiesFromFormPost {
return undef;
}
#----------------------------------------------------------------------------
=head2 rotate ( angle )
Rotate the photo clockwise by the specified C<angle> (in degrees) including the
thumbnail and all resolutions.
=cut
sub rotate {
my $self = shift;
my $angle = shift;
my $storage = $self->getStorageLocation;
# Rotate all files in the storage
foreach my $file (@{$storage->getFiles}) {
$storage->rotate($file, $angle);
}
# Re-create thumbnail
$self->generateThumbnail;
}
#----------------------------------------------------------------------------
=head2 setFile ( filename )

View file

@ -22,6 +22,7 @@ use WebGUI::International;
use WebGUI::Utility;
use WebGUI::HTML;
use WebGUI::ProgressBar;
use WebGUI::Storage;
use Archive::Any;
@ -992,6 +993,7 @@ sub www_addArchive {
$var->{ form_start }
= WebGUI::Form::formHeader( $session, {
action => $self->getUrl('func=addArchiveSave'),
name => 'name="galleryAlbumAddArchive"',
});
$var->{ form_end }
= WebGUI::Form::formFooter( $session );
@ -1257,6 +1259,43 @@ sub www_edit {
$session->errorHandler->error("Couldn't demote asset '$assetId' because we couldn't instantiate it.");
}
}
# Rotate to the left
elsif ( grep { $_ =~ /^rotateLeft-(.{22})$/ } $form->param ) {
my $assetId = ( grep { $_ =~ /^rotateLeft-(.{22})$/ } $form->param )[0];
$assetId =~ s/^rotateLeft-//;
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
if ( $asset ) {
# Add revision and create a new version tag by doing so
my $newRevision = $asset->addRevision;
# Rotate photo (i.e. all attached image files) by 90° CCW
$newRevision->rotate(-90);
# Auto-commit version tag
$newRevision->requestAutoCommit;
}
else {
$session->log->error("Couldn't rotate asset '$assetId' because we couldn't instantiate it.");
}
}
# Rotate to the right
elsif ( grep { $_ =~ /^rotateRight-(.{22})$/ } $form->param ) {
my $assetId = ( grep { $_ =~ /^rotateRight-(.{22})$/ } $form->param )[0];
$assetId =~ s/^rotateRight-//;
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
if ( $asset ) {
# Add revision and create a new version tag by doing so
my $newRevision = $asset->addRevision;
# Rotate photo (i.e. all attached image files) by 90° CW
$newRevision->rotate(90);
# Auto-commit version tag
$newRevision->requestAutoCommit;
}
else {
$session->log->error("Couldn't rotate asset '$assetId' because we couldn't instantiate it.");
}
}
# Delete the file
elsif ( grep { $_ =~ /^delete-(.{22})$/ } $form->param ) {
my $assetId = ( grep { $_ =~ /^delete-(.{22})$/ } $form->param )[0];
$assetId =~ s/^delete-//;
@ -1276,6 +1315,7 @@ sub www_edit {
$var->{ form_start }
= WebGUI::Form::formHeader( $session, {
action => $self->getParent->getUrl('func=editSave;assetId=new;class='.__PACKAGE__),
extras => 'name="galleryAlbumAdd"',
})
. WebGUI::Form::hidden( $session, {
name => "ownerUserId",
@ -1294,6 +1334,7 @@ sub www_edit {
$var->{ form_start }
= WebGUI::Form::formHeader( $session, {
action => $self->getUrl('func=edit'),
extras => 'name="galleryAlbumEdit"',
})
. WebGUI::Form::hidden( $session, {
name => "ownerUserId",
@ -1355,23 +1396,44 @@ sub www_edit {
id => "assetIdThumbnail_$file->{ assetId }",
} );
# Raw HTML here to provide proper value for the image
my $promoteLabel = $i18n->get( 'Move Up', 'Icon' );
$file->{ form_promote }
= qq{<input type="submit" name="promote-$file->{assetId}" class="promote" value="$promoteLabel" />}
;
= WebGUI::Form::submit( $session, {
name => "promote-$file->{assetId}",
value => $i18n->get( 'Move Up', 'Icon' ),
class => "promote",
});
my $demoteLabel = $i18n->get( 'Move Down', 'Icon' );
$file->{ form_demote }
= qq{<input type="submit" name="demote-$file->{assetId}" class="demote" value="$demoteLabel" />}
;
= WebGUI::Form::submit( $session, {
name => "demote-$file->{assetId}",
value => $i18n->get( 'Move Down', 'Icon' ),
class => "demote",
});
my $deleteConfirm = $i18n->get( 'template delete message', 'Asset_Photo' );
my $deleteLabel = $i18n->get( 'Delete', 'Icon' );
$file->{ form_delete }
= qq{<input type="submit" name="delete-$file->{assetId}" class="delete" value="$deleteLabel" }
. qq{ onclick="return confirm('$deleteConfirm')" />}
;
= WebGUI::Form::submit( $session, {
name => "delete-$file->{assetId}",
value => $i18n->get( 'Delete', 'Icon' ),
class => "delete",
extras => "onclick=\"return confirm('$deleteConfirm')\"",
});
$file->{ form_rotateLeft }
= WebGUI::Form::submit( $session, {
name => "rotateLeft-$file->{assetId}",
value => $i18n->get( 'rotate left' ),
class => "rotateLeft",
});
$file->{ form_rotateRight }
= WebGUI::Form::submit( $session, {
name => "rotateRight-$file->{assetId}",
value => $i18n->get( 'rotate right' ),
class => "rotateRight",
});
$file->{ form_synopsis }
= WebGUI::Form::HTMLArea( $session, {

View file

@ -331,6 +331,14 @@ our $HELP = {
name => 'form_demote',
description => 'helpvar form_demote',
},
{
name => 'form_rotateLeft',
description => 'helpvar form_rotateLeft',
},
{
name => 'form_rotateRight',
description => 'helpvar form_rotateRight',
},
{
name => 'form_synopsis',
description => 'helpvar form_synopsis',

View file

@ -23,6 +23,18 @@ our $I18N = {
context => "Label for Save button",
},
'rotate left' => {
message => "90&deg; CCW",
lastUpdated => 1270582436,
context => "Label for rotate left button",
},
'rotate right' => {
message => "90&deg; CW",
lastUpdated => 1270582436,
context => "Label for rotate right button",
},
'save message' => {
message => 'Album settings saved.',
lastUpdated => 0,
@ -38,12 +50,11 @@ our $I18N = {
lastUpdated => 0,
},
'delete message' => {
message => 'Album has been deleted. <a href="%s">Return to Gallery</a>',
lastUpdated => 0,
},
'help common title' => {
message => 'Gallery Album Variables (Common)',
lastUpdated => 0,
@ -524,6 +535,18 @@ our $I18N = {
lastUpdated => 1213631346,
context => q{Description of template variable},
},
'helpvar form_rotateLeft' => {
message => q{A button to rotate the photo by 90&deg; counter clockwise.},
lastUpdated => 1270582436,
context => q{Description of template variable},
},
'helpvar form_rotateRight' => {
message => q{A button to rotate the photo by 90&deg; clockwise.},
lastUpdated => 1270582436,
context => q{Description of template variable},
},
'helpvar form_delete' => {
message => q{A button to delete the image.},

View file

@ -0,0 +1,109 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../../lib";
# The goal of this test is to confirm correct rotation of all files attached
# to a Photo asset after calling the rotate method.
# We will only do a quick check by comparing dimensions of all attached files
# after rotation. Checks on individual pixels are alreay done in testing code
# for WebGUI::Storage
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use Test::Deep;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
# Name version tag and make sure it gets cleaned up
$versionTag->set({name=>"Photo rotation test"});
addToCleanup($versionTag);
# Create gallery and a single album
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
imageResolutions => "1024x768",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::GalleryAlbum",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
# Create single photo inside the album
my $photo
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
# Attach image file to photo asset (setFile also makes download versions)
$photo->setFile( WebGUI::Test->getTestCollateralPath("rotation_test.png") );
my $storage = $photo->getStorageLocation;
# Commit all changes
$versionTag->commit;
#----------------------------------------------------------------------------
plan tests => 2;
#----------------------------------------------------------------------------
# Save dimensions of images
my @oldDims;
foreach my $file ( @{$storage->getFiles('showAll') } ) {
push ( @oldDims, [ $storage->getSizeInPixels($file) ] ) unless $file eq '.';
}
# Rotate photo (i.e. all attached images) by 90° CW
$photo->rotate(90);
# Save new dimensions of images in reverse order
my @newDims;
foreach my $file ( @{$storage->getFiles('showAll') } ) {
push ( @newDims, [ reverse($storage->getSizeInPixels($file)) ] ) unless $file eq '.';
}
# Compare dimensions
cmp_deeply( \@oldDims, \@newDims, "Check if all files were rotated by 90° CW" );
# Rotate photo (i.e. all attached images) by 90° CCW
$photo->rotate(-90);
# Save new dimensions of images in original order
my @newerDims;
foreach my $file ( @{$storage->getFiles('showAll') } ) {
push ( @newerDims, [ $storage->getSizeInPixels($file) ] ) unless $file eq '.';
}
# Compare dimensions
cmp_deeply( \@oldDims, \@newerDims, "Check if all files were rotated by 90° CCW" );

View file

@ -9,9 +9,10 @@
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Test editing a GalleryAlbum from the web interface
#
#
# Test editing a GalleryAlbum from the web interface. Currently, it
# is tested whether...
# - users can add albums.
# - photos can be rotated.
use FindBin;
use strict;
@ -73,7 +74,7 @@ if ( !$mech->success ) {
plan skip_all => "Cannot load URL '$baseUrl'. Will not test.";
}
plan tests => 6; # Increment this number for each test you create
plan tests => 11; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Visitor user cannot add albums
@ -112,6 +113,65 @@ $mech->content_contains(
my $album = WebGUI::Asset->newByDynamicClass( $session, $gallery->getAlbumIds->[0] );
cmp_deeply( $properties, subhashof( $album->get ), "Properties from edit form are set correctly" );
#----------------------------------------------------------------------------
# Photos can be rotated using the respective form buttons
# Use album from previous test
my $album = $gallery->getFirstChild;
# Add single photo to this album. No need to commit since auto-commit was
# enabled for the Gallery asset.
my $photo
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
});
my $photoId = $photo->getId;
# Attach image file to photo asset (setFile also makes download versions)
$photo->setFile( WebGUI::Test->getTestCollateralPath("rotation_test.png") );
my $storage = $photo->getStorageLocation;
# Save dimensions of images
my @oldDims;
foreach my $file ( @{$storage->getFiles('showAll') } ) {
push ( @oldDims, [ $storage->getSizeInPixels($file) ] ) unless $file eq '.';
}
# Rotate photo (i.e. all attached images) by 90° CW
$mech->get_ok( $baseUrl . $album->getUrl('func=edit'), 'Request GalleryAlbum edit screen' );
# Select the proper form
$mech->form_name( 'galleryAlbumEdit' );
# Try to click the "rotate right" button
$mech->submit_form_ok( {
button => 'rotateRight-' . $photoId,
}, 'Request rotation of photo by 90° CW' );
# Save new dimensions of images in reverse order
my @newDims;
foreach my $file ( @{$storage->getFiles('showAll') } ) {
push ( @newDims, [ reverse($storage->getSizeInPixels($file)) ] ) unless $file eq '.';
}
# Compare dimensions
cmp_deeply( \@oldDims, \@newDims, "Check if all files were rotated by 90° CW" );
# Rotate photo (i.e. all attached images) by 90° CCW. No need to request the edit view since
# an updated view was returned after the last form submittal.
$mech->form_name( 'galleryAlbumEdit' );
# Try to click the "rotate left" button
$mech->submit_form_ok( {
button => 'rotateLeft-' . $photoId,
}, 'Request rotation of photo by 90° CCW' );
# Save new dimensions of images in original order
my @newerDims;
foreach my $file ( @{$storage->getFiles('showAll') } ) {
push ( @newerDims, [ $storage->getSizeInPixels($file) ] ) unless $file eq '.';
}
# Compare dimensions
cmp_deeply( \@oldDims, \@newerDims, "Check if all files were rotated by 90° CCW" );
#----------------------------------------------------------------------------
# getMechLogin( baseUrl, WebGUI::User, "identifier" )
# Returns a Test::WWW::Mechanize session after logging in the given user using

View file

@ -65,7 +65,7 @@ my $extensionTests = [
},
];
plan tests => 49 + scalar @{ $extensionTests }; # increment this value for each test you create
plan tests => 54 + scalar @{ $extensionTests }; # increment this value for each test you create
my $session = WebGUI::Test->session;
@ -277,6 +277,40 @@ foreach my $testImage (@testImages) {
$session->setting->set('maxImageSize', $origMaxImageSize );
####################################################
#
# rotate
#
####################################################
my $rotateTest = WebGUI::Storage->create( $session );
WebGUI::Test->storagesToDelete($rotateTest);
# Add test image to the storage
ok( $rotateTest->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath("rotation_test.png")), "Can add test image to storage" );
# Rotate test image by 90° CW
my $file = $rotateTest->getFiles->[0];
$rotateTest->rotate($file, 90);
# Check dimensions
cmp_bag( [$rotateTest->getSizeInPixels( $file )], [2,3], "Check size of photo after rotating 90° CW" );
# Check pixels
my $image = Image::Magick->new;
$image->Read( $rotateTest->getPath($file) );
is( $image->GetPixel(x=>2, y=>0), 0, "Pixel at location [2,0] should be black" );
# Rotate test image by 90° CCW
my $file = $rotateTest->getFiles->[0];
$rotateTest->rotate($file, -90);
# Check dimensions
cmp_bag( [$rotateTest->getSizeInPixels( $file )], [3,2], "Check size of photo after rotating 90° CCW" );
# Check pixels
$image = Image::Magick->new;
$image->Read( $rotateTest->getPath($file) );
is( $image->GetPixel(x=>0, y=>0), 0, "Pixel at location [0,0] should be black" );
TODO: {
local $TODO = "Methods that need to be tested";
ok(0, 'resize');

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B