diff options
author | Stefan Giehl <stefan@matomo.org> | 2022-07-25 12:07:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-25 12:07:06 +0300 |
commit | eeb20ec4eb3ad3d0ac5c4ec952852cdde3ffad38 (patch) | |
tree | 495b1f1dfe5c6e84f1ab4e2a84a54bb2000836ea /plugins/CoreHome | |
parent | 6cc723685d3c1c9b399b09e9b691b9f2dba80bce (diff) |
Fix sizing of subtables with different column count (#19540)
* Don't try to align column width of subtables where column count differs from base table
* Improve fix and avoid table resizes when not needed
* fix tests
* updates expected test files
* [TEMP] submodule update
* add some comments
Diffstat (limited to 'plugins/CoreHome')
4 files changed, 57 insertions, 14 deletions
diff --git a/plugins/CoreHome/javascripts/dataTable.js b/plugins/CoreHome/javascripts/dataTable.js index 253a942fc4..95444fa5df 100644 --- a/plugins/CoreHome/javascripts/dataTable.js +++ b/plugins/CoreHome/javascripts/dataTable.js @@ -542,19 +542,21 @@ $.extend(DataTable.prototype, UIControl.prototype, { var paddingLeft = elem.css('paddingLeft'); paddingLeft = paddingLeft ? Math.round(parseFloat(paddingLeft)) : 0; var paddingRight = elem.css('paddingRight'); - paddingRight = paddingRight ? Math.round(parseFloat(paddingLeft)) : 0; + paddingRight = paddingRight ? Math.round(parseFloat(paddingRight)) : 0; - labelWidth = labelWidth - paddingLeft - paddingRight; + if (elem.find('.prefix-numeral').length) { + labelWidth -= Math.round(parseFloat(elem.find('.prefix-numeral').outerWidth())); + } - return labelWidth; + return labelWidth - paddingLeft - paddingRight; } setMaxTableWidthIfNeeded(domElem, 1200); - var isTableVisualization = this.jsViewDataTable - && typeof this.jsViewDataTable === 'string' - && typeof this.jsViewDataTable.indexOf === 'function' - && this.jsViewDataTable.indexOf('table') !== -1; + var isTableVisualization = this.param.viewDataTable + && typeof this.param.viewDataTable === 'string' + && typeof this.param.viewDataTable.indexOf === 'function' + && this.param.viewDataTable.indexOf('table') !== -1; if (isTableVisualization) { // we do this only for html tables @@ -569,9 +571,41 @@ $.extend(DataTable.prototype, UIControl.prototype, { labelColumnWidth = labelColumnMaxWidth; } + // special handling if the loaded datatable is a subtable + if ($(domElem).closest('.subDataTableContainer').length) { + var parentTable = $(domElem).closest('table.dataTable'); + var tableColumns = $('table:eq(0)>thead th', domElem).length; + var parentTableColumns = $('>thead th', parentTable).length; + var labelColumn = $('>tbody td.label:eq(0)', parentTable); + var labelWidthParentTable = labelColumn.outerWidth(); + + // if the subtable has the same column count as the main table, we rearrange all tables + if (parentTableColumns === tableColumns) { + labelColumnWidth = Math.min(labelColumnWidth, labelWidthParentTable); + + // rearrange base table labels, so the tables are displayed aligned + $('>tbody>tr:not(.subDataTableContainer)>td.label', parentTable).each(function() { + $(this).css({ + width: removePaddingFromWidth($(this), labelColumnWidth) + 'px' + }); + }); + + // rearrange all subtables having the same column count + $('>tbody>tr.subDataTableContainer', parentTable).each(function() { + if ($('table:eq(0)>thead th', this).length === parentTableColumns) { + $(this).css({ + width: removePaddingFromWidth($(this), labelColumnWidth) + 'px' + }); + } + }); + } + } + if (labelColumnWidth) { $('td.label', domElem).each(function() { - $(this).width(removePaddingFromWidth($(this), labelColumnWidth)); + $(this).css({ + width: removePaddingFromWidth($(this), labelColumnWidth) + 'px' + }); }); } @@ -583,8 +617,13 @@ $.extend(DataTable.prototype, UIControl.prototype, { // on resize of the window we re-calculate everything. var timeout = null; + var windowWidth = 0; var resizeDataTable = function() { + if (windowWidth === $(window).width()) { + return; // only resize a data table if the width changes + } + if (timeout) { clearTimeout(timeout); } @@ -598,6 +637,7 @@ $.extend(DataTable.prototype, UIControl.prototype, { $('td.label', domElem).width(''); } self.setFixWidthToMakeEllipsisWork(domElem); + windowWidth = $(window).width(); } else { $(window).off('resize', resizeDataTable); } @@ -1446,7 +1486,7 @@ $.extend(DataTable.prototype, UIControl.prototype, { var self = this; // highlight all columns on hover - $(domElem).on('mouseenter', 'td', function (e) { + $(domElem).on('mouseenter', 'td:not(.cellSubDataTable)', function (e) { e.stopPropagation(); var $this = $(e.target); if ($this.hasClass('label')) { diff --git a/plugins/CoreHome/stylesheets/dataTable/_rowActions.less b/plugins/CoreHome/stylesheets/dataTable/_rowActions.less index e059898521..a78b998205 100644 --- a/plugins/CoreHome/stylesheets/dataTable/_rowActions.less +++ b/plugins/CoreHome/stylesheets/dataTable/_rowActions.less @@ -13,6 +13,7 @@ table.dataTable .dataTableRowActions a { float: left; padding: 6px 4px 6px 0; margin: 0; + width: auto!important; .rowActionIcon { font-size: 19px; diff --git a/plugins/CoreHome/stylesheets/dataTable/_subDataTable.less b/plugins/CoreHome/stylesheets/dataTable/_subDataTable.less index e7f2dcda37..39a2c27dbd 100644 --- a/plugins/CoreHome/stylesheets/dataTable/_subDataTable.less +++ b/plugins/CoreHome/stylesheets/dataTable/_subDataTable.less @@ -8,7 +8,6 @@ table.subDataTable thead th { font-weight: normal; font-size: 12px; text-align: left; - padding: .3em 1em; border: 0; border-top: 1px solid #e7e7e7; border-bottom: 1px solid #e7e7e7; diff --git a/plugins/CoreHome/templates/_dataTableCell.twig b/plugins/CoreHome/templates/_dataTableCell.twig index 8f58c15029..4881d41da2 100644 --- a/plugins/CoreHome/templates/_dataTableCell.twig +++ b/plugins/CoreHome/templates/_dataTableCell.twig @@ -5,9 +5,6 @@ <a rel="noreferrer noopener" target="_blank" href='{% if row.getMetadata('url')|slice(0,4) not in ['http','ftp:'] %}http://{% endif %}{{ row.getMetadata('url')|rawSafeDecoded }}'> - {% if not row.getMetadata('logo') %} - <span class="icon-outlink"></span> - {% endif %} {% endif %} {% set totals = dataTable.getMetadata('totals') %} @@ -25,7 +22,13 @@ <span class='label{% if row.getMetadata('is_aggregate') %} highlighted{% endif %}' {% if properties is defined and properties.tooltip_metadata_name is not empty %}title="{{ row.getMetadata(properties.tooltip_metadata_name) }}"{% endif %}> - {% if column=='label' %}{{ piwik.logoHtml(row.getMetadata(), row.getColumn('label')) }}{% endif %} + {% if column=='label' %} + {% if not row.getIdSubDataTable() and row.getMetadata('url') and not row.getMetadata('logo') %} + <span class="icon-outlink"></span> + {% else %} + {{ piwik.logoHtml(row.getMetadata(), row.getColumn('label')) }} + {% endif %} + {% endif %} {% if row.getMetadata('html_label_prefix') %}<span class='label-prefix'>{{ row.getMetadata('html_label_prefix') | raw }} </span>{% endif -%} {% endif %}<span class="value"> {%- if row.getColumn(column) or (column=='label' and row.getColumn(column) is same as("0")) %}{% if column=='label' %}{{- row.getColumn(column)|rawSafeDecoded -}}{% else %}{% if row.getMetadata('html_column_' ~ column ~ '_prefix') %}<span class='column-prefix'>{{ row.getMetadata('html_column_' ~ column ~ '_prefix') | raw }}</span>{% endif -%}{{- row.getColumn(column)|number(2,0)|rawSafeDecoded -}}{% if row.getMetadata('html_column_' ~ column ~ '_suffix') %}<span class='column-suffix'>{{ row.getMetadata('html_column_' ~ column ~ '_suffix') | raw }}</span>{% endif -%}{% endif %} |