Instrument www_demote, www_promote, demote, promote and swapRank with ProgressBar code.

This commit is contained in:
Colin Kuskie 2009-06-19 15:34:31 +00:00
parent cbc308c55a
commit e518dbe1b3
4 changed files with 70 additions and 18 deletions

View file

@ -333,6 +333,8 @@ sub www_editBranchSave {
};
delete $self->{_parent};
$self->session->asset($self->getParent);
##Since this method originally returned the user to the AssetManager, we don't need
##to use $pb->finish to redirect back there.
return $self->getParent->www_manageAssets;
}

View file

@ -138,14 +138,20 @@ Swaps lineage with sister below. Returns 1 if there is a sister to swap. Otherwi
This will update the lineage of $self, but not the sister.
=head3 outputSub
A reference to a subroutine that output messages should be sent to. Typically this would
go to ProgressBar.
=cut
sub demote {
my $self = shift;
my $self = shift;
my $outputSub = shift || sub {};
my ($sisterLineage) = $self->session->db->quickArray("select min(lineage) from asset
where parentId=? and state='published' and lineage>?",[$self->get('parentId'), $self->get('lineage')]);
if (defined $sisterLineage) {
$self->swapRank($sisterLineage);
$self->swapRank($sisterLineage, undef, $outputSub);
$self->{_properties}{lineage} = $sisterLineage;
return 1;
}
@ -789,20 +795,26 @@ sub newByLineage {
#-------------------------------------------------------------------
=head2 promote ( )
=head2 promote ( [ $outputSub ] )
Keeps the same rank of lineage, swaps with sister above. Returns 1 if there is a sister to swap. Otherwise returns 0.
This will update the lineage of $self, but not the sister.
=head3 outputSub
A reference to a subroutine that output messages should be sent to. Typically this would
go to ProgressBar.
=cut
sub promote {
my $self = shift;
my $self = shift;
my $outputSub = shift || sub {};
my ($sisterLineage) = $self->session->db->quickArray("select max(lineage) from asset
where parentId=? and state='published' and lineage<?",[$self->get("parentId"), $self->get("lineage")]);
if (defined $sisterLineage) {
$self->swapRank($sisterLineage);
$self->swapRank($sisterLineage, undef, $outputSub);
$self->{_properties}{lineage} = $sisterLineage;
return 1;
}
@ -898,13 +910,16 @@ no in the objects.
=cut
sub swapRank {
my $self = shift;
my $second = shift;
my $first = shift || $self->get("lineage");
my $self = shift;
my $second = shift;
my $first = shift || $self->get("lineage");
my $outputSub = shift || sub {};
my $temp = substr($self->session->id->generate(),0,6); # need a temp in order to do the swap
$self->session->db->beginTransaction;
$outputSub->('swap first'); ##Note, i18n call passed in from caller-1
$self->cascadeLineage($temp,$first);
$self->cascadeLineage($first,$second);
$outputSub->('swap second');
$self->cascadeLineage($second,$temp);
$self->session->db->commit;
$self->updateHistory("swapped lineage between ".$first." and ".$second);
@ -921,10 +936,15 @@ Demotes self and returns www_view method of getContainer of self if canEdit, oth
=cut
sub www_demote {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
$self->demote;
return $self->session->asset($self->getContainer)->www_view;
my $self = shift;
my $session = $self->session;
return $self->session->privilege->insufficient() unless $self->canEdit;
my $i18n = WebGUI::International->new($session, 'Asset');
my $pb = WebGUI::ProgressBar->new($session);
$pb->start($i18n->get('demote'), $session->url->extras('adminConsole/assets.gif'));
$pb->update(sprintf $i18n->get('demote %s'), $self->getTitle);
$self->demote(sub{ $pb->update($i18n->get(shift))});
$pb->finish($self->getContainer->getUrl);
}
@ -937,10 +957,15 @@ Returns www_view method of getContainer of self. Promotes self. If canEdit is Fa
=cut
sub www_promote {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
$self->promote;
return $self->session->asset($self->getContainer)->www_view;
my $self = shift;
my $session = $self->session;
return $self->session->privilege->insufficient() unless $self->canEdit;
my $i18n = WebGUI::International->new($session, 'Asset');
my $pb = WebGUI::ProgressBar->new($session);
$pb->start($i18n->get('promote'), $session->url->extras('adminConsole/assets.gif'));
$pb->update(sprintf $i18n->get('promote %s'), $self->getTitle);
$self->promote(sub{ $pb->update($i18n->get(shift))});
$pb->finish($self->getContainer->getUrl);
}

View file

@ -217,13 +217,31 @@ our $I18N = {
'restore' => {
message => q|Restore|,
lastUpdated => 0,
context => q|Used in asset context menus.|
context => q|Used in asset context menus.|,
},
'promote' => {
message => q|Promote|,
lastUpdated => 0,
context => q|Used in asset context menus.|
context => q|Used in asset context menus.|,
},
'promote %s' => {
message => q|promote %s|,
lastUpdated => 0,
context => q|Used in asset context menus.|,
},
'swap first' => {
message => q|swap first|,
lastUpdated => 0,
context => q|swap, to exchange places|,
},
'swap second' => {
message => q|swap second|,
lastUpdated => 0,
context => q|swap, to exchange places|,
},
'promote help' => {
@ -242,6 +260,12 @@ our $I18N = {
lastUpdated => 0,
},
'demote %s' => {
message => q|demote %s|,
lastUpdated => 0,
context => q|Used in asset context menus.|,
},
'cut' => {
message => q|Cut|,
lastUpdated => 0,