the 'cut' drop down (AssetHelper) operation basically worked, but the screen wasn't redrawn after the change, and the JSON returned during Fork polling in WebGUI::AssetHelper::Cut didn't match what the YAHOO.WebGUI.Fork.poll callback in WebGUI.Admin.prototype.openForkDialog was expecting so status communication had to be wired up. wG::ProgressTree exposes 'flat' now too for the sake of computing a progress bar. looking at only the roots nodes is ineffective; in this case, the number of root nodes would only ever be 1 though the number of child nodes to be processed could be much higher. WebGUI.Admin.prototype.openForkDialog's callback to YAHOO.WebGUI.Fork.poll handles a status JSON message (JSON inside of JSON, ugh) of "reload" and there's an admin.reload() method now. that's also callable from WebGUI.Admin.prototype.processPlugin and was done in the style of its handlers.
This commit is contained in:
parent
3061626753
commit
8be9ed7d59
3 changed files with 81 additions and 6 deletions
|
|
@ -4,6 +4,8 @@ use strict;
|
|||
use base qw/WebGUI::AssetHelper/;
|
||||
use Scalar::Util qw( blessed );
|
||||
use Monkey::Patch;
|
||||
use JSON;
|
||||
use Data::Dumper;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
|
|
@ -68,6 +70,7 @@ sub process {
|
|||
=head2 cut ( process, args )
|
||||
|
||||
Handle the actual cutting in the forked process.
|
||||
After this routine returns, C<Forks> marks this task as finished.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -80,14 +83,40 @@ sub cut {
|
|||
|
||||
# Build a tree and update process status
|
||||
my $tree = WebGUI::ProgressTree->new( $process->session, $assetIds );
|
||||
$process->update( sub { $tree->json } );
|
||||
|
||||
# flat() return s a hash of all nodes to be done
|
||||
my $maxValue = keys %{ $tree->flat };
|
||||
|
||||
my $update_progress = sub {
|
||||
# update the Fork's progress with how many are done
|
||||
my $flat = $tree->flat;
|
||||
my @done = grep { $_->{success} or $_->{failure} } values %$flat;
|
||||
my $current_value = scalar @done;
|
||||
my $info = {
|
||||
maxValue => $maxValue,
|
||||
value => $current_value,
|
||||
message => 'Working...',
|
||||
reload => 1, # this won't take effect until Fork.pm returns finished => 1 and this status is propogated to WebGUI.Admin.prototype.openForkDialog's callback
|
||||
@_,
|
||||
};
|
||||
$info->{refresh} = 1 if $maxValue == $current_value;
|
||||
# $info->{debug_flat_keys} = join ',', keys %$flat;
|
||||
# $info->{debug_tree} = Dumper( $tree->tree );
|
||||
my $json = JSON::encode_json( $info );
|
||||
$process->update( $json );
|
||||
};
|
||||
|
||||
$update_progress->( debug_initial => 1 );
|
||||
|
||||
# Monkeypatch a sub to get a status update
|
||||
my $patch = Monkey::Patch::patch_class(
|
||||
'WebGUI::Asset', 'updateHistory', sub {
|
||||
my ( $orig, $self, @args ) = @_;
|
||||
$tree->success( $self->assetId );
|
||||
$process->update( sub { $tree->json } );
|
||||
|
||||
$tree->success( $self->assetId ); # this should add it to the @done set / $current_value count as computed above
|
||||
|
||||
$update_progress->();
|
||||
|
||||
$self->$orig( @args );
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -145,12 +145,26 @@ sub focus {
|
|||
|
||||
=head2 tree
|
||||
|
||||
A hashy representation of the status of this tree of assets.
|
||||
Return an arrayref of hashes of the root nodes of the assets being worked on.
|
||||
Entries in the hashes include C<assetId>, C<parentId>, C<url>, and possibily C<children>.
|
||||
If C<chlidren> is present, it contains an array of similar hash nodes which might also have C<children>.
|
||||
|
||||
=cut
|
||||
|
||||
sub tree { $_[0]->{tree} }
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 flat
|
||||
|
||||
Return a hashref mapping C<assetId> to a hash of C<assetId>, C<parentId>, and C<url>.
|
||||
This is a flattened representation of what C<tree> returns.
|
||||
|
||||
=cut
|
||||
|
||||
sub flat { $_[0]->{flat} }
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 json
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue