diff --git a/lib/WebGUI/AssetHelper/Cut.pm b/lib/WebGUI/AssetHelper/Cut.pm index dd8e79a96..4d8b32b65 100644 --- a/lib/WebGUI/AssetHelper/Cut.pm +++ b/lib/WebGUI/AssetHelper/Cut.pm @@ -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 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 ); } ); diff --git a/lib/WebGUI/ProgressTree.pm b/lib/WebGUI/ProgressTree.pm index b83497bfa..91179c40e 100644 --- a/lib/WebGUI/ProgressTree.pm +++ b/lib/WebGUI/ProgressTree.pm @@ -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, C, C, and possibily C. +If C is present, it contains an array of similar hash nodes which might also have C. =cut sub tree { $_[0]->{tree} } +#------------------------------------------------------------------- + +=head2 flat + +Return a hashref mapping C to a hash of C, C, and C. +This is a flattened representation of what C returns. + +=cut + +sub flat { $_[0]->{flat} } + + #------------------------------------------------------------------- =head2 json diff --git a/www/extras/admin/admin.js b/www/extras/admin/admin.js index f09c17bc9..8fdd01ded 100644 --- a/www/extras/admin/admin.js +++ b/www/extras/admin/admin.js @@ -171,7 +171,6 @@ WebGUI.Admin = function(cfg){ } } ); - }; /** @@ -288,6 +287,27 @@ WebGUI.Admin.prototype.gotoAsset } }; +/** + * reload() + * Open the appropriate tab (View or Tree) and force a reload of the current URL + */ +WebGUI.Admin.prototype.reload += function () { + if ( this.tabBar.get('activeIndex') > 1 ) { + this.tabBar.selectTab( 0 ); + this.currentTab = "view"; + } + if ( this.currentTab == "view" ) { + window.frames[ "view" ].location.reload(1); + this.treeDirty = 1; + } + else if ( this.currentTab == "tree" ) { + // Make tree request + this.tree.goto( window.frames[ "view" ].location.href ); + this.viewDirty = 1; + } +}; + /** * showView ( [url] ) * Open the view tab, optionally navigating to the given URL @@ -695,6 +715,7 @@ WebGUI.Admin.prototype.requestHelper * scriptFile : Load a JS file * scriptFunc : Run a JS function. Used with scriptFile * scriptArgs : Arguments to scriptFunc. Used with scriptFile + * reload : Reload the current page eg after an asset cut or paste */ WebGUI.Admin.prototype.processPlugin = function ( resp ) { @@ -719,6 +740,9 @@ WebGUI.Admin.prototype.processPlugin else if ( resp.redirect ) { this.gotoAsset( resp.redirect ); } + else if ( resp.reload ) { + this.reload(); + } else { alert( "Unknown plugin response: " + YAHOO.lang.JSON.stringify(resp) ); } @@ -851,6 +875,7 @@ WebGUI.Admin.prototype.openForkDialog url : '?op=fork;pid=' + forkId, draw : function(data) { var status = YAHOO.lang.JSON.parse( data.status ); + // console.log(status); if ( status ) { pbTaskBar.set( 'maxValue', status.total ); pbTaskBar.set( 'value', status.finished ); @@ -859,10 +884,15 @@ WebGUI.Admin.prototype.openForkDialog }, finish : function(data){ var status = YAHOO.lang.JSON.parse( data.status ); + // console.log(status); if ( status.redirect ) { - alert("Dispensing product..."); + // alert("Dispensing product..."); window.admin.gotoAsset( status.redirect ); } + if ( status.reload ) { + // alert("Reload requested..."); + window.admin.reload(); + } dialog.destroy(); dialog = null; // TODO: Handle the last request of the forked process @@ -1877,6 +1907,8 @@ WebGUI.Admin.Tree.prototype.runHelperForSelected var self = this; var assetIds = this.getSelected(); + // alert("ok"); + // Open the dialog with two progress bars var dialog = new YAHOO.widget.Panel( 'helperForkModalDialog', { "width" : '350px',