* Refactor importfromlib view of testcase.
This commit is contained in:
@@ -180,6 +180,41 @@ $config->testcase->zerocase->dtable->fieldList['actions']['menu'] = array('c
|
||||
$config->testcase->zerocase->dtable->fieldList['actions']['required'] = true;
|
||||
$config->testcase->zerocase->dtable->fieldList['actions']['group'] = '7';
|
||||
|
||||
$config->testcase->importfromlib = new stdclass();
|
||||
$config->testcase->importfromlib->dtable = new stdclass();
|
||||
$config->testcase->importfromlib->dtable->fieldList['id']['name'] = 'id';
|
||||
$config->testcase->importfromlib->dtable->fieldList['id']['title'] = $lang->idAB;
|
||||
$config->testcase->importfromlib->dtable->fieldList['id']['type'] = 'checkID';
|
||||
$config->testcase->importfromlib->dtable->fieldList['id']['fixed'] = false;
|
||||
|
||||
$config->testcase->importfromlib->dtable->fieldList['branch']['name'] = 'branch';
|
||||
$config->testcase->importfromlib->dtable->fieldList['branch']['title'] = $lang->testcase->branch;
|
||||
$config->testcase->importfromlib->dtable->fieldList['branch']['type'] = 'category';
|
||||
|
||||
$config->testcase->importfromlib->dtable->fieldList['pri']['name'] = 'pri';
|
||||
$config->testcase->importfromlib->dtable->fieldList['pri']['title'] = $lang->testcase->pri;
|
||||
$config->testcase->importfromlib->dtable->fieldList['pri']['type'] = 'pri';
|
||||
|
||||
$config->testcase->importfromlib->dtable->fieldList['title']['name'] = 'title';
|
||||
$config->testcase->importfromlib->dtable->fieldList['title']['title'] = $lang->testcase->title;
|
||||
$config->testcase->importfromlib->dtable->fieldList['title']['type'] = 'title';
|
||||
$config->testcase->importfromlib->dtable->fieldList['title']['fixed'] = false;
|
||||
$config->testcase->importfromlib->dtable->fieldList['title']['link'] = array('module' => 'testcase', 'method' => 'view', 'params' => "caseID={id}");
|
||||
$config->testcase->importfromlib->dtable->fieldList['title']['data-toggle'] = 'modal';
|
||||
|
||||
$config->testcase->importfromlib->dtable->fieldList['fromModule']['name'] = 'fromModule';
|
||||
$config->testcase->importfromlib->dtable->fieldList['fromModule']['title'] = $lang->testcase->fromModule;
|
||||
$config->testcase->importfromlib->dtable->fieldList['fromModule']['type'] = 'category';
|
||||
|
||||
$config->testcase->importfromlib->dtable->fieldList['module']['name'] = 'module';
|
||||
$config->testcase->importfromlib->dtable->fieldList['module']['title'] = $lang->testcase->module;
|
||||
$config->testcase->importfromlib->dtable->fieldList['module']['type'] = 'html';
|
||||
|
||||
$config->testcase->importfromlib->dtable->fieldList['type']['name'] = 'type';
|
||||
$config->testcase->importfromlib->dtable->fieldList['type']['title'] = $lang->testcase->type;
|
||||
$config->testcase->importfromlib->dtable->fieldList['type']['type'] = 'status';
|
||||
$config->testcase->importfromlib->dtable->fieldList['type']['statusMap'] = $lang->testcase->typeList;
|
||||
|
||||
$config->scene->dtable = new stdclass();
|
||||
$config->scene->dtable->fieldList['id']['title'] = $lang->idAB;
|
||||
$config->scene->dtable->fieldList['id']['type'] = 'checkID';
|
||||
|
||||
@@ -2058,17 +2058,23 @@ class testcase extends control
|
||||
if($product->type != 'normal') $branches = array(BRANCH_MAIN => $this->lang->branch->main) + $this->branch->getPairs($productID, 'active', $projectID);
|
||||
|
||||
$libraries = $this->loadModel('caselib')->getLibraries();
|
||||
if(empty($libraries))
|
||||
{
|
||||
echo js::alert($this->lang->testcase->noLibrary);
|
||||
return print(js::locate($this->session->caseList));
|
||||
}
|
||||
if(empty($libraries)) return $this->send(array('result' => 'fail', 'message' => $this->lang->testcase->noLibrary, 'load' => $this->session->caseList));
|
||||
|
||||
if(empty($libID) or !isset($libraries[$libID])) $libID = key($libraries);
|
||||
|
||||
if($_POST)
|
||||
{
|
||||
$this->testcase->importFromLib($productID, $libID, $branch);
|
||||
return print(js::reload('parent'));
|
||||
$result = $this->testcase->importFromLib($productID, $libID, $branch);
|
||||
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
if(!empty($result) && is_string($result))
|
||||
{
|
||||
$imported = trim($result, ',');
|
||||
return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->testcase->importedCases, $imported)));
|
||||
}
|
||||
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->importSuccess, 'load' => true));
|
||||
}
|
||||
|
||||
$this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->testcase->setMenu($this->products, $productID, $branch);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
window.renderModuleItem = function(result, info)
|
||||
{
|
||||
if(info.col.name == 'module' && info.col.type == 'html')
|
||||
{
|
||||
const $module = $('#moduleSelect select').empty();
|
||||
|
||||
$module.attr('name', `module[${info.row.data.id}]`);
|
||||
|
||||
$.each(info.row.data.moduleItems, function(moduleID, moduleName)
|
||||
{
|
||||
$module.append('<option value="' + moduleID + '">' + moduleName + '</option>');
|
||||
});
|
||||
|
||||
result[0] = null;
|
||||
result[result.length] = {html: $('#moduleSelect').html()};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function reload()
|
||||
{
|
||||
const libID = $(this).val();
|
||||
const link = $.createLink('testcase','importFromLib','productID=' + productID + '&branch=' + branch + '&libID=' + libID);
|
||||
|
||||
location.href = link;
|
||||
}
|
||||
|
||||
$(document).off('click', '.import-btn').on('click', '.import-btn', function()
|
||||
{
|
||||
const dtable = zui.DTable.query($(this).target);
|
||||
const checkedList = dtable.$.getChecks();
|
||||
if(!checkedList.length) return false;
|
||||
|
||||
const url = $('#importFromLibForm').attr('action');
|
||||
const formData = new FormData($("#importFromLibForm")[0]);
|
||||
checkedList.forEach((id) => formData.append(`caseIdList[${id}]`, id));
|
||||
|
||||
$.ajaxSubmit({url: url, data: formData});
|
||||
|
||||
return false;
|
||||
});
|
||||
@@ -1830,11 +1830,10 @@ class testcaseModel extends model
|
||||
$this->loadModel('action')->create('case', $caseID, 'fromlib', '', $case->lib);
|
||||
}
|
||||
}
|
||||
if(!empty($imported))
|
||||
{
|
||||
$imported = trim($imported, ',');
|
||||
return print(js::error(sprintf($this->lang->testcase->importedCases, $imported)));
|
||||
}
|
||||
|
||||
if(!empty($imported)) return $imported;
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The import from lib view file of testcase module of ZenTaoPMS.
|
||||
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
|
||||
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||
* @author Tingting Dai <daitingting@easycorp.ltd>
|
||||
* @package testcase
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
namespace zin;
|
||||
|
||||
jsVar('app', $app->tab);
|
||||
jsVar('productID', $productID);
|
||||
jsVar('branch', $branch);
|
||||
|
||||
featureBar
|
||||
(
|
||||
to::before
|
||||
(
|
||||
backBtn
|
||||
(
|
||||
$lang->goback,
|
||||
set::icon('back'),
|
||||
set::url($this->session->caseList),
|
||||
set::class('secondary')
|
||||
),
|
||||
select
|
||||
(
|
||||
zui::width('200px'),
|
||||
set::name('fromlib'),
|
||||
set::items($libraries),
|
||||
set::value($libID),
|
||||
set::placeholder($lang->testcase->placeholder->selectLib),
|
||||
on::change('reload')
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
div
|
||||
(
|
||||
setid('searchFormPanel'),
|
||||
searchToggle
|
||||
(
|
||||
set::open(true),
|
||||
set::module('testsuite')
|
||||
)
|
||||
);
|
||||
|
||||
$config->testcase->importfromlib->dtable->fieldList['fromModule']['map'] = $libModules;
|
||||
if($product->type == 'normal') unset($config->testcase->importfromlib->dtable->fieldList['branch']);
|
||||
|
||||
foreach($cases as $case)
|
||||
{
|
||||
$case->fromModule = $case->module;
|
||||
|
||||
$caseBranches = $branches;
|
||||
$caseBranch = ($branch == 'all' || empty($branch)) ? 0 : $branch;
|
||||
foreach($caseBranches as $branchID => $branchName)
|
||||
{
|
||||
if(empty($canImportModules[$branchID][$case->id]))
|
||||
{
|
||||
unset($caseBranches[$branchID]);
|
||||
|
||||
if($caseBranch == $branchID) $caseBranch = key($caseBranches);
|
||||
}
|
||||
}
|
||||
|
||||
$case->moduleItems = $canImportModules[$caseBranch][$case->id];
|
||||
}
|
||||
|
||||
$footToolbar = array('items' => array(array('text' => $lang->testcase->import, 'btnType' => 'secondary', 'className' => 'import-btn')));
|
||||
|
||||
formBase
|
||||
(
|
||||
setID('importFromLibForm'),
|
||||
set::action(createLink('testcase', 'importFromLib', "product={$productID}&branch={$branch}&libID={$libID}")),
|
||||
set::actions(array()),
|
||||
|
||||
dtable
|
||||
(
|
||||
set::cols($config->testcase->importfromlib->dtable->fieldList),
|
||||
set::data($cases),
|
||||
set::onRenderCell(jsRaw('window.renderModuleItem')),
|
||||
set::checkable(true),
|
||||
set::footToolbar($footToolbar),
|
||||
set::footPager(usePager()),
|
||||
)
|
||||
);
|
||||
|
||||
div
|
||||
(
|
||||
setID('moduleSelect'),
|
||||
setClass('hidden'),
|
||||
select
|
||||
(
|
||||
set::name('module[]'),
|
||||
)
|
||||
);
|
||||
|
||||
render();
|
||||
Reference in New Issue
Block a user