Commit 42c6b366 by Oláh István Gergely

dashboard: add generated url to index nodes

parent 7f20e972
...@@ -238,7 +238,8 @@ $(function () { ...@@ -238,7 +238,8 @@ $(function () {
'name': result[i].name.toLowerCase(), 'name': result[i].name.toLowerCase(),
'icon': result[i].icon, 'icon': result[i].icon,
'status': result[i].status, 'status': result[i].status,
}); 'url': result[i].url,
});
} }
}); });
$.ajaxSetup( { "async": true } ); $.ajaxSetup( { "async": true } );
...@@ -254,7 +255,8 @@ $(function () { ...@@ -254,7 +255,8 @@ $(function () {
} }
for(var i=0; i<5 && i<search_result.length; i++) for(var i=0; i<5 && i<search_result.length; i++)
html += generateNodeHTML(search_result[i].pk, search_result[i].name, html += generateNodeHTML(search_result[i].pk, search_result[i].name,
search_result[i].icon, search_result[i].status); search_result[i].icon, search_result[i].status,
search_result[i].url);
if(search_result.length == 0) if(search_result.length == 0)
html += '<div class="list-group-item">No result</div>'; html += '<div class="list-group-item">No result</div>';
$("#dashboard-node-list").html(html); $("#dashboard-node-list").html(html);
...@@ -293,13 +295,13 @@ function generateVmHTML(pk, name, host, icon, _status, fav) { ...@@ -293,13 +295,13 @@ function generateVmHTML(pk, name, host, icon, _status, fav) {
'</a>'; '</a>';
} }
function generateNodeHTML(pk, name, icon, _status) { function generateNodeHTML(pk, name, icon, _status, url) {
return '<a href="/dashboard/node/' + pk + '/" class="list-group-item">' + return '<a href="' + url + '" class="list-group-item" >' +
'<span class="index-node-list-name">' + '<span class="index-node-list-name">' +
'<i class="' + icon + '" title="' + _status + '"></i> ' + name + '<i class="' + icon + '" title="' + _status + '"></i> ' + name +
'</span>' + '</span>' +
'<div style="clear: both;"></div>' + '<div style="clear: both;"></div>' +
'</a>'; '</a>';
} }
/* copare vm-s by fav, pk order */ /* copare vm-s by fav, pk order */
......
...@@ -931,11 +931,12 @@ class NodeList(LoginRequiredMixin, SuperuserRequiredMixin, SingleTableView): ...@@ -931,11 +931,12 @@ class NodeList(LoginRequiredMixin, SuperuserRequiredMixin, SingleTableView):
nodes = [{ nodes = [{
'pk': i.pk, 'pk': i.pk,
'name': i.name, 'name': i.name,
'icon': '', 'icon': i.get_status_icon(),
'status': ''} for i in nodes] 'url': i.get_absolute_url(),
'status': i.state.lower()} for i in nodes]
return HttpResponse( return HttpResponse(
json.dumps(list(nodes)), # instances is ValuesQuerySet json.dumps(list(nodes)),
content_type="application/json", content_type="application/json",
) )
else: else:
......
...@@ -268,6 +268,14 @@ class Node(OperatedMixin, TimeStampedModel): ...@@ -268,6 +268,14 @@ class Node(OperatedMixin, TimeStampedModel):
def byte_ram_usage(self): def byte_ram_usage(self):
return self.ram_usage * self.ram_size return self.ram_usage * self.ram_size
def get_status_icon(self):
return {
'OFFLINE': 'icon-minus-sign',
'DISABLED': 'icon-moon',
'MISSING': 'icon-warning-sign',
'ONLINE': 'icon-play-sign'}.get(self.get_state(),
'icon-question-sign')
@node_available @node_available
def update_vm_states(self): def update_vm_states(self):
"""Update state of Instances running on this Node. """Update state of Instances running on this Node.
...@@ -317,14 +325,6 @@ class Node(OperatedMixin, TimeStampedModel): ...@@ -317,14 +325,6 @@ class Node(OperatedMixin, TimeStampedModel):
cls.objects.filter(enabled=enabled).select_related('host') cls.objects.filter(enabled=enabled).select_related('host')
if i.online == online]) if i.online == online])
def get_status_icon(self):
return {
'OFFLINE': 'icon-minus-sign',
'DISABLED': 'icon-moon',
'MISSING': 'icon-warning-sign',
'ONLINE': 'icon-play-sign'}.get(self.get_state(),
'icon-question-sign')
@permalink @permalink
def get_absolute_url(self): def get_absolute_url(self):
return ('dashboard.views.node-detail', None, {'pk': self.id}) return ('dashboard.views.node-detail', None, {'pk': self.id})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment