Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
12 deletions
+58
-12
circle/dashboard/forms.py
+18
-0
circle/dashboard/static/dashboard/dashboard.js
+1
-1
circle/dashboard/templates/dashboard/vm-list.html
+21
-8
circle/dashboard/views.py
+18
-3
No files found.
circle/dashboard/forms.py
View file @
662f025a
...
...
@@ -1129,3 +1129,21 @@ class VmResourcesForm(forms.ModelForm):
class
Meta
:
model
=
Instance
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 () {
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
;
window
.
location
.
href
=
"/dashboard/vm/list/?s="
+
input
+
"&stype=2"
;
}
});
...
...
circle/dashboard/templates/dashboard/vm-list.html
View file @
662f025a
...
...
@@ -15,11 +15,16 @@
</div>
<h3
class=
"no-margin"
><i
class=
"fa fa-desktop"
></i>
{% trans "Virtual machines" %}
</h3>
</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=
"{% trans "
Search
..."%}"
/>
<div
class=
"pull-right"
style=
"max-width: 300px; margin-top: 15px; margin-right: 15px;"
>
<form
action=
""
method=
"GET"
>
<div
class=
"input-group"
>
{{ search_form.s }}
<div
class=
"input-group-btn"
>
<button
type=
"submit"
class=
"form-control btn btn-primary input-tags"
title=
"search"
><i
class=
"fa fa-search"
></i></button>
{{ search_form.stype }}
<button
type=
"submit"
class=
"btn btn-primary input-tags"
>
<i
class=
"fa fa-search"
></i>
</button>
</div>
</div>
</form>
</div>
...
...
@@ -27,10 +32,18 @@
<p>
<strong>
{% trans "Group actions" %}
</strong>
<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
disabled
href=
"#"
class=
"btn btn-default btn-xs"
><i
class=
"fa fa-refresh"
></i>
{% trans "Reboot" %}
</a>
<a
disabled
href=
"#"
class=
"btn btn-default btn-xs"
><i
class=
"fa fa-off"
></i>
{% trans "Shutdown" %}
</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 "
Migrate
"
%}"
disabled
>
<i
class=
"fa fa-truck"
></i>
</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>
</div>
<div
class=
"panel-body"
>
...
...
circle/dashboard/views.py
View file @
662f025a
...
...
@@ -70,7 +70,7 @@ from .forms import (
VmSaveForm
,
UserKeyForm
,
VmRenewForm
,
CirclePasswordChangeForm
,
VmCreateDiskForm
,
VmDownloadDiskForm
,
TraitsForm
,
RawDataForm
,
GroupPermissionForm
,
AclUserAddForm
,
VmResourcesForm
,
VmAddInterfaceForm
,
VmResourcesForm
,
VmAddInterfaceForm
,
VmListSearchForm
)
from
.tables
import
(
...
...
@@ -1552,6 +1552,11 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
'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
):
if
self
.
request
.
is_ajax
():
favs
=
Instance
.
objects
.
filter
(
...
...
@@ -1576,8 +1581,7 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
def
get_queryset
(
self
):
logger
.
debug
(
'VmList.get_queryset() called. User:
%
s'
,
unicode
(
self
.
request
.
user
))
queryset
=
Instance
.
get_objects_with_level
(
'user'
,
self
.
request
.
user
)
.
filter
(
destroyed_at
=
None
)
queryset
=
self
.
create_default_queryset
()
self
.
create_fake_get
()
sort
=
self
.
request
.
GET
.
get
(
"sort"
)
...
...
@@ -1592,6 +1596,17 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
**
self
.
get_queryset_filters
())
.
select_related
(
'owner'
,
'node'
)
.
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
):
"""
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