Skip to content

Commit

Permalink
initial release of Asset Report asset allowing reports to be created …
Browse files Browse the repository at this point in the history
…using asset properties.
  • Loading branch information
khenn committed Aug 10, 2010
1 parent cb2bb75 commit 22da7c4
Show file tree
Hide file tree
Showing 10 changed files with 1,405 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -13,6 +13,7 @@
- fixed #11432: DataTable date input
- fixed #11772: Metadata in Post doesn't set default value correctly
- fixed #11768: Edit Branch does not update File wgaccess permissions
- added Asset Report Asset allowing creation of reports based on Asset Properties.

7.9.10
- fixed #11721: spamStopWords not in WebGUI.conf.original
Expand Down
Binary file not shown.
25 changes: 25 additions & 0 deletions docs/upgrades/upgrade_7.9.10-7.9.11.pl
Expand Up @@ -32,6 +32,7 @@ BEGIN

# upgrade functions go here
alterStoryTopicTable($session);
addAssetReport($session);

finish($session); # this line required

Expand All @@ -45,6 +46,30 @@ BEGIN
# print "DONE!\n" unless $quiet;
#}

#----------------------------------------------------------------------------
# Describe what our function does
sub addAssetReport {
my $session = shift;
print "\tAdding Asset Report Asset ... " unless $quiet;

#Add the database table
$session->db->write(q{
CREATE TABLE `AssetReport` (
`assetId` char(22) character set utf8 collate utf8_bin NOT NULL,
`revisionDate` bigint(20) NOT NULL,
`settings` mediumtext,
`templateId` char(22) character set utf8 collate utf8_bin default NULL,
`paginateAfter` bigint(20) default NULL,
PRIMARY KEY (`assetId`,`revisionDate`)
)
});

#Add the asset to the config file
$session->config->addToHash( "assets", "WebGUI::Asset::Wobject::AssetReport", { category => "utilities" } );

print "DONE!\n" unless $quiet;
}

#----------------------------------------------------------------------------
# Describe what our function does
sub alterStoryTopicTable {
Expand Down
297 changes: 297 additions & 0 deletions lib/WebGUI/Asset/Wobject/AssetReport.pm
@@ -0,0 +1,297 @@
package WebGUI::Asset::Wobject::AssetReport;

$VERSION = "1.0.0";

#-------------------------------------------------------------------
# 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 strict;
use Tie::IxHash;
use WebGUI::International;
use WebGUI::Paginator;
use WebGUI::Utility;
use Class::C3;
use base qw/WebGUI::AssetAspect::Installable WebGUI::Asset::Wobject/;

#-------------------------------------------------------------------

=head2 definition ( session, definition )
=cut

sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new( $session, 'Asset_AssetReport' );

tie my %properties, 'Tie::IxHash', (
settings => {
tab => 'properties',
fieldType => 'AssetReportQuery',
defaultValue => undef,
},
templateId => {
tab => "display",
fieldType => "template",
namespace => "AssetReport",
defaultValue => "sJtcUCfn0CVbKdb4QM61Yw",
label => $i18n->get("templateId label"),
hoverHelp => $i18n->get("templateId description"),
},
paginateAfter => {
tab => 'display',
fieldType => 'integer',
defaultValue => 25,
label => $i18n->get( 'paginateAfter label' ),
hoverHelp => $i18n->get( 'paginateAfter description' ),
},
);

push @{$definition}, {
assetName => $i18n->get('assetName'),
autoGenerateForms => 1,
tableName => 'AssetReport',
className => 'WebGUI::Asset::Wobject::AssetReport',
properties => \%properties,
};

return $class->SUPER::definition( $session, $definition );
} ## end sub definition


#----------------------------------------------------------------------------

=head2 prepareView ( )
Prepare the view. Add stuff to HEAD.
=cut

sub prepareView {
my $self = shift;
$self->SUPER::prepareView(@_);
my $session = $self->session;

# Prepare the template
my $template = WebGUI::Asset::Template->new( $session, $self->get("templateId") );
if (!$template) {
WebGUI::Error::ObjectNotFound::Template->throw(
error => qq{Template not found},
templateId => $self->get("templateId"),
assetId => $self->getId,
);
}
$template->prepare;
$self->{_template} = $template;

return;
} ## end sub prepareView

#----------------------------------------------------------------------------

=head2 getTemplateVars ( )
Get template variables common to all views of the Asset Report.
=cut

