From 8c242b7e88d3cd76c9d576dcf39e1c2492bb423f Mon Sep 17 00:00:00 2001 From: bfederle Date: Thu, 22 Dec 2011 10:31:22 -0800 Subject: [PATCH] Projects dashboard fixes and cleanup -Fix dashboard calling API twice per item -Only show 8 latest events, to shortern load time -Whitespace/code cleanup --- ui/scripts/projects.js | 34 +++++++++++++++++++------------- ui/scripts/ui-custom/projects.js | 23 ++++++++++----------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/ui/scripts/projects.js b/ui/scripts/projects.js index d33374914ae..44c15ddbbaf 100644 --- a/ui/scripts/projects.js +++ b/ui/scripts/projects.js @@ -18,13 +18,13 @@ success: function(json) { updatedResources++; if (updatedResources == totalResources) { - args.response.success(); + args.response.success(); } } }); }); }, - + dataProvider: function(args) { $.ajax({ url: createURL('listResourceLimits'), @@ -70,7 +70,7 @@ }); } }); - + } }, @@ -80,9 +80,9 @@ $.ajax({ url: createURL('listVirtualMachines'), success: function(json) { - var instances = json.listvirtualmachinesresponse.virtualmachine ? + var instances = json.listvirtualmachinesresponse.virtualmachine ? json.listvirtualmachinesresponse.virtualmachine : []; - + dataFns.storage($.extend(data, { runningInstances: $.grep(instances, function(instance) { return instance.state == 'Running'; @@ -124,7 +124,7 @@ id: network.networkofferingid }, success: function(json) { - totalBandwidth += + totalBandwidth += json.listnetworkofferingsresponse.networkoffering[0].networkrate; } }); @@ -193,13 +193,19 @@ events: function(data) { $.ajax({ url: createURL('listEvents', { ignoreProject: true }), + data: { + page: 1, + pageSize: 8 + }, success: function(json) { var events = json.listeventsresponse.event; complete($.extend(data, { events: $.map(events, function(event) { return { - date: event.created.substr(5, 2) + '/' + event.created.substr(8, 2) + '/' + event.created.substr(2, 2), + date: event.created.substr(5, 2) + + '/' + event.created.substr(8, 2) + + '/' + event.created.substr(2, 2), desc: event.description }; }) @@ -381,7 +387,7 @@ actionPreFilter: function(args) { if (!cloudStack.context.projects && args.context.multiRule[0].role != 'Admin') { // This is for the new project wizard - return ['destroy']; + return ['destroy']; } if (args.context.multiRule[0].role != 'Admin') { @@ -489,10 +495,10 @@ data.listprojectsresponse.project ? data.listprojectsresponse.project : [], function(elem) { - return $.extend(elem, { - displayText: elem.displaytext - }); - }) + return $.extend(elem, { + displayText: elem.displaytext + }); + }) }); } }); @@ -812,14 +818,14 @@ var projectsActionFilter = function(args) { var allowedActions = ['destroy']; - + if (args.context.item.account == cloudStack.context.users[0].account || args.context.users[0].role == '1') { if (args.context.item.state == 'Suspended') { allowedActions.push('enable'); } else if (args.context.item.state == 'Active') { allowedActions.push('disable'); } - + return allowedActions; } diff --git a/ui/scripts/ui-custom/projects.js b/ui/scripts/ui-custom/projects.js index 72afa1685f6..c362e918bbc 100644 --- a/ui/scripts/ui-custom/projects.js +++ b/ui/scripts/ui-custom/projects.js @@ -4,7 +4,7 @@ * User management multi-edit */ userManagement: function(args) { - var multiEdit = !args.useInvites ? + var multiEdit = !args.useInvites ? cloudStack.projects.addUserForm : cloudStack.projects.inviteForm; @@ -62,7 +62,7 @@ } else { $item.hide().html(value).fadeIn(); } - }); + }); } }); } @@ -94,14 +94,14 @@ if (g_capabilities.projectinviterequired) { tabs.invitations = function() { return $('
').addClass('management-invite').data('tab-title', 'Invitations'); - }; + }; } tabs.resources = function() { var $resources = $('
').addClass('resources').data('tab-title', 'Resources'); var $form = $('
'); var $submit = $('').attr({ - type: 'submit' + type: 'submit' }).val('Apply'); cloudStack.projects.resourceManagement.dataProvider({ @@ -118,7 +118,7 @@ name: resource.type, value: resource.value }).addClass('required'); - + $field.append($label, $input); $field.appendTo($form); }); @@ -147,7 +147,7 @@ } } }); - + return false; }); @@ -156,7 +156,7 @@ } } }); - + return $resources; }; } @@ -167,14 +167,15 @@ // Make UI tabs $.each(tabs, function(tabName, tab) { var $tab = $('
  • ').appendTo($tabs.find('ul:first')); + var $tabContent = tab(); var $tabLink = $('') .attr({ href: '#project-view-dashboard-' + tabName }) - .html(tab().data('tab-title')) + .html($tabContent.data('tab-title')) .appendTo($tab); var $content = $('
    ') .appendTo($tabs) .attr({ id: 'project-view-dashboard-' + tabName }) - .append(tab); + .append($tabContent); }); $tabs.find('ul li:first').addClass('first'); @@ -252,7 +253,7 @@ var project = args.data; $(window).trigger('cloudStack.fullRefresh'); - + $loading.remove(); // Confirmation @@ -346,7 +347,7 @@ var $instanceRow = args.$instanceRow; $instanceRow.animate({ opacity: 0.5 }); - + cloudStack.projects.addUserForm.actions.destroy.action({ context: $.extend(true, {}, cloudStack.context, { projects: [project],