Merge "Sortable instances"
This commit is contained in:
commit
78b26a6e4e
@ -196,6 +196,20 @@ $.tablesorter.addParser({
|
|||||||
type: 'numeric'
|
type: 'numeric'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$.tablesorter.addParser({
|
||||||
|
// set a unique id
|
||||||
|
id: 'timesinceSorter',
|
||||||
|
is: function(s) {
|
||||||
|
// Not an auto-detected parser
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
// compare int values
|
||||||
|
format: function(s, table, cell, cellIndex) {
|
||||||
|
return $(cell).find('span').data('seconds');
|
||||||
|
},
|
||||||
|
type: 'numeric'
|
||||||
|
});
|
||||||
|
|
||||||
horizon.datatables.disable_buttons = function() {
|
horizon.datatables.disable_buttons = function() {
|
||||||
$("table .table_actions").on("click", ".btn.disabled", function(event){
|
$("table .table_actions").on("click", ".btn.disabled", function(event){
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -260,6 +274,8 @@ $(parent).find("table.datatable").each(function () {
|
|||||||
header_options[i] = {sorter: 'sizeSorter'};
|
header_options[i] = {sorter: 'sizeSorter'};
|
||||||
} else if ($th.data('type') == 'ip'){
|
} else if ($th.data('type') == 'ip'){
|
||||||
header_options[i] = {sorter: 'ipAddress'};
|
header_options[i] = {sorter: 'ipAddress'};
|
||||||
|
} else if ($th.data('type') == 'timesince'){
|
||||||
|
header_options[i] = {sorter: 'timesinceSorter'};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$table.tablesorter({
|
$table.tablesorter({
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
import iso8601
|
import iso8601
|
||||||
|
|
||||||
from django.template.defaultfilters import register # noqa
|
from django.template.defaultfilters import register # noqa
|
||||||
|
from django.template.defaultfilters import timesince # noqa
|
||||||
|
from django.utils.safestring import mark_safe # noqa
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
@ -36,3 +39,12 @@ def parse_isotime(timestr):
|
|||||||
raise ValueError(e.message)
|
raise ValueError(e.message)
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
raise ValueError(e.message)
|
raise ValueError(e.message)
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def timesince_sortable(dt):
|
||||||
|
delta = timezone.now() - dt
|
||||||
|
# timedelta.total_seconds() not supported on python < 2.7
|
||||||
|
seconds = delta.seconds + (delta.days * 24 * 3600)
|
||||||
|
return mark_safe("<span data-seconds=\"%d\">%s</span>" %
|
||||||
|
(seconds, timesince(dt)))
|
||||||
|
@ -117,7 +117,9 @@ class AdminInstancesTable(tables.DataTable):
|
|||||||
verbose_name=_("Power State"))
|
verbose_name=_("Power State"))
|
||||||
created = tables.Column("created",
|
created = tables.Column("created",
|
||||||
verbose_name=_("Uptime"),
|
verbose_name=_("Uptime"),
|
||||||
filters=(filters.parse_isotime, timesince))
|
filters=(filters.parse_isotime,
|
||||||
|
filters.timesince_sortable),
|
||||||
|
attrs={'data-type': 'timesince'})
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
name = "instances"
|
name = "instances"
|
||||||
|
@ -596,7 +596,9 @@ class InstancesTable(tables.DataTable):
|
|||||||
verbose_name=_("Power State"))
|
verbose_name=_("Power State"))
|
||||||
created = tables.Column("created",
|
created = tables.Column("created",
|
||||||
verbose_name=_("Uptime"),
|
verbose_name=_("Uptime"),
|
||||||
filters=(filters.parse_isotime, timesince))
|
filters=(filters.parse_isotime,
|
||||||
|
filters.timesince_sortable),
|
||||||
|
attrs={'data-type': 'timesince'})
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
name = "instances"
|
name = "instances"
|
||||||
|
@ -5,6 +5,7 @@ from django.utils.translation import ugettext_lazy as _ # noqa
|
|||||||
|
|
||||||
from horizon import tables
|
from horizon import tables
|
||||||
from horizon.templatetags import sizeformat
|
from horizon.templatetags import sizeformat
|
||||||
|
from horizon.utils import filters
|
||||||
|
|
||||||
|
|
||||||
class CSVSummary(tables.LinkAction):
|
class CSVSummary(tables.LinkAction):
|
||||||
@ -59,7 +60,8 @@ class ProjectUsageTable(BaseUsageTable):
|
|||||||
link=get_instance_link)
|
link=get_instance_link)
|
||||||
uptime = tables.Column('uptime_at',
|
uptime = tables.Column('uptime_at',
|
||||||
verbose_name=_("Uptime"),
|
verbose_name=_("Uptime"),
|
||||||
filters=(timesince,))
|
filters=(filters.timesince_sortable,),
|
||||||
|
attrs={'data-type': 'timesince'})
|
||||||
|
|
||||||
def get_object_id(self, datum):
|
def get_object_id(self, datum):
|
||||||
return datum.get('instance_id', id(datum))
|
return datum.get('instance_id', id(datum))
|
||||||
|
Loading…
Reference in New Issue
Block a user