sub getTemplateVars {
my $self = shift;
my $session = $self->session;

my $var = $self->get;

#Build the lineage query
my $settings = JSON->new->decode($self->getValue("settings"));

#TO DO - ADD CACHE CONTROL

my $assetId = $settings->{startNode};
my $asset = WebGUI::Asset->newByDynamicClass($session,$assetId);

my $rules = {};
$rules->{'isa'} = $settings->{className};

#Build where condition
my $condition = $settings->{anySelect};
$rules->{'whereClause'} = undef;
my $where = $settings->{where};
foreach my $key (keys %{$where}) {
my $clause = $where->{$key};
my $prop = $clause->{propSelect};
my $op = $clause->{opSelect};
my $value = $clause->{valText};

$rules->{'whereClause'} .= qq{ $condition } if ($key > 1);
$rules->{'whereClause'} .= qq{$prop $op $value};
}

if($rules->{'whereClause'}) {
$rules->{'joinClass'} = $settings->{className};
}

#Build the order by condition
my $order = $settings->{order};
my @order = keys %{$order};
if(scalar(@order)) {
$rules->{'orderByClause'} = undef;
foreach my $key (@order) {
my $orderBy = $order->{$key};
my $orderSelect = $orderBy->{orderSelect};
my $dirSelect = $orderBy->{dirSelect};

$rules->{'orderByClause'} .= q{, } if($key > 1);
$rules->{'orderByClause'} .= qq{$orderSelect $dirSelect};
}
}

if($settings->{'limit'}) {
$rules->{'limit'} = $settings->{'limit'};
}
my $sql = $asset->getLineageSql(["descendants"],$rules);

my $p = WebGUI::Paginator->new($session,$self->getUrl,$self->get("paginateAfter"));
$p->setDataByQuery($sql);

#Build the data for all the assets on the page
$var->{'asset_loop'} = [];
my $data = $p->getPageData;
foreach my $row (@{$data}) {
my $returnAsset = WebGUI::Asset->new($session,$row->{assetId},$row->{className},$row->{revisionDate});
push(@{$var->{'asset_loop'}},$returnAsset->get);
}

#Append template variables
$p->appendTemplateVars($var);

return $var;
}

#----------------------------------------------------------------------------

=head2 view ( )
method called by the www_view method. Returns a processed template
to be displayed within the page style.
=cut

sub view {
my $self = shift;
my $var = $self->getTemplateVars;

return $self->processTemplate( $var, undef, $self->{_template} );
} ## end sub view

#-------------------------------------------------------------------
# Install Methods Below - Do Not Modify

#-------------------------------------------------------------------
sub install {
my $class = shift;
my $session = shift;
$class->next::method( $session );

### Create a folder asset to store the default template
my $importNode = WebGUI::Asset->getImportNode($session);
my $folder = $importNode->addChild({
className => "WebGUI::Asset::Wobject::Folder",
title => "Asset Report",
menuTitle => "Asset Report",
url => "pb_asset_report",
groupIdView =>"3"
},"AssetReportFolder00001");

### Add the template to the folder
$folder->addChild({
className => "WebGUI::Asset::Template",
namespace => "AssetReport",
title => "Asset Report Default Template",
menuTitle => "Asset Report Default Template",
ownerUserId => "3",
groupIdView => "7",
groupIdEdit => "4",
isHidden => 1,
isDefault => 1,
template => qq{
<a name="id<tmpl_var assetId>" id="id<tmpl_var assetId>"></a>
<tmpl_if session.var.adminOn>
<p><tmpl_var controls></p>
</tmpl_if>
<tmpl_if displayTitle>
<h2><tmpl_var title></h2>
</tmpl_if>
<tmpl_if error_loop>
<ul class="errors">
<tmpl_loop error_loop>
<li><b><tmpl_var error.message></b></li>
</tmpl_loop>
</ul>
</tmpl_if>
<tmpl_if description>
<tmpl_var description>
<p />
</tmpl_if>
<table border="1" cellspacing="0" cellpadding="3">
<thead>
<tr>
<th>Title</th>
<th>Creation Date</th>
<th>Created By</th>
</tr>
</thead>
<tbody>
<tmpl_loop asset_loop>
<tr>
<td><a href="<tmpl_var url>"><tmpl_var title></a></td>
<td>^D('%C %D, %y %h:%s %p',<tmpl_var creationDate>);</td>
<td>^User('username',<tmpl_var createdBy>);</td>
</tr>
</tmpl_loop>
</tbody>
</table>
<tmpl_if pagination.pageCount.isMultiple>
<div class="pagination">
<tmpl_var pagination.previousPage> <tmpl_var pagination.pageList.upTo20> <tmpl_var pagination.nextPage>
</div>
</tmpl_if>
},
headBlock =>"",
}, "AssetReport00000000001");

### Commit version tag
my $tag = WebGUI::VersionTag->new($session, WebGUI::VersionTag->getWorking($session)->getId);
if (defined $tag) {
$tag->set({comments=>"Template added/updated by Asset Install Process"});
$tag->requestCommit;
}
}

#-------------------------------------------------------------------
sub uninstall {
my $class = shift;
my $session = shift;
$class->next::method( $session );

my $template = WebGUI::Asset->newByDynamicClass($session,"AssetReport00000000001");
$template->purge if($template);

my $folder = WebGUI::Asset->newByDynamicClass($session,"AssetReportFolder00001");
$folder->purge if($folder);
}

1;

0 comments on commit 22da7c4

Please sign in to comment.