Merge "Added custom parser for tablesorter.js"
This commit is contained in:
commit
da7f44cdc2
@ -92,7 +92,9 @@ class ContainersTable(tables.DataTable):
|
|||||||
objects = tables.Column("object_count",
|
objects = tables.Column("object_count",
|
||||||
verbose_name=_('Objects'),
|
verbose_name=_('Objects'),
|
||||||
empty_value="0")
|
empty_value="0")
|
||||||
size = tables.Column(get_size_used, verbose_name=_('Size'))
|
size = tables.Column(get_size_used,
|
||||||
|
verbose_name=_('Size'),
|
||||||
|
attrs={'data-type': 'size'})
|
||||||
|
|
||||||
def get_object_id(self, container):
|
def get_object_id(self, container):
|
||||||
return container.name
|
return container.name
|
||||||
@ -159,7 +161,8 @@ class ObjectsTable(tables.DataTable):
|
|||||||
size = tables.Column("size",
|
size = tables.Column("size",
|
||||||
verbose_name=_('Size'),
|
verbose_name=_('Size'),
|
||||||
filters=(filesizeformat,),
|
filters=(filesizeformat,),
|
||||||
summation="sum")
|
summation="sum",
|
||||||
|
attrs={'data-type': 'size'})
|
||||||
|
|
||||||
def get_object_id(self, obj):
|
def get_object_id(self, obj):
|
||||||
return obj.name
|
return obj.name
|
||||||
|
@ -268,7 +268,9 @@ class InstancesTable(tables.DataTable):
|
|||||||
link=("horizon:nova:instances:detail"),
|
link=("horizon:nova:instances:detail"),
|
||||||
verbose_name=_("Instance Name"))
|
verbose_name=_("Instance Name"))
|
||||||
ip = tables.Column(get_ips, verbose_name=_("IP Address"))
|
ip = tables.Column(get_ips, verbose_name=_("IP Address"))
|
||||||
size = tables.Column(get_size, verbose_name=_("Size"))
|
size = tables.Column(get_size,
|
||||||
|
verbose_name=_("Size"),
|
||||||
|
attrs={'data-type': 'size'})
|
||||||
keypair = tables.Column(get_keyname, verbose_name=_("Keypair"))
|
keypair = tables.Column(get_keyname, verbose_name=_("Keypair"))
|
||||||
status = tables.Column("status",
|
status = tables.Column("status",
|
||||||
filters=(title, replace_underscores),
|
filters=(title, replace_underscores),
|
||||||
|
@ -137,7 +137,9 @@ class VolumesTableBase(tables.DataTable):
|
|||||||
description = tables.Column("display_description",
|
description = tables.Column("display_description",
|
||||||
verbose_name=_("Description"),
|
verbose_name=_("Description"),
|
||||||
truncate=40)
|
truncate=40)
|
||||||
size = tables.Column(get_size, verbose_name=_("Size"))
|
size = tables.Column(get_size,
|
||||||
|
verbose_name=_("Size"),
|
||||||
|
attrs={'data-type': 'size'})
|
||||||
status = tables.Column("status",
|
status = tables.Column("status",
|
||||||
filters=(title,),
|
filters=(title,),
|
||||||
verbose_name=_("Status"),
|
verbose_name=_("Status"),
|
||||||
|
@ -24,11 +24,17 @@ class CreateFlavor(tables.LinkAction):
|
|||||||
classes = ("ajax-modal", "btn-create")
|
classes = ("ajax-modal", "btn-create")
|
||||||
|
|
||||||
|
|
||||||
|
def get_size(flavor):
|
||||||
|
return _("%sMB") % flavor.ram
|
||||||
|
|
||||||
|
|
||||||
class FlavorsTable(tables.DataTable):
|
class FlavorsTable(tables.DataTable):
|
||||||
flavor_id = tables.Column('id', verbose_name=('ID'))
|
flavor_id = tables.Column('id', verbose_name=('ID'))
|
||||||
name = tables.Column('name', verbose_name=_('Flavor Name'))
|
name = tables.Column('name', verbose_name=_('Flavor Name'))
|
||||||
vcpus = tables.Column('vcpus', verbose_name=_('VCPUs'))
|
vcpus = tables.Column('vcpus', verbose_name=_('VCPUs'))
|
||||||
ram = tables.Column('ram', verbose_name=_('Memory'))
|
ram = tables.Column(get_size,
|
||||||
|
verbose_name=_('Memory'),
|
||||||
|
attrs={'data-type': 'size'})
|
||||||
disk = tables.Column('disk', verbose_name=_('Root Disk'))
|
disk = tables.Column('disk', verbose_name=_('Root Disk'))
|
||||||
ephemeral = tables.Column('OS-FLV-EXT-DATA:ephemeral',
|
ephemeral = tables.Column('OS-FLV-EXT-DATA:ephemeral',
|
||||||
verbose_name=_('Ephemeral Disk'))
|
verbose_name=_('Ephemeral Disk'))
|
||||||
@ -37,4 +43,4 @@ class FlavorsTable(tables.DataTable):
|
|||||||
name = "flavors"
|
name = "flavors"
|
||||||
verbose_name = _("Flavors")
|
verbose_name = _("Flavors")
|
||||||
table_actions = (CreateFlavor, DeleteFlavor)
|
table_actions = (CreateFlavor, DeleteFlavor)
|
||||||
row_actions = (DeleteFlavor, )
|
row_actions = (DeleteFlavor,)
|
||||||
|
@ -74,7 +74,8 @@ class SyspanelInstancesTable(tables.DataTable):
|
|||||||
ip = tables.Column(get_ips, verbose_name=_("IP Address"))
|
ip = tables.Column(get_ips, verbose_name=_("IP Address"))
|
||||||
size = tables.Column(get_size,
|
size = tables.Column(get_size,
|
||||||
verbose_name=_("Size"),
|
verbose_name=_("Size"),
|
||||||
classes=('nowrap-col',))
|
classes=('nowrap-col',),
|
||||||
|
attrs={'data-type': 'size'})
|
||||||
status = tables.Column("status",
|
status = tables.Column("status",
|
||||||
filters=(title, replace_underscores),
|
filters=(title, replace_underscores),
|
||||||
verbose_name=_("Status"),
|
verbose_name=_("Status"),
|
||||||
|
@ -148,21 +148,50 @@ horizon.datatables.confirm = function (action) {
|
|||||||
return modal;
|
return modal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$.tablesorter.addParser({
|
||||||
|
// set a unique id
|
||||||
|
id: 'sizeSorter',
|
||||||
|
is: function(s) {
|
||||||
|
// Not an auto-detected parser
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
// compare int values
|
||||||
|
format: function(s) {
|
||||||
|
var sizes = {BYTE: 0, B: 0, KB: 1, MB: 2,
|
||||||
|
GB: 3, TB: 4, PB: 5};
|
||||||
|
var regex = /([\d\.,]+)\s*(byte|B|KB|MB|GB|TB|PB)+/i;
|
||||||
|
var match = s.match(regex);
|
||||||
|
if (match && match.length === 3){
|
||||||
|
return parseFloat(match[1]) *
|
||||||
|
Math.pow(1024, sizes[match[2].toUpperCase()]);
|
||||||
|
}
|
||||||
|
return parseInt(s, 10);
|
||||||
|
},
|
||||||
|
type: 'numeric'
|
||||||
|
});
|
||||||
|
|
||||||
horizon.datatables.set_table_sorting = function (parent) {
|
horizon.datatables.set_table_sorting = function (parent) {
|
||||||
// Function to initialize the tablesorter plugin strictly on sortable columns.
|
// Function to initialize the tablesorter plugin strictly on sortable columns.
|
||||||
$(parent).find("table.table").each(function () {
|
$(parent).find("table.table").each(function () {
|
||||||
var $this = $(this),
|
var $table = $(this),
|
||||||
header_options = {};
|
header_options = {};
|
||||||
$this.find("thead th").each(function (i, val) {
|
// Disable if not sortable or has <= 1 item
|
||||||
// Disable if not sortable or has <= 1 item
|
if ($table.find('tbody tr').not('.empty').length > 1){
|
||||||
if (!$(this).hasClass('sortable') || $this.find('tbody tr').not('.empty').length <= 1) {
|
$table.find("thead th").each(function (i, val) {
|
||||||
header_options[i] = {sorter: false};
|
$th = $(this);
|
||||||
}
|
if (!$th.hasClass('sortable')) {
|
||||||
});
|
header_options[i] = {sorter: false};
|
||||||
$this.tablesorter({
|
} else if ($th.data('type') == 'size'){
|
||||||
headers: header_options,
|
// set as [i-1] as there is one more <th> in <thead>
|
||||||
cancelSelection: false
|
// than <td>'s in <tbody>
|
||||||
});
|
header_options[i-1] = {sorter: 'sizeSorter'};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$table.tablesorter({
|
||||||
|
headers: header_options,
|
||||||
|
cancelSelection: false
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ class BaseUsageTable(tables.DataTable):
|
|||||||
disk = tables.Column('local_gb', verbose_name=_("Disk"))
|
disk = tables.Column('local_gb', verbose_name=_("Disk"))
|
||||||
memory = tables.Column('memory_mb',
|
memory = tables.Column('memory_mb',
|
||||||
verbose_name=_("RAM"),
|
verbose_name=_("RAM"),
|
||||||
filters=(mbformat,))
|
filters=(mbformat,),
|
||||||
|
attrs={"data-type": "size"})
|
||||||
hours = tables.Column('vcpu_hours', verbose_name=_("VCPU Hours"),
|
hours = tables.Column('vcpu_hours', verbose_name=_("VCPU Hours"),
|
||||||
filters=(lambda v: floatformat(v, 2),))
|
filters=(lambda v: floatformat(v, 2),))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user