Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
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
()
{
if
(
$
(
'.timeline .activity:first i:first'
).
hasClass
(
'icon-spin'
))
checkNewActivity
();
/* do we need to check for new activities */
if
(
decideActivityRefresh
())
{
checkNewActivity
(
false
,
1
);
}
/* save resources */
$
(
'#vm-details-resources-save'
).
click
(
function
()
{
...
...
@@ -172,48 +174,41 @@ function removePort(data) {
});
}
function
checkNewActivity
()
{
var
latest
=
$
(
'.activity:first'
).
data
(
'activity-id'
);
var
latest_sub
=
$
(
'div[data-activity-id="'
+
latest
+
'"] .sub-timeline .sub-activity:first'
).
data
(
'activity-id'
);
function
decideActivityRefresh
()
{
var
check
=
false
;
/* 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
];
$
.
ajax
({
type
:
'
POS
T'
,
type
:
'
GE
T'
,
url
:
'/dashboard/vm/'
+
instance
+
'/activity/'
,
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)},
data
:
{
'latest'
:
latest
,
'latest_sub'
:
latest_sub
},
data
:
{
'only_state'
:
only_state
},
success
:
function
(
data
)
{
if
(
data
[
'new_sub_activities'
].
length
>
0
)
{
d
=
data
[
'new_sub_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
(
!
only_state
)
{
$
(
"#activity-timeline"
).
html
(
data
[
'activities'
]);
}
if
(
data
[
'is_parent_finished'
])
{
var
c
=
"icon-plus"
$
(
'div[data-activity-id="'
+
latest
+
'"] .icon-refresh.icon-spin:first'
).
removeClass
(
'icon-refresh'
).
removeClass
(
'icon-spin'
).
addClass
(
c
);
}
$
(
"#vm-details-state"
).
html
(
data
[
'state'
]);
if
(
data
[
'latest_sub_finished'
]
!=
null
)
{
s
=
$
(
'div[data-activity-id="'
+
latest_sub
+
'"]'
)
$
(
'.icon-refresh.icon-spin'
,
s
).
remove
();
$
(
s
).
append
(
data
[
'latest_sub_finished'
]);
if
(
decideActivityRefresh
())
{
console
.
log
(
"szia"
);
setTimeout
(
function
()
{
checkNewActivity
(
true
,
runs
+
1
)},
1000
+
runs
*
250
);
}
if
(
data
[
'is_parent_finished'
])
return
;
else
setTimeout
(
checkNewActivity
,
1000
);
},
error
:
function
()
{
...
...
circle/dashboard/templates/dashboard/vm-detail.html
View file @
0003f774
...
...
@@ -51,7 +51,7 @@
<div
class=
"row"
>
<div
class=
"col-md-4"
id=
"vm-info-pane"
>
<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"
>
<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"
>
...
...
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 @@
}
</style>
<div
class=
"timeline"
>
{% for a in activity %}
<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
id=
"activity-timeline"
class=
"timeline"
>
{% include "dashboard/vm-detail/_activity-timeline.html" %}
</div>
{% block extra_js %}
...
...
circle/dashboard/views.py
View file @
0003f774
...
...
@@ -14,13 +14,14 @@ from django.core import signing
from
django.core.urlresolvers
import
reverse
,
reverse_lazy
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
Http404
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
import
(
TemplateView
,
DetailView
,
View
,
DeleteView
,
UpdateView
,
CreateView
)
from
django.contrib
import
messages
from
django.utils.translation
import
ugettext
as
_
from
django.template.defaultfilters
import
title
from
django.template.loader
import
render_to_string
from
django.forms.models
import
inlineformset_factory
from
django_tables2
import
SingleTableView
...
...
@@ -151,7 +152,7 @@ class VmDetailView(CheckedDetailView):
ia
=
InstanceActivity
.
objects
.
filter
(
instance
=
self
.
object
,
parent
=
None
)
.
order_by
(
'-started'
)
.
select_related
()
context
[
'activit
y
'
]
=
ia
context
[
'activit
ies
'
]
=
ia
context
[
'vlans'
]
=
Vlan
.
get_objects_with_level
(
'user'
,
self
.
request
.
user
...
...
@@ -1186,40 +1187,25 @@ class LeaseDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
return
HttpResponseRedirect
(
success_url
)
@require_
POS
T
@require_
GE
T
def
vm_activity
(
request
,
pk
):
object
=
Instance
.
objects
.
get
(
pk
=
pk
)
if
not
object
.
has_level
(
request
.
user
,
'owner'
):
instance
=
Instance
.
objects
.
get
(
pk
=
pk
)
if
not
instance
.
has_level
(
request
.
user
,
'owner'
):
raise
PermissionDenied
()
latest
=
request
.
POST
.
get
(
'latest'
)
latest_sub
=
request
.
POST
.
get
(
'latest_sub'
)
instance
=
Instance
.
objects
.
get
(
pk
=
pk
)
new_sub_activities
=
InstanceActivity
.
objects
.
filter
(
parent
=
latest
,
pk__gt
=
latest_sub
,
instance
=
instance
)
# new_activities = InstanceActivity.objects.filter(
# parent=None, instance=instance, pk__gt=latest).values('finished')
latest_sub_finished
=
InstanceActivity
.
objects
.
get
(
pk
=
latest_sub
)
.
finished
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
response
=
{}
only_state
=
request
.
GET
.
get
(
"only_state"
)
response
[
'state'
]
=
instance
.
state
if
only_state
is
not
None
and
only_state
==
"false"
:
# instance activity
print
"Sdsa"
activities
=
render_to_string
(
"dashboard/vm-detail/_activity-timeline.html"
,
{
'activities'
:
InstanceActivity
.
objects
.
filter
(
instance
=
instance
,
parent
=
None
)
.
order_by
(
'-started'
)
.
select_related
()}
)
}
for
a
in
new_sub_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
)
}
response
[
'activities'
]
=
activities
return
HttpResponse
(
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