From d81da2876b89c5087fe645255d464f1b4c8ba8bf Mon Sep 17 00:00:00 2001 From: wangyidong Date: Wed, 13 May 2020 17:22:01 +0800 Subject: [PATCH] * finish task #7180. --- module/caselib/control.php | 37 ++-- module/caselib/view/showimport.html.php | 216 +++++++++++------------ module/file/lang/zh-cn.php | 1 + module/file/model.php | 6 +- module/testcase/control.php | 35 ++-- module/testcase/view/showimport.html.php | 21 ++- 6 files changed, 174 insertions(+), 142 deletions(-) diff --git a/module/caselib/control.php b/module/caselib/control.php index a4fd5b7884..04d6ecbb28 100644 --- a/module/caselib/control.php +++ b/module/caselib/control.php @@ -557,29 +557,31 @@ class caselib extends control /** * Show import case. * - * @param int $libID + * @param int $libID + * @param int $pagerID + * @param int $maxImport * @access public * @return void */ - public function showImport($libID, $pagerID = 1) + public function showImport($libID, $pagerID = 1, $maxImport = 0) { $this->loadModel('testcase'); - $file = $this->session->importFile; - $cachePath = $this->loadModel('file')->getShowImportPath(); - $cacheFile = $cachePath . DS . md5(basename($file)); - $maxImport = $this->config->file->maxImport; + $file = $this->session->importFile; + $tmpPath = $this->loadModel('file')->getImportTmp(); + $tmpFile = $tmpPath . DS . md5(basename($file)); + if($_POST) { $this->caselib->createFromImport($libID); if($this->post->isEndPage) { - unlink($cacheFile); + unlink($tmpFile); die(js::locate(inlink('browse', "libID=$libID"), 'parent')); } else { - die(js::locate(inlink('showImport', "libID=$libID&pagerID=" . $this->post->pagerID + 1), 'parent')); + die(js::locate(inlink('showImport', "libID=$libID&pagerID=" . ($this->post->pagerID + 1) . "&maxImport=$maxImport"), 'parent')); } } @@ -602,9 +604,9 @@ class caselib extends control $fields = array_flip($fields); - if($pagerID != 1 and file_exists($cacheFile)) + if(!empty($maxImport) and file_exists($tmpFile)) { - $data = unserialize(file_get_contents($cacheFile)); + $data = unserialize(file_get_contents($tmpFile)); $caseData = $data['caseData']; $stepData = $data['stepData']; } @@ -737,7 +739,7 @@ class caselib extends control $data['caseData'] = $caseData; $data['stepData'] = $stepData; - file_put_contents($cacheFile, serialize($data)); + file_put_contents($tmpFile, serialize($data)); } if(empty($caseData)) @@ -749,12 +751,20 @@ class caselib extends control } $allCount = count($caseData); + if(empty($maxImport) and $allCount > $this->config->file->maxImport) + { + $this->view->allCount = $allCount; + $this->view->maxImport = $maxImport; + $this->view->libID = $libID; + die($this->display()); + } + $allPager = ceil($allCount / $maxImport); $caseData = array_slice($caseData, ($pagerID - 1) * $maxImport, $maxImport, true); - if(empty($caseData)) die(js::locate(inlink('browse', "productID=$productID&branch=$branch"))); + if(empty($caseData)) die(js::locate(inlink('browse', "libID=$libID"))); /* Judge whether the editedTasks is too large and set session. */ - $countInputVars = count($caseData) * 9 + $stepVars; + $countInputVars = count($caseData) * 9 + (isset($stepVars) ? $stepVars : 0); $showSuhosinInfo = common::judgeSuhosinSetting($countInputVars); if($showSuhosinInfo) $this->view->suhosinInfo = extension_loaded('suhosin') ? sprintf($this->lang->suhosinInfo, $countInputVars) : sprintf($this->lang->maxVarsInfo, $countInputVars); @@ -770,6 +780,7 @@ class caselib extends control $this->view->allCount = $allCount; $this->view->allPager = ceil($allCount / $maxImport); $this->view->pagerID = $pagerID; + $this->view->maxImport = $maxImport; $this->display(); } } diff --git a/module/caselib/view/showimport.html.php b/module/caselib/view/showimport.html.php index 556b57a78d..1f0eb5addc 100644 --- a/module/caselib/view/showimport.html.php +++ b/module/caselib/view/showimport.html.php @@ -1,136 +1,130 @@ -
- +

caselib->import;?>

+

file->importSummary, $allCount, html::input('maxImport', $config->file->maxImport, "style='width:50px'"), ceil($allCount / $config->file->maxImport));?>

+

import, "id='import'", 'btn btn-primary');?>

+
+ + +
+
+

