Commit c2b0ca67 by Bach Dániel

Merge remote-tracking branch 'origin/group-search' into feature-indexview-fixes

Conflicts:
	circle/dashboard/templates/dashboard/index-groups.html
	circle/dashboard/tests/test_views.py
	circle/dashboard/views.py
parents 87ae1cb3 19c9ac38
...@@ -269,6 +269,46 @@ $(function () { ...@@ -269,6 +269,46 @@ $(function () {
} }
}); });
/* search for groups */
var my_groups = []
$("#dashboard-group-search-input").keyup(function(e) {
// if my_groups is empty get a list of our groups
if(my_groups.length < 1) {
$.ajaxSetup( { "async": false } );
$.get("/dashboard/group/list/", function(result) {
for(var i in result) {
my_groups.push({
'url': result[i].url,
'name': result[i].name.toLowerCase(),
});
}
});
$.ajaxSetup( { "async": true } );
}
input = $("#dashboard-group-search-input").val().toLowerCase();
var search_result = []
var html = '';
for(var i in my_groups) {
if(my_groups[i].name.indexOf(input) != -1) {
search_result.push(my_groups[i]);
}
}
for(var i=0; i<5 && i<search_result.length; i++)
html += generateGroupHTML(search_result[i].url, search_result[i].name);
if(search_result.length == 0)
html += '<div class="list-group-item">No result</div>';
$("#dashboard-group-list").html(html);
// if there is only one result and ENTER is pressed redirect
if(e.keyCode == 13 && search_result.length == 1) {
window.location.href = search_result[0].url;
}
if(e.keyCode == 13 && search_result.length > 1 && input.length > 0) {
window.location.href = "/dashboard/group/list/?s=" + input;
}
});
/* notification message toggle */ /* notification message toggle */
$(document).on('click', ".notification-message-subject", function() { $(document).on('click', ".notification-message-subject", function() {
$(".notification-message-text", $(this).parent()).slideToggle(); $(".notification-message-text", $(this).parent()).slideToggle();
...@@ -296,6 +336,12 @@ function generateVmHTML(pk, name, host, icon, _status, fav, is_last) { ...@@ -296,6 +336,12 @@ function generateVmHTML(pk, name, host, icon, _status, fav, is_last) {
'</a>'; '</a>';
} }
function generateGroupHTML(url, name) {
return '<a href="' + url + '" class="list-group-item real-link">'+
'<i class="icon-group"></i> '+ name +
'</a>';
}
/* copare vm-s by fav, pk order */ /* copare vm-s by fav, pk order */
function compareVmByFav(a, b) { function compareVmByFav(a, b) {
if(a.fav && b.fav) { if(a.fav && b.fav) {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<div href="#" class="list-group-item list-group-footer text-right"> <div href="#" class="list-group-item list-group-footer text-right">
<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="{% trans "Search..." %}" /> <input id="dashboard-group-search-input" type="text" class="form-control" placeholder="{% trans "Search..." %}" />
<div class="input-group-btn"> <div class="input-group-btn">
<button type="submit" class="form-control btn btn-primary"><i class="icon-search"></i></button> <button type="submit" class="form-control btn btn-primary"><i class="icon-search"></i></button>
</div> </div>
......
...@@ -1476,6 +1476,49 @@ class GroupDetailTest(LoginMixin, TestCase): ...@@ -1476,6 +1476,49 @@ class GroupDetailTest(LoginMixin, TestCase):
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
class GroupListTest(LoginMixin, TestCase):
fixtures = ['test-vm-fixture.json', 'node.json']
def setUp(self):
self.u1 = User.objects.create(username='user1')
self.u1.set_password('password')
self.u1.save()
permlist = Permission.objects.all()
self.u1.user_permissions.add(
filter(lambda element: 'group' in element.name and
'add' in element.name, permlist)[0])
self.u2 = User.objects.create(username='user2')
self.u2.set_password('password')
self.u2.save()
self.g1 = Group.objects.create(name='group1')
self.g1.profile.set_user_level(self.u1, 'owner')
self.g1.save()
self.g2 = Group.objects.create(name='group2')
self.g2.profile.set_user_level(self.u1, 'owner')
self.g2.save()
self.g3 = Group.objects.create(name='group3')
self.g3.profile.set_user_level(self.u1, 'owner')
self.g3.save()
def test_anon_filter(self):
c = Client()
response = c.get('/dashboard/group/list/?s="3"')
self.assertEqual(response.status_code, 302)
def test_permitteduser_filter(self):
c = Client()
self.login(c, 'user1')
response = c.get('/dashboard/group/list/?s="3"')
self.assertEqual(response.status_code, 200)
def tearDown(self):
super(GroupListTest, self).tearDown()
self.u1.delete()
self.u2.delete()
self.g1.delete()
self.g2.delete()
class VmDetailVncTest(LoginMixin, TestCase): class VmDetailVncTest(LoginMixin, TestCase):
fixtures = ['test-vm-fixture.json', 'node.json'] fixtures = ['test-vm-fixture.json', 'node.json']
......
...@@ -1160,7 +1160,7 @@ class GroupList(LoginRequiredMixin, SingleTableView): ...@@ -1160,7 +1160,7 @@ class GroupList(LoginRequiredMixin, SingleTableView):
groups = [{ groups = [{
'url': reverse("dashboard.views.group-detail", 'url': reverse("dashboard.views.group-detail",
kwargs={'pk': i.pk}), kwargs={'pk': i.pk}),
'name': i.name} for i in self.queryset] 'name': i.name} for i in self.get_queryset()]
return HttpResponse( return HttpResponse(
json.dumps(list(groups)), json.dumps(list(groups)),
content_type="application/json", content_type="application/json",
......
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