VersionTag rollback moved to Fork

This commit is contained in:
Paul Driver 2010-10-06 08:51:27 -07:00
parent 895ce37917
commit 04fa1ca794
8 changed files with 241 additions and 105 deletions

View file

@ -35,42 +35,18 @@ These subroutines are available from this package:
use Template;
use HTML::Entities;
use JSON;
use WebGUI::Fork::ProgressBar;
my $template = <<'TEMPLATE';
<p>
<div id='meter'>
<div id='meter-bar'>
<div id='meter-text'></div>
</div>
</div>
<div id='meter'></div>
Current asset: <span id='focus'></span>
(<span id='finished'></span>/<span id='total'></span>).<br />
<span id='elapsed'></span> seconds elapsed.
<ul id='tree'></ul>
[% MACRO inc(file) BLOCK %]<script src="$extras/$file"></script>[% END %]
[% MACRO yui(file) BLOCK %][% inc("yui/build/$file") %][% END %]
[% yui("yahoo/yahoo-min.js") %]
[% yui("json/json-min.js") %]
[% yui("event/event-min.js") %]
[% yui("connection/connection_core-min.js") %]
[% inc("underscore/underscore-min.js") %]
<script>
(function (params) {
var JSON = YAHOO.lang.JSON, statusUrl = params.statusUrl;
var bar = new YAHOO.WebGUI.Fork.ProgressBar();
function finish() {
var redir = params.redirect;
if (redir) {
setTimeout(function() {
// The idea here is to only allow local redirects
var loc = window.location;
loc.href = loc.protocol + '//' + loc.host + redir;
}, 1000);
}
}
function error(msg) {
alert(msg);
}
function setHtml(id, html) {
document.getElementById(id).innerHTML = html;
}
@ -82,18 +58,18 @@ Current asset: <span id='focus'></span>
total += 1;
txt = asset.url;
if (asset.focus) {
li.className += 'focus';
focus = asset.url;
if (asset.success) {
li.className = 'success';
finished += 1;
}
else if (asset.failure) {
li.className = 'failure';
txt += ' (' + asset.failure + ')';
finished += 1;
}
else if (asset.success) {
li.className = 'success';
finished += 1;
if (asset.focus) {
li.className += 'focus';
focus = asset.url;
}
li.appendChild(document.createTextNode(txt));
if (notes = asset.notes) {
@ -117,55 +93,31 @@ Current asset: <span id='focus'></span>
_.each(JSON.parse(data.status), function (root) {
recurse(root, tree);
});
pct = Math.floor((finished/total)*100) + '%';
setHtml('meter-text', pct);
document.getElementById('meter-bar').style.width = pct;
bar.update(finished, total);
setHtml('total', total);
setHtml('finished', finished);
setHtml('focus', focus || 'nothing');
setHtml('elapsed', 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);
finish();
}
else {
draw(data);
setTimeout(fetch, 1000);
}
YAHOO.util.Event.onDOMReady(function () {
bar.render('meter');
YAHOO.WebGUI.Fork.poll({
url : params.statusUrl,
draw : draw,
finish : function () {
YAHOO.WebGUI.Fork.redirect(params.redirect);
},
failure: function (o) {
error("Could not communicate with server");
error : function (msg) {
alert(msg)
}
};
YAHOO.util.Connect.asyncRequest('GET', statusUrl, callback, null);
}
YAHOO.util.Event.onDOMReady(fetch);
});
});
}([% params %]));
</script>
TEMPLATE
my $stylesheet = <<'STYLESHEET';
<style>
#meter { border: thin solid black; position: relative }
#meter-bar { background-color: lime; font-size: 18pt;
height: 20pt; line-height: 20pt }
#meter-text { position: absolute; top: 0; left: 0; width: 100%;
text-align: center }
#tree li { color: black }
#tree li.focus { color: cyan }
#tree li.failure { color: red }
@ -184,22 +136,11 @@ See WebGUI::Operation::Fork.
sub handler {
my $process = shift;
my $session = $process->session;
my $style = $session->style;
my $url = $session->url;
my $form = $session->form;
my $tt = Template->new( { INTERPOLATE => 1 } );
my %vars = (
params => JSON::encode_json( {
statusUrl => $url->page( $process->contentPairs('Status') ),
redirect => scalar $form->get('proceed'),
}
),
extras => $url->extras,
);
$tt->process( \$template, \%vars, \my $content ) or die $tt->error;
my $console = WebGUI::AdminConsole->new( $session, $form->get('icon') );
$session->style->setRawHeadTags($stylesheet);
return $console->render( $content, encode_entities( $form->get('title') ) );
} ## end sub handler
$style->setRawHeadTags($stylesheet);
$style->setScript($url->extras('underscore/underscore-min.js'));
WebGUI::Fork::ProgressBar::renderBar($process, $template);
}
1;