From 0829a7b31536aaeaba5c17aa158f581c3eb16f59 Mon Sep 17 00:00:00 2001 From: qixinzhi Date: Tue, 26 Sep 2023 08:01:44 +0000 Subject: [PATCH] * Fix dynamic table cell width,bug#38980. --- ...count_of_daily_resolved_bug_in_product.php | 2 +- module/metric/css/preview.ui.css | 4 +- module/metric/js/preview.ui.js | 50 +++++++++---------- module/metric/zen.php | 10 ++-- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/module/metric/calc/product/scale/count_of_daily_resolved_bug_in_product.php b/module/metric/calc/product/scale/count_of_daily_resolved_bug_in_product.php index 400667dce0..384faf2139 100644 --- a/module/metric/calc/product/scale/count_of_daily_resolved_bug_in_product.php +++ b/module/metric/calc/product/scale/count_of_daily_resolved_bug_in_product.php @@ -30,7 +30,7 @@ class count_of_daily_resolved_bug_in_product extends baseCalc public function calculate($row) { - if($row->status != 'resolved' || empty($row->resolvedDate)) return false; + if($row->status == 'active' || empty($row->resolvedDate)) return false; $date = substr($row->resolvedDate, 0, 10); list($year, $month, $day) = explode('-', $date); diff --git a/module/metric/css/preview.ui.css b/module/metric/css/preview.ui.css index 52d6fbdf56..a176dd316d 100644 --- a/module/metric/css/preview.ui.css +++ b/module/metric/css/preview.ui.css @@ -43,8 +43,8 @@ .chart-multiple {height: 290px; width: 100%;} .chart-type {width: 30%; padding-left: 50px;} -.table-and-chart .table-side {flex: 0 0 400px; overflow-x: hidden;} -.table-and-chart .chart-side {flex: 0 0 calc(100% - 400px);} +.table-and-chart .table-side {flex: 0 0 480px; overflow-x: hidden;} +.table-and-chart .chart-side {flex: 0 0 calc(100% - 480px);} .table-and-chart .chart-center {display:flex; justify-content: center; align-items: center;} .icon-18 {font-size: 18px;} diff --git a/module/metric/js/preview.ui.js b/module/metric/js/preview.ui.js index d65825a760..72167d5a73 100644 --- a/module/metric/js/preview.ui.js +++ b/module/metric/js/preview.ui.js @@ -394,10 +394,32 @@ window.renderChart = function(metricID = current.id, header = resultHeader, data window.initDTable = function($obj, head, data) { var height = 310; + var width = 480; if(viewType == 'single') height = $('.table-side').height(); if(!head || !data) return; - var commonWidth = 140; + var commonWidth = { + scope: 160, + date: 96, + value: 96, + calcTime: 128, + }; + + var cols = head.map(function(col){ return col.name; }); + + var cellWidth = {}; + cols.forEach(function(col) { + if(commonWidth[col]) { + cellWidth[col] = commonWidth[col]; + } + }); + + colsWidth = Object.values(cellWidth).reduce((a, b) => a + b, 0); + Object.keys(cellWidth).forEach(function(col) { + cellWidth[col] = Math.floor(cellWidth[col] / colsWidth * width); + }); + + console.log(cellWidth); new zui.DTable($obj,{ responsive: true, @@ -410,30 +432,8 @@ window.initDTable = function($obj, head, data) // footer: ['pager'], onRenderCell: function(result, {row, col}) { - var colCount = Object.keys(row.data).length; - if(colCount == 3) commonWidth = 86; - if(colCount == 4) commonWidth = 64; - - if(col.name != 'calcTime') - { - var html = `${row.data[col.name]}`; - result[0] = {html: html}; - } - - if(colCount == 4) - { - if(col.name == 'date') - { - var html = `${row.data[col.name]}`; - result[0] = {html: html}; - } - - if(col.name == 'value') - { - var html = `${row.data[col.name]}`; - result[0] = {html: html}; - } - } + var html = `${row.data[col.name]}`; + result[0] = {html: html}; return result; } diff --git a/module/metric/zen.php b/module/metric/zen.php index 5c753b12f6..73d683db43 100644 --- a/module/metric/zen.php +++ b/module/metric/zen.php @@ -359,10 +359,10 @@ class metricZen extends metric $scope = current($scopeList); $header = array(); - if(!empty($scopeList)) $header[] = array('name' => 'scope', 'title' => $this->lang->metric->scopeList[$scope] . $this->lang->metric->name); - if(!empty($dateList)) $header[] = array('name' => 'date', 'title' => $this->lang->metric->date); - $header[] = array('name' => 'value', 'title' => $this->lang->metric->value); - if(in_array('date', $fieldList)) $header[] = array('name' => 'calcTime', 'title' => $this->lang->metric->calcTime, 'width' => 150); + if(!empty($scopeList)) $header[] = array('name' => 'scope', 'title' => $this->lang->metric->scopeList[$scope] . $this->lang->metric->name, 'width' => 160); + if(!empty($dateList)) $header[] = array('name' => 'date', 'title' => $this->lang->metric->date, 'width' => 96); + $header[] = array('name' => 'value', 'title' => $this->lang->metric->value, 'width' => 96); + if(in_array('date', $fieldList)) $header[] = array('name' => 'calcTime', 'title' => $this->lang->metric->calcTime, 'width' => 128); return $header; } @@ -398,7 +398,7 @@ class metricZen extends metric $row->scopeID = $record[$scope]; } $row->value = is_numeric($record['value']) ? round((float)$record['value'], 2) : $record['value']; - if(isset($record['date'])) $row->calcTime = $record['date']; + if(isset($record['date'])) $row->calcTime = date("Y-m-d H:m", strtotime($record['date'])); $tableData[] = $row; }