Add a progress bar for long running ops. First implementation is

with paste.  Also fix bugs with redirecting from the admin bar back to a
page instead of staying in the Asset Manager.
This commit is contained in:
Colin Kuskie 2009-06-18 19:39:35 +00:00
parent f2ebb5c54b
commit 8be0a5c734
8 changed files with 245 additions and 18 deletions

View file

@ -12,6 +12,8 @@
Default' ( Martin Kamerbeek / Oqapi )
- fixed: In the Asset Manager, if you pasted an asset if returned you to the page instead the manager.
- fixed: In the Asset Manager, only display a Select All button if there is more than one asset.
- fixed: Add a progress indicator for long running functions so the user knows something is happening.
- fixed: In the Asset Manager, if you pasted an package or prototype if returned you to the page instead the manager.
7.7.10
- Made a change to LDAP auth that adds an OR to that query so that it also searches for a row with fieldData REGEXP '^uid=(value-from-ldap-directory-server),'. (Wes Morgan)

View file

@ -36,6 +36,7 @@ use WebGUI::Form;
use WebGUI::HTML;
use WebGUI::HTMLForm;
use WebGUI::Keyword;
use WebGUI::ProgressBar;
use WebGUI::Search::Index;
use WebGUI::TabForm;
use WebGUI::Utility;

View file

