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
0003f774
authored
Feb 12, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: rework activity ajax
parent
ad85f38e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
92 deletions
+74
-92
circle/dashboard/static/dashboard/vm-details.js
+30
-35
circle/dashboard/templates/dashboard/vm-detail.html
+1
-1
circle/dashboard/templates/dashboard/vm-detail/_activity-timeline.html
+23
-0
circle/dashboard/templates/dashboard/vm-detail/activity.html
+2
-24
circle/dashboard/views.py
+18
-32
No files found.
circle/dashboard/static/dashboard/vm-details.js
View file @
0003f774
$
(
function
()
{
$
(
function
()
{
if
(
$
(
'.timeline .activity:first i:first'
).
hasClass
(
'icon-spin'
))
/* do we need to check for new activities */
checkNewActivity
();
if
(
decideActivityRefresh
())
{
checkNewActivity
(
false
,
1
);
}
/* save resources */
/* save resources */
$
(
'#vm-details-resources-save'
).
click
(
function
()
{
$
(
'#vm-details-resources-save'
).
click
(
function
()
{
...
@@ -172,48 +174,41 @@ function removePort(data) {
...
@@ -172,48 +174,41 @@ function removePort(data) {
});
});
}
}
function
checkNewActivity
()
{
function
decideActivityRefresh
()
{
var
latest
=
$
(
'.activity:first'
).
data
(
'activity-id'
);
var
check
=
false
;
var
latest_sub
=
$
(
'div[data-activity-id="'
+
latest
+
'"] .sub-timeline .sub-activity:first'
).
data
(
'activity-id'
);
/* if something is still spinning */
if
(
$
(
'.timeline .activity:first i:first'
).
hasClass
(
'icon-spin'
))
check
=
true
;
/* if there is only one activity */
if
(
$
(
'#activity-timeline div[class="activity"]'
).
length
<
2
)
check
=
true
;
return
check
;
}
function
checkNewActivity
(
only_state
,
runs
)
{
// set default only_state to false
only_state
=
typeof
only_state
!==
'undefined'
?
only_state
:
false
;
var
instance
=
location
.
href
.
split
(
'/'
);
instance
=
instance
[
instance
.
length
-
2
];
var
instance
=
location
.
href
.
split
(
'/'
);
instance
=
instance
[
instance
.
length
-
2
];
$
.
ajax
({
$
.
ajax
({
type
:
'
POS
T'
,
type
:
'
GE
T'
,
url
:
'/dashboard/vm/'
+
instance
+
'/activity/'
,
url
:
'/dashboard/vm/'
+
instance
+
'/activity/'
,
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)},
data
:
{
'only_state'
:
only_state
},
data
:
{
'latest'
:
latest
,
'latest_sub'
:
latest_sub
},
success
:
function
(
data
)
{
success
:
function
(
data
)
{
if
(
data
[
'new_sub_activities'
].
length
>
0
)
{
if
(
!
only_state
)
{
d
=
data
[
'new_sub_activities'
];
$
(
"#activity-timeline"
).
html
(
data
[
'activities'
]);
html
=
""
for
(
var
i
=
0
;
i
<
d
.
length
;
i
++
)
{
html
+=
'<div data-activity-id="'
+
d
[
i
].
id
+
'" class="sub-activity">'
+
d
[
i
].
name
+
' - '
;
if
(
d
[
i
].
finished
!=
null
)
{
html
+=
d
[
i
].
finished
}
else
{
html
+=
'<i class="icon-refresh icon-spin" class="sub-activity-loading-icon"></i>'
;
}
html
+=
'</div>'
;
}
$
(
'div[data-activity-id="'
+
latest_sub
+
'"] .sub-activity .sub-activity-loading-icon'
).
remove
();
$
(
'div[data-activity-id="'
+
latest
+
'"] .sub-timeline'
).
prepend
(
html
);
}
}
if
(
data
[
'is_parent_finished'
])
{
$
(
"#vm-details-state"
).
html
(
data
[
'state'
]);
var
c
=
"icon-plus"
$
(
'div[data-activity-id="'
+
latest
+
'"] .icon-refresh.icon-spin:first'
).
removeClass
(
'icon-refresh'
).
removeClass
(
'icon-spin'
).
addClass
(
c
);
}
if
(
data
[
'latest_sub_finished'
]
!=
null
)
{
if
(
decideActivityRefresh
())
{
s
=
$
(
'div[data-activity-id="'
+
latest_sub
+
'"]'
)
console
.
log
(
"szia"
);
$
(
'.icon-refresh.icon-spin'
,
s
).
remove
();
setTimeout
(
$
(
s
).
append
(
data
[
'latest_sub_finished'
]);
function
()
{
checkNewActivity
(
true
,
runs
+
1
)},
1000
+
runs
*
250
);
}
}
if
(
data
[
'is_parent_finished'
])
return
;
else
setTimeout
(
checkNewActivity
,
1000
);
},
},
error
:
function
()
{
error
:
function
()
{
...
...
circle/dashboard/templates/dashboard/vm-detail.html
View file @
0003f774
...
@@ -51,7 +51,7 @@
...
@@ -51,7 +51,7 @@
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-4"
id=
"vm-info-pane"
>
<div
class=
"col-md-4"
id=
"vm-info-pane"
>
<div
class=
"big"
>
<div
class=
"big"
>
<span
class=
"label label-success"
>
{{ instance.state }}
</span>
<span
id=
"vm-details-state"
class=
"label label-success"
>
{{ instance.state }}
</span>
<div
class=
"btn-group"
>
<div
class=
"btn-group"
>
<button
type=
"button"
class=
"btn btn-warning dropdown-toggle"
data-toggle=
"dropdown"
>
Action
<i
class=
"icon-caret-down"
></i></button>
<button
type=
"button"
class=
"btn btn-warning dropdown-toggle"
data-toggle=
"dropdown"
>
Action
<i
class=
"icon-caret-down"
></i></button>
<ul
class=
"dropdown-menu"
role=
"menu"
>
<ul
class=
"dropdown-menu"
role=
"menu"
>
...
...
circle/dashboard/templates/dashboard/vm-detail/_activity-timeline.html
0 → 100644
View file @
0003f774
{% for a in activities %}
<div
class=
"activity"
data-activity-id=
"{{ a.pk }}"
>
<span
class=
"timeline-icon"
>
<i
class=
"{% if not a.finished %} icon-refresh icon-spin {% else %}icon-plus{% endif %}"
></i>
</span>
<strong>
{{ a.get_readable_name }}
</strong>
{{ a.started|date:"Y-m-d H:i" }}, {{ a.user }}
{% if a.children.count > 0 %}
<div
class=
"sub-timeline"
>
{% for s in a.children.all %}
<div
data-activity-id=
"{{ s.pk }}"
class=
"sub-activity"
>
{{ s.get_readable_name }} -
{% if s.finished %}
{{ s.finished|time:"H:i:s" }}
{% else %}
<i
class=
"icon-refresh icon-spin"
class=
"sub-activity-loading-icon"
></i>
{% endif %}
</div>
{% endfor %}
</div>
{% endif %}
</div>
{% endfor %}
circle/dashboard/templates/dashboard/vm-detail/activity.html
View file @
0003f774
...
@@ -8,30 +8,8 @@
...
@@ -8,30 +8,8 @@
}
}
</style>
</style>
<div
class=
"timeline"
>
<div
id=
"activity-timeline"
class=
"timeline"
>
{% for a in activity %}
{% include "dashboard/vm-detail/_activity-timeline.html" %}
<div
class=
"activity"
data-activity-id=
"{{ a.pk }}"
>
<span
class=
"timeline-icon"
>
<i
class=
"{% if not a.finished %} icon-refresh icon-spin {% else %}icon-plus{% endif %}"
></i>
</span>
<strong>
{{ a.get_readable_name }}
</strong>
{{ a.started|date:"Y-m-d H:i" }}, {{ a.user }}
{% if a.children.count > 0 %}
<div
class=
"sub-timeline"
>
{% for s in a.children.all %}
<div
data-activity-id=
"{{ s.pk }}"
class=
"sub-activity"
>
{{ s.get_readable_name }} -
{% if s.finished %}
{{ s.finished|time:"H:i:s" }}
{% else %}
<i
class=
"icon-refresh icon-spin"
class=
"sub-activity-loading-icon"
></i>
{% endif %}
</div>
{% endfor %}
</div>
{% endif %}
</div>
{% endfor %}
</div>
</div>
{% block extra_js %}
{% block extra_js %}
...
...
circle/dashboard/views.py
View file @
0003f774
...
@@ -14,13 +14,14 @@ from django.core import signing
...
@@ -14,13 +14,14 @@ from django.core import signing
from
django.core.urlresolvers
import
reverse
,
reverse_lazy
from
django.core.urlresolvers
import
reverse
,
reverse_lazy
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
Http404
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
Http404
from
django.shortcuts
import
redirect
,
render
from
django.shortcuts
import
redirect
,
render
from
django.views.decorators.http
import
require_
POS
T
from
django.views.decorators.http
import
require_
GE
T
from
django.views.generic.detail
import
SingleObjectMixin
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.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
django.template.defaultfilters
import
title
from
django.template.defaultfilters
import
title
from
django.template.loader
import
render_to_string
from
django.forms.models
import
inlineformset_factory
from
django.forms.models
import
inlineformset_factory
from
django_tables2
import
SingleTableView
from
django_tables2
import
SingleTableView
...
@@ -151,7 +152,7 @@ class VmDetailView(CheckedDetailView):
...
@@ -151,7 +152,7 @@ class VmDetailView(CheckedDetailView):
ia
=
InstanceActivity
.
objects
.
filter
(
ia
=
InstanceActivity
.
objects
.
filter
(
instance
=
self
.
object
,
parent
=
None
instance
=
self
.
object
,
parent
=
None
)
.
order_by
(
'-started'
)
.
select_related
()
)
.
order_by
(
'-started'
)
.
select_related
()
context
[
'activit
y
'
]
=
ia
context
[
'activit
ies
'
]
=
ia
context
[
'vlans'
]
=
Vlan
.
get_objects_with_level
(
context
[
'vlans'
]
=
Vlan
.
get_objects_with_level
(
'user'
,
self
.
request
.
user
'user'
,
self
.
request
.
user
...
@@ -1186,40 +1187,25 @@ class LeaseDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
...
@@ -1186,40 +1187,25 @@ class LeaseDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
return
HttpResponseRedirect
(
success_url
)
return
HttpResponseRedirect
(
success_url
)
@require_
POS
T
@require_
GE
T
def
vm_activity
(
request
,
pk
):
def
vm_activity
(
request
,
pk
):
object
=
Instance
.
objects
.
get
(
pk
=
pk
)
instance
=
Instance
.
objects
.
get
(
pk
=
pk
)
if
not
object
.
has_level
(
request
.
user
,
'owner'
):
if
not
instance
.
has_level
(
request
.
user
,
'owner'
):
raise
PermissionDenied
()
raise
PermissionDenied
()
latest
=
request
.
POST
.
get
(
'latest'
)
response
=
{}
latest_sub
=
request
.
POST
.
get
(
'latest_sub'
)
only_state
=
request
.
GET
.
get
(
"only_state"
)
instance
=
Instance
.
objects
.
get
(
pk
=
pk
)
response
[
'state'
]
=
instance
.
state
new_sub_activities
=
InstanceActivity
.
objects
.
filter
(
if
only_state
is
not
None
and
only_state
==
"false"
:
# instance activity
parent
=
latest
,
pk__gt
=
latest_sub
,
print
"Sdsa"
instance
=
instance
)
activities
=
render_to_string
(
# new_activities = InstanceActivity.objects.filter(
"dashboard/vm-detail/_activity-timeline.html"
,
# parent=None, instance=instance, pk__gt=latest).values('finished')
{
'activities'
:
InstanceActivity
.
objects
.
filter
(
latest_sub_finished
=
InstanceActivity
.
objects
.
get
(
pk
=
latest_sub
)
.
finished
instance
=
instance
,
parent
=
None
)
.
order_by
(
'-started'
)
.
select_related
()}
time_string
=
"
%
H:
%
M:
%
S"
new_sub_activities
=
[
{
'name'
:
a
.
get_readable_name
(),
'id'
:
a
.
pk
,
'finished'
:
None
if
a
.
finished
is
None
else
a
.
finished
.
strftime
(
time_string
)
)
}
for
a
in
new_sub_activities
response
[
'activities'
]
=
activities
]
response
=
{
'new_sub_activities'
:
new_sub_activities
,
# TODO 'new_acitivites': new_activities,
'is_parent_finished'
:
True
if
InstanceActivity
.
objects
.
get
(
pk
=
latest
)
.
finished
is
not
None
else
False
,
'latest_sub_finished'
:
None
if
latest_sub_finished
is
None
else
latest_sub_finished
.
strftime
(
time_string
)
}
return
HttpResponse
(
return
HttpResponse
(
json
.
dumps
(
response
),
json
.
dumps
(
response
),
...
...
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