From 34b513aa8919f6bceb1a7cc9c179c982b4cd07f9 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 11 Feb 2010 15:55:20 -0800 Subject: [PATCH] Partial update of SQLReport for Moose. Still needs to resolve i18n labels in the properties where the label is concatenated with a string. --- lib/WebGUI/Asset/Wobject/SQLReport.pm | 449 ++++++++++++++------------ 1 file changed, 239 insertions(+), 210 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/SQLReport.pm b/lib/WebGUI/Asset/Wobject/SQLReport.pm index 89b7a01de..ab1f99500 100644 --- a/lib/WebGUI/Asset/Wobject/SQLReport.pm +++ b/lib/WebGUI/Asset/Wobject/SQLReport.pm @@ -20,8 +20,226 @@ use WebGUI::Utility; use WebGUI::Asset::Wobject; use WebGUI::Text qw(:csv); -our @ISA = qw(WebGUI::Asset::Wobject); +use WebGUI::Definition::Asset; +extends 'WebGUI::Asset::Wobject'; +aspect assetName => ['assetName', 'Asset_SQLReport']; +aspect uiLevel => 5; +aspect icon => 'sqlReport.gif'; +aspect tableName => 'SQLReport'; +property templateId => ( + fieldType => "template", + default => 'PBtmpl0000000000000059', + label => [72, 'Asset_SQLReport'], + hoverHelp => ['72 description', 'Asset_SQLReport'], + namespace => "SQLReport" + ); +property cacheTimeout => ( + fieldType => "interval", + default => 0, + label => ['cache timeout', 'Asset_SQLReport'], + hoverHelp => ['cache timeout description', 'Asset_SQLReport'], + uiLevel => 8, + ); +property paginateAfter => ( + fieldType => "integer", + default => 50, + label => ['14', 'Asset_SQLReport'], + hoverHelp => ['14 description', 'Asset_SQLReport'], + ); +property dbQuery1 => ( + fieldType => "codearea", + default => undef, + label => $i18n->get(4) . ' 1', + ); +property prequeryStatements1 => ( + fieldType => "codearea", + default => undef, + label => $i18n->get('Prequery statements') . ' 1', + ); +property preprocessMacros1 => ( + fieldType => "yesNo", + default => 0, + label => $i18n->get(15) . ' 1', + ); +property placeholderParams1 => ( + fieldType => "textarea", + default => undef, + label => $i18n->get('Placeholder Parameters') . ' 1', + ); +property databaseLinkId1 => ( + fieldType => "databaseLink", + default => 0, + label => $i18n->get("1075", 'WebGUI').' 1', + ); +property dbQuery2 => ( + fieldType => "codearea", + default => undef, + label => $i18n->get(4) . ' 2', + ); +property prequeryStatements2 => ( + fieldType => "codearea", + default => undef, + label => $i18n->get('Prequery statements') . ' 2', + ); +property preprocessMacros2 => ( + fieldType => "yesNo", + default => 0, + label => $i18n->get(15) . ' 2', + ); +property placeholderParams2 => ( + fieldType => "textarea", + default => undef, + label => $i18n->get('Placeholder Parameters') . ' 2', + ); +property databaseLinkId2 => ( + fieldType => "databaseLink", + default => 0, + label => $i18n->get("1075", 'WebGUI').' 2', + ); +property dbQuery3 => ( + fieldType => "codearea", + default => undef, + label => $i18n->get(4) . ' 3', + ); +property prequeryStatements3 => ( + fieldType => "codearea", + default => undef, + label => $i18n->get('Prequery statements') . ' 3', + ); +property preprocessMacros3 => ( + fieldType => "yesNo", + default => 0, + label => $i18n->get(15) . ' 3', + ); +property placeholderParams3 => ( + fieldType => "textarea", + default => undef, + label => $i18n->get('Placeholder Parameters') . ' 3', + ); +property databaseLinkId3 => ( + fieldType => "databaseLink", + default => 0, + label => $i18n->get("1075", 'WebGUI').' 3', + ); +property dbQuery4 => ( + fieldType => "codearea", + default => undef, + label => $i18n->get(4) . ' 4', + ); +property prequeryStatements4 => ( + fieldType => "codearea", + default => undef, + label => $i18n->get('Prequery statements') . ' 4', + ); +property preprocessMacros4 => ( + fieldType => "yesNo", + default => 0, + label => $i18n->get(15) . ' 4', + ); +property placeholderParams4 => ( + fieldType => "textarea", + default => undef, + label => $i18n->get('Placeholder Parameters') . ' 4', + ); +property databaseLinkId4 => ( + fieldType => "databaseLink", + default => 0, + label => $i18n->get("1075", 'WebGUI').' 4', + ); +property dbQuery5 => ( + fieldType => "codearea", + default => undef, + label => $i18n->get(4) . ' 5', + ); +property prequeryStatements5 => ( + fieldType => "codearea", + default => undef, + label => $i18n->get('Prequery statements') . ' 5', + ); +property preprocessMacros5 => ( + fieldType => "yesNo", + default => 0, + label => $i18n->get(15) . '5', + ); +property placeholderParams5 => ( + fieldType => "textarea", + default => undef, + label => $i18n->get('Placeholder Parameters') . ' 5', + ); +property databaseLinkId5 => ( + fieldType => "databaseLink", + default => 0, + label => $i18n->get("1075", 'WebGUI').' 5', + ); +property debugMode => ( + fieldType => "yesNo", + default => 0, + label => [16, 'Asset_SQLReport'], + hoverHelp => ['16 description', 'Asset_SQLReport'], + ); + # download +property downloadType => ( + fieldType => "text", + default => "none", + label => ["download type", 'Asset_SQLReport'], + hoverHelp => $i18n->get("download type description"), + vertical => 1, + options => \&_downloadType_options, + extras => "onclick='changeDownloadType(this)'" + ); +sub _downoadType_options { + my $self = shift; + tie my %downloadTypes, 'Tie::IxHash', + "none" => "No Download", + "csv" => "CSV", + "template" => "Template", + ; + return \%downloadTypes; +} +property downloadFilename => ( + fieldType => "text", + default => "", + label => ["download filename", 'Asset_SQLReport'], + hoverHelp => ["download filename description", 'Asset_SQLReport'], + ); +property downloadTemplateId => ( + fieldType => "template", + default => 'SQLReportDownload00001', + label => ["download template", 'Asset_SQLReport'], + hoverHelp => ["download template description", 'Asset_SQLReport'], + namespace => "SQLReport/Download", + ); +property downloadMimeType => ( + fieldType => "text", + default => "text/html", + label => ["download mimetype", 'Asset_SQLReport'], + hoverHelp => ["download mimetype description", 'Asset_SQLReport'], + options => \&_downloadMimeType_options, + ); +sub _downloadMimeType_options { + my $self = shift; + my %downloadMimeType; + tie %downloadMimeType, 'Tie::IxHash', + "application/octet-stream" => "application/octet-stream", + "application/xml" => "application/xml", + "application/csv" => "application/csv", + "text/html" => "text/html", + "text/plain" => "text/plain", + ; + return \%downloadMimeType; +} +property downloadUserGroup => ( + fieldType => "group", + builder => '_downloadUserGroup_default', + lazy => 1, + label => ["download usergroup", 'Asset_SQLReport'], + hoverHelp => ["download usergroup description", 'Asset_SQLReport'], + ); +sub _downloadUserGroup_default { + my $self = shift; + return $self->groupIdView; +} #------------------------------------------------------------------- @@ -33,184 +251,8 @@ sub definition { my %properties; tie %properties, 'Tie::IxHash'; %properties = ( - templateId =>{ - fieldType=>"template", - defaultValue=>'PBtmpl0000000000000059', - label=>$i18n->get(72), - }, - cacheTimeout=>{ - fieldType=>"interval", - defaultValue=>0, - label=>$i18n->get('cache timeout'), - }, - paginateAfter=>{ - fieldType=>"integer", - defaultValue=>50, - label=>$i18n->get(14), - }, - dbQuery1=>{ - fieldType=>"codearea", - defaultValue=>undef, - label=>$i18n->get(4) . ' 1', - }, - prequeryStatements1=>{ - fieldType=>"codearea", - defaultValue=>undef, - label => $i18n->get('Prequery statements') . ' 1', - }, - preprocessMacros1=>{ - fieldType=>"yesNo", - defaultValue=>0, - label=>$i18n->get(15) . ' 1', - }, - placeholderParams1=>{ - fieldType=>"textarea", - defaultValue=>undef, - label=>$i18n->get('Placeholder Parameters') . ' 1', - }, - databaseLinkId1=>{ - fieldType=>"databaseLink", - defaultValue=>0, - label=>$i18n->get("1075", 'WebGUI').' 1', - }, - dbQuery2=>{ - fieldType=>"codearea", - defaultValue=>undef, - label=>$i18n->get(4) . ' 2', - }, - prequeryStatements2=>{ - fieldType=>"codearea", - defaultValue=>undef, - label => $i18n->get('Prequery statements') . ' 2', - }, - preprocessMacros2=>{ - fieldType=>"yesNo", - defaultValue=>0, - label=>$i18n->get(15) . ' 2', - }, - placeholderParams2=>{ - fieldType=>"textarea", - defaultValue=>undef, - label=>$i18n->get('Placeholder Parameters') . ' 2', - }, - databaseLinkId2=>{ - fieldType=>"databaseLink", - defaultValue=>0, - label=>$i18n->get("1075", 'WebGUI').' 2', - }, - dbQuery3=>{ - fieldType=>"codearea", - defaultValue=>undef, - label=>$i18n->get(4) . ' 3', - }, - prequeryStatements3=>{ - fieldType=>"codearea", - defaultValue=>undef, - label => $i18n->get('Prequery statements') . ' 3', - }, - preprocessMacros3=>{ - fieldType=>"yesNo", - defaultValue=>0, - label=>$i18n->get(15) . ' 3', - }, - placeholderParams3=>{ - fieldType=>"textarea", - defaultValue=>undef, - label=>$i18n->get('Placeholder Parameters') . ' 3', - }, - databaseLinkId3=>{ - fieldType=>"databaseLink", - defaultValue=>0, - label=>$i18n->get("1075", 'WebGUI').' 3', - }, - dbQuery4=>{ - fieldType=>"codearea", - defaultValue=>undef, - label=>$i18n->get(4) . ' 4', - }, - prequeryStatements4=>{ - fieldType=>"codearea", - defaultValue=>undef, - label => $i18n->get('Prequery statements') . ' 4', - }, - preprocessMacros4=>{ - fieldType=>"yesNo", - defaultValue=>0, - label=>$i18n->get(15) . ' 4', - }, - placeholderParams4=>{ - fieldType=>"textarea", - defaultValue=>undef, - label=>$i18n->get('Placeholder Parameters') . ' 4', - }, - databaseLinkId4=>{ - fieldType=>"databaseLink", - defaultValue=>0, - label=>$i18n->get("1075", 'WebGUI').' 4', - }, - dbQuery5=>{ - fieldType=>"codearea", - defaultValue=>undef, - label=>$i18n->get(4) . ' 5', - }, - prequeryStatements5=>{ - fieldType=>"codearea", - defaultValue=>undef, - label => $i18n->get('Prequery statements') . ' 5', - }, - preprocessMacros5=>{ - fieldType=>"yesNo", - defaultValue=>0, - label=>$i18n->get(15) . '5', - }, - placeholderParams5=>{ - fieldType=>"textarea", - defaultValue=>undef, - label=>$i18n->get('Placeholder Parameters') . ' 5', - }, - databaseLinkId5=>{ - fieldType=>"databaseLink", - defaultValue=>0, - label=>$i18n->get("1075", 'WebGUI').' 5', - }, - debugMode=>{ - fieldType=>"yesNo", - defaultValue=>0, - label=>$i18n->get(16), - }, - - # download - downloadType=>{ - fieldType=>"text", - defaultValue=>"none", - label=>$i18n->get("download type"), - }, - downloadFilename=>{ - fieldType=>"text", - defaultValue=>"", - label=>$i18n->get("download filename"), - }, - downloadTemplateId=>{ - fieldType=>"template", - defaultValue=>'SQLReportDownload00001', - label=>$i18n->get("download template"), - }, - downloadMimeType=>{ - fieldType=>"text", - defaultValue=>"text/html", - label=>$i18n->get("download mimetype"), - }, - downloadUserGroup=>{ - fieldType => "group", - defaultValue => "7", - label => $i18n->get("download usergroup"), - }, ); push(@{$definition}, { - assetName=>$i18n->get('assetName'), - uiLevel => 5, - icon=>'sqlReport.gif', - tableName=>'SQLReport', className=>'WebGUI::Asset::Wobject::SQLReport', properties => \%properties, autoGenerateForms => 0, @@ -229,7 +271,7 @@ touched. Default to using $self->get('cacheTimeout') seconds ago. sub getContentLastModified { my $self = shift; - return (time - $self->get("cacheTimeout")); + return (time - $self->cacheTimeout); } #------------------------------------------------------------------- @@ -268,11 +310,6 @@ sub getEditForm { ### Download # Download Type my %downloadTypes; - tie %downloadTypes, 'Tie::IxHash', - "none" => "No Download", - "csv" => "CSV", - "template" => "Template", - ; $tabform->getTab("properties")->radioList( -name=>"downloadType", # ID is downloadType_formId @@ -303,14 +340,6 @@ sub getEditForm { ); # Download mimeType (if necessary) - my %downloadMimeType; - tie %downloadMimeType, 'Tie::IxHash', - "application/octet-stream" => "application/octet-stream", - "application/xml" => "application/xml", - "application/csv" => "application/csv", - "text/html" => "text/html", - "text/plain" => "text/plain", - ; $tabform->getTab("properties")->selectBox( -name=>"downloadMimeType", @@ -442,7 +471,7 @@ sub download { my $self = shift; # Instead of going through some costly exercises... - return undef if ($self->getValue("downloadType") eq "none"); + return undef if ($self->downloadType eq "none"); # Initiate an empty debug loop $self->{_debug_loop} = [] ; @@ -451,7 +480,7 @@ sub download { $self->_storeQueries(); # If we're downloading CSV - if ($self->getValue("downloadType") eq "csv") { + if ($self->downloadType eq "csv") { my $data = $self->_processQuery(0,0); my $out = ""; @@ -471,9 +500,9 @@ sub download { return $out; } - elsif ($self->getValue("downloadType") eq "template") { + elsif ($self->downloadType eq "template") { my $data = $self->_processQuery(1,0); - return $self->processTemplate($data,$self->get("downloadTemplateId")); + return $self->processTemplate($data,$self->downloadTemplateId); } else { # I don't know what to do @@ -494,11 +523,11 @@ See WebGUI::Asset::prepareView() for details. sub prepareView { my $self = shift; $self->SUPER::prepareView(); - my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); + my $template = WebGUI::Asset::Template->new($self->session, $self->templateId); if (!$template) { WebGUI::Error::ObjectNotFound::Template->throw( error => qq{Template not found}, - templateId => $self->get("templateId"), + templateId => $self->templateId, assetId => $self->getId, ); } @@ -533,7 +562,7 @@ if the user is not in Admin Mode. sub view { my $self = shift; my $cache = $self->session->cache; - if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) { + if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) { my $out = eval{$cache->get("view_".$self->getId)}; return $out if $out; } @@ -551,16 +580,16 @@ sub view { #use Data::Dumper; return '
'.Dumper($var).'
'; # Add the "Download data" link if the user is allowed to download - if ($self->getValue("downloadType") ne "none" - && $self->session->user->isInGroup($self->getValue("downloadUserGroup")) + if ($self->downloadType ne "none" + && $self->session->user->isInGroup($self->downloadUserGroup) ) { $var->{'canDownload'} = 1; $var->{'downloadLink'} = $self->_getDownloadLink($self); } my $out = $self->processTemplate($var,undef,$self->{_viewTemplate}); - if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) { - eval{$cache->set("view_".$self->getId, $out, $self->get("cacheTimeout"))}; + if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) { + eval{$cache->set("view_".$self->getId, $out, $self->cacheTimeout)}; } return $out; } @@ -681,7 +710,7 @@ sub _processQuery { if (defined $dbh) { if ($dbLink->queryIsAllowed($query)) { # Check and execute prequery statements first - foreach (split(/\n/, $self->getValue("prequeryStatements".$nr))) { + foreach (split(/\n/, $self->get('prequeryStatements' .$nr))) { my $prequeryStatement = $_; WebGUI::Macro::process($self->session, \$prequeryStatement) if ($self->{_query}{$nr}{preprocessMacros}); @@ -711,7 +740,7 @@ sub _processQuery { .'='.$self->session->url->escape($self->session->form->process($_))); } } - my $paginateAfter = ($page == 1) ? $self->get("paginateAfter") : 99999999; + my $paginateAfter = ($page == 1) ? $self->paginateAfter : 99999999; my $paginatePage = ($nr > 1) ? 1 : $self->session->form->param('pn'); my $p = WebGUI::Paginator->new($self->session,$url,$paginateAfter, undef, $paginatePage); my $error = $p->setDataByQuery($query,$dbh,1,$placeholderParams); @@ -790,20 +819,20 @@ sub www_download { my $self = shift; # Only allow if download type is not "none" - return undef if $self->getValue("downloadType") eq "none"; + return undef if $self->downloadType eq "none"; # Only allow users in appropriate group return $self->session->privilege->noAccess() - unless $self->session->user->isInGroup($self->getValue("downloadUserGroup")); + unless $self->session->user->isInGroup($self->downloadUserGroup); # Set filename and mimetype - if ($self->getValue("downloadType") eq "csv") + if ($self->downloadType eq "csv") { - $self->session->http->setFilename($self->getValue("downloadFilename"),"application/octet-stream"); + $self->session->http->setFilename($self->downloadFilename,"application/octet-stream"); } else { - $self->session->http->setFilename($self->getValue("downloadFilename"),$self->getValue("downloadMimeType")); + $self->session->http->setFilename($self->downloadFilename, $self->downloadMimeType); } $self->session->http->sendHeader; @@ -824,7 +853,7 @@ See WebGUI::Asset::Wobject::www_view() for details. sub www_view { my $self = shift; - $self->session->http->setCacheControl($self->get("cacheTimeout")); + $self->session->http->setCacheControl($self->cacheTimeout); $self->SUPER::www_view(@_); }