@ -35,9 +35,6 @@ These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 canPaste ( )
@ -183,8 +180,8 @@ Alphanumeric ID tag of Asset.
=cut
sub paste {
my $self = shift;
my $assetId = shift;
my $self = shift;
my $assetId = shift;
my $pastedAsset = WebGUI::Asset->newByDynamicClass($self->session,$assetId);
return 0 unless ($self->get("state") eq "published");
return 0 unless ($pastedAsset->canPaste()); ##Allow pasted assets to have a say about pasting.
@ -508,17 +505,53 @@ sub www_pasteList {
my $session = $self->session;
return $session->privilege->insufficient() unless $self->canEdit;
my $form = $session->form;
ASSET: foreach my $clipId ($form->param("assetId")) {
my $pasteAsset = WebGUI::Asset->newPending($session, $clipId);
next ASSET unless $pasteAsset->canEdit;
$self->paste($clipId);
}
if ($form->param("proceed") eq 'manageAssets') {
return $self->www_manageAssets();
my $pb = WebGUI::ProgressBar->new($session);
##Need to store the list of assetIds for the status subroutine
my @assetIds = $form->param('assetId');
$session->scratch->set('assetPasteList', JSON::to_json(\@assetIds));
if ($form->param('proceed') eq 'manageAssets') {
$session->scratch->set('assetPasteReturnUrl', $self->getUrl('op=manageAssets'));
}
else {
return "";
$session->scratch->set('assetPasteReturnUrl', $self->getUrl);
}
$session->scratch->set('assetPasteList', JSON::to_json(\@assetIds));
##Need to set the URL that should be displayed when it is done
my $i18n = WebGUI::International->new($session, 'Asset');
$pb->setIcon($session->url->extras('adminConsole/assets.gif'));
return $pb->render({
title => $i18n->get('Paste Assets'),
statusUrl => $self->getUrl('func=pasteListStatus'),
});
}
#-------------------------------------------------------------------
=head2 www_pasteListStatus ( )
Pastes a selection of assets. If canEdit is False, returns an insufficient privileges page.
Returns the user to the manageAssets screen.
=cut
sub www_pasteListStatus {
my $self = shift;
my $session = $self->session;
my $pb = WebGUI::ProgressBar->new($session);
if (! $self->canEdit ) {
return $session->privilege->insufficient('no style')."return to site";
}
my $assetIds = $session->scratch->get('assetPasteList') || '[]';
my @assetIds = @{ JSON::from_json($assetIds) };
my $i18n = WebGUI::International->new($session, 'Asset');
ASSET: foreach my $clipId (@assetIds) {
my $pasteAsset = WebGUI::Asset->newPending($session, $clipId);
next ASSET unless $pasteAsset && $pasteAsset->canEdit;
$pb->print(sprintf $i18n->get("Pasting %s"), $pasteAsset->getTitle);
$self->paste($clipId);
}
$pb->redirect( $session->scratch->get('assetPasteReturnUrl') );
return "";
}

View file

@ -474,6 +474,7 @@ ENDHTML
$output .= '<div class="functionPane"><fieldset><legend>'.$i18n->get(1082).'</legend>'
.WebGUI::Form::formHeader($session, {action=>$currentAsset->getUrl})
.WebGUI::Form::hidden($session,{name=>"func",value=>"pasteList"})
.WebGUI::Form::hidden($session,{name=>"proceed",value=>"manageAssets"})
.( $clipNum > 1
? WebGUI::Form::checkbox($session,{extras=>'onclick="toggleClipboardSelectAll(this.form);"'}).' '.$i18n->get("select all").'<br />'
: ''

View file

@ -87,14 +87,14 @@ sub process {
# stuff to do if we're on a page with an asset
if ($asset) {
my $inAssetManager = $session->form->get('op') eq 'assetManager';
my $proceed = $session->form->get('op') eq 'assetManager' ? ';proceed=manageAssets' : '';
# clipboard
my $clipboardItems = $session->asset->getAssetsInClipboard(1);
if (scalar (@$clipboardItems)) {
$out .= q{<dt class="a-m-t">}.$i18n->get("1082").q{</dt><dd class="a-m-d"><div class="bd">};
foreach my $item (@{$clipboardItems}) {
my $title = $asset->getTitle;
$out .= q{<a class="link" href="}.$asset->getUrl("func=paste;assetId=".$item->getId).q{">}
$out .= q{<a class="link" href="}.$asset->getUrl("func=pasteList;assetId=".$item->getId.$proceed).q{">}
.q{<img src="}.$item->getIcon(1).q{" style="border: 0px; vertical-align: middle;" alt="icon" /> }
.$item->getTitle.q{</a>};
}
@ -119,7 +119,6 @@ sub process {
# assets
my %assetList = %{$config->get('assets')};
my $proceed = $inAssetManager ? ';proceed=manageAssets' : '';
foreach my $assetClass (keys %assetList) {
my $dummy = WebGUI::Asset->newByPropertyHashRef($session,{dummy=>1, className=>$assetClass});
next unless defined $dummy;
@ -136,7 +135,7 @@ sub process {
foreach my $package (@{$session->asset->getPackageList}) {
next unless ($package->canView && $package->canAdd($session) && $package->getUiLevel <= $userUiLevel);
$categories{packages}{items}{$package->getTitle} = {
url => $asset->getUrl("func=deployPackage;assetId=".$package->getId),
url => $asset->getUrl("func=deployPackage;assetId=".$package->getId.$proceed),
icon => $package->getIcon(1),
};
}
@ -149,7 +148,7 @@ sub process {
foreach my $prototype (@{ $session->asset->getPrototypeList }) {
next unless ($prototype->canView && $prototype->canAdd($session) && $prototype->getUiLevel <= $userUiLevel);
$categories{prototypes}{items}{$prototype->getTitle} = {
url => $asset->getUrl("func=add;class=".$prototype->get('className').";prototype=".$prototype->getId),
url => $asset->getUrl("func=add;class=".$prototype->get('className').";prototype=".$prototype->getId.$proceed),
icon => $prototype->getIcon(1),
};
}

175
lib/WebGUI/ProgressBar.pm Normal file
View file

@ -0,0 +1,175 @@
package WebGUI::ProgressBar;
=head1 LEGAL
-------------------------------------------------------------------
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
-------------------------------------------------------------------
=cut
use strict;
=head1 NAME
Package WebGUI::ProgressBar
=head1 DESCRIPTION
Render a progress bar for the user inside a nice style.
=head1 SYNOPSIS
use WebGUI::ProgressBar;
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 new ( session )
Constructor.
=head3 session
A reference to the current session.
=cut
sub new {
my $class = shift;
my $session = shift;
my $self = {};
$self->{_session} = $session;
$self->{_counter} = 1;
bless $self, $class;
return $self;
}
#-------------------------------------------------------------------
=head2 print ( $message )
Sends a message and increments the status bar.
=head3 $message
A message to be displayed in the status bar.
=cut
sub print {
my $self = shift;
my $message = shift; ##JS string escaping?
$self->{_counter} += 1;
my $text = sprintf(<<EOJS, $self->{_counter}, $message);
<script>
parent.document.getElementById("progressMeter").style.width='%dpx';
parent.document.getElementById("progressStatus").innerHTML='%s';
</script>
EOJS
$self->session->output->print($text);
return '';
}
#-------------------------------------------------------------------
=head2 redirect ( $url )
Redirects the user out of the status page.
=head3 $url
The URL to send the user to.
=cut
sub redirect {
my $self = shift;
my $url = shift;
my $text = sprintf(<<EOJS, $url);
<script>
parent.location.href='%s';
</script>
EOJS
$self->session->output->print($text);
return '';
}
#-------------------------------------------------------------------
=head2 render ( $options )
Returns a templated progress bar implemented in CSS and JS.
=head3 options
A hashref of options to configure the progress bar
=head3 title
A title to display above the progress bar.
=head3 statusUrl
The URL that the progress bar should use to get status information.
=cut
sub render {
my $self = shift;
my $options = shift;
$self->session->http->setCacheControl("none");
my %var = %{ $options };
$var{"icon"} = $self->{_icon};
my $template = WebGUI::Asset::Template->new($self->session, 'YP9WaMPJHvCJl-YwrLVcPw');
my $output = $template->process(\%var);
return $self->session->style->process($output,"PBtmpl0000000000000137");
}
#-------------------------------------------------------------------
=head2 session ( )
Returns a reference to the current session.
=cut
sub session {
my $self = shift;
return $self->{_session};
}
#-------------------------------------------------------------------
=head2 setIcon ( icon )
Sets the _function icon to parameter.
=head3 icon
A string representing the location of the icon.
=cut
sub setIcon {
my $self = shift;
my $icon = shift;
if ($icon) {
$self->{_icon} = $icon;
}
}
1;

View file

@ -272,6 +272,17 @@ our $I18N = {
context => q|To remove an item from the clipboard, and put it on the current page.|
},
'Paste Assets' => {
message => q|Paste Assets|,
lastUpdated => 1245342798,
},
'Pasting %s' => {
message => q|Pasting %s|,
lastUpdated => 1245343280,
context => q|short for "I am pasting this asset onto the page."|
},
'this asset only' => {
message => q|This&nbsp;Asset&nbsp;Only|,
lastUpdated => 0,

View file

@ -4470,6 +4470,11 @@ Users may override this setting in their profile.
lastUpdated => 0,
},
'Working...' => {
message => 'Working...',
lastUpdated => 0,
},
};
1;