From 056b1c8947326a5def37136caa0ef5b1af9a475f Mon Sep 17 00:00:00 2001 From: bfederle Date: Tue, 20 Dec 2011 10:30:15 -0800 Subject: [PATCH] WIP: Install wizard error handling --- ui/scripts-test/installWizard.js | 9 ++- ui/scripts/installWizard.js | 70 ++++++++++------- ui/scripts/network.js | 4 +- ui/scripts/ui-custom/installWizard.js | 105 +++++++++++++++++++------- 4 files changed, 131 insertions(+), 57 deletions(-) diff --git a/ui/scripts-test/installWizard.js b/ui/scripts-test/installWizard.js index 3f4c9342560..7a2b6a13e1f 100644 --- a/ui/scripts-test/installWizard.js +++ b/ui/scripts-test/installWizard.js @@ -218,7 +218,9 @@ action: function(args) { var complete = args.response.success; + var error = args.response.error; var message = args.response.message; + var startFn = args.startFn; var createZone = function(args) { message('Creating zone'); @@ -245,6 +247,7 @@ message('Creating cluster'); setTimeout(function() { createHost(); + //error('addCluster', 'Could not create cluster.', createPod); }, 500); }; @@ -274,7 +277,11 @@ setTimeout(complete, 5000); }; - createZone(); + if (startFn) { + startFn(); + } else { + createZone(); + } } }; }(jQuery, cloudStack, testData)); diff --git a/ui/scripts/installWizard.js b/ui/scripts/installWizard.js index f995c258774..d844c72a874 100644 --- a/ui/scripts/installWizard.js +++ b/ui/scripts/installWizard.js @@ -230,8 +230,10 @@ action: function(args) { var complete = args.response.success; + var error = args.response.error; var message = args.response.message; var data = args.data; + var startFn = args.startFn; var createZone = function(args) { message('Creating zone'); @@ -388,10 +390,7 @@ args.complete({ data: { zone: zoneObj } }); } }, - error: function(XMLHttpResponse) { - var errorMsg = parseXMLHttpResponse(XMLHttpResponse); - alert("updateNetworkServiceProvider failed. Error: " + errorMsg); - } + error: args.error }); }); } @@ -402,13 +401,12 @@ } } }, - error: function(XMLHttpResponse) { - var errorMsg = parseXMLHttpResponse(XMLHttpResponse); - alert("configureVirtualRouterElement failed. Error: " + errorMsg); - } + error: args.error }); }); - } + }, + + error: args.error }); } else if (result.jobstatus == 2) { @@ -416,24 +414,21 @@ } } }, - error: function(XMLHttpResponse) { - var errorMsg = parseXMLHttpResponse(XMLHttpResponse); - alert("updatePhysicalNetwork failed. Error: " + errorMsg); - } + error: args.error }); }); } }); //NaaS (end) }, - error: function(XMLHttpResponse) { - var errorMsg = parseXMLHttpResponse(XMLHttpResponse); - args.response.error(errorMsg); - } + error: args.error }); }; - addZoneAction({ data: data.zone, complete: createPod }); + addZoneAction({ data: data.zone, complete: createPod, error: function(json) { + debugger; + error('addZone', parseXMLHttpResponse(json), createZone); + } }); }; var createPod = function(args) { @@ -458,7 +453,7 @@ }, error: function(XMLHttpResponse) { var errorMsg = parseXMLHttpResponse(XMLHttpResponse); - args.response.error(errorMsg); + error(errorMsg); } }); }; @@ -571,17 +566,19 @@ success: function(json) { //var item = json.createvlaniprangeresponse.vlan; }, - error: function(XMLHttpResponse) { - //var errorMsg = parseXMLHttpResponse(XMLHttpResponse); - //args.response.error(errorMsg); + error: function(json) { + error('addNetwork', parseXMLHttpResponse(json), function() { + createNetwork(args); + }); } }); } }, - error: function(XMLHttpResponse) { - var errorMsg = parseXMLHttpResponse(XMLHttpResponse); - args.response.error(errorMsg); + error: function(json) { + error('addNetwork', parseXMLHttpResponse(json), function() { + createNetwork(args); + }); } }); }; @@ -602,6 +599,11 @@ response: { success: function(successArgs) { createCluster({ data: $.extend(args.data, { guestNetwork: successArgs.data })}); + }, + error: function(json) { + error('addNetwork', parseXMLHttpResponse(json), function() { + createNetwork(args); + }); } }, data: { @@ -615,7 +617,7 @@ networkOfferingId: networkOfferingID } }); - } + } }); }; @@ -638,6 +640,11 @@ cluster: data.addclusterresponse.cluster[0] }) }); + }, + error: function(json) { + error('addCluster', parseXMLHttpResponse(json), function() { + createCluster(args); + }); } }); }; @@ -664,6 +671,11 @@ host: data.addhostresponse.host[0] }) }); + }, + error: function(json) { + error('addHost', parseXMLHttpResponse(json), function() { + createHost(args); + }); } }); }; @@ -734,7 +746,11 @@ }, 5000); }; - createZone(); + if (startFn) { + startFn(); + } else { + createZone(); + } } }; }(jQuery, cloudStack, testData)); diff --git a/ui/scripts/network.js b/ui/scripts/network.js index 3d6ddb7980b..8cd5606ad82 100644 --- a/ui/scripts/network.js +++ b/ui/scripts/network.js @@ -86,8 +86,8 @@ name: { label: 'Name' }, zonename: { label: 'Zone' }, type: { label: 'Type' }, - traffictype: { label: 'Traffic Type' }, - gateway: { label: 'Gateway' }, + vlan: { label: 'VLAN' }, + cidr: { label: 'CIDR' }, state: { label: 'State', indicator: { 'Implemented': 'on', 'Setup': 'on' } } }, dataProvider: function(args) { diff --git a/ui/scripts/ui-custom/installWizard.js b/ui/scripts/ui-custom/installWizard.js index c999b7482e0..360c8abe22d 100644 --- a/ui/scripts/ui-custom/installWizard.js +++ b/ui/scripts/ui-custom/installWizard.js @@ -5,6 +5,9 @@ var $container = args.$container; var state = {}; // Hold wizard form state + var launchStart; // Holds last launch callback, in case of error + var $launchState; + /** * Successful installation action */ @@ -36,8 +39,10 @@ * @param stateStepID ID to group state elements in (i.e., zone, pod, cluster, ...) * @param $elem (optional) Element containing
, to serialize for state */ - var goTo = cloudStack._goto = function(stepID, stateID, $elem) { - var $nextStep = steps[stepID](); + var goTo = cloudStack._goto = function(stepID, stateID, $elem, options) { + if (!options) options = {}; + + var $nextStep = steps[stepID]({ nextStep: options.nextStep }); var $body = $installWizard.find('.body'); if (stateID && $elem) { @@ -83,7 +88,7 @@ $prev.click(function() { goTo(prevStepID); }); - + return function(args) { showDiagram(diagram); @@ -95,7 +100,7 @@ ); }; }, - + /** * A standard form-based wizard step template * -- relies on createForm for form generation @@ -134,7 +139,7 @@ $form.find('.form-item').addClass('field'); $prev.appendTo($form.find('form')); $save.appendTo($form.find('form')); - + // Submit handler $form.find('form').submit(function() { form.completeAction($form); @@ -153,8 +158,19 @@ $container.append($form.prepend($title)); showTooltip($form, tooltipID); - + return function(args) { + var overrideGotoEvent = function(event) { + goTo(args.nextStep); + + return false; + }; + + if (args && args.nextStep) { + $save.unbind('click'); + $save.click(overrideGotoEvent); + } + // Setup diagram, tooltips showDiagram(diagram); setTimeout(function() { @@ -350,7 +366,7 @@ nextStepID: 'addZone', diagram: '.part.zone' }), - + /** * Add zone form */ @@ -622,31 +638,66 @@ launch: function(args) { var $intro = $('
').addClass('intro'); var $title = $('
').addClass('title') - .html('Now building your cloud...'); - var $subtitle = $('
').addClass('subtitle') - .html(''); + .html('Now building your cloud...').appendTo($intro); + var $subtitle = $('
').addClass('subtitle').html('').appendTo($intro); - cloudStack.installWizard.action({ - data: state, - response: { - message: function(msg) { - var $li = $('
  • ').html(msg); - - $subtitle.append($li); - - $li.siblings().addClass('complete'); - }, - success: function() { - goTo('complete'); - } + var doAction = function() { + if (launchStart) { + $('.subtitle').children().remove(); } - }); + + cloudStack.installWizard.action({ + data: state, + startFn: launchStart, + response: { + message: function(msg) { + var $li = $('
  • ').html(msg); + if (launchStart) { + $li.appendTo('.subtitle'); + $li.parent().find('li') + .filter(function() { + return this != $li.get(0); + }).addClass('complete'); + } else { + $subtitle.append($li); + $li.siblings().addClass('complete'); + } + }, + success: function() { + goTo('complete'); + }, + error: function(stepID, message, callback) { + if (launchStart) { + $subtitle = $('.subtitle'); + $subtitle.children().remove(); + $('li').children().remove(); + } + + launchStart = callback; + $subtitle.find('li:last').addClass('error'); + + $subtitle.append( + $('

    ').html( + 'Something went wrong; you may go back and correct any errors.' + ), + $('

    ').addClass('button').append( + $('').html('Go back') + ).click(function() { + goTo(stepID, null, null, { + nextStep: 'launch' + }); + }) + ); + } + } + }); + }; + + doAction(); showDiagram('.part.loading'); - return $intro.append( - $title, $subtitle - ); + return $intro; }, complete: function(args) {