Convert FilePump over to the new Crud.
This commit is contained in:
parent
9abb4a8ee6
commit
2ad9fc1c16
3 changed files with 117 additions and 101 deletions
|
|
@ -86,7 +86,7 @@ sub www_addBundleSave {
|
|||
return $session->privilege->insufficient() unless canView($session);
|
||||
my $form = $session->form;
|
||||
my $bundleName = $form->get('bundleName');
|
||||
my $bundle = WebGUI::FilePump::Bundle->create($session, {
|
||||
my $bundle = WebGUI::FilePump::Bundle->new($session, {
|
||||
bundleName => $bundleName,
|
||||
lastModified => time(),
|
||||
});
|
||||
|
|
@ -273,7 +273,7 @@ EOTABLE
|
|||
;
|
||||
|
||||
my $rows = '';
|
||||
my $files = $bundle->get($fileType);
|
||||
my $files = $bundle->$fileType;
|
||||
foreach my $file (@{ $files }) {
|
||||
my $urlFrag = 'bundleId='.$bundleId.';fileType='.$type.';fileId='.$file->{fileId};
|
||||
$rows .= sprintf '<tr><td>%s</td><td>%s</td><td>%s</td></tr>',
|
||||
|
|
@ -342,20 +342,20 @@ sub www_manage {
|
|||
my $getABundle = WebGUI::FilePump::Bundle->getAllIterator($session,{ orderBy => 'bundleName' } );
|
||||
my $notYet = $i18n->get('not yet');
|
||||
while (my $bundle = $getABundle->()) {
|
||||
my $lastModified = $bundle->get('lastModified');
|
||||
my $lastBuild = $bundle->get('lastBuild');
|
||||
my $lastModified = $bundle->lastModified;
|
||||
my $lastBuild = $bundle->lastBuild;
|
||||
my $build = '';
|
||||
if ($lastModified > $lastBuild) {
|
||||
$build = sprintf q| <a href="%s">(%s)</a>|,
|
||||
$url->gateway($url->getRequestedUrl,'op=filePump;func=buildBundle;bundleId='.$bundle->getId),
|
||||
$url->gateway($url->getRequestedUrl,'op=filePump;func=buildBundle;bundleId='.$bundle->bundleId),
|
||||
$i18n->get('build');
|
||||
}
|
||||
$rows .= sprintf '<tr><td>%s</td><td><a href="%s">%s</a></td><td>%s</td><td>%s</td>',
|
||||
$session->icon->delete('op=filePump;func=deleteBundle;bundleId='.$bundle->getId),
|
||||
$url->gateway($url->getRequestedUrl,'op=filePump;func=editBundle;bundleId='.$bundle->getId),
|
||||
$bundle->get('bundleName'),
|
||||
$bundle->get('lastModified') ? $dt->epochToHuman($lastModified) : $notYet,
|
||||
$bundle->get('lastBuild') ? $dt->epochToHuman($lastBuild).$build : $notYet,
|
||||
$session->icon->delete('op=filePump;func=deleteBundle;bundleId='.$bundle->bundleId),
|
||||
$url->gateway($url->getRequestedUrl,'op=filePump;func=editBundle;bundleId='.$bundle->bundleId),
|
||||
$bundle->bundleName,
|
||||
$bundle->lastModified ? $dt->epochToHuman($lastModified) : $notYet,
|
||||
$bundle->lastBuild ? $dt->epochToHuman($lastBuild).$build : $notYet,
|
||||
;
|
||||
}
|
||||
my $output = sprintf <<EOHTML, $i18n->get('bundle name'), $i18n->get('last modified'), $i18n->get('last build'), $rows;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,61 @@
|
|||
package WebGUI::FilePump::Bundle;
|
||||
|
||||
use base qw/WebGUI::Crud WebGUI::JSONCollateral/;
|
||||
use Moose;
|
||||
use WebGUI::Definition::Crud;
|
||||
extends 'WebGUI::Crud';
|
||||
define tableName => 'filePumpBundle';
|
||||
define tableKey => 'bundleId';
|
||||
has bundleId => (
|
||||
required => 1,
|
||||
is => 'ro',
|
||||
);
|
||||
property bundleName => (
|
||||
label => 'bundleName',
|
||||
fieldType => 'text',
|
||||
builder => '_default_bundleName',
|
||||
lazy => 1,
|
||||
);
|
||||
sub _default_bundleName {
|
||||
my $session = shift->session;
|
||||
my $i18n = WebGUI::International->new($session, 'FilePump');
|
||||
return $i18n->get('new bundle');
|
||||
}
|
||||
property lastModified => (
|
||||
label => 'lastModified',
|
||||
fieldType => 'integer',
|
||||
default => 0,
|
||||
);
|
||||
property lastBuild => (
|
||||
label => 'lastBuild',
|
||||
fieldType => 'integer',
|
||||
default => 0,
|
||||
);
|
||||
property jsFiles => (
|
||||
label => 'jsFiles',
|
||||
fieldType => 'textarea',
|
||||
default => sub { [] },
|
||||
traits => ['Array', 'WebGUI::Definition::Meta::Property::Serialize',],
|
||||
isa => 'WebGUI::Type::JSONArray',
|
||||
coerce => 1,
|
||||
);
|
||||
property cssFiles => (
|
||||
label => 'cssFiles',
|
||||
fieldType => 'textarea',
|
||||
default => sub { [] },
|
||||
traits => ['Array', 'WebGUI::Definition::Meta::Property::Serialize',],
|
||||
isa => 'WebGUI::Type::JSONArray',
|
||||
coerce => 1,
|
||||
);
|
||||
property otherFiles => (
|
||||
label => 'otherFiles',
|
||||
fieldType => 'textarea',
|
||||
default => sub { [] },
|
||||
traits => ['Array', 'WebGUI::Definition::Meta::Property::Serialize',],
|
||||
isa => 'WebGUI::Type::JSONArray',
|
||||
coerce => 1,
|
||||
);
|
||||
with 'WebGUI::Role::Asset::JSONCollateral';
|
||||
|
||||
use strict;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::International;
|
||||
|
|
@ -17,6 +72,44 @@ use Data::Dumper;
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 properties
|
||||
|
||||
=head3 tableName
|
||||
|
||||
filePumpBundle
|
||||
|
||||
=head3 tableKey
|
||||
|
||||
bundleId
|
||||
|
||||
=head3 sequenceKey
|
||||
|
||||
None. Bundles have no sequence amongst themselves.
|
||||
|
||||
=head3 properties
|
||||
|
||||
=head4 bundleName
|
||||
|
||||
The name of a bundle
|
||||
|
||||
=head4 lastBuild
|
||||
|
||||
The date the bundle was last built. This is used to generate the name of the bundled files
|
||||
for this bundle.
|
||||
|
||||
=head4 lastModified
|
||||
|
||||
The date the bundle was last modified. With this, and the lastBuild date, you can determine
|
||||
which bundles need to be rebuilt.
|
||||
|
||||
=head4 jsFiles, cssFiles, otherFiles
|
||||
|
||||
JSON blobs with files attached to the bundle. js = javascript, css = Cascading Style Sheets, other
|
||||
means anything else.
|
||||
|
||||
=cut
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addFile ( $type, $uri )
|
||||
|
||||
Adds a file of the requested type to the bundle. Returns 1 if the add was successful.
|
||||
|
|
@ -42,7 +135,7 @@ sub addFile {
|
|||
my $collateralType = $type eq 'JS' ? 'jsFiles'
|
||||
: $type eq 'CSS' ? 'cssFiles'
|
||||
: 'otherFiles';
|
||||
my $files = $self->get($collateralType);
|
||||
my $files = $self->$collateralType;
|
||||
my $uriExists = $self->getJSONCollateralDataIndex($files, 'uri', $uri) != -1 ? 1 : 0;
|
||||
return 0, 'Duplicate URI' if $uriExists;
|
||||
|
||||
|
|
@ -91,13 +184,13 @@ the method returns 0, along with an error message.
|
|||
sub build {
|
||||
my ($self) = @_;
|
||||
my $newBuild = time();
|
||||
my $originalBuild = $self->get('lastBuild');
|
||||
my $originalBuild = $self->lastBuild;
|
||||
|
||||
##Whole lot of building
|
||||
my $error = undef;
|
||||
|
||||
##JavaScript first
|
||||
my $jsFiles = $self->get('jsFiles');
|
||||
my $jsFiles = $self->jsFiles;
|
||||
my $concatenatedJS = '';
|
||||
JSFILE: foreach my $jsFile (@{ $jsFiles }) {
|
||||
my $uri = $jsFile->{uri};
|
||||
|
|
@ -112,7 +205,7 @@ sub build {
|
|||
return (0, $error) if ($error);
|
||||
|
||||
##CSS next
|
||||
my $cssFiles = $self->get('cssFiles');
|
||||
my $cssFiles = $self->cssFiles;
|
||||
my $concatenatedCSS = '';
|
||||
CSSFILE: foreach my $cssFile (@{ $cssFiles }) {
|
||||
my $uri = $cssFile->{uri};
|
||||
|
|
@ -138,7 +231,7 @@ sub build {
|
|||
}
|
||||
|
||||
##Copy files over
|
||||
my $otherFiles = $self->get('otherFiles');
|
||||
my $otherFiles = $self->otherFiles;
|
||||
OTHERFILE: foreach my $file (@{ $otherFiles }) {
|
||||
my $uri = $file->{uri};
|
||||
my $results = $self->fetch($uri);
|
||||
|
|
@ -287,84 +380,6 @@ sub _buildFile {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 crud_definition
|
||||
|
||||
WebGUI::Crud definition for this class.
|
||||
|
||||
=head3 tableName
|
||||
|
||||
filePumpBundle
|
||||
|
||||
=head3 tableKey
|
||||
|
||||
bundleId
|
||||
|
||||
=head3 sequenceKey
|
||||
|
||||
None. Bundles have no sequence amongst themselves.
|
||||
|
||||
=head3 properties
|
||||
|
||||
=head4 bundleName
|
||||
|
||||
The name of a bundle
|
||||
|
||||
=head4 lastBuild
|
||||
|
||||
The date the bundle was last built. This is used to generate the name of the bundled files
|
||||
for this bundle.
|
||||
|
||||
=head4 lastModified
|
||||
|
||||
The date the bundle was last modified. With this, and the lastBuild date, you can determine
|
||||
which bundles need to be rebuilt.
|
||||
|
||||
=head4 jsFiles, cssFiles, otherFiles
|
||||
|
||||
JSON blobs with files attached to the bundle. js = javascript, css = Cascading Style Sheets, other
|
||||
means anything else.
|
||||
|
||||
=cut
|
||||
|
||||
sub crud_definition {
|
||||
my ($class, $session) = @_;
|
||||
my $definition = $class->SUPER::crud_definition($session);
|
||||
my $i18n = WebGUI::International->new($session, 'FilePump');
|
||||
$definition->{tableName} = 'filePumpBundle';
|
||||
$definition->{tableKey} = 'bundleId';
|
||||
$definition->{sequenceKey} = '';
|
||||
my $properties = $definition->{properties};
|
||||
$properties->{bundleName} = {
|
||||
fieldType => 'text',
|
||||
defaultValue => $i18n->get('new bundle'),
|
||||
};
|
||||
$properties->{lastModified} = {
|
||||
fieldType => 'integer',
|
||||
defaultValue => 0,
|
||||
};
|
||||
$properties->{lastBuild} = {
|
||||
fieldType => 'integer',
|
||||
defaultValue => 0,
|
||||
};
|
||||
$properties->{jsFiles} = {
|
||||
fieldType => 'textarea',
|
||||
defaultValue => [],
|
||||
serialize => 1,
|
||||
};
|
||||
$properties->{cssFiles} = {
|
||||
fieldType => 'textarea',
|
||||
defaultValue => [],
|
||||
serialize => 1,
|
||||
};
|
||||
$properties->{otherFiles} = {
|
||||
fieldType => 'textarea',
|
||||
defaultValue => [],
|
||||
serialize => 1,
|
||||
};
|
||||
return $definition;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -514,7 +529,7 @@ sub fetchAsset {
|
|||
return {} if Exception::Class->caught();
|
||||
##Check for a snippet, or snippet subclass?
|
||||
my $guts = {
|
||||
lastModified => $asset->get('lastModified'),
|
||||
lastModified => $asset->lastModified,
|
||||
content => '',
|
||||
};
|
||||
if ($asset->isa('WebGUI::Asset::Snippet')) {
|
||||
|
|
@ -522,7 +537,7 @@ sub fetchAsset {
|
|||
WebGUI::Macro::process($self->session, \( $guts->{content} ) );
|
||||
}
|
||||
elsif ($asset->isa('WebGUI::Asset::File')) {
|
||||
$guts->{content} = $asset->getStorageLocation->getFileContentsAsScalar($asset->get('filename'));
|
||||
$guts->{content} = $asset->getStorageLocation->getFileContentsAsScalar($asset->filename);
|
||||
}
|
||||
return $guts;
|
||||
}
|
||||
|
|
@ -640,7 +655,7 @@ Returns a urlized version of the bundle name, safe for URLs and filenames.
|
|||
|
||||
sub bundleUrl {
|
||||
my ($self) = @_;
|
||||
return $self->session->url->urlize($self->get('bundleName'));
|
||||
return $self->session->url->urlize($self->bundleName);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -658,7 +673,7 @@ Another time stamp to use instead of the lastModified timestamp.
|
|||
|
||||
sub getPathClassDir {
|
||||
my ($self, $lastBuild) = @_;
|
||||
$lastBuild ||= $self->get('lastBuild');
|
||||
$lastBuild ||= $self->lastBuild;
|
||||
return Path::Class::Dir->new(
|
||||
$self->session->config->get('uploadsPath'),
|
||||
'filepump',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue