From 20aff0463398c7f26824e4b2887d8ac5ad4ef460 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 11 Feb 2010 17:43:26 -0800 Subject: [PATCH] Update Matrix and MatrixListing for Moose. Needs the Comments Role in order to check tests further. --- lib/WebGUI/Asset/MatrixListing.pm | 195 ++++++----- lib/WebGUI/Asset/Wobject/Matrix.pm | 544 ++++++++++++++--------------- 2 files changed, 367 insertions(+), 372 deletions(-) diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm index 7539558bc..adaf4121c 100644 --- a/lib/WebGUI/Asset/MatrixListing.pm +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -16,10 +16,107 @@ package WebGUI::Asset::MatrixListing; use strict; use Tie::IxHash; -use Class::C3; -use base qw(WebGUI::AssetAspect::Comments WebGUI::Asset); -use WebGUI::Utility; +#use base qw(WebGUI::AssetAspect::Comments WebGUI::Asset); +use WebGUI::Definition::Asset; +extends 'WebGUI::Asset'; +aspect assetName => ['assetName', 'Asset_MatrixListing'], +aspect tableName => 'MatrixListing', +property screenshots => ( + tab => "properties", + fieldType => "image", + default => undef, + maxAttachments => 20, + label => ["screenshots label", 'Asset_MatrixListing'], + hoverHelp => ["screenshots description", 'Asset_MatrixListing'], + ); +property description => ( + tab => "properties", + fieldType => "HTMLArea", + default => undef, + label => ["description label", 'Asset_MatrixListing'], + hoverHelp => ["description description", 'Asset_MatrixListing'], + ); +property version => ( + tab => "properties", + fieldType => "text", + default => undef, + label => ["version label", 'Asset_MatrixListing'], + hoverHelp => ["version description", 'Asset_MatrixListing'], + ); +property score => ( + fieldType => 'integer', + default => 0, + noFormPost => 1, + ); +property views => ( + fieldType => 'integer', + default => 0, + noFormPost => 1, + ); +property compares => ( + fieldType => 'integer', + default => 0, + noFormPost => 1, + ); +property clicks => ( + fieldType => 'integer', + default => 0, + noFormPost => 1, + ); +property viewsLastIp => ( + fieldType => 'text', + default => undef, + noFormPost => 1, + ); +property comparesLastIp => ( + fieldType => 'text', + default => undef, + noFormPost => 1, + ); +property clicksLastIp => ( + fieldType => 'text', + default => undef, + noFormPost => 1, + ); +property maintainer => ( + tab => "properties", + fieldType => "user", + builder => '_maintainer_default', + lazy => 1, + label => ["maintainer label", 'Asset_MatrixListing'], + hoverHelp => ["maintainer description", 'Asset_MatrixListing'], + ); +sub _maintainer_default { + return shift->session->user->userId; +} +property manufacturerName => ( + tab => "properties", + fieldType => "text", + default => undef, + label => ["manufacturerName label", 'Asset_MatrixListing'], + hoverHelp => ["manufacturerName description", 'Asset_MatrixListing'] + ); +property manufacturerURL => ( + tab => "properties", + fieldType => "url", + default => undef, + label => ["manufacturerURL label", 'Asset_MatrixListing'], + hoverHelp => ["manufacturerURL description", 'Asset_MatrixListing'] + ); +property productURL => ( + tab => "properties", + fieldType => "url", + default => undef, + label => ["productURL label", 'Asset_MatrixListing'], + hoverHelp => ["productURL description", 'Asset_MatrixListing'] + ); +property lastUpdated => ( + default => sub { time() }, + noFormPost => 1, + fieldType => 'hidden', + ); +use WebGUI::Utility; =head1 NAME @@ -117,100 +214,8 @@ sub definition { tie %properties, 'Tie::IxHash'; my $i18n = WebGUI::International->new($session, "Asset_MatrixListing"); %properties = ( - screenshots => { - tab =>"properties", - fieldType =>"image", - defaultValue =>undef, - maxAttachments =>20, - label =>$i18n->get("screenshots label"), - hoverHelp =>$i18n->get("screenshots description") - }, - description => { - tab =>"properties", - fieldType =>"HTMLArea", - defaultValue =>undef, - label =>$i18n->get("description label"), - hoverHelp =>$i18n->get("description description") - }, - version => { - tab =>"properties", - fieldType =>"text", - defaultValue =>undef, - label =>$i18n->get("version label"), - hoverHelp =>$i18n->get("version description") - }, - score => { - defaultValue =>0, - autoGenerate =>0, - noFormPost =>1, - }, - views => { - defaultValue =>0, - autoGenerate =>0, - noFormPost =>1, - }, - compares => { - defaultValue =>0, - autoGenerate =>0, - noFormPost =>1, - }, - clicks => { - defaultValue =>0, - autoGenerate =>0, - noFormPost =>1, - }, - viewsLastIp => { - defaultValue =>undef, - autoGenerate =>0, - noFormPost =>1, - }, - comparesLastIp => { - defaultValue =>undef, - autoGenerate =>0, - noFormPost =>1, - }, - clicksLastIp => { - defaultValue =>undef, - autoGenerate =>0, - noFormPost =>1, - }, - maintainer => { - tab =>"properties", - fieldType =>"user", - defaultValue =>$session->user->userId, - label =>$i18n->get("maintainer label"), - hoverHelp =>$i18n->get("maintainer description") - }, - manufacturerName => { - tab =>"properties", - fieldType =>"text", - defaultValue =>undef, - label =>$i18n->get("manufacturerName label"), - hoverHelp =>$i18n->get("manufacturerName description") - }, - manufacturerURL => { - tab =>"properties", - fieldType =>"url", - defaultValue =>undef, - label =>$i18n->get("manufacturerURL label"), - hoverHelp =>$i18n->get("manufacturerURL description") - }, - productURL => { - tab =>"properties", - fieldType =>"url", - defaultValue =>undef, - label =>$i18n->get("productURL label"), - hoverHelp =>$i18n->get("productURL description") - }, - lastUpdated => { - defaultValue =>time(), - fieldType =>'hidden', - }, ); push(@{$definition}, { - assetName=>$i18n->get('assetName'), - autoGenerateForms=>1, - tableName=>'MatrixListing', className=>'WebGUI::Asset::MatrixListing', properties=>\%properties }); diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index cc9f3b83d..1c3a4f047 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -17,8 +17,218 @@ use Tie::IxHash; use JSON; use WebGUI::International; use WebGUI::Utility; +use WebGUI::Definition::Asset; +use feature ":5.10"; +extends 'WebGUI::Asset::Wobject'; +aspect assetName => ['assetName', 'Asset_Matrix']; +aspect icon => 'matrix.gif'; +aspect tableName => 'Matrix'; +property templateId => ( + fieldType => "template", + default => 'matrixtmpl000000000001', + tab => "display", + noFormPost => 0, + namespace => "Matrix", + hoverHelp => ['template description', 'Asset_Matrix'], + label => ['template label', 'Asset_Matrix'], + ); +property searchTemplateId => ( + default => "matrixtmpl000000000005", + fieldType => "template", + tab => "display", + namespace => "Matrix/Search", + hoverHelp => ['search template description', 'Asset_Matrix'], + label => ['search template label', 'Asset_Matrix'], + ); +property detailTemplateId => ( + default => "matrixtmpl000000000003", + fieldType => "template", + tab => "display", + namespace => "Matrix/Detail", + hoverHelp => ['detail template description', 'Asset_Matrix'], + label => ['detail template label', 'Asset_Matrix'], + ); +property compareTemplateId => ( + default => "matrixtmpl000000000002", + fieldType => "template", + tab => "display", + namespace => "Matrix/Compare", + hoverHelp => ['compare template description', 'Asset_Matrix'], + label => ['compare template label', 'Asset_Matrix'], + ); +property editListingTemplateId => ( + default => "matrixtmpl000000000004", + fieldType => "template", + tab => "display", + namespace => "Matrix/EditListing", + hoverHelp => ['edit listing template description', 'Asset_Matrix'], + label => ['edit listing template label', 'Asset_Matrix'], + ); +property screenshotsTemplateId => ( + default => "matrixtmpl000000000006", + fieldType => "template", + tab => "display", + namespace => "Matrix/Screenshots", + hoverHelp => ['screenshots template description', 'Asset_Matrix'], + label => ['screenshots template label', 'Asset_Matrix'], + ); +property screenshotsConfigTemplateId => ( + default => "matrixtmpl000000000007", + fieldType => "template", + tab => "display", + namespace => "Matrix/ScreenshotsConfig", + hoverHelp => ['screenshots config template description', 'Asset_Matrix'], + label => ['screenshots config template label', 'Asset_Matrix'], + ); +property defaultSort => ( + fieldType => "selectBox", + tab => "display", + options => \&_defaultSort_options, + default => "title", + hoverHelp => ['default sort description', 'Asset_Matrix'], + label => ['default sort label', 'Asset_Matrix'], + ); +sub _defaultSort_options { + my $session = shift->session; + my $i18n = WebGUI::International->new($session, 'Asset_Matrix'); + my $options = { + score => $i18n->get('sort by score label'), + title => $i18n->get('sort alpha numeric label'), + lineage => $i18n->get('sort by asset rank label'), + lastUpdated => $i18n->get('sort by last updated label'), + }; + return $options; +} +property compareColorNo => ( + fieldType => "color", + tab => "display", + default => "#ffaaaa", + hoverHelp => ['compare color no description', 'Asset_Matrix'], + label => ['compare color no label', 'Asset_Matrix'], + ); +property compareColorLimited => ( + fieldType => "color", + tab => "display", + default => "#ffffaa", + hoverHelp => ['compare color limited description', 'Asset_Matrix'], + label => ['compare color limited label', 'Asset_Matrix'], + ); +property compareColorCostsExtra => ( + fieldType => "color", + tab => "display", + default => "#ffffaa", + hoverHelp => ['compare color costs extra description', 'Asset_Matrix'], + label => ['compare color costs extra label', 'Asset_Matrix'], + ); +property compareColorFreeAddOn => ( + fieldType => "color", + tab => "display", + default => "#ffffaa", + hoverHelp => ['compare color free add on description', 'Asset_Matrix'], + label => ['compare color free add on label', 'Asset_Matrix'], + ); +property compareColorYes => ( + fieldType => "color", + tab => "display", + default => "#aaffaa", + hoverHelp => ['compare color yes description', 'Asset_Matrix'], + label => ['compare color yes label', 'Asset_Matrix'], + ); +property maxScreenshotWidth => ( + fieldType => "integer", + tab => "display", + default => "800", + hoverHelp => ['max screenshot width description', 'Asset_Matrix'], + label => ['max screenshot width label', 'Asset_Matrix'], + ); +property maxScreenshotHeight => ( + fieldType => "integer", + tab => "display", + default => "600", + hoverHelp => ['max screenshot height description', 'Asset_Matrix'], + label => ['max screenshot height label', 'Asset_Matrix'], + ); +property categories => ( + fieldType => "textarea", + tab => "properties", + builder => '_categories_builder', + lazy => 1, + hoverHelp => ['categories description', 'Asset_Matrix'], + label => ['categories label', 'Asset_Matrix'], + subtext => ['categories subtext', 'Asset_Matrix'], + ); +sub _categories_builder { + my $session = shift->session; + my $i18n = WebGUI::International->new($session, 'Asset_Matrix'); + return $i18n->get('categories default value'); +} +property maxComparisons => ( + fieldType => "integer", + tab => "properties", + default => 25, + hoverHelp => ['max comparisons description', 'Asset_Matrix'], + label => ['max comparisons label', 'Asset_Matrix'], + ); +property maxComparisonsPrivileged => ( + fieldType => "integer", + tab => "properties", + default => 10, + hoverHelp => ['max comparisons privileged description', 'Asset_Matrix'], + label => ['max comparisons privileged label', 'Asset_Matrix'], + ); +property maxComparisonsGroup => ( + fieldType => "group", + tab => "properties", + hoverHelp => ['maxgroup description', 'Asset_Matrix'], + label => ['maxgroup label', 'Asset_Matrix'], + ); +property maxComparisonsGroupInt => ( + fieldType => "integer", + tab => "properties", + default => 25, + hoverHelp => ['maxgroup per description', 'Asset_Matrix'], + label => ['maxgroup per label', 'Asset_Matrix'], + ); +property groupToAdd => ( + fieldType => "group", + tab => "security", + default => 2, + hoverHelp => ['group to add description', 'Asset_Matrix'], + label => ['group to add label', 'Asset_Matrix'], + ); +property submissionApprovalWorkflowId => ( + fieldType => "workflow", + tab => "security", + type => 'WebGUI::VersionTag', + default => "pbworkflow000000000003", + hoverHelp => ['submission approval workflow description', 'Asset_Matrix'], + label => ['submission approval workflow label', 'Asset_Matrix'], + ); +property ratingsDuration => ( + fieldType => "interval", + tab => "properties", + default => 7776000, # 3 months 3*30*24*60*60 + hoverHelp => ['ratings duration description', 'Asset_Matrix'], + label => ['ratings duration label', 'Asset_Matrix'], + ); +property statisticsCacheTimeout => ( + tab => "display", + fieldType => "interval", + default => 3600, + uiLevel => 8, + label => ["statistics cache timeout label", 'Asset_Matrix'], + hoverHelp => ["statistics cache timeout description", 'Asset_Matrix'], + ); +property listingsCacheTimeout => ( + tab => "display", + fieldType => "interval", + default => 3600, + uiLevel => 8, + label => ["listings cache timeout label", 'Asset_Matrix'], + hoverHelp => ["listings cache timeout description", 'Asset_Matrix'], + ); + use WebGUI::Asset::MatrixListing; -use base 'WebGUI::Asset::Wobject'; #---------------------------------------------------------------------------- @@ -33,7 +243,7 @@ sub canAddMatrixListing { my $user = $self->session->user; # Users in the groupToAdd group can add listings - if ( $user->isInGroup( $self->get("groupToAdd") ) ) { + if ( $user->isInGroup( $self->groupToAdd ) ) { return 1; } # Users who can edit matrix can add listings @@ -64,237 +274,16 @@ sub canEdit { return $self->canAddMatrixListing(); } else { - if ($userId eq $self->get("ownerUserId")) { + if ($userId eq $self->ownerUserId) { return 1; } my $user = WebGUI::User->new($self->session, $userId); - return $user->isInGroup($self->get("groupIdEdit")); + return $user->isInGroup($self->groupIdEdit); } } #------------------------------------------------------------------- -=head2 definition ( ) - -defines wobject properties for Matrix instances. - -=cut - -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift; - my $i18n = WebGUI::International->new($session, 'Asset_Matrix'); - - my %properties; - tie %properties, 'Tie::IxHash'; - %properties = ( - templateId =>{ - fieldType =>"template", - defaultValue =>'matrixtmpl000000000001', - tab =>"display", - noFormPost =>0, - namespace =>"Matrix", - hoverHelp =>$i18n->get('template description'), - label =>$i18n->get('template label'), - }, - searchTemplateId=>{ - defaultValue =>"matrixtmpl000000000005", - fieldType =>"template", - tab =>"display", - namespace =>"Matrix/Search", - hoverHelp =>$i18n->get('search template description'), - label =>$i18n->get('search template label'), - }, - detailTemplateId=>{ - defaultValue =>"matrixtmpl000000000003", - fieldType =>"template", - tab =>"display", - namespace =>"Matrix/Detail", - hoverHelp =>$i18n->get('detail template description'), - label =>$i18n->get('detail template label'), - }, - compareTemplateId=>{ - defaultValue =>"matrixtmpl000000000002", - fieldType =>"template", - tab =>"display", - namespace =>"Matrix/Compare", - hoverHelp =>$i18n->get('compare template description'), - label =>$i18n->get('compare template label'), - }, - editListingTemplateId=>{ - defaultValue =>"matrixtmpl000000000004", - fieldType =>"template", - tab =>"display", - namespace =>"Matrix/EditListing", - hoverHelp =>$i18n->get('edit listing template description'), - label =>$i18n->get('edit listing template label'), - }, - screenshotsTemplateId=>{ - defaultValue =>"matrixtmpl000000000006", - fieldType =>"template", - tab =>"display", - namespace =>"Matrix/Screenshots", - hoverHelp =>$i18n->get('screenshots template description'), - label =>$i18n->get('screenshots template label'), - }, - screenshotsConfigTemplateId=>{ - defaultValue =>"matrixtmpl000000000007", - fieldType =>"template", - tab =>"display", - namespace =>"Matrix/ScreenshotsConfig", - hoverHelp =>$i18n->get('screenshots config template description'), - label =>$i18n->get('screenshots config template label'), - }, - defaultSort=>{ - fieldType =>"selectBox", - tab =>"display", - options =>{ - score => $i18n->get('sort by score label'), - title => $i18n->get('sort alpha numeric label'), - lineage => $i18n->get('sort by asset rank label'), - lastUpdated => $i18n->get('sort by last updated label'), - }, - defaultValue =>"title", - hoverHelp =>$i18n->get('default sort description'), - label =>$i18n->get('default sort label'), - }, - compareColorNo=>{ - fieldType =>"color", - tab =>"display", - defaultValue =>"#ffaaaa", - hoverHelp =>$i18n->get('compare color no description'), - label =>$i18n->get('compare color no label'), - }, - compareColorLimited=>{ - fieldType =>"color", - tab =>"display", - defaultValue =>"#ffffaa", - hoverHelp =>$i18n->get('compare color limited description'), - label =>$i18n->get('compare color limited label'), - }, - compareColorCostsExtra=>{ - fieldType =>"color", - tab =>"display", - defaultValue =>"#ffffaa", - hoverHelp =>$i18n->get('compare color costs extra description'), - label =>$i18n->get('compare color costs extra label'), - }, - compareColorFreeAddOn=>{ - fieldType =>"color", - tab =>"display", - defaultValue =>"#ffffaa", - hoverHelp =>$i18n->get('compare color free add on description'), - label =>$i18n->get('compare color free add on label'), - }, - compareColorYes=>{ - fieldType =>"color", - tab =>"display", - defaultValue =>"#aaffaa", - 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", - defaultValue =>$i18n->get('categories default value'), - hoverHelp =>$i18n->get('categories description'), - label =>$i18n->get('categories label'), - subtext =>$i18n->get('categories subtext'), - }, - maxComparisons=>{ - fieldType =>"integer", - tab =>"properties", - defaultValue =>25, - hoverHelp =>$i18n->get('max comparisons description'), - label =>$i18n->get('max comparisons label'), - }, - maxComparisonsPrivileged=>{ - fieldType =>"integer", - tab =>"properties", - defaultValue =>10, - hoverHelp =>$i18n->get('max comparisons privileged description'), - label =>$i18n->get('max comparisons privileged label'), - }, - maxComparisonsGroup=>{ - fieldType =>"group", - tab =>"properties", - hoverHelp =>$i18n->get('maxgroup description'), - label =>$i18n->get('maxgroup label'), - }, - maxComparisonsGroupInt=>{ - fieldType =>"integer", - tab =>"properties", - defaultValue =>25, - hoverHelp =>$i18n->get('maxgroup per description'), - label =>$i18n->get('maxgroup per label'), - }, - groupToAdd=>{ - fieldType =>"group", - tab =>"security", - defaultValue =>2, - hoverHelp =>$i18n->get('group to add description'), - label =>$i18n->get('group to add label'), - }, - submissionApprovalWorkflowId=>{ - fieldType =>"workflow", - tab =>"security", - type =>'WebGUI::VersionTag', - defaultValue =>"pbworkflow000000000003", - hoverHelp =>$i18n->get('submission approval workflow description'), - label =>$i18n->get('submission approval workflow label'), - }, - ratingsDuration=>{ - fieldType =>"interval", - tab =>"properties", - defaultValue =>7776000, # 3 months 3*30*24*60*60 - hoverHelp =>$i18n->get('ratings duration description'), - label =>$i18n->get('ratings duration label'), - }, - statisticsCacheTimeout => { - tab => "display", - fieldType => "interval", - defaultValue => 3600, - uiLevel => 8, - label => $i18n->get("statistics cache timeout label"), - hoverHelp => $i18n->get("statistics cache timeout description") - }, - listingsCacheTimeout => { - tab => "display", - fieldType => "interval", - defaultValue => 3600, - uiLevel => 8, - label => $i18n->get("listings cache timeout label"), - hoverHelp => $i18n->get("listings cache timeout description") - }, - ); - push(@{$definition}, { - assetName=>$i18n->get('assetName'), - icon=>'matrix.gif', - autoGenerateForms=>1, - tableName=>'Matrix', - className=>'WebGUI::Asset::Wobject::Matrix', - properties=>\%properties - }); - return $class->SUPER::definition($session, $definition); -} - -#------------------------------------------------------------------- - =head2 deleteAttribute ( attributeId ) Deletes an attribute and listing data for this attribute from Collateral. @@ -395,7 +384,7 @@ sub getCategories { my %categories; tie %categories, 'Tie::IxHash'; - my $categories = $self->getValue("categories"); + my $categories = $self->categories; $categories =~ s/\r//g; chomp($categories); @@ -424,22 +413,23 @@ sub getCompareColor { my $self = shift; my $value = shift; - if($value == 0){ - return $self->get('compareColorNo'); + given($value) { + when(0) { + return $self->compareColorNo; + } + when(1){ + return $self->compareColorLimited; + } + when(2){ + return $self->compareColorCostsExtra; + } + when(3){ + return $self->compareColorFreeAddOn; + } + when(4){ + return $self->compareColorYes; + } } - elsif($value == 1){ - return $self->get('compareColorLimited'); - } - elsif($value == 2){ - return $self->get('compareColorCostsExtra'); - } - elsif($value == 3){ - return $self->get('compareColorFreeAddOn'); - } - elsif($value == 4){ - return $self->get('compareColorYes'); - } - } #------------------------------------------------------------------- @@ -465,13 +455,13 @@ sub getCompareForm { my $maxComparisons; if($self->session->user->isVisitor){ - $maxComparisons = $self->get('maxComparisons'); + $maxComparisons = $self->maxComparisons; } - elsif($self->session->user->isInGroup( $self->get("maxComparisonsGroup") )) { - $maxComparisons = $self->get('maxComparisonsGroupInt'); + elsif($self->session->user->isInGroup( $self->maxComparisonsGroup )) { + $maxComparisons = $self->maxComparisonsGroupInt; } else{ - $maxComparisons = $self->get('maxComparisonsPrivileged'); + $maxComparisons = $self->maxComparisonsPrivileged; } $maxComparisons += 0; $form .= "\n