diff --git a/module/datatable/model.php b/module/datatable/model.php
index 3b16d3eb63..965cd72f7d 100644
--- a/module/datatable/model.php
+++ b/module/datatable/model.php
@@ -14,6 +14,7 @@
class datatableModel extends model
{
/**
+ * 获取列表字段的基本配置信息。
* Get field list.
*
* @param string $module
@@ -21,7 +22,7 @@ class datatableModel extends model
* @access public
* @return array
*/
- public function getFieldList($module, $method = '')
+ public function getFieldList(string $module, string $method = ''): array
{
/* Load corresponding module. */
if(!isset($this->config->$module)) $this->loadModel($module);
@@ -74,15 +75,16 @@ class datatableModel extends model
}
/**
+ * 获取列表显示的字段信息。
* Get save setting field.
*
* @param string $module
* @param string $method
* @param bool $showAll
* @access public
- * @return object
+ * @return array
*/
- public function getSetting(string $module, string $method = '', bool $showAll = false)
+ public function getSetting(string $module, string $method = '', bool $showAll = false): array
{
if(!$method) $method = $this->app->getMethodName();
$datatableId = $module . ucfirst($method);
@@ -133,6 +135,7 @@ class datatableModel extends model
}
/**
+ * 获取期望的配置项。
* Format fields by config.
*
* @param string $module
@@ -141,9 +144,9 @@ class datatableModel extends model
* @access public
* @return array
*/
- public function formatFields($module, $fieldList, $onlyshow = true): array
+ public function formatFields(string $module, array $fieldList, bool $onlyshow = true): array
{
- $this->app->loadLang('module');
+ $this->app->loadLang($module);
$setting = array();
$order = 1;
@@ -170,106 +173,18 @@ class datatableModel extends model
}
/**
+ * 字段排序规则。
* Sort cols.
*
- * @param object $a
- * @param object $b
+ * @param array $a
+ * @param array $b
* @static
* @access public
* @return int
*/
- public static function sortCols($a, $b)
+ public static function sortCols(array $a, array $b): int
{
if(!isset($a['order']) or !isset($b['order'])) return 0;
return $a['order'] - $b['order'];
}
-
- /**
- * Print table head.
- *
- * @param object $col
- * @param string $orderBy
- * @param string $vars
- * @param bool $checkBox
- * @access public
- * @return void
- */
- public function printHead($col, $orderBy, $vars, $checkBox = true)
- {
- $id = $col->id;
- if($col->show)
- {
- $fixed = $col->fixed == 'no' ? 'true' : 'false';
- $width = is_numeric($col->width) ? "{$col->width}px" : $col->width;
- $title = isset($col->title) ? "title='$col->title'" : '';
- $title = (isset($col->name) and $col->name) ? "title='$col->name'" : $title;
- if($id == 'id' and (int)$width < 90) $width = '90px';
- $align = $id == 'actions' ? 'text-center' : '';
- $align = in_array($id, array('budget', 'teamCount', 'estimate', 'consume', 'consumed', 'left')) ? 'text-right' : $align;
-
- $style = '';
- $data = '';
- $data .= "data-width='$width'";
- $style .= "width:$width;";
- if(isset($col->minWidth))
- {
- $data .= "data-minWidth='{$col->minWidth}px'";
- $style .= "min-width:{$col->minWidth}px;";
- }
- if(isset($col->maxWidth))
- {
- $data .= "data-maxWidth='{$col->maxWidth}px'";
- $style .= "max-width:{$col->maxWidth}px;";
- }
- if(isset($col->pri)) $data .= "data-pri='{$col->pri}'";
-
- echo "
";
- if($id == 'actions')
- {
- echo $this->lang->actions;
- }
- elseif(isset($col->sort) and $col->sort == 'no')
- {
- echo $col->title;
- }
- else
- {
- if($id == 'id' && $checkBox) echo "";
- common::printOrderLink($id, $orderBy, $vars, $col->title);
- }
- echo ' | ';
- }
- }
-
- /**
- * Set fixed field width
- *
- * @param object $setting
- * @param int $minLeftWidth
- * @param int $minRightWidth
- * @access public
- * @return array
- */
- public function setFixedFieldWidth($setting, $minLeftWidth = '550', $minRightWidth = '140')
- {
- $widths['leftWidth'] = 30;
- $widths['rightWidth'] = 0;
- $hasLeftAuto = false;
- $hasRightAuto = false;
- foreach($setting as $key => $value)
- {
- if($value->fixed != 'no')
- {
- if($value->fixed == 'left' and $value->width == 'auto') $hasLeftAuto = true;
- if($value->fixed == 'right' and $value->width == 'auto') $hasRightAuto = true;
- $widthKey = $value->fixed . 'Width';
- if(!isset($widths[$widthKey])) $widths[$widthKey] = 0;
- $widths[$widthKey] += (int)trim($value->width, 'px');
- }
- }
- if($widths['leftWidth'] <= 550 and $hasLeftAuto) $widths['leftWidth'] = 550;
- if($widths['rightWidth'] <= 0 and $hasRightAuto) $widths['rightWidth'] = 140;
-
- return $widths;
- }
}
diff --git a/module/datatable/test/model/formatfields.php b/module/datatable/test/model/formatfields.php
new file mode 100755
index 0000000000..d7f7f1ccbc
--- /dev/null
+++ b/module/datatable/test/model/formatfields.php
@@ -0,0 +1,31 @@
+#!/usr/bin/env php
+loadModel('datatable');
+
+$fieldList = array('id' => array('show' => true), 'name' => array('show' => true), 'status' => array('show' => false), 'desc' => array('required' => true));
+
+r($tester->datatable->formatFields('product', $fieldList)) && p('id:order;id:title;name:order;name:title') && e('1,编号,2,产品名称'); //获取产品模块的目标配置
+r($tester->datatable->formatFields('project', $fieldList)) && p('id:order;id:title;name:order;name:title') && e('1,项目ID,2,项目名称'); //获取项目模块的目标配置的目标配置
diff --git a/module/datatable/test/model/getFieldList.php b/module/datatable/test/model/getFieldList.php
deleted file mode 100755
index 858b76cb3d..0000000000
--- a/module/datatable/test/model/getFieldList.php
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env php
-> ID
-获取项目模块browse方法自定义列 >> 项目名称
-获取执行模块task方法自定义列 >> 70
-获取测试用例模块browse方法自定义列 >> auto
-
-*/
-
-$datatable = new datatableTest();
-r($datatable->getFieldListTest('product', 'browse')) && p('id:title') && e('ID'); //获取产品模块browse方法自定义列
-r($datatable->getFieldListTest('project', 'browse')) && p('name:title') && e('项目名称'); //获取项目模块browse方法自定义列
-r($datatable->getFieldListTest('execution', 'task')) && p('id:width') && e('70'); //获取执行模块task方法自定义列
-r($datatable->getFieldListTest('testcase', 'browse')) && p('title:width') && e('auto'); //获取测试用例模块browse方法自定义列
\ No newline at end of file
diff --git a/module/datatable/test/model/getSetting.php b/module/datatable/test/model/getSetting.php
deleted file mode 100755
index 4b16b8f126..0000000000
--- a/module/datatable/test/model/getSetting.php
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env php
-> ID
-获取项目模块browse方法设置 >> 项目名称
-获取执行模块task方法设置 >> 70
-获取测试用例模块browse方法设置 >> auto
-
-*/
-
-$datatable = new datatableTest();
-r($datatable->getSettingTest('product', 'browse')) && p('0:title') && e('ID'); //获取产品模块browse方法设置
-r($datatable->getSettingTest('project', 'browse')) && p('1:title') && e('项目名称'); //获取项目模块browse方法设置
-r($datatable->getSettingTest('execution', 'task')) && p('0:width') && e('70'); //获取执行模块task方法设置
-r($datatable->getSettingTest('testcase', 'browse')) && p('2:width') && e('auto'); //获取测试用例模块browse方法设置
\ No newline at end of file
diff --git a/module/datatable/test/model/getfieldlist.php b/module/datatable/test/model/getfieldlist.php
new file mode 100755
index 0000000000..efa24431ea
--- /dev/null
+++ b/module/datatable/test/model/getfieldlist.php
@@ -0,0 +1,42 @@
+#!/usr/bin/env php
+gen(1);
+
+/**
+
+title=测试 datatableModel::getFieldList();
+timeout=0
+cid=1
+
+- 获取产品模块browse方法自定义列
+ - 第id条的title属性 @ID
+ - 第id条的width属性 @80
+ - 第title条的title属性 @研发需求名称
+ - 第title条的width属性 @0.44
+- 获取项目模块browse方法自定义列
+ - 第id条的title属性 @ID
+ - 第id条的width属性 @80
+ - 第name条的title属性 @项目名称
+ - 第name条的width属性 @0.44
+- 获取执行模块task方法自定义列
+ - 第id条的title属性 @ID
+ - 第id条的width属性 @80
+ - 第name条的title属性 @任务名称
+ - 第name条的width属性 @0.5
+- 获取测试用例模块browse方法自定义列
+ - 第id条的title属性 @ID
+ - 第id条的width属性 @80
+ - 第title条的title属性 @用例名称
+ - 第title条的width属性 @0.44
+
+*/
+
+$datatable = new datatableTest();
+r($datatable->getFieldListTest('product', 'browse')) && p('id:title;id:width;title:title;title:width') && e('ID,80,研发需求名称,0.44'); //获取产品模块browse方法自定义列
+r($datatable->getFieldListTest('project', 'browse')) && p('id:title;id:width;name:title;name:width') && e('ID,80,项目名称,0.44'); //获取项目模块browse方法自定义列
+r($datatable->getFieldListTest('execution', 'task')) && p('id:title;id:width;name:title;name:width') && e('ID,80,任务名称,0.5'); //获取执行模块task方法自定义列
+r($datatable->getFieldListTest('testcase', 'browse')) && p('id:title;id:width;title:title;title:width') && e('ID,80,用例名称,0.44'); //获取测试用例模块browse方法自定义列
diff --git a/module/datatable/test/model/getsetting.php b/module/datatable/test/model/getsetting.php
new file mode 100755
index 0000000000..766c45c0c3
--- /dev/null
+++ b/module/datatable/test/model/getsetting.php
@@ -0,0 +1,40 @@
+#!/usr/bin/env php
+getSettingTest('product', 'browse')) && p('id:title;id:width;title:title;title:width') && e('ID,80,研发需求名称,0.44'); //获取产品模块browse方法自定义列
+r($datatable->getSettingTest('project', 'browse')) && p('id:title;id:width;name:title;name:width') && e('ID,80,项目名称,0.44'); //获取项目模块browse方法自定义列
+r($datatable->getSettingTest('execution', 'task')) && p('id:title;id:width;name:title;name:width') && e('ID,80,任务名称,0.5'); //获取执行模块task方法自定义列
+r($datatable->getSettingTest('testcase', 'browse')) && p('id:title;id:width;title:title;title:width') && e('ID,80,用例名称,0.44'); //获取测试用例模块browse方法自定义列
diff --git a/module/datatable/test/model/printHead.php b/module/datatable/test/model/printHead.php
deleted file mode 100755
index 6708e8e6b2..0000000000
--- a/module/datatable/test/model/printHead.php
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/env php
-> 1
-获取产品模块browse方法头部html带排序 >> 1
-获取产品模块browse方法头部html带参数 >> 1
-获取产品模块browse方法头部html带checkbox >> 1
-
-*/
-
-$datatable = new datatableTest();
-$productSetting = $datatable->getSettingTest('product', 'browse');
-
-$data = array('cols' => $productSetting[0], 'orderBy' => '', 'vars' => '', 'checkBox' => false);
-$data_order = array('cols' => $productSetting[0], 'orderBy' => 'id_asc', 'vars' => '', 'checkBox' => false);
-$data_vars = array('cols' => $productSetting[0], 'orderBy' => 'id_asc', 'vars' => 'productID=1', 'checkBox' => false);
-$data_check = array('cols' => $productSetting[0], 'orderBy' => 'id_asc', 'vars' => 'productID=1', 'checkBox' => true);
-
-r($datatable->printHeadTest($data)) && p() && e(1); //获取产品模块browse方法头部html
-r($datatable->printHeadTest($data_order)) && p() && e(1); //获取产品模块browse方法头部html带排序
-r($datatable->printHeadTest($data_vars)) && p() && e(1); //获取产品模块browse方法头部html带参数
-r($datatable->printHeadTest($data_check)) && p() && e(1); //获取产品模块browse方法头部html带checkbox
diff --git a/module/datatable/test/model/setFixedFieldWidth.php b/module/datatable/test/model/setFixedFieldWidth.php
deleted file mode 100755
index f6c7a6dcc9..0000000000
--- a/module/datatable/test/model/setFixedFieldWidth.php
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env php
-> 550
-获取项目模块browse方法设置宽度 >> 180
-获取执行模块browse方法设置宽度 >> 550
-获取测试用例模块browse方法设置宽度 >> 150
-
-*/
-
-$datatable = new datatableTest();
-$productSetting = $datatable->getSettingTest('product', 'browse');
-$projectSetting = $datatable->getSettingTest('project', 'browse');
-$executionSetting = $datatable->getSettingTest('execution', 'task');
-$testcaseSetting = $datatable->getSettingTest('testcase', 'browse');
-
-r($datatable->setFixedFieldWidthTest($productSetting)) && p('leftWidth') && e('550'); //获取产品模块browse方法设置宽度
-r($datatable->setFixedFieldWidthTest($projectSetting)) && p('rightWidth') && e('180'); //获取项目模块browse方法设置宽度
-r($datatable->setFixedFieldWidthTest($executionSetting)) && p('leftWidth') && e('550'); //获取执行模块browse方法设置宽度
-r($datatable->setFixedFieldWidthTest($testcaseSetting)) && p('rightWidth') && e('150'); //获取测试用例模块browse方法设置宽度
\ No newline at end of file
diff --git a/module/datatable/test/model/sortcols.php b/module/datatable/test/model/sortcols.php
new file mode 100755
index 0000000000..7a1fb65413
--- /dev/null
+++ b/module/datatable/test/model/sortcols.php
@@ -0,0 +1,29 @@
+#!/usr/bin/env php
+loadModel('datatable');
+
+$array1 = array('order' => 1);
+$array2 = array('order' => 2);
+$array3 = array();
+
+r($tester->datatable->sortcols($array1, $array2)) && p() && e('-1'); //获取1和2的排序结果
+r($tester->datatable->sortcols($array2, $array1)) && p() && e('1'); //获取2和1的排序结果
+r($tester->datatable->sortcols($array1, $array1)) && p() && e('0'); //获取1和1的排序结果
+r($tester->datatable->sortcols($array3, $array3)) && p() && e('0'); //获取非正确数组的排序结果