mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fix sorting of sizes on the statistics views by sorting raw values and prettifying on the client side. Includes Jasmine tests for the prettyfying function. Fixes #2315
This commit is contained in:
parent
c32bf7780e
commit
94b7fc483a
@ -627,6 +627,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
|
|||||||
canDropCascade: true,
|
canDropCascade: true,
|
||||||
hasDepends: true,
|
hasDepends: true,
|
||||||
hasStatistics: true,
|
hasStatistics: true,
|
||||||
|
statsPrettifyFields: ['Index size'],
|
||||||
Init: function() {
|
Init: function() {
|
||||||
/* Avoid multiple registration of menus */
|
/* Avoid multiple registration of menus */
|
||||||
if (this.initialized)
|
if (this.initialized)
|
||||||
|
@ -19,6 +19,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
|||||||
hasSQL: true,
|
hasSQL: true,
|
||||||
hasDepends: true,
|
hasDepends: true,
|
||||||
hasStatistics: true,
|
hasStatistics: true,
|
||||||
|
statsPrettifyFields: ['Index size'],
|
||||||
parent_type: 'table',
|
parent_type: 'table',
|
||||||
canDrop: true,
|
canDrop: true,
|
||||||
canDropCascade: true,
|
canDropCascade: true,
|
||||||
|
@ -12,7 +12,8 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
|||||||
sqlAlterHelp: 'sql-alterindex.html',
|
sqlAlterHelp: 'sql-alterindex.html',
|
||||||
sqlCreateHelp: 'sql-createindex.html',
|
sqlCreateHelp: 'sql-createindex.html',
|
||||||
columns: ['name', 'description'],
|
columns: ['name', 'description'],
|
||||||
hasStatistics: true
|
hasStatistics: true,
|
||||||
|
statsPrettifyFields: ['Size', 'Index size']
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -215,6 +216,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
|||||||
hasSQL: true,
|
hasSQL: true,
|
||||||
hasDepends: true,
|
hasDepends: true,
|
||||||
hasStatistics: true,
|
hasStatistics: true,
|
||||||
|
statsPrettifyFields: ['Size', 'Index size'],
|
||||||
Init: function() {
|
Init: function() {
|
||||||
/* Avoid mulitple registration of menus */
|
/* Avoid mulitple registration of menus */
|
||||||
if (this.initialized)
|
if (this.initialized)
|
||||||
|
@ -4,12 +4,12 @@ SELECT
|
|||||||
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
||||||
idx_blks_read AS {{ conn|qtIdent(_('Index blocks read')) }},
|
idx_blks_read AS {{ conn|qtIdent(_('Index blocks read')) }},
|
||||||
idx_blks_hit AS {{ conn|qtIdent(_('Index blocks hit')) }},
|
idx_blks_hit AS {{ conn|qtIdent(_('Index blocks hit')) }},
|
||||||
pg_size_pretty(pg_relation_size({{ exid }}::OID)) AS {{ conn|qtIdent(_('Index size')) }}
|
pg_relation_size({{ exid }}::OID) AS {{ conn|qtIdent(_('Index size')) }}
|
||||||
{#=== Extended stats ===#}
|
{#=== Extended stats ===#}
|
||||||
{% if is_pgstattuple %}
|
{% if is_pgstattuple %}
|
||||||
,version AS {{ conn|qtIdent(_('Version')) }},
|
,version AS {{ conn|qtIdent(_('Version')) }},
|
||||||
tree_level AS {{ conn|qtIdent(_('Tree level')) }},
|
tree_level AS {{ conn|qtIdent(_('Tree level')) }},
|
||||||
pg_size_pretty(index_size) AS {{ conn|qtIdent(_('Index size')) }},
|
index_size AS {{ conn|qtIdent(_('Index size')) }},
|
||||||
root_block_no AS {{ conn|qtIdent(_('Root block no')) }},
|
root_block_no AS {{ conn|qtIdent(_('Root block no')) }},
|
||||||
internal_pages AS {{ conn|qtIdent(_('Internal pages')) }},
|
internal_pages AS {{ conn|qtIdent(_('Internal pages')) }},
|
||||||
leaf_pages AS {{ conn|qtIdent(_('Leaf pages')) }},
|
leaf_pages AS {{ conn|qtIdent(_('Leaf pages')) }},
|
||||||
|
@ -3,7 +3,7 @@ SELECT
|
|||||||
idx_scan AS {{ conn|qtIdent(_('Index scans')) }},
|
idx_scan AS {{ conn|qtIdent(_('Index scans')) }},
|
||||||
idx_tup_read AS {{ conn|qtIdent(_('Index tuples read')) }},
|
idx_tup_read AS {{ conn|qtIdent(_('Index tuples read')) }},
|
||||||
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
||||||
pg_size_pretty(pg_relation_size(indexrelid)) AS {{ conn|qtIdent(_('Size')) }}
|
pg_relation_size(indexrelid) AS {{ conn|qtIdent(_('Size')) }}
|
||||||
FROM
|
FROM
|
||||||
pg_stat_all_indexes stat
|
pg_stat_all_indexes stat
|
||||||
JOIN pg_class cls ON cls.oid=indexrelid
|
JOIN pg_class cls ON cls.oid=indexrelid
|
||||||
|
@ -4,12 +4,12 @@ SELECT
|
|||||||
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
||||||
idx_blks_read AS {{ conn|qtIdent(_('Index blocks read')) }},
|
idx_blks_read AS {{ conn|qtIdent(_('Index blocks read')) }},
|
||||||
idx_blks_hit AS {{ conn|qtIdent(_('Index blocks hit')) }},
|
idx_blks_hit AS {{ conn|qtIdent(_('Index blocks hit')) }},
|
||||||
pg_size_pretty(pg_relation_size({{ idx }}::OID)) AS {{ conn|qtIdent(_('Index size')) }}
|
pg_relation_size({{ idx }}::OID) AS {{ conn|qtIdent(_('Index size')) }}
|
||||||
{#=== Extended stats ===#}
|
{#=== Extended stats ===#}
|
||||||
{% if is_pgstattuple %}
|
{% if is_pgstattuple %}
|
||||||
,version AS {{ conn|qtIdent(_('Version')) }},
|
,version AS {{ conn|qtIdent(_('Version')) }},
|
||||||
tree_level AS {{ conn|qtIdent(_('Tree level')) }},
|
tree_level AS {{ conn|qtIdent(_('Tree level')) }},
|
||||||
pg_size_pretty(index_size) AS {{ conn|qtIdent(_('Index size')) }},
|
index_size AS {{ conn|qtIdent(_('Index size')) }},
|
||||||
root_block_no AS {{ conn|qtIdent(_('Root block no')) }},
|
root_block_no AS {{ conn|qtIdent(_('Root block no')) }},
|
||||||
internal_pages AS {{ conn|qtIdent(_('Internal pages')) }},
|
internal_pages AS {{ conn|qtIdent(_('Internal pages')) }},
|
||||||
leaf_pages AS {{ conn|qtIdent(_('Leaf pages')) }},
|
leaf_pages AS {{ conn|qtIdent(_('Leaf pages')) }},
|
||||||
|
@ -4,12 +4,12 @@ SELECT
|
|||||||
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
||||||
idx_blks_read AS {{ conn|qtIdent(_('Index blocks read')) }},
|
idx_blks_read AS {{ conn|qtIdent(_('Index blocks read')) }},
|
||||||
idx_blks_hit AS {{ conn|qtIdent(_('Index blocks hit')) }},
|
idx_blks_hit AS {{ conn|qtIdent(_('Index blocks hit')) }},
|
||||||
pg_size_pretty(pg_relation_size({{ cid }}::OID)) AS {{ conn|qtIdent(_('Index size')) }}
|
pg_relation_size({{ cid }}::OID) AS {{ conn|qtIdent(_('Index size')) }}
|
||||||
{#=== Extended stats ===#}
|
{#=== Extended stats ===#}
|
||||||
{% if is_pgstattuple %}
|
{% if is_pgstattuple %}
|
||||||
,version AS {{ conn|qtIdent(_('Version')) }},
|
,version AS {{ conn|qtIdent(_('Version')) }},
|
||||||
tree_level AS {{ conn|qtIdent(_('Tree level')) }},
|
tree_level AS {{ conn|qtIdent(_('Tree level')) }},
|
||||||
pg_size_pretty(index_size) AS {{ conn|qtIdent(_('Index size')) }},
|
index_size AS {{ conn|qtIdent(_('Index size')) }},
|
||||||
root_block_no AS {{ conn|qtIdent(_('Root block no')) }},
|
root_block_no AS {{ conn|qtIdent(_('Root block no')) }},
|
||||||
internal_pages AS {{ conn|qtIdent(_('Internal pages')) }},
|
internal_pages AS {{ conn|qtIdent(_('Internal pages')) }},
|
||||||
leaf_pages AS {{ conn|qtIdent(_('Leaf pages')) }},
|
leaf_pages AS {{ conn|qtIdent(_('Leaf pages')) }},
|
||||||
|
@ -13,7 +13,10 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
|||||||
label: '{{ _('Tables') }}',
|
label: '{{ _('Tables') }}',
|
||||||
type: 'coll-table',
|
type: 'coll-table',
|
||||||
columns: ['name', 'relowner', 'description'],
|
columns: ['name', 'relowner', 'description'],
|
||||||
hasStatistics: true
|
hasStatistics: true,
|
||||||
|
statsPrettifyFields: ['Size', 'Indexes size', 'Table size',
|
||||||
|
'Toast table size', 'Tuple length',
|
||||||
|
'Dead tuple length', 'Free space']
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -25,6 +28,9 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
|||||||
hasSQL: true,
|
hasSQL: true,
|
||||||
hasDepends: true,
|
hasDepends: true,
|
||||||
hasStatistics: true,
|
hasStatistics: true,
|
||||||
|
statsPrettifyFields: ['Size', 'Indexes size', 'Table size',
|
||||||
|
'Toast table size', 'Tuple length',
|
||||||
|
'Dead tuple length', 'Free space'],
|
||||||
sqlAlterHelp: 'sql-altertable.html',
|
sqlAlterHelp: 'sql-altertable.html',
|
||||||
sqlCreateHelp: 'sql-createtable.html',
|
sqlCreateHelp: 'sql-createtable.html',
|
||||||
dialogHelp: '{{ url_for('help.static', filename='table_dialog.html') }}',
|
dialogHelp: '{{ url_for('help.static', filename='table_dialog.html') }}',
|
||||||
|
@ -14,12 +14,12 @@ SELECT
|
|||||||
autovacuum_count AS {{ conn|qtIdent(_('Autovacuum counter')) }},
|
autovacuum_count AS {{ conn|qtIdent(_('Autovacuum counter')) }},
|
||||||
analyze_count AS {{ conn|qtIdent(_('Analyze counter')) }},
|
analyze_count AS {{ conn|qtIdent(_('Analyze counter')) }},
|
||||||
autoanalyze_count AS {{ conn|qtIdent(_('Autoanalyze counter')) }},
|
autoanalyze_count AS {{ conn|qtIdent(_('Autoanalyze counter')) }},
|
||||||
pg_size_pretty(pg_relation_size(st.relid)
|
pg_relation_size(st.relid)
|
||||||
+ CASE WHEN cl.reltoastrelid = 0 THEN 0 ELSE pg_relation_size(cl.reltoastrelid)
|
+ CASE WHEN cl.reltoastrelid = 0 THEN 0 ELSE pg_relation_size(cl.reltoastrelid)
|
||||||
+ COALESCE((SELECT SUM(pg_relation_size(indexrelid))
|
+ COALESCE((SELECT SUM(pg_relation_size(indexrelid))
|
||||||
FROM pg_index WHERE indrelid=cl.reltoastrelid)::int8, 0) END
|
FROM pg_index WHERE indrelid=cl.reltoastrelid)::int8, 0) END
|
||||||
+ COALESCE((SELECT SUM(pg_relation_size(indexrelid))
|
+ COALESCE((SELECT SUM(pg_relation_size(indexrelid))
|
||||||
FROM pg_index WHERE indrelid=st.relid)::int8, 0)) AS {{ conn|qtIdent(_('Size')) }}
|
FROM pg_index WHERE indrelid=st.relid)::int8, 0) AS {{ conn|qtIdent(_('Size')) }}
|
||||||
FROM
|
FROM
|
||||||
pg_stat_all_tables st
|
pg_stat_all_tables st
|
||||||
JOIN
|
JOIN
|
||||||
|
@ -25,23 +25,23 @@ SELECT
|
|||||||
autovacuum_count AS {{ conn|qtIdent(_('Autovacuum counter')) }},
|
autovacuum_count AS {{ conn|qtIdent(_('Autovacuum counter')) }},
|
||||||
analyze_count AS {{ conn|qtIdent(_('Analyze counter')) }},
|
analyze_count AS {{ conn|qtIdent(_('Analyze counter')) }},
|
||||||
autoanalyze_count AS {{ conn|qtIdent(_('Autoanalyze counter')) }},
|
autoanalyze_count AS {{ conn|qtIdent(_('Autoanalyze counter')) }},
|
||||||
pg_size_pretty(pg_relation_size(stat.relid)) AS {{ conn|qtIdent(_('Table size')) }},
|
pg_relation_size(stat.relid) AS {{ conn|qtIdent(_('Table size')) }},
|
||||||
CASE WHEN cl.reltoastrelid = 0 THEN NULL ELSE pg_size_pretty(pg_relation_size(cl.reltoastrelid)
|
CASE WHEN cl.reltoastrelid = 0 THEN NULL ELSE pg_relation_size(cl.reltoastrelid)
|
||||||
+ COALESCE((SELECT SUM(pg_relation_size(indexrelid))
|
+ COALESCE((SELECT SUM(pg_relation_size(indexrelid))
|
||||||
FROM pg_index WHERE indrelid=cl.reltoastrelid)::int8, 0))
|
FROM pg_index WHERE indrelid=cl.reltoastrelid)::int8, 0)
|
||||||
END AS {{ conn|qtIdent(_('Toast table size')) }},
|
END AS {{ conn|qtIdent(_('Toast table size')) }},
|
||||||
pg_size_pretty(COALESCE((SELECT SUM(pg_relation_size(indexrelid))
|
COALESCE((SELECT SUM(pg_relation_size(indexrelid))
|
||||||
FROM pg_index WHERE indrelid=stat.relid)::int8, 0))
|
FROM pg_index WHERE indrelid=stat.relid)::int8, 0)
|
||||||
AS {{ conn|qtIdent(_('Indexes size')) }}
|
AS {{ conn|qtIdent(_('Indexes size')) }}
|
||||||
{% if is_pgstattuple %}
|
{% if is_pgstattuple %}
|
||||||
{#== EXTENDED STATS ==#}
|
{#== EXTENDED STATS ==#}
|
||||||
,tuple_count AS {{ conn|qtIdent(_('Tuple count')) }},
|
,tuple_count AS {{ conn|qtIdent(_('Tuple count')) }},
|
||||||
pg_size_pretty(tuple_len) AS {{ conn|qtIdent(_('Tuple length')) }},
|
tuple_len AS {{ conn|qtIdent(_('Tuple length')) }},
|
||||||
tuple_percent AS {{ conn|qtIdent(_('Tuple percent')) }},
|
tuple_percent AS {{ conn|qtIdent(_('Tuple percent')) }},
|
||||||
dead_tuple_count AS {{ conn|qtIdent(_('Dead tuple count')) }},
|
dead_tuple_count AS {{ conn|qtIdent(_('Dead tuple count')) }},
|
||||||
pg_size_pretty(dead_tuple_len) AS {{ conn|qtIdent(_('Dead tuple length')) }},
|
dead_tuple_len AS {{ conn|qtIdent(_('Dead tuple length')) }},
|
||||||
dead_tuple_percent AS {{ conn|qtIdent(_('Dead tuple percent')) }},
|
dead_tuple_percent AS {{ conn|qtIdent(_('Dead tuple percent')) }},
|
||||||
pg_size_pretty(free_space) AS {{ conn|qtIdent(_('Free space')) }},
|
free_space AS {{ conn|qtIdent(_('Free space')) }},
|
||||||
free_percent AS {{ conn|qtIdent(_('Free percent')) }}
|
free_percent AS {{ conn|qtIdent(_('Free percent')) }}
|
||||||
FROM
|
FROM
|
||||||
pgstattuple('{{schema_name}}.{{table_name}}'), pg_stat_all_tables stat
|
pgstattuple('{{schema_name}}.{{table_name}}'), pg_stat_all_tables stat
|
||||||
|
@ -12,7 +12,8 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
|
|||||||
label: '{{ _('Databases') }}',
|
label: '{{ _('Databases') }}',
|
||||||
type: 'coll-database',
|
type: 'coll-database',
|
||||||
columns: ['name', 'datowner', 'comments'],
|
columns: ['name', 'datowner', 'comments'],
|
||||||
hasStatistics: true
|
hasStatistics: true,
|
||||||
|
statsPrettifyFields: ['Size', 'Size of temporary files']
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
|
|||||||
hasSQL: true,
|
hasSQL: true,
|
||||||
hasDepends: true,
|
hasDepends: true,
|
||||||
hasStatistics: true,
|
hasStatistics: true,
|
||||||
|
statsPrettifyFields: ['Size', 'Size of temporary files'],
|
||||||
canDrop: function(node) {
|
canDrop: function(node) {
|
||||||
return node.canDrop;
|
return node.canDrop;
|
||||||
},
|
},
|
||||||
|
@ -17,11 +17,11 @@ SELECT
|
|||||||
slave.confl_bufferpin AS {{ conn|qtIdent(_('Bufferpin conflicts')) }},
|
slave.confl_bufferpin AS {{ conn|qtIdent(_('Bufferpin conflicts')) }},
|
||||||
slave.confl_deadlock AS {{ conn|qtIdent(_('Deadlock conflicts')) }},
|
slave.confl_deadlock AS {{ conn|qtIdent(_('Deadlock conflicts')) }},
|
||||||
temp_files AS {{ conn|qtIdent(_("Temporary files")) }},
|
temp_files AS {{ conn|qtIdent(_("Temporary files")) }},
|
||||||
pg_size_pretty(temp_bytes) AS {{ conn|qtIdent(_("Size of temporary files")) }},
|
temp_bytes AS {{ conn|qtIdent(_("Size of temporary files")) }},
|
||||||
deadlocks AS {{ conn|qtIdent(_("Deadlocks")) }},
|
deadlocks AS {{ conn|qtIdent(_("Deadlocks")) }},
|
||||||
blk_read_time AS {{ conn|qtIdent(_("Block read time")) }},
|
blk_read_time AS {{ conn|qtIdent(_("Block read time")) }},
|
||||||
blk_write_time AS {{ conn|qtIdent(_("Block write time")) }},
|
blk_write_time AS {{ conn|qtIdent(_("Block write time")) }},
|
||||||
pg_size_pretty(pg_database_size(db.datid)) AS {{ conn|qtIdent(_('Size')) }}
|
pg_database_size(db.datid) AS {{ conn|qtIdent(_('Size')) }}
|
||||||
FROM
|
FROM
|
||||||
pg_stat_database db
|
pg_stat_database db
|
||||||
LEFT JOIN pg_stat_database_conflicts slave ON db.datid=slave.datid
|
LEFT JOIN pg_stat_database_conflicts slave ON db.datid=slave.datid
|
||||||
|
@ -16,7 +16,7 @@ SELECT
|
|||||||
slave.confl_snapshot AS {{ conn|qtIdent(_('Snapshot conflicts')) }},
|
slave.confl_snapshot AS {{ conn|qtIdent(_('Snapshot conflicts')) }},
|
||||||
slave.confl_bufferpin AS {{ conn|qtIdent(_('Bufferpin conflicts')) }},
|
slave.confl_bufferpin AS {{ conn|qtIdent(_('Bufferpin conflicts')) }},
|
||||||
slave.confl_deadlock AS {{ conn|qtIdent(_('Deadlock conflicts')) }},
|
slave.confl_deadlock AS {{ conn|qtIdent(_('Deadlock conflicts')) }},
|
||||||
pg_size_pretty(pg_database_size(db.datid)) AS {{ conn|qtIdent(_('Size')) }}
|
pg_database_size(db.datid) AS {{ conn|qtIdent(_('Size')) }}
|
||||||
FROM
|
FROM
|
||||||
pg_stat_database db
|
pg_stat_database db
|
||||||
LEFT JOIN pg_stat_database_conflicts slave ON db.datid=slave.datid
|
LEFT JOIN pg_stat_database_conflicts slave ON db.datid=slave.datid
|
||||||
|
@ -9,7 +9,8 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
|||||||
label: '{{ _('Tablespaces') }}',
|
label: '{{ _('Tablespaces') }}',
|
||||||
type: 'coll-tablespace',
|
type: 'coll-tablespace',
|
||||||
columns: ['name', 'spcuser', 'description'],
|
columns: ['name', 'spcuser', 'description'],
|
||||||
hasStatistics: true
|
hasStatistics: true,
|
||||||
|
statsPrettifyFields: ['Size']
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
|||||||
canDrop: true,
|
canDrop: true,
|
||||||
hasDepends: true,
|
hasDepends: true,
|
||||||
hasStatistics: true,
|
hasStatistics: true,
|
||||||
|
statsPrettifyFields: ['Size'],
|
||||||
Init: function() {
|
Init: function() {
|
||||||
/* Avoid mulitple registration of menus */
|
/* Avoid mulitple registration of menus */
|
||||||
if (this.initialized)
|
if (this.initialized)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{### SQL to fetch tablespace object stats ###}
|
{### SQL to fetch tablespace object stats ###}
|
||||||
{% if tsid %}
|
{% if tsid %}
|
||||||
SELECT pg_size_pretty(pg_tablespace_size({{ tsid|qtLiteral }}::OID)) AS {{ conn|qtIdent(_('Size')) }}
|
SELECT pg_tablespace_size({{ tsid|qtLiteral }}::OID) AS {{ conn|qtIdent(_('Size')) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
SELECT ts.spcname AS {{ conn|qtIdent(_('Name')) }},
|
SELECT ts.spcname AS {{ conn|qtIdent(_('Name')) }},
|
||||||
pg_size_pretty(pg_tablespace_size(ts.oid)) AS {{ conn|qtIdent(_('Size')) }}
|
pg_tablespace_size(ts.oid) AS {{ conn|qtIdent(_('Size')) }}
|
||||||
FROM
|
FROM
|
||||||
pg_catalog.pg_tablespace ts;
|
pg_catalog.pg_tablespace ts;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
define([
|
define([
|
||||||
'underscore', 'underscore.string', 'jquery', 'pgadmin.browser', 'backgrid',
|
'underscore', 'underscore.string', 'jquery', 'pgadmin.browser', 'backgrid',
|
||||||
'alertify', 'wcdocker', 'pgadmin.backgrid', 'pgadmin.alertifyjs', 'pgadmin.browser.messages',
|
'alertify', 'sources/size_prettify'
|
||||||
], function(_, S, $, pgBrowser, Backgrid, Alertify) {
|
], function(_, S, $, pgBrowser, Backgrid, Alertify, sizePrettify) {
|
||||||
|
|
||||||
if (pgBrowser.NodeStatistics)
|
if (pgBrowser.NodeStatistics)
|
||||||
return pgBrowser.NodeStatistics;
|
return pgBrowser.NodeStatistics;
|
||||||
@ -12,6 +12,25 @@ define([
|
|||||||
return pgBrowser.NodeStatistics;
|
return pgBrowser.NodeStatistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var SizeFormatter = Backgrid.SizeFormatter = function () {};
|
||||||
|
_.extend(SizeFormatter.prototype, {
|
||||||
|
/**
|
||||||
|
Takes a raw value from a model and returns the human readable formatted
|
||||||
|
string for display.
|
||||||
|
|
||||||
|
@member Backgrid.SizeFormatter
|
||||||
|
@param {*} rawData
|
||||||
|
@param {Backbone.Model} model Used for more complicated formatting
|
||||||
|
@return {*}
|
||||||
|
*/
|
||||||
|
fromRaw: function (rawData, model) {
|
||||||
|
return sizePrettify(rawData);
|
||||||
|
},
|
||||||
|
toRaw: function (formattedData, model) {
|
||||||
|
return formattedData;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var PGBooleanCell = Backgrid.Extension.SwitchCell.extend({
|
var PGBooleanCell = Backgrid.Extension.SwitchCell.extend({
|
||||||
defaults: _.extend({}, Backgrid.Extension.SwitchCell.prototype.defaults)
|
defaults: _.extend({}, Backgrid.Extension.SwitchCell.prototype.defaults)
|
||||||
}),
|
}),
|
||||||
@ -200,9 +219,9 @@ define([
|
|||||||
if (res.data) {
|
if (res.data) {
|
||||||
var data = res.data;
|
var data = res.data;
|
||||||
if (node.hasCollectiveStatistics || data['rows'].length > 1) {
|
if (node.hasCollectiveStatistics || data['rows'].length > 1) {
|
||||||
self.__createMultiLineStatistics.call(self, data);
|
self.__createMultiLineStatistics.call(self, data, node.statsPrettifyFields);
|
||||||
} else {
|
} else {
|
||||||
self.__createSingleLineStatistics.call(self, data);
|
self.__createSingleLineStatistics.call(self, data, node.statsPrettifyFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.grid) {
|
if (self.grid) {
|
||||||
@ -294,24 +313,29 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
__createMultiLineStatistics: function(data) {
|
__createMultiLineStatistics: function(data, prettifyFields) {
|
||||||
var rows = data['rows'],
|
var rows = data['rows'],
|
||||||
columns = data['columns'];
|
columns = data['columns'];
|
||||||
|
|
||||||
this.columns = [];
|
this.columns = [];
|
||||||
for (var idx in columns) {
|
for (var idx in columns) {
|
||||||
var c = columns[idx];
|
var rawColumn = columns[idx],
|
||||||
this.columns.push({
|
col = {
|
||||||
editable: false,
|
editable: false,
|
||||||
name: c['name'],
|
name: rawColumn['name'],
|
||||||
cell: typeCellMapper[c['type_code']] || 'string'
|
cell: typeCellMapper[rawColumn['type_code']] || 'string'
|
||||||
});
|
};
|
||||||
|
if (_.indexOf(prettifyFields, rawColumn['name']) != -1) {
|
||||||
|
col['formatter'] = SizeFormatter
|
||||||
|
}
|
||||||
|
this.columns.push(col);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.collection.reset(rows);
|
this.collection.reset(rows);
|
||||||
},
|
},
|
||||||
|
|
||||||
__createSingleLineStatistics: function(data) {
|
__createSingleLineStatistics: function(data, prettifyFields) {
|
||||||
var row = data['rows'][0],
|
var row = data['rows'][0],
|
||||||
columns = data['columns']
|
columns = data['columns']
|
||||||
res = [];
|
res = [];
|
||||||
@ -322,7 +346,7 @@ define([
|
|||||||
res.push({
|
res.push({
|
||||||
'statistics': name,
|
'statistics': name,
|
||||||
// Check if row is undefined?
|
// Check if row is undefined?
|
||||||
'value': row && row[name] ? row[name] : null
|
'value': row && row[name] ? ((_.indexOf(prettifyFields, name) != -1) ? sizePrettify(row[name]) : row[name]) : null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
web/pgadmin/static/js/size_prettify.js
Normal file
24
web/pgadmin/static/js/size_prettify.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
define([],
|
||||||
|
function () {
|
||||||
|
var sizePrettify = function (rawSize) {
|
||||||
|
var size = Math.abs(rawSize),
|
||||||
|
limit = 10 * 1024,
|
||||||
|
limit2 = limit - 1,
|
||||||
|
cnt = 0,
|
||||||
|
sizeUnits = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'];
|
||||||
|
|
||||||
|
if (size < limit)
|
||||||
|
return size + ' ' + sizeUnits[cnt]; // return in bytes format
|
||||||
|
else
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
size = size / 1024;
|
||||||
|
cnt += 1;
|
||||||
|
} while (size > limit2);
|
||||||
|
|
||||||
|
return Math.round(size) + ' ' + sizeUnits[cnt];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return sizePrettify;
|
||||||
|
});
|
68
web/regression/javascript/size_prettify_spec.js
Normal file
68
web/regression/javascript/size_prettify_spec.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// pgAdmin 4 - PostgreSQL Tools
|
||||||
|
//
|
||||||
|
// Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
||||||
|
// This software is released under the PostgreSQL Licence
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
define(["sources/size_prettify"], function (sizePrettify) {
|
||||||
|
describe("sizePrettify", function () {
|
||||||
|
describe("when size is 0", function () {
|
||||||
|
it("returns 0 bytes", function () {
|
||||||
|
expect(sizePrettify(0)).toEqual("0 bytes");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when size >= 10kB and size < 10 MB", function () {
|
||||||
|
it("returns size in kB", function () {
|
||||||
|
expect(sizePrettify(10240)).toEqual("10 kB");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns size in kB", function () {
|
||||||
|
expect(sizePrettify(99999)).toEqual("98 kB");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("when size >= 10MB and size < 10 GB", function () {
|
||||||
|
it("returns size in MB", function () {
|
||||||
|
expect(sizePrettify(10485760)).toEqual("10 MB");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns size in MB", function () {
|
||||||
|
expect(sizePrettify(44040192)).toEqual("42 MB");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("when size >= 10GB and size < 10 TB", function () {
|
||||||
|
it("returns size in GB", function () {
|
||||||
|
expect(sizePrettify(10737418240)).toEqual("10 GB");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns size in GB", function () {
|
||||||
|
expect(sizePrettify(10736344498176)).toEqual("9999 GB");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when size >= 10TB and size < 10 PB", function () {
|
||||||
|
it("returns size in TB", function () {
|
||||||
|
expect(sizePrettify(10995116277760)).toEqual("10 TB");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns size in TB", function () {
|
||||||
|
expect(sizePrettify(29995116277760)).toEqual("27 TB");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when size >= 10 PB", function () {
|
||||||
|
it("returns size in PB", function () {
|
||||||
|
expect(sizePrettify(11258999068426200)).toEqual("10 PB");
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user