* finish task #7180.

This commit is contained in:
wangyidong
2020-05-13 17:22:01 +08:00
parent 82945a1be1
commit d81da2876b
6 changed files with 174 additions and 142 deletions
+24 -13
View File
@@ -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();
}
}
+105 -111
View File
@@ -1,136 +1,130 @@
<?php include '../../common/view/header.html.php';?>
<style>
.affix {position:fixed; top:0px; width:95.6%;z-index:10000;}
</style>
<?php if(isset($suhosinInfo)):?>
<div class='alert alert-info'><?php echo $suhosinInfo?></div>
<?php else:?>
<?php elseif(empty($maxImport)):?>
<div id="mainContent" class="main-content">
<div class="main-header">
<h2><?php echo $lang->caselib->import;?></h2>
</div>
<p><?php echo sprintf($lang->file->importSummary, $allCount, html::input('maxImport', $config->file->maxImport, "style='width:50px'"), ceil($allCount / $config->file->maxImport));?></p>
<p><?php echo html::commonButton($lang->import, "id='import'", 'btn btn-primary');?></p>
</div>
<script>
$(function()
{
$('#maxImport').keyup(function()
{
if(parseInt($('#maxImport').val())) $('#times').html(Math.ceil(parseInt($('#allCount').html()) / parseInt($('#maxImport').val())));
});
$('#import').click(function(){location.href = createLink('caselib', 'showImport', "libID=<?php echo $libID;?>&pageID=1&maxImport=" + $('#maxImport').val())})
});
</script>
<?php else:?>
<div id="mainContent" class="main-content">
<div class="main-header clearfix">
<h2><?php echo $lang->caselib->import;?></h2>
</div>
<form target='hiddenwin' method='post'>
<table class='table active-disabled table-form table-striped'>
<thead>
<tr>
<th class='w-70px'><?php echo $lang->testcase->id?></th>
<th><?php echo $lang->testcase->title?></th>
<th class='w-150px'><?php echo $lang->testcase->module?></th>
<th class='w-80px'><?php echo $lang->testcase->pri?></th>
<th class='w-130px'><?php echo $lang->testcase->type?></th>
<th><?php echo $lang->testcase->stage?></th>
<th class='w-80px'><?php echo $lang->testcase->keywords?></th>
<th><?php echo $lang->testcase->precondition?></th>
<th class='w-300px col-content'>
<table class='w-p100 table-borderless'>
<tr>
<th><?php echo $lang->testcase->stepDesc?></th>
<th><?php echo $lang->testcase->stepExpect?></th>
</tr>
</table>
</th>
</tr>
</thead>
<tbody>
<?php
$insert = true;
$hideContentCol = true;
?>
<?php foreach($caseData as $key => $case):?>
<?php if(empty($case->title)) continue;?>
<?php if(!empty($case->id) and !isset($cases[$case->id])) $case->id = 0;?>
<tr class='text-left' valign='top'>
<td>
<?php
if(!empty($case->id))
{
echo $case->id . html::hidden("id[$key]", $case->id);
$insert = false;
}
else
{
echo $key . " <sup class='text-green small'>{$lang->testcase->new}</sup>";
}
echo html::hidden("lib[$key]", $libID);
?>
</td>
<td><?php echo html::input("title[$key]", $case->title, "class='form-control' style='margin-top:2px'")?></td>
<td style='overflow:visible'><?php echo html::select("module[$key]", $modules, isset($case->module) ? $case->module : (!empty($case->id) ? $cases[$case->id]->module : ''), "class='form-control chosen'")?></td>
<td><?php echo html::select("pri[$key]", $lang->testcase->priList, isset($case->pri) ? $case->pri : (!empty($case->id) ? $cases[$case->id]->pri : ''), "class='form-control chosen'")?></td>
<td><?php echo html::select("type[$key]", $lang->testcase->typeList, isset($case->type) ? $case->type : (!empty($case->id) ? $cases[$case->id]->type : ''), "class='form-control chosen'")?></td>
<td style='overflow:visible'><?php echo html::select("stage[$key][]", $lang->testcase->stageList, !empty($case->stage) ? $case->stage : (!empty($case->id) ? $cases[$case->id]->stage : ''), "multiple='multiple' class='form-control chosen'")?></td>
<td><?php echo html::input("keywords[$key]", isset($case->keywords) ? $case->keywords : "", "class='form-control'")?></td>
<td><?php echo html::textarea("precondition[$key]", isset($case->precondition) ? htmlspecialchars($case->precondition) : "", "class='form-control'")?></td>
<td class='col-content'>
<?php if(isset($stepData[$key]['desc'])):?>
<table class='w-p100 bd-0'>
<?php foreach($stepData[$key]['desc'] as $id => $desc):?>
<?php
if(empty($desc['content'])) continue;
$hideContentCol = false;
?>
<tr class='step'>
<td><?php echo $id . html::hidden("stepType[$key][$id]", $desc['type'])?></td>
<td><?php echo html::textarea("desc[$key][$id]", htmlspecialchars($desc['content']), "class='form-control'")?></td>
<td><?php if($desc['type'] != 'group') echo html::textarea("expect[$key][$id]", isset($stepData[$key]['expect'][$id]['content']) ? htmlspecialchars($stepData[$key]['expect'][$id]['content']) : '', "class='form-control'")?></td>
</tr>
<?php endforeach;?>
</table>
<?php endif;?>
</td>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan='9' class='text-center form-actions'>
<table class='table table-form' id='showData'>
<thead>
<tr>
<th class='w-70px'><?php echo $lang->testcase->id?></th>
<th><?php echo $lang->testcase->title?></th>
<th class='w-150px'><?php echo $lang->testcase->module?></th>
<th class='w-80px'><?php echo $lang->testcase->pri?></th>
<th class='w-130px'><?php echo $lang->testcase->type?></th>
<th><?php echo $lang->testcase->stage?></th>
<th class='w-80px'><?php echo $lang->testcase->keywords?></th>
<th><?php echo $lang->testcase->precondition?></th>
<th class='w-300px col-content'>
<table class='w-p100 table-borderless'>
<tr>
<th><?php echo $lang->testcase->stepDesc?></th>
<th><?php echo $lang->testcase->stepExpect?></th>
</tr>
</table>
</th>
</tr>
</thead>
<tbody>
<?php
$insert = true;
$hideContentCol = true;
?>
<?php foreach($caseData as $key => $case):?>
<?php if(empty($case->title)) continue;?>
<?php if(!empty($case->id) and !isset($cases[$case->id])) $case->id = 0;?>
<tr class='text-left' valign='top'>
<td>
<?php
if(!$insert)
if(!empty($case->id))
{
echo "<button type='button' data-toggle='modal' data-target='#importNoticeModal' class='btn btn-primary btn-wide'>{$lang->save}</button>";
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 . " <sup class='text-green small'>{$lang->testcase->new}</sup>";
}
echo ' &nbsp; ' . html::backButton();
echo ' &nbsp; ' . sprintf($lang->file->importPager, $allCount, $pagerID, $allPager);
echo html::hidden("lib[$key]", $libID);
?>
</td>
<td><?php echo html::input("title[$key]", $case->title, "class='form-control' style='margin-top:2px'")?></td>
<td style='overflow:visible'><?php echo html::select("module[$key]", $modules, isset($case->module) ? $case->module : (!empty($case->id) ? $cases[$case->id]->module : ''), "class='form-control chosen'")?></td>
<td><?php echo html::select("pri[$key]", $lang->testcase->priList, isset($case->pri) ? $case->pri : (!empty($case->id) ? $cases[$case->id]->pri : ''), "class='form-control chosen'")?></td>
<td><?php echo html::select("type[$key]", $lang->testcase->typeList, isset($case->type) ? $case->type : (!empty($case->id) ? $cases[$case->id]->type : ''), "class='form-control chosen'")?></td>
<td style='overflow:visible'><?php echo html::select("stage[$key][]", $lang->testcase->stageList, !empty($case->stage) ? $case->stage : (!empty($case->id) ? $cases[$case->id]->stage : ''), "multiple='multiple' class='form-control chosen'")?></td>
<td><?php echo html::input("keywords[$key]", isset($case->keywords) ? $case->keywords : "", "class='form-control'")?></td>
<td><?php echo html::textarea("precondition[$key]", isset($case->precondition) ? htmlspecialchars($case->precondition) : "", "class='form-control'")?></td>
<td class='col-content'>
<?php if(isset($stepData[$key]['desc'])):?>
<table class='w-p100 bd-0'>
<?php foreach($stepData[$key]['desc'] as $id => $desc):?>
<?php
if(empty($desc['content'])) continue;
$hideContentCol = false;
?>
<tr class='step'>
<td><?php echo $id . html::hidden("stepType[$key][$id]", $desc['type'])?></td>
<td><?php echo html::textarea("desc[$key][$id]", htmlspecialchars($desc['content']), "class='form-control'")?></td>
<td><?php if($desc['type'] != 'group') echo html::textarea("expect[$key][$id]", isset($stepData[$key]['expect'][$id]['content']) ? htmlspecialchars($stepData[$key]['expect'][$id]['content']) : '', "class='form-control'")?></td>
</tr>
<?php endforeach;?>
</table>
<?php endif;?>
</td>
</tr>
</tfoot>
</table>
<?php if(!$insert) include '../../common/view/noticeimport.html.php';?>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan='9' class='text-center form-actions'>
<?php
if(!$insert)
{
echo "<button type='button' data-toggle='modal' data-target='#importNoticeModal' class='btn btn-primary btn-wide'>{$lang->save}</button>";
}
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 ' &nbsp; ' . html::backButton();
echo ' &nbsp; ' . sprintf($lang->file->importPager, $allCount, $pagerID, $allPager);
?>
</td>
</tr>
</tfoot>
</table>
<?php if(!$insert) include '../../common/view/noticeimport.html.php';?>
</form>
</div>
<?php endif;?>
<?php if($hideContentCol):?>
<?php if(isset($hideContentCol) and $hideContentCol):?>
<style>#mainContent .col-content{display: none;}</style>
<?php endif;?>
<script>
$(function(){affix('thead')})
function affix(obj)
{
var fixH = $(obj).offset().top;
var first = true;
$(window).scroll(function()
{
var scroH = $(this).scrollTop();
if(scroH>=fixH && first)
{
$(obj).parent().parent().before("<table id='headerClone' class='table'></table>");
$('#headerClone').append($(obj).clone()).addClass('affix');
$('.active-disabled ' + obj + ' th').each(function(i){$('#headerClone ' + obj + ' th').eq(i).width($(this).width())});
first = false;
}
else if(scroH<fixH)
{
$("#headerClone").remove();
first = true;
}
});
}
$(function(){$.fixedTableHead('#showData');});
</script>
<?php include '../../common/view/footer.html.php';?>
+1
View File
@@ -49,6 +49,7 @@ $lang->file->childTaskTips = "任务名称前有'>'标记的为子任务";
$lang->file->uploadImagesExplain = '注:请上传"jpg, jpeg, gif, png"格式的图片,程序会以文件名作为标题,以图片作为内容。';
$lang->file->saveAndNext = '保存并跳转下一页';
$lang->file->importPager = '共有<strong>%s</strong>条记录,当前第<strong>%s</strong>页,共有<strong>%s</strong>页';
$lang->file->importSummary = "本次导入共有<strong id='allCount'>%s</strong>条记录,每页导入%s条,需要导入<strong id='times'>%s</strong>次";
$lang->file->errorNotExists = "<span class='text-red'>文件夹 '%s' 不存在</span>";
$lang->file->errorCanNotWrite = "<span class='text-red'>文件夹 '%s' 不可写,请改变文件夹的权限。在linux中输入指令: <span class='code'>sudo chmod -R 777 %s</span></span>";
+3 -3
View File
@@ -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;
+23 -12
View File
@@ -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();
}
+18 -3
View File
@@ -1,11 +1,26 @@
<?php include '../../common/view/header.html.php';?>
<style>
.affix {position:fixed; top:0px; width:95.6%;z-index:10000;}
</style>
<?php js::set('productID', $productID);?>
<?php js::set('branch', $branch);?>
<?php if(isset($suhosinInfo)):?>
<div class='alert alert-info'><?php echo $suhosinInfo?></div>
<?php elseif(empty($maxImport)):?>
<div id="mainContent" class="main-content">
<div class="main-header">
<h2><?php echo $lang->testcase->import;?></h2>
</div>
<p><?php echo sprintf($lang->file->importSummary, $allCount, html::input('maxImport', $config->file->maxImport, "style='width:50px'"), ceil($allCount / $config->file->maxImport));?></p>
<p><?php echo html::commonButton($lang->import, "id='import'", 'btn btn-primary');?></p>
</div>
<script>
$(function()
{
$('#maxImport').keyup(function()
{
if(parseInt($('#maxImport').val())) $('#times').html(Math.ceil(parseInt($('#allCount').html()) / parseInt($('#maxImport').val())));
});
$('#import').click(function(){location.href = createLink('testcase', 'showImport', "productID=<?php echo $productID;?>&branch=<?php echo $branch?>&pageID=1&maxImport=" + $('#maxImport').val())})
});
</script>
<?php else:?>
<div id="mainContent" class="main-content">
<div class="main-header clearfix">