Skip to content

Commit d6ceef2

Browse files
committed
Implement refresh VPC chart
1 parent 3c24380 commit d6ceef2

1 file changed

Lines changed: 110 additions & 75 deletions

File tree

ui/modules/vpc/vpc.js

Lines changed: 110 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
$browser: $browser,
2828
context: $.extend(true, {}, context, {
2929
networks: [tier]
30-
})
30+
}),
31+
onActionComplete: function() {
32+
$tier.closest('.vpc-network-chart').trigger('reload');
33+
}
3134
})
3235
);
3336

@@ -92,6 +95,8 @@
9295
// Success
9396
function(args) {
9497
$loading.remove();
98+
$placeholder.closest('.vpc-network-chart').trigger('reload');
99+
95100
// addNewTier({
96101
// ipAddresses: ipAddresses,
97102
// $browser: $browser,
@@ -181,90 +186,120 @@
181186
var vpcChart = function(args) {
182187
var context = args.context;
183188
var vpcItem = context.vpc[0];
184-
var $chart = $('<div>').addClass('vpc-network-chart');
185-
var $tiers = $('<div>').addClass('tiers');
186-
var $toolbar = $('<div>').addClass('toolbar');
187-
188-
$toolbar.appendTo($chart);
189-
$tiers.appendTo($chart);
190189

191-
// Get tiers
192-
vpc.tiers.dataProvider({
193-
context: context,
194-
response: {
195-
success: function(data) {
196-
var tiers = data.tiers;
197-
198-
$(tiers).map(function(index, tier) {
199-
var $tier = elems.tier({
200-
context: context,
201-
tier: tier,
202-
dashboardItems: [
203-
{
204-
id: 'tierLoadBalancers',
205-
name: 'Load balancers',
206-
total: 5
207-
},
208-
{
209-
id: 'tierPortForwarders',
210-
name: 'Port forwarders',
211-
total: 4
212-
},
213-
{
214-
id: 'tierStaticNATs',
215-
name: 'Static NATs',
216-
total: 3
217-
},
218-
{
219-
id: 'tierVMs',
220-
name: 'Virtual Machines',
221-
total: 300
222-
}
223-
]
190+
var chart = function(args) {
191+
args = args ? args : {};
192+
193+
var $chart = $('<div>').addClass('vpc-network-chart');
194+
var $tiers = $('<div>').addClass('tiers');
195+
var $toolbar = $('<div>').addClass('toolbar');
196+
var $refresh = $('<div>').addClass('button refresh');
197+
198+
$refresh.appendTo($toolbar);
199+
$toolbar.appendTo($chart);
200+
$tiers.appendTo($chart);
201+
202+
$refresh.click(function() {
203+
$('.vpc-network-chart').trigger('reload');
204+
});
205+
206+
// Get tiers
207+
var $loading = $('<div>').addClass('loading-overlay').prependTo($chart);
208+
vpc.tiers.dataProvider({
209+
context: context,
210+
response: {
211+
success: function(data) {
212+
var tiers = data.tiers;
213+
214+
$(tiers).map(function(index, tier) {
215+
var $tier = elems.tier({
216+
context: context,
217+
tier: tier,
218+
dashboardItems: [
219+
{
220+
id: 'tierLoadBalancers',
221+
name: 'Load balancers',
222+
total: 5
223+
},
224+
{
225+
id: 'tierPortForwarders',
226+
name: 'Port forwarders',
227+
total: 4
228+
},
229+
{
230+
id: 'tierStaticNATs',
231+
name: 'Static NATs',
232+
total: 3
233+
},
234+
{
235+
id: 'tierVMs',
236+
name: 'Virtual Machines',
237+
total: 300
238+
}
239+
]
240+
});
241+
242+
$tier.appendTo($tiers);
224243
});
225244

226-
$tier.appendTo($tiers);
227-
});
245+
// Add placeholder tier
246+
$tiers.append(elems.tierPlaceholder({
247+
context: context
248+
}));
228249

229-
// Add placeholder tier
230-
$tiers.append(elems.tierPlaceholder({
231-
context: context
232-
}));
250+
$loading.remove();
251+
252+
if (args.complete) {
253+
args.complete($chart);
254+
}
255+
}
233256
}
234-
}
235-
});
257+
});
258+
259+
// Router
260+
$router = elems.router({
261+
context: context,
262+
dashboardItems: [
263+
{
264+
id: 'privateGateways',
265+
name: 'Private gateways',
266+
total: 1
267+
},
268+
{
269+
id: 'publicIPs',
270+
name: 'Public IP addresses',
271+
total: 2
272+
},
273+
{
274+
id: 'siteToSiteVPNs',
275+
name: 'Site-to-site VPNs',
276+
total: 3
277+
},
278+
{
279+
id: 'networkACLLists',
280+
name: 'Network ACL lists',
281+
total: 2
282+
}
283+
]
284+
}).appendTo($chart);
285+
286+
$chart.bind('reload', function() {
287+
chart({
288+
complete: function($newChart) {
289+
$chart.replaceWith($newChart);
290+
}
291+
});
292+
});
293+
294+
return $chart;
295+
};
236296

237-
// Router
238-
$router = elems.router({
239-
context: context,
240-
dashboardItems: [
241-
{
242-
id: 'privateGateways',
243-
name: 'Private gateways',
244-
total: 1
245-
},
246-
{
247-
id: 'publicIPs',
248-
name: 'Public IP addresses',
249-
total: 2
250-
},
251-
{
252-
id: 'siteToSiteVPNs',
253-
name: 'Site-to-site VPNs',
254-
total: 3
255-
},
256-
{
257-
id: 'networkACLLists',
258-
name: 'Network ACL lists',
259-
total: 2
260-
}
261-
]
262-
}).appendTo($chart);
263-
264297
$('#browser .container').cloudBrowser('addPanel', {
265298
title: vpcItem.displaytext ? vpcItem.displaytext : vpcItem.name,
266299
maximizeIfSelected: true,
267300
complete: function($panel) {
301+
var $chart = chart();
302+
268303
$chart.appendTo($panel);
269304
}
270305
});

0 commit comments

Comments
 (0)