From 27851983470b73d0722b32f1cb24c68e3c2d3b99 Mon Sep 17 00:00:00 2001 From: sunguangming Date: Tue, 13 Jun 2023 10:20:50 +0800 Subject: [PATCH] * Code for dtable actions, transfer setting to array. --- framework/helper.class.php | 17 +++++++- module/datatable/control.php | 6 ++- module/datatable/model.php | 66 +++++++++++++++---------------- module/execution/ui/task.html.php | 5 ++- 4 files changed, 55 insertions(+), 39 deletions(-) diff --git a/framework/helper.class.php b/framework/helper.class.php index cb4023edfe..29b64b4c11 100644 --- a/framework/helper.class.php +++ b/framework/helper.class.php @@ -457,7 +457,22 @@ function formatTime(string|null $time, string $format = ''): string */ function initTableData($items, &$fieldList, $checkModel) { - if(empty($fieldList['actions'])) return $items; + /* Find actions in index array. */ + if(empty($fieldList['actions'])) + { + $types = array_column($fieldList, 'type'); + $index = array_search('actions', $types); + + if($index) + { + $fieldList['actions'] = $fieldList[$index]; + unset($fieldList[$index]); + } + else + { + return $items; + } + } foreach($fieldList['actions']['menu'] as $actionMenu) { diff --git a/module/datatable/control.php b/module/datatable/control.php index 08cd4979d1..38ffc8c723 100644 --- a/module/datatable/control.php +++ b/module/datatable/control.php @@ -79,7 +79,8 @@ class datatable extends control $account = $this->app->user->account; if($account == 'guest') return $this->send(array('result' => 'fail', 'message' => 'guest.')); - $fieldList = $this->datatable->getFieldList($module); + $rawModule = zget($this->config->datatable->moduleAlias, "$module-$method", $module); + $fieldList = $this->datatable->getFieldList($rawModule); $fields = json_decode($this->post->fields); foreach($fields as $index => $field) { @@ -115,6 +116,8 @@ class datatable extends control $moduleName = $module; $target = $module . ucfirst($method); + $this->view->module = $module; + if($module == 'testtask') { $this->loadModel('testcase'); @@ -182,7 +185,6 @@ class datatable extends control } if($extra == 'unsetStory' and isset($cols['story'])) unset($cols['story']); - $this->view->module = $module; $this->view->method = $method; $this->view->cols = $cols; $this->display(); diff --git a/module/datatable/model.php b/module/datatable/model.php index 4b33d00994..52d32d472d 100644 --- a/module/datatable/model.php +++ b/module/datatable/model.php @@ -82,7 +82,7 @@ class datatableModel extends model $module = zget($this->config->datatable->moduleAlias, "$module-$method", $module); if(!isset($this->config->$module)) $this->loadModel($module); - if(isset($this->config->datatable->$datatableId->cols)) $setting = json_decode($this->config->datatable->$datatableId->cols); + if(isset($this->config->datatable->$datatableId->cols)) $setting = json_decode($this->config->datatable->$datatableId->cols, true); $fieldList = $this->getFieldList($module); if(empty($setting)) @@ -92,28 +92,28 @@ class datatableModel extends model { if(empty($value['required']) and empty($value['show'])) continue; - $set = new stdclass(); - $set->order = $order++; - $set->id = $key; - $set->show = true; - $set->width = $value['width']; - $set->type = $value['type']; - $set->fixed = isset($value['fixed']) ? $value['fixed'] : ''; - $set->title = isset($value['title']) ? $value['title'] : $this->lang->$module->{$key}; - $set->name = isset($value['name']) ? $value['name'] : $key; - $set->sortType = isset($value['sortType']) ? $value['sortType'] : false; - $set->group = isset($value['group']) ? $value['group'] : ''; - $set->link = isset($value['link']) ? $value['link'] : ''; + $set = array(); + $set['order'] = $order++; + $set['id'] = $key; + $set['show'] = true; + $set['width'] = $value['width']; + $set['type'] = $value['type']; + $set['fixed'] = isset($value['fixed']) ? $value['fixed'] : ''; + $set['title'] = isset($value['title']) ? $value['title'] : $this->lang->$module->{$key}; + $set['name'] = isset($value['name']) ? $value['name'] : $key; + $set['sortType'] = isset($value['sortType']) ? $value['sortType'] : false; + $set['group'] = isset($value['group']) ? $value['group'] : ''; + $set['link'] = isset($value['link']) ? $value['link'] : ''; - if(isset($value['minWidth'])) $set->minWidth = $value['minWidth']; - if(isset($value['maxWidth'])) $set->maxWidth = $value['maxWidth']; - if(isset($value['pri'])) $set->pri = $value['pri']; - if(isset($value['statusMap'])) $set->statusMap = $value['statusMap']; - if(isset($value['actionsMap'])) $set->actionsMap = $value['actionsMap']; - if(isset($value['checkbox'])) $set->checkbox = $value['checkbox']; - if(isset($value['map'])) $set->map = $value['map']; - if(isset($value['flex'])) $set->flex = $value['flex']; - if(isset($value['nestedToggle'])) $set->nestedToggle = $value['nestedToggle']; + if(isset($value['minWidth'])) $set['minWidth'] = $value['minWidth']; + if(isset($value['maxWidth'])) $set['maxWidth'] = $value['maxWidth']; + if(isset($value['pri'])) $set['pri'] = $value['pri']; + if(isset($value['statusMap'])) $set['statusMap'] = $value['statusMap']; + if(isset($value['actionsMap'])) $set['actionsMap'] = $value['actionsMap']; + if(isset($value['checkbox'])) $set['checkbox'] = $value['checkbox']; + if(isset($value['map'])) $set['map'] = $value['map']; + if(isset($value['flex'])) $set['flex'] = $value['flex']; + if(isset($value['nestedToggle'])) $set['nestedToggle'] = $value['nestedToggle']; $setting[$key] = $set; } @@ -122,18 +122,19 @@ class datatableModel extends model { foreach($setting as $key => $set) { - if(empty($set->show)) - { - unset($setting[$key]); - continue; - } - if($this->session->currentProductType === 'normal' and $set->id === 'branch') + if(empty($set['show'])) { unset($setting[$key]); continue; } - if($set->name == 'actions') $set->width = $fieldList[$set->name]['width']; + if($this->session->currentProductType === 'normal' and $set['id'] === 'branch') + { + unset($setting[$key]); + continue; + } + + if($set['name'] == 'actions') $set['width'] = $fieldList['actions']['width']; } } @@ -153,11 +154,8 @@ class datatableModel extends model */ public static function sortCols($a, $b) { - $a = (object)$a; - $b = (object)$b; - - if(!isset($a->order)) return 0; - return $a->order - $b->order; + if(!isset($a['order']) or !isset($b['order'])) return 0; + return $a['order'] - $b['order']; } /** diff --git a/module/execution/ui/task.html.php b/module/execution/ui/task.html.php index f4c00f1db6..7040a0caeb 100644 --- a/module/execution/ui/task.html.php +++ b/module/execution/ui/task.html.php @@ -48,7 +48,8 @@ if(common::canModify('execution', $execution)) } } -$tableData = initTableData($tasks, $config->task->dtable->fieldList, $this->task); +$cols = $this->loadModel('datatable')->getSetting('execution'); +$tableData = initTableData($tasks, $cols, $this->task); toolbar ( @@ -186,7 +187,7 @@ jsVar('checkedSummary', $lang->execution->checkedSummary); dtable ( set::userMap($memberPairs), - set::cols(array_values($config->task->dtable->fieldList)), + set::cols($cols), set::data($tableData), set::checkable($canBatchAction), set::sortLink(jsRaw('createSortLink')),