caselib->import;?>

+
- - - - - - - - - - - - - - - - - $case):?> - title)) continue;?> - id) and !isset($cases[$case->id])) $case->id = 0;?> - - - - - - - - - - - - - - - - + + + + +
testcase->id?>testcase->title?>testcase->module?>testcase->pri?>testcase->type?>testcase->stage?>testcase->keywords?>testcase->precondition?> - - - - - -
testcase->stepDesc?>testcase->stepExpect?>
-
- id)) - { - echo $case->id . html::hidden("id[$key]", $case->id); - $insert = false; - } - else - { - echo $key . " {$lang->testcase->new}"; - } - echo html::hidden("lib[$key]", $libID); - ?> - title, "class='form-control' style='margin-top:2px'")?>module) ? $case->module : (!empty($case->id) ? $cases[$case->id]->module : ''), "class='form-control chosen'")?>testcase->priList, isset($case->pri) ? $case->pri : (!empty($case->id) ? $cases[$case->id]->pri : ''), "class='form-control chosen'")?>testcase->typeList, isset($case->type) ? $case->type : (!empty($case->id) ? $cases[$case->id]->type : ''), "class='form-control chosen'")?>testcase->stageList, !empty($case->stage) ? $case->stage : (!empty($case->id) ? $cases[$case->id]->stage : ''), "multiple='multiple' class='form-control chosen'")?>keywords) ? $case->keywords : "", "class='form-control'")?>precondition) ? htmlspecialchars($case->precondition) : "", "class='form-control'")?> - - - $desc):?> - - - - - - - -
- -
+ + + + + + + + + + + + + + + + + $case):?> + title)) continue;?> + id) and !isset($cases[$case->id])) $case->id = 0;?> + + + + + + + + + + - -
testcase->id?>testcase->title?>testcase->module?>testcase->pri?>testcase->type?>testcase->stage?>testcase->keywords?>testcase->precondition?> + + + + + +
testcase->stepDesc?>testcase->stepExpect?>
+
id)) { - echo ""; + echo $case->id . html::hidden("id[$key]", $case->id); + $insert = false; } else { - echo html::submitButton($isEndPage ? $this->lang->save : $this->lang->file->saveAndNext); - echo html::hidden('isEndPage', $isEndPage ? 1 : 0); - echo html::hidden('pagerID', $pagerID); + echo $key . " {$lang->testcase->new}"; } - echo '   ' . html::backButton(); - echo '   ' . sprintf($lang->file->importPager, $allCount, $pagerID, $allPager); + echo html::hidden("lib[$key]", $libID); ?> title, "class='form-control' style='margin-top:2px'")?>module) ? $case->module : (!empty($case->id) ? $cases[$case->id]->module : ''), "class='form-control chosen'")?>testcase->priList, isset($case->pri) ? $case->pri : (!empty($case->id) ? $cases[$case->id]->pri : ''), "class='form-control chosen'")?>testcase->typeList, isset($case->type) ? $case->type : (!empty($case->id) ? $cases[$case->id]->type : ''), "class='form-control chosen'")?>testcase->stageList, !empty($case->stage) ? $case->stage : (!empty($case->id) ? $cases[$case->id]->stage : ''), "multiple='multiple' class='form-control chosen'")?>keywords) ? $case->keywords : "", "class='form-control'")?>precondition) ? htmlspecialchars($case->precondition) : "", "class='form-control'")?> + + + $desc):?> + + + + + + + +
+ +
- + + +
+ {$lang->save}"; + } + else + { + echo html::submitButton($isEndPage ? $this->lang->save : $this->lang->file->saveAndNext); + echo html::hidden('isEndPage', $isEndPage ? 1 : 0); + echo html::hidden('pagerID', $pagerID); + } + echo '   ' . html::backButton(); + echo '   ' . sprintf($lang->file->importPager, $allCount, $pagerID, $allPager); + ?> +
+
- + diff --git a/module/file/lang/zh-cn.php b/module/file/lang/zh-cn.php index 19e3082480..6cc82004a8 100644 --- a/module/file/lang/zh-cn.php +++ b/module/file/lang/zh-cn.php @@ -49,6 +49,7 @@ $lang->file->childTaskTips = "任务名称前有'>'标记的为子任务"; $lang->file->uploadImagesExplain = '注:请上传"jpg, jpeg, gif, png"格式的图片,程序会以文件名作为标题,以图片作为内容。'; $lang->file->saveAndNext = '保存并跳转下一页'; $lang->file->importPager = '共有%s条记录,当前第%s页,共有%s页'; +$lang->file->importSummary = "本次导入共有%s条记录,每页导入%s条,需要导入%s次"; $lang->file->errorNotExists = "文件夹 '%s' 不存在"; $lang->file->errorCanNotWrite = "文件夹 '%s' 不可写,请改变文件夹的权限。在linux中输入指令: sudo chmod -R 777 %s"; diff --git a/module/file/model.php b/module/file/model.php index b701d16eb8..676508d3cf 100644 --- a/module/file/model.php +++ b/module/file/model.php @@ -349,14 +349,14 @@ class fileModel extends model } /** - * Get showImport path. + * Get tmp import path. * * @access public * @return string */ - public function getShowImportPath() + public function getImportTmp() { - $path = $this->app->getCacheRoot() . 'showimport'; + $path = $this->app->getTmpRoot() . 'import'; if(!is_dir($path)) mkdir($path, 0755, true); return $path; diff --git a/module/testcase/control.php b/module/testcase/control.php index e7c0bb5379..6cdda645e2 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1397,8 +1397,8 @@ class testcase extends control if(count($columnKey) <= 3 or $this->post->encode != 'utf-8') { - $fc = file_get_contents($fileName); $encode = $this->post->encode != "utf-8" ? $this->post->encode : 'gbk'; + $fc = file_get_contents($fileName); $fc = helper::convertEncoding($fc, $encode, 'utf-8'); file_put_contents($fileName, $fc); @@ -1500,29 +1500,30 @@ class testcase extends control /** * Show import data * - * @param int $productID + * @param int $productID * @param int $branch * @param int $pagerID + * @param int $maxImport * @access public * @return void */ - public function showImport($productID, $branch = 0, $pagerID = 1) + public function showImport($productID, $branch = 0, $pagerID = 1, $maxImport = 0) { - $file = $this->session->importFile; - $cachePath = $this->loadModel('file')->getShowImportPath(); - $cacheFile = $cachePath . DS . md5(basename($file)); - $maxImport = $this->config->file->maxImport; + $file = $this->session->importFile; + $tmpPath = $this->loadModel('file')->getImportTmp(); + $tmpFile = $tmpPath . DS . md5(basename($file)); + if($_POST) { $this->testcase->createFromImport($productID, (int)$branch); if($this->post->isEndPage) { - unlink($cacheFile); + unlink($tmpFile); die(js::locate(inlink('browse', "productID=$productID"), 'parent')); } else { - die(js::locate(inlink('showImport', "productID=$productID&branch=$branch&pagerID=" . ($this->post->pagerID + 1)), 'parent')); + die(js::locate(inlink('showImport', "productID=$productID&branch=$branch&pagerID=" . ($this->post->pagerID + 1) . "&maxImport=$maxImport"), 'parent')); } } @@ -1535,9 +1536,9 @@ class testcase extends control $fields = $this->testcase->getImportFields($productID); $fields = array_flip($fields); - if($pagerID != 1 and file_exists($cacheFile)) + if(!empty($maxImport) and file_exists($tmpFile)) { - $data = unserialize(file_get_contents($cacheFile)); + $data = unserialize(file_get_contents($tmpFile)); $caseData = $data['caseData']; $stepData = $data['stepData']; } @@ -1670,7 +1671,7 @@ class testcase extends control $data['caseData'] = $caseData; $data['stepData'] = $stepData; - file_put_contents($cacheFile, serialize($data)); + file_put_contents($tmpFile, serialize($data)); } if(empty($caseData)) @@ -1680,6 +1681,15 @@ class testcase extends control } $allCount = count($caseData); + if(empty($maxImport) and $allCount > $this->config->file->maxImport) + { + $this->view->allCount = $allCount; + $this->view->maxImport = $maxImport; + $this->view->productID = $productID; + $this->view->branch = $branch; + die($this->display()); + } + $allPager = ceil($allCount / $maxImport); $caseData = array_slice($caseData, ($pagerID - 1) * $maxImport, $maxImport, true); if(empty($caseData)) die(js::locate(inlink('browse', "productID=$productID&branch=$branch"))); @@ -1705,6 +1715,7 @@ class testcase extends control $this->view->pagerID = $pagerID; $this->view->branch = $branch; $this->view->product = $this->products[$productID]; + $this->view->maxImport = $maxImport; $this->display(); } diff --git a/module/testcase/view/showimport.html.php b/module/testcase/view/showimport.html.php index ad8842d514..a0cf5a4333 100644 --- a/module/testcase/view/showimport.html.php +++ b/module/testcase/view/showimport.html.php @@ -1,11 +1,26 @@ -
+ +
+
+

testcase->import;?>

+
+

file->importSummary, $allCount, html::input('maxImport', $config->file->maxImport, "style='width:50px'"), ceil($allCount / $config->file->maxImport));?>

+

import, "id='import'", 'btn btn-primary');?>

+
+