Commit 0a8706da by Kálmán Viktor

dashboard: search in vm list

parent 93b78ecd
...@@ -144,7 +144,7 @@ $(function () { ...@@ -144,7 +144,7 @@ $(function () {
for(var i in result) { for(var i in result) {
my_vms.push({ my_vms.push({
'pk': result[i].pk, 'pk': result[i].pk,
'name': result[i].name, 'name': result[i].name.toLowerCase(),
'state': result[i].state, 'state': result[i].state,
'fav': result[i].fav, 'fav': result[i].fav,
}); });
...@@ -153,7 +153,7 @@ $(function () { ...@@ -153,7 +153,7 @@ $(function () {
$.ajaxSetup( { "async": true } ); $.ajaxSetup( { "async": true } );
} }
input = $("#dashboard-vm-search-input").val(); input = $("#dashboard-vm-search-input").val().toLowerCase();
var search_result = [] var search_result = []
var html = ''; var html = '';
for(var i in my_vms) { for(var i in my_vms) {
...@@ -173,6 +173,9 @@ $(function () { ...@@ -173,6 +173,9 @@ $(function () {
if(e.keyCode == 13 && search_result.length == 1) { if(e.keyCode == 13 && search_result.length == 1) {
window.location.href = "/dashboard/vm/" + search_result[0].pk + "/"; window.location.href = "/dashboard/vm/" + search_result[0].pk + "/";
} }
if(e.keyCode == 13 && search_result.length > 1 && input.length > 0) {
window.location.href = "/dashboard/vm/list/?s=" + input;
}
}); });
}); });
......
...@@ -9,6 +9,14 @@ ...@@ -9,6 +9,14 @@
<div class="panel-heading"> <div class="panel-heading">
<h3 class="no-margin"><i class="icon-desktop"></i> Your virtual machines</h3> <h3 class="no-margin"><i class="icon-desktop"></i> Your virtual machines</h3>
</div> </div>
<div class="pull-right" style="max-width: 250px; margin-top: 15px; margin-right: 15px;">
<form action="" method="GET" class="input-group">
<input type="text" name="s"{% if request.GET.s %} value="{{ request.GET.s }}"{% endif %} class="form-control input-tags" placeholder="Search..." />
<div class="input-group-btn">
<button type="submit" class="form-control btn btn-primary input-tags" title="search"><i class="icon-search"></i></button>
</div>
</form>
</div>
<div class="panel-body vm-list-group-control"> <div class="panel-body vm-list-group-control">
<p> <p>
<strong>Group actions</strong> <strong>Group actions</strong>
......
...@@ -607,8 +607,12 @@ class VmList(LoginRequiredMixin, SingleTableView): ...@@ -607,8 +607,12 @@ class VmList(LoginRequiredMixin, SingleTableView):
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))
return Instance.get_objects_with_level( queryset = Instance.get_objects_with_level(
'user', self.request.user).filter(destroyed=None).all() 'user', self.request.user).filter(destroyed=None)
s = self.request.GET.get("s")
if s:
queryset = queryset.filter(name__icontains=s)
return queryset
class NodeList(LoginRequiredMixin, SuperuserRequiredMixin, SingleTableView): class NodeList(LoginRequiredMixin, SuperuserRequiredMixin, SingleTableView):
......
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