Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
662f025a
authored
Aug 05, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: better vm list filtering
parent
f40be5ae
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
13 deletions
+59
-13
circle/dashboard/forms.py
+18
-0
circle/dashboard/static/dashboard/dashboard.js
+1
-1
circle/dashboard/templates/dashboard/vm-list.html
+22
-9
circle/dashboard/views.py
+18
-3
No files found.
circle/dashboard/forms.py
View file @
662f025a
...
@@ -1129,3 +1129,21 @@ class VmResourcesForm(forms.ModelForm):
...
@@ -1129,3 +1129,21 @@ class VmResourcesForm(forms.ModelForm):
class
Meta
:
class
Meta
:
model
=
Instance
model
=
Instance
fields
=
(
'num_cores'
,
'priority'
,
'ram_size'
,
)
fields
=
(
'num_cores'
,
'priority'
,
'ram_size'
,
)
vm_search_choices
=
(
(
0
,
_
(
"owned"
)),
(
1
,
_
(
"shared"
)),
(
2
,
_
(
"all"
)),
)
class
VmListSearchForm
(
forms
.
Form
):
s
=
forms
.
CharField
(
widget
=
forms
.
TextInput
(
attrs
=
{
'class'
:
"form-control input-tags"
,
'placeholder'
:
_
(
"Search..."
),
}))
stype
=
forms
.
ChoiceField
(
vm_search_choices
,
widget
=
forms
.
Select
(
attrs
=
{
'class'
:
"btn btn-default input-tags"
,
}))
circle/dashboard/static/dashboard/dashboard.js
View file @
662f025a
...
@@ -264,7 +264,7 @@ $(function () {
...
@@ -264,7 +264,7 @@ $(function () {
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
)
{
if
(
e
.
keyCode
==
13
&&
search_result
.
length
>
1
&&
input
.
length
>
0
)
{
window
.
location
.
href
=
"/dashboard/vm/list/?s="
+
input
;
window
.
location
.
href
=
"/dashboard/vm/list/?s="
+
input
+
"&stype=2"
;
}
}
});
});
...
...
circle/dashboard/templates/dashboard/vm-list.html
View file @
662f025a
...
@@ -15,11 +15,16 @@
...
@@ -15,11 +15,16 @@
</div>
</div>
<h3
class=
"no-margin"
><i
class=
"fa fa-desktop"
></i>
{% trans "Virtual machines" %}
</h3>
<h3
class=
"no-margin"
><i
class=
"fa fa-desktop"
></i>
{% trans "Virtual machines" %}
</h3>
</div>
</div>
<div
class=
"pull-right"
style=
"max-width: 250px; margin-top: 15px; margin-right: 15px;"
>
<div
class=
"pull-right"
style=
"max-width: 300px; margin-top: 15px; margin-right: 15px;"
>
<form
action=
""
method=
"GET"
class=
"input-group"
>
<form
action=
""
method=
"GET"
>
<input
type=
"text"
name=
"s"
{%
if
request
.
GET
.
s
%}
value=
"{{ request.GET.s }}"
{%
endif
%}
class=
"form-control input-tags"
placeholder=
"{% trans "
Search
..."%}"
/>
<div
class=
"input-group"
>
<div
class=
"input-group-btn"
>
{{ search_form.s }}
<button
type=
"submit"
class=
"form-control btn btn-primary input-tags"
title=
"search"
><i
class=
"fa fa-search"
></i></button>
<div
class=
"input-group-btn"
>
{{ search_form.stype }}
<button
type=
"submit"
class=
"btn btn-primary input-tags"
>
<i
class=
"fa fa-search"
></i>
</button>
</div>
</div>
</div>
</form>
</form>
</div>
</div>
...
@@ -27,10 +32,18 @@
...
@@ -27,10 +32,18 @@
<p>
<p>
<strong>
{% trans "Group actions" %}
</strong>
<strong>
{% trans "Group actions" %}
</strong>
<button
id=
"vm-list-group-select-all"
class=
"btn btn-info btn-xs"
>
{% trans "Select all" %}
</button>
<button
id=
"vm-list-group-select-all"
class=
"btn btn-info btn-xs"
>
{% trans "Select all" %}
</button>
<a
class=
"btn btn-default btn-xs"
id=
"vm-list-group-migrate"
disabled
><i
class=
"fa fa-truck"
></i>
{% trans "Migrate" %}
</a>
<a
href=
"#"
class=
"btn btn-default btn-xs"
title=
"{% trans "
Migrate
"
%}"
disabled
>
<a
disabled
href=
"#"
class=
"btn btn-default btn-xs"
><i
class=
"fa fa-refresh"
></i>
{% trans "Reboot" %}
</a>
<i
class=
"fa fa-truck"
></i>
<a
disabled
href=
"#"
class=
"btn btn-default btn-xs"
><i
class=
"fa fa-off"
></i>
{% trans "Shutdown" %}
</a>
</a>
<a
id=
"vm-list-group-delete"
disabled
href=
"#"
class=
"btn btn-danger btn-xs"
><i
class=
"fa fa-times"
></i>
{% trans "Destroy" %}
</a>
<a
href=
"#"
class=
"btn btn-default btn-xs"
title=
"{% trans "
Reboot
"
%}"
disabled
>
<i
class=
"fa fa-refresh"
></i>
</a>
<a
href=
"#"
class=
"btn btn-default btn-xs"
title=
"{% trans "
Shutdown
"
%}"
disabled
>
<i
class=
"fa fa-power-off"
></i>
</a>
<a
title=
"{% trans "
Destroy
"
%}"
id=
"vm-list-group-delete"
disabled
href=
"#"
class=
"btn btn-danger btn-xs"
disabled
>
<i
class=
"fa fa-times"
></i>
</a>
</p>
</p>
</div>
</div>
<div
class=
"panel-body"
>
<div
class=
"panel-body"
>
...
...
circle/dashboard/views.py
View file @
662f025a
...
@@ -70,7 +70,7 @@ from .forms import (
...
@@ -70,7 +70,7 @@ from .forms import (
VmSaveForm
,
UserKeyForm
,
VmRenewForm
,
VmSaveForm
,
UserKeyForm
,
VmRenewForm
,
CirclePasswordChangeForm
,
VmCreateDiskForm
,
VmDownloadDiskForm
,
CirclePasswordChangeForm
,
VmCreateDiskForm
,
VmDownloadDiskForm
,
TraitsForm
,
RawDataForm
,
GroupPermissionForm
,
AclUserAddForm
,
TraitsForm
,
RawDataForm
,
GroupPermissionForm
,
AclUserAddForm
,
VmResourcesForm
,
VmAddInterfaceForm
,
VmResourcesForm
,
VmAddInterfaceForm
,
VmListSearchForm
)
)
from
.tables
import
(
from
.tables
import
(
...
@@ -1552,6 +1552,11 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
...
@@ -1552,6 +1552,11 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
'owner'
:
"owner__username"
,
'owner'
:
"owner__username"
,
}
}
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
context
=
super
(
VmList
,
self
)
.
get_context_data
(
*
args
,
**
kwargs
)
context
[
'search_form'
]
=
VmListSearchForm
(
self
.
request
.
GET
)
return
context
def
get
(
self
,
*
args
,
**
kwargs
):
def
get
(
self
,
*
args
,
**
kwargs
):
if
self
.
request
.
is_ajax
():
if
self
.
request
.
is_ajax
():
favs
=
Instance
.
objects
.
filter
(
favs
=
Instance
.
objects
.
filter
(
...
@@ -1576,8 +1581,7 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
...
@@ -1576,8 +1581,7 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
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
))
queryset
=
Instance
.
get_objects_with_level
(
queryset
=
self
.
create_default_queryset
()
'user'
,
self
.
request
.
user
)
.
filter
(
destroyed_at
=
None
)
self
.
create_fake_get
()
self
.
create_fake_get
()
sort
=
self
.
request
.
GET
.
get
(
"sort"
)
sort
=
self
.
request
.
GET
.
get
(
"sort"
)
...
@@ -1592,6 +1596,17 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
...
@@ -1592,6 +1596,17 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
**
self
.
get_queryset_filters
())
.
select_related
(
'owner'
,
'node'
**
self
.
get_queryset_filters
())
.
select_related
(
'owner'
,
'node'
)
.
distinct
()
)
.
distinct
()
def
create_default_queryset
(
self
):
stype
=
self
.
request
.
GET
.
get
(
"stype"
,
"0"
)
superuser
=
stype
==
"2"
shared
=
stype
==
"1"
level
=
"owner"
if
stype
==
"0"
else
"user"
queryset
=
Instance
.
get_objects_with_level
(
level
,
self
.
request
.
user
,
group_also
=
shared
,
disregard_superuser
=
not
superuser
,
)
.
filter
(
destroyed_at
=
None
)
return
queryset
def
create_fake_get
(
self
):
def
create_fake_get
(
self
):
"""
"""
Updates the request's GET dict to filter the vm list
Updates the request's GET dict to filter the vm list
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment