* Init dateType in metric getByID function.

This commit is contained in:
songchenxuan
2024-01-09 10:57:11 +08:00
parent 0c6a73f56e
commit b63b670d28
3 changed files with 20 additions and 5 deletions
+2 -2
View File
@@ -81,7 +81,7 @@ class metric extends control
list($groupHeader, $groupData) = $this->metric->getGroupTable($resultHeader, $resultData);
$this->view->groupHeader = $groupHeader;
$this->view->groupData = $groupData;
$this->view->dateType = $current ? $this->metric->getDateTypeByCode($current->code) : 'nodate';
$this->view->dateType = $current ? $current->dateType : 'nodate';
$this->view->dateLabels = $this->metric->getDateLabels($this->view->dateType);
$this->view->defaultDate = $this->metric->getDefaultDate($this->view->dateLabels);
$this->view->tableWidth = $this->metricZen->getViewTableWidth($groupHeader);
@@ -293,7 +293,7 @@ class metric extends control
list($groupHeader, $groupData) = $this->metric->getGroupTable($resultHeader, $resultData);
$this->view->groupHeader = $groupHeader;
$this->view->groupData = $groupData;
$this->view->dateType = $this->metric->getDateTypeByCode($metric->code);
$this->view->dateType = $metric->dateType;
$this->view->dateLabels = $this->metric->getDateLabels($this->view->dateType);
$this->view->defaultDate = $this->metric->getDefaultDate($this->view->dateLabels);
$this->view->tableWidth = $this->metricZen->getViewTableWidth($groupHeader);
+7
View File
@@ -454,6 +454,7 @@ class metricModel extends model
$metric->collectConf = $oldMetric->collectConf;
$metric->execTime = $oldMetric->execTime;
}
if(empty($metric->dateType)) $metric->dateType = $this->getDateTypeByCode($metric->code);
return $metric;
}
@@ -1962,8 +1963,14 @@ class metricModel extends model
public function getDateTypeByCode(string $code)
{
/* Get dateType form db first. */
$dateType = $this->getByCode($code, 'dateType');
if(!empty($dateType)) return $dateType;
/* Get dateType from config second. */
if(isset($this->config->metric->dateType[$code])) return $this->config->metric->dateType[$code];
/* At last, infer dateType by code. */
$dataFields = $this->getMetricRecordDateField($code);
return $this->getDateType($dataFields);
}
+11 -3
View File
@@ -190,7 +190,15 @@ class screenModel extends model
$type = $component->chartConfig->package;
$type = $this->getChartType($type);
$table = $this->config->objectTables[$type];
$chart = $this->dao->select('*')->from($table)->where('id')->eq($chartID)->fetch();
if($type == 'metric')
{
$chart = $this->loadModel('metric')->getByID($chartID);
}
else
{
$chart = $this->dao->select('*')->from($table)->where('id')->eq($chartID)->fetch();
}
if($type == 'metric') return $this->genMetricComponent($chart);
return $this->genComponentData($chart, $type, $component);
@@ -1770,7 +1778,7 @@ class screenModel extends model
$this->loadModel('metric');
$isObjectMetric = $this->metric->isObjectMetric($resultHeader);
$dateType = $this->metric->getDateTypeByCode($metric->code);
$dateType = $metric->dateType;
$filters = $this->processMetricFilter($filterParams, $dateType);
@@ -1861,7 +1869,7 @@ class screenModel extends model
$option = new stdclass();
$option->displayType = 'normal';
$option->cardType = 'A';
$option->dateType = $this->metric->getDateTypeByCode($metric->code);
$option->dateType = $metric->dateType;
$option->bgColor = '#26292EFF';
$option->border = array('color' => '#515458FF', 'width' => 1, 'radius' => 2);
$option->scope = $metric->scope;