diff --git a/ui/scripts-test/dashboard.js b/ui/scripts-test/dashboard.js
index 70e56f4eb44..705cf3cd425 100644
--- a/ui/scripts-test/dashboard.js
+++ b/ui/scripts-test/dashboard.js
@@ -1,11 +1,61 @@
-(function(cloudStack) {
+(function(cloudStack, testData) {
// Admin dashboard
cloudStack.sections.dashboard = {
title: 'Dashboard',
show: function() {
- return $('
![]()
').attr({
- src: 'images/screens/Dashboard2.jpg'
+ var $dashboard = $('#template').find('div.dashboard.admin').clone();
+
+ $dashboard.find('.view-all').click(function() {
+ $('#navigation li.events').click();
+ });
+
+ var getData = function() {
+ // Populate data
+ $dashboard.find('[data-item]').hide();
+ cloudStack.sections.dashboard.dataProvider({
+ response: {
+ success: function(args) {
+ var data = args.data;
+
+ $.each(data, function(key, value) {
+ var $elem = $dashboard.find('[data-item=' + key + ']');
+
+ $elem.each(function() {
+ var $item = $(this);
+ if ($item.hasClass('chart-line')) {
+ $item.show().animate({ width: value + '%' });
+ } else {
+ $item.hide().html(value).fadeIn();
+ }
+ });
+ });
+ }
+ }
+ });
+ };
+
+ getData();
+
+ return $dashboard;
+ },
+
+ dataProvider: function(args) {
+ args.response.success({
+ data: {
+ publicIPAllocated: 50,
+ publicIPTotal: 100,
+ publicIPPercentage: 50,
+ privateIPAllocated: 50,
+ privateIPTotal: 100,
+ privateIPPercentage: (100 / 50) * 10,
+ memoryAllocated: 256,
+ memoryTotal: 1024,
+ memoryPercentage: (1024 / 256) * 10,
+ cpuAllocated: 500,
+ cpuTotal: 1200,
+ cpuPercentage: (1200 / 500) * 10
+ }
});
}
- };
-})(cloudStack);
+ };
+})(cloudStack, testData);
diff --git a/ui/scripts/dashboard.js b/ui/scripts/dashboard.js
index 5b7a2b28f75..0de0544312e 100644
--- a/ui/scripts/dashboard.js
+++ b/ui/scripts/dashboard.js
@@ -9,18 +9,103 @@
$('#navigation li.events').click();
});
- return $dashboard;
- }
- };
+ var getData = function() {
+ // Populate data
+ $dashboard.find('[data-item]').hide();
+ cloudStack.sections.dashboard.dataProvider({
+ response: {
+ success: function(args) {
+ var data = args.data;
- // User dashboard
- /*
- cloudStack.sections['dashboard-user'] = {
- title: 'Dashboard (user)',
- show: function() {
- return $('#template').find('div.dashboard.user').clone();
+ $.each(data, function(key, value) {
+ var $elem = $dashboard.find('[data-item=' + key + ']');
+
+ $elem.each(function() {
+ var $item = $(this);
+ if ($item.hasClass('chart-line')) {
+ $item.show().animate({ width: value + '%' });
+ } else {
+ $item.hide().html(value).fadeIn();
+ }
+ });
+ });
+ }
+ }
+ });
+ };
+
+ getData();
+
+ return $dashboard;
+ },
+
+ dataProvider: function(args) {
+ var dataFns = {
+ zones: function(data) {
+ $.ajax({
+ url: createURL('listZones'),
+ success: function(json) {
+ dataFns.capacity({
+ zones: json.listzonesresponse.zone
+ });
+ }
+ });
+ },
+ capacity: function(data) {
+ if (data.zones) {
+ $.ajax({
+ url: createURL('listCapacity'),
+ success: function(json) {
+ var capacities = json.listcapacityresponse.capacity;
+
+ var capacity = function(id, converter) {
+ return $.grep(capacities, function(capacity) {
+ return capacity.type == id;
+ })[0];
+ };
+
+ complete($.extend(data, {
+ publicIPAllocated: capacity(8).capacityused,
+ publicIPTotal: capacity(8).capacitytotal,
+ publicIPPercentage: parseInt(capacity(8).percentused),
+ privateIPAllocated: capacity(5).capacityused,
+ privateIPTotal: capacity(5).capacitytotal,
+ privateIPPercentage: parseInt(capacity(8).percentused),
+ memoryAllocated: cloudStack.converters.convertBytes(capacity(0).capacityused),
+ memoryTotal: cloudStack.converters.convertBytes(capacity(0).capacitytotal),
+ memoryPercentage: parseInt(capacity(0).percentused),
+ cpuAllocated: cloudStack.converters.convertHz(capacity(1).capacityused),
+ cpuTotal: cloudStack.converters.convertHz(capacity(1).capacitytotal),
+ cpuPercentage: parseInt(capacity(1).percentused)
+ }));
+ }
+ });
+ } else {
+ complete($.extend(data, {
+ publicIPAllocated: 0,
+ publicIPTotal: 0,
+ publicIPPercentage: 0,
+ privateIPAllocated: 0,
+ privateIPTotal: 0,
+ privateIPPercentage: 0,
+ memoryAllocated: 0,
+ memoryTotal: 0,
+ memoryPercentage: 0,
+ cpuAllocated: 0,
+ cpuTotal: 0,
+ cpuPercentage: 0
+ }));
+ }
+ }
+ };
+
+ var complete = function(data) {
+ args.response.success({
+ data: data
+ });
+ };
+
+ dataFns.zones({});
}
};
- */
-
})(cloudStack, testData);