Rename to WebGUI::Fork
This commit is contained in:
parent
c8fd0b56ed
commit
f2e0a4f667
12 changed files with 88 additions and 88 deletions
173
lib/WebGUI/Fork/AssetExport.pm
Normal file
173
lib/WebGUI/Fork/AssetExport.pm
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
package WebGUI::Fork::AssetExport;
|
||||
|
||||
=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;
|
||||
use warnings;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
WebGUI::Fork::AssetExport
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Renders an admin console page that polls ::Status to draw a friendly graphical
|
||||
representation of how an export is coming along.
|
||||
|
||||
=head1 SUBROUTINES
|
||||
|
||||
These subroutines are available from this package:
|
||||
|
||||
=cut
|
||||
|
||||
use Template;
|
||||
|
||||
my $template = <<'TEMPLATE';
|
||||
<p>
|
||||
Currently exporting <span id='current'></span>
|
||||
(<span id='finished'></span>/<span id='total'></span>).<br />
|
||||
<span id='elapsed'></span> seconds elapsed.
|
||||
</p>
|
||||
<ul id='tree'></ul>
|
||||
[% MACRO yui(file) BLOCK %]
|
||||
<script src="$extras/yui/build/$file"></script>
|
||||
[% END %]
|
||||
[% yui("yahoo/yahoo-min.js") %]
|
||||
[% yui("json/json-min.js") %]
|
||||
[% yui("event/event-min.js") %]
|
||||
[% yui("connection/connection_core-min.js") %]
|
||||
<script>
|
||||
(function (statusUrl) {
|
||||
var JSON = YAHOO.lang.JSON;
|
||||
function error(msg) {
|
||||
alert(msg);
|
||||
}
|
||||
function draw(data) {
|
||||
var ul, old, finished = 0, total = 0, current;
|
||||
function recurse(asset, node) {
|
||||
var li = document.createElement('li'), txt, notes, ul, i;
|
||||
|
||||
total += 1;
|
||||
|
||||
txt = asset.url;
|
||||
if (asset.current) {
|
||||
li.className += 'current';
|
||||
current = asset.url;
|
||||
}
|
||||
else if (asset.badUserPrivileges) {
|
||||
li.className = 'error';
|
||||
txt += ' (bad user privileges)';
|
||||
finished += 1;
|
||||
}
|
||||
else if (asset.notExportable) {
|
||||
li.className = 'error';
|
||||
txt += ' (not exportable)';
|
||||
finished += 1;
|
||||
}
|
||||
else if (asset.done) {
|
||||
li.className = 'done';
|
||||
finished += 1;
|
||||
}
|
||||
li.appendChild(document.createTextNode(txt));
|
||||
if (asset.collateralNotes) {
|
||||
notes = document.createElement('p');
|
||||
notes.innerHTML = asset.collateralNotes;
|
||||
li.appendChild(notes);
|
||||
}
|
||||
if (asset.children) {
|
||||
ul = document.createElement('ul');
|
||||
for (i = 0; i < asset.children.length; i += 1) {
|
||||
recurse(asset.children[i], ul);
|
||||
li.appendChild(ul);
|
||||
}
|
||||
}
|
||||
node.appendChild(li);
|
||||
}
|
||||
ul = document.createElement('ul');
|
||||
old = document.getElementById('tree');
|
||||
ul.id = old.id;
|
||||
recurse(JSON.parse(data.status), ul);
|
||||
old.parentNode.replaceChild(ul, old);
|
||||
document.getElementById('total').innerHTML = total;
|
||||
document.getElementById('finished').innerHTML = finished;
|
||||
document.getElementById('current').innerHTML = current || 'nothing';
|
||||
document.getElementById('elapsed').innerHTML = data.elapsed;
|
||||
}
|
||||
function fetch() {
|
||||
var callback = {
|
||||
success: function (o) {
|
||||
var data, status;
|
||||
if (o.status != 200) {
|
||||
error("Server returned bad response");
|
||||
return;
|
||||
}
|
||||
data = JSON.parse(o.responseText);
|
||||
if (data.error) {
|
||||
error(data.error);
|
||||
}
|
||||
else if (data.finished) {
|
||||
draw(data);
|
||||
}
|
||||
else {
|
||||
draw(data);
|
||||
setTimeout(fetch, 1000);
|
||||
}
|
||||
},
|
||||
failure: function (o) {
|
||||
error("Could not communicate with server");
|
||||
}
|
||||
};
|
||||
YAHOO.util.Connect.asyncRequest('GET', statusUrl, callback, null);
|
||||
}
|
||||
YAHOO.util.Event.onDOMReady(fetch);
|
||||
}("$statusUrl"));
|
||||
</script>
|
||||
TEMPLATE
|
||||
|
||||
my $stylesheet = <<'STYLESHEET';
|
||||
<style>
|
||||
#tree li { color: black }
|
||||
#tree li.current { color: cyan }
|
||||
#tree li.error { color: red }
|
||||
#tree li.done { color: green }
|
||||
</style>
|
||||
STYLESHEET
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 handler ( process )
|
||||
|
||||
See WebGUI::Operation::Fork.
|
||||
|
||||
=cut
|
||||
|
||||
sub handler {
|
||||
my $process = shift;
|
||||
my $session = $process->session;
|
||||
my $url = $session->url;
|
||||
my $tt = Template->new( { INTERPOLATE => 1 } );
|
||||
my %vars = (
|
||||
statusUrl => $url->page( $process->contentPairs('Status') ),
|
||||
extras => $session->url->extras,
|
||||
);
|
||||
$tt->process( \$template, \%vars, \my $content ) or die $tt->error;
|
||||
|
||||
my $console = WebGUI::AdminConsole->new( $process->session, 'assets' );
|
||||
$session->style->setRawHeadTags($stylesheet);
|
||||
my $i18n = WebGUI::International->new( $session, 'Asset' );
|
||||
return $console->render( $content, $i18n->get('Page Export Status') );
|
||||
} ## end sub handler
|
||||
|
||||
1;
|
||||
84
lib/WebGUI/Fork/Status.pm
Normal file
84
lib/WebGUI/Fork/Status.pm
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
package WebGUI::Fork::Status;
|
||||
|
||||
use JSON;
|
||||
|
||||
=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;
|
||||
use warnings;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
WebGUI::Fork::Status
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Returns a json response of the following form:
|
||||
|
||||
{
|
||||
"finished" : true,
|
||||
"elapsed" : 10,
|
||||
"status" : "whatever is in the status field. Could be anything.",
|
||||
"error" : "whatever is in the error field"
|
||||
}
|
||||
|
||||
Note that if your status is JSON, you'll have to decode that seperately, so
|
||||
something like:
|
||||
|
||||
decoded = JSON.parse(r.responseText);
|
||||
status = JSON.parse(decoded.status);
|
||||
|
||||
Finished is obviously true or false. Notably, it will be true in the error
|
||||
case: so to status.finished && !status.error means successful completion.
|
||||
Error will only be present if the process died for some reason.
|
||||
|
||||
Status will always be present, mostly so you can see what the last status was
|
||||
before it died.
|
||||
|
||||
Elapsed will be the number of seconds since the process started (or until the
|
||||
process finished, if it is finished).
|
||||
|
||||
=head1 SUBROUTINES
|
||||
|
||||
These subroutines are available from this package:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 handler ( process )
|
||||
|
||||
See the synopsis for what kind of response this generates.
|
||||
|
||||
=cut
|
||||
|
||||
sub handler {
|
||||
my $process = shift;
|
||||
my $status = $process->getStatus;
|
||||
my ( $finished, $startTime, $endTime, $error ) = $process->get( 'finished', 'startTime', 'endTime', 'error' );
|
||||
|
||||
$endTime = time() unless $finished;
|
||||
|
||||
my %status = (
|
||||
status => $status,
|
||||
elapsed => ( $endTime - $startTime ),
|
||||
finished => ( $finished ? \1 : \0 ),
|
||||
);
|
||||
$status{error} = $error if $finished;
|
||||
$process->session->http->setMimeType('text/plain');
|
||||
JSON::encode_json( \%status );
|
||||
} ## end sub handler
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue