Commit cfc2fc67 by Kálmán Viktor

dashboard: search vms from the landing page

parent 8943cc40
...@@ -95,9 +95,51 @@ $(function () { ...@@ -95,9 +95,51 @@ $(function () {
return false; return false;
}); });
/* search for vms */
var my_vms = []
$("#dashboard-vm-search-input").keyup(function() {
// if my_vms is empty get a list of our vms
if(my_vms.length < 1) {
$.ajaxSetup( { "async": false } );
$.get("/dashboard/vm/list/", function(result) {
for(var i in result) {
my_vms.push({
'pk': result[i].pk,
'name': result[i].fields.name,
'state': result[i].fields.state,
});
}
});
$.ajaxSetup( { "async": true } );
}
input = $("#dashboard-vm-search-input").val();
var search_result = []
var html = '';
for(var i in my_vms) {
if(my_vms[i].name.indexOf(input) != -1) {
search_result.push(my_vms[i]);
}
}
for(var i=0; i<5 && i<search_result.length; i++)
html += generateVmHTML(search_result[i].pk, search_result[i].name)
if(search_result.length == 0)
html += '<div class="list-group-item">No result</div>';
$("#dashboard-vm-list").html(html);
});
}); });
function generateVmHTML(pk, name) {
return '<a href="/dashboard/vm/' + pk + '/" class="list-group-item">' +
'<i class="icon-play-sign"></i> ' + name +
'<div class="pull-right">' +
'<i class="icon-star text-primary" title="" data-original-title="Mark as favorite."></i>' +
'</div>' +
'</a>';
}
function addSliderMiscs() { function addSliderMiscs() {
$('.vm-slider').each(function() { $('.vm-slider').each(function() {
$("<span>").addClass("output").html($(this).val()).insertAfter($(this)); $("<span>").addClass("output").html($(this).val()).insertAfter($(this));
......
...@@ -13,15 +13,17 @@ ...@@ -13,15 +13,17 @@
</h3> </h3>
</div> </div>
<div class="list-group" id="vm-list-view"> <div class="list-group" id="vm-list-view">
{% for i in instances %} <div id="dashboard-vm-list">
<a href="{{ i.get_absolute_url }}" class="list-group-item"> {% for i in instances %}
<i class="icon-{% if i.state == "RUNNING" %}play-sign{% else %}pause{% endif %}"></i> {{ i.name }} <div class="pull-right"><i class="icon-star text-primary" title="Mark as favorite."></i></div> <a href="{{ i.get_absolute_url }}" class="list-group-item">
<i class="icon-{% if i.state == "RUNNING" %}play-sign{% else %}pause{% endif %}"></i> {{ i.name }} <div class="pull-right"><i class="icon-star text-primary" title="Mark as favorite."></i></div>
</a> </a>
{% endfor %} {% endfor %}
</div>
<div href="#" class="list-group-item list-group-footer"> <div href="#" class="list-group-item list-group-footer">
<div class="row"> <div class="row">
<div class="col-sm-6 col-xs-6 input-group input-group-sm"> <div class="col-sm-6 col-xs-6 input-group input-group-sm">
<input type="text" class="form-control" placeholder="Search..." /> <input id="dashboard-vm-search-input" type="text" class="form-control" placeholder="Search..." />
<div class="input-group-btn"> <div class="input-group-btn">
<button type="submit" class="form-control btn btn-primary" title="search"><i class="icon-search"></i></button> <button type="submit" class="form-control btn btn-primary" title="search"><i class="icon-search"></i></button>
</div> </div>
......
...@@ -17,6 +17,7 @@ from django.views.generic.detail import SingleObjectMixin ...@@ -17,6 +17,7 @@ from django.views.generic.detail import SingleObjectMixin
from django.views.generic import (TemplateView, DetailView, View, DeleteView, from django.views.generic import (TemplateView, DetailView, View, DeleteView,
UpdateView, CreateView) UpdateView, CreateView)
from django.contrib import messages from django.contrib import messages
from django.core import serializers
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.forms.models import inlineformset_factory from django.forms.models import inlineformset_factory
...@@ -431,6 +432,17 @@ class VmList(LoginRequiredMixin, SingleTableView): ...@@ -431,6 +432,17 @@ class VmList(LoginRequiredMixin, SingleTableView):
table_pagination = False table_pagination = False
model = Instance model = Instance
def get(self, *args, **kwargs):
if self.request.is_ajax():
vms = serializers.serialize('json', self.get_queryset(),
fields=('pk', 'name', 'state'))
return HttpResponse(
vms,
content_type="application/json",
)
else:
return super(VmList, self).get(*args, **kwargs)
def get_queryset(self): def get_queryset(self):
logger.debug('VmList.get_queryset() called. User: %s', logger.debug('VmList.get_queryset() called. User: %s',
unicode(self.request.user)) unicode(self.request.user))
......
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