From 5edc08f8b69243a09cacef6de2af5cb162e7088e Mon Sep 17 00:00:00 2001 From: liugang Date: Thu, 15 Jun 2023 19:57:52 +0800 Subject: [PATCH] * testtask: refactor the cases page. --- module/testtask/js/cases.ui.js | 29 +++-- module/testtask/ui/cases.html.php | 206 +++++++++++++++++------------- 2 files changed, 132 insertions(+), 103 deletions(-) diff --git a/module/testtask/js/cases.ui.js b/module/testtask/js/cases.ui.js index 4738daa70e..57cf48bb5b 100644 --- a/module/testtask/js/cases.ui.js +++ b/module/testtask/js/cases.ui.js @@ -1,4 +1,4 @@ -$(document).on('click', '.batch-btn', function() +$(document).off('click', '.batch-btn').on('click', '.batch-btn', function() { const dtable = zui.DTable.query(this); const checkedList = dtable.$.getChecks(); @@ -19,17 +19,24 @@ $(document).on('click', '.batch-btn', function() { if(result) { - const ztfURL = $.createLink('zanode', 'ajaxRunZTFScript', 'scriptID=' + automation); - $.post(ztfURL, form); - } + const ztfURL = $.createLink('zanode', 'ajaxRunZTFScript', 'scriptID=' + automation); + $.post(ztfURL, form, function(result) + { + if(result.result == 'fail') + { + zui.Modal.alert(result.message); + return false; + } - if($(this).hasClass('ajax-btn')) - { - $.ajaxSubmit({url, data: form}); - } - else - { - postAndLoadPage(url, form); + if($(this).hasClass('ajax-btn')) + { + $.ajaxSubmit({url, data: form}); + } + else + { + postAndLoadPage(url, form); + } + }, 'json'); } }}); } diff --git a/module/testtask/ui/cases.html.php b/module/testtask/ui/cases.html.php index 9b794ed083..9d3c8de0cb 100644 --- a/module/testtask/ui/cases.html.php +++ b/module/testtask/ui/cases.html.php @@ -4,135 +4,157 @@ declare(strict_types=1); * The cases view file of testtask 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 Yuting Wang + * @author Gang Liu * @package testtask * @link https://www.zentao.net */ namespace zin; -$app->loadLang('zanode'); -jsVar('runCaseConfirm', $lang->zanode->runCaseConfirm); -jsVar('automation', !empty($automation) ? $automation->id : 0); -$removeLink = $browseType == 'bymodule' ? inlink('cases', "taskID=$taskID&browseType=$browseType¶m=0&orderBy=$orderBy&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}") : 'javascript:removeCookieByKey("taskCaseModule")'; +$app->loadLang('zanode'); + +jsVar('automation', !empty($automation) ? $automation->id : 0); +jsVar('runCaseConfirm', $lang->zanode->runCaseConfirm); + +$canCreateSuite = hasPriv('testsuite', 'create'); +$canGroupCase = hasPriv('testtask', 'groupcase'); +$canLinkCase = hasPriv('testtask', 'linkCase'); +$canExport = hasPriv('testcase', 'export'); +$canReport = hasPriv('testtask', 'report'); +$canView = hasPriv('testtask', 'view'); +$canBatchEdit = hasPriv('testcase', 'batchEdit'); +$canBatchUnlink = hasPriv('testtask', 'batchUnlinkCases'); +$canBatchAssign = hasPriv('testtask', 'batchAssign'); +$canBatchRun = hasPriv('testtask', 'batchRun'); +$canBatchAction = ($canBeChanged && ($canBatchEdit || $canBatchUnlink || $canBatchAssign || $canBatchRun)); + +$closeLink = $browseType == 'bymodule' ? inlink('cases', "taskID=$task->id&browseType=$browseType¶m=0&orderBy=$orderBy&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}") : 'javascript:removeCookieByKey("taskCaseModule")'; sidebar ( moduleMenu(set(array ( 'modules' => $moduleTree, 'activeKey' => $moduleID, - 'closeLink' => $removeLink + 'closeLink' => $closeLink ))) ); +/* Process variables of sutie menu. */ +$suiteItems = array(); +if(empty($suiteList)) +{ + if($canCreateSuite && (empty($productID) || common::canModify('product', $product))) + { + $suiteItems[] = array('text' => $lang->testsuite->create, 'url' => $this->createLink('testsuite', 'create', "productID=$productID")); + } +} +else +{ + foreach($suites as $id => $name) + { + $suiteItems[] = array('text' => $name, 'url' => inlink('cases', "taskID=$task->id&browseType=bySuite¶m=$id"), 'active' => $name == $suiteName); + } +} + featureBar ( - set::current($type), - set::linkParams("taskID={$taskID}&browseType={key}¶m=0"), - li(searchToggle()) + set::linkParams("taskID=$task->id&browseType={key}¶m=0"), + $canGroupCase ? li + ( + set::class('nav-item'), + a + ( + set::href(inlink('groupCase', "taskID=$task->id&groupBy=story")), + set('data-app', $app->tab), + $lang->testcase->groupByStories + ) + ) : null, + dropdown + ( + btn + ( + setClass('ghost'), + $suiteName + ), + set::items($suiteItems) + ), + li(searchToggle(set::open($browseType == 'bysearch'))), + li(btn(setClass('ghost'), set::icon('unfold-all'), $lang->sort)) ); toolbar ( - common::hasPriv('testtask', 'linkCase') ? item(set(array + set::items ( - 'icon' => 'link', - 'text' => $lang->testtask->linkCase, - 'class' => 'ghost', - 'url' => createLink('testtask', 'linkCase', "taskID={$task->id}") - ))) : null, - common::hasPriv('testcase', 'export') ? item(set(array - ( - 'icon' => 'export', - 'text' => $lang->export, - 'class' => 'ghost', - 'url' => createLink('testcase', 'export', "productID={$productID}&orderBy=case_desc&taskID={$task->id}") - ))) : null, - common::hasPriv('testtask', 'report') ? item(set(array - ( - 'icon' => 'bar-chart', - 'text' => $lang->testtask->report->common, - 'class' => 'ghost', - 'url' => createLink('testtask', 'report', "productID={$productID}&taskID={$task->id}&browseType={$browseType}&branchID={$task->branch}&moduleID=" . (empty($moduleID) ? '' : $moduleID)) - ))) : null, - common::hasPriv('testtask', 'view') ? item(set(array - ( - 'icon' => 'list-alt', - 'text' => $lang->testtask->view, - 'class' => 'ghost', - 'url' => createLink('testtask', 'view', "taskID={$task->id}") - ))) : null, - item(set(array - ( - 'icon' => 'back', - 'text' => $lang->goback, - 'class' => 'ghost', - 'url' => createLink('testtask', 'browse', "productID={$productID}") - ))), + array + ( + $canLinkCase ? array('class' => 'ghost', 'icon' => 'link', 'text' => $lang->testtask->linkCase, 'url' => inlink('linkCase', "taskID=$task->id")): null, + $canExport ? array('class' => 'ghost', 'icon' => 'export', 'text' => $lang->export, 'url' => $this->createLink('testcase', 'export', "productID=$productID&orderBy=case_desc&taskID=$task->id"), 'data-toggle' => 'modal') : null, + $canReport ? array('class' => 'ghost', 'icon' => 'bar-chart', 'text' => $lang->testtask->report->common, 'url' => "productID=$productID&taskID=$task->id&browseType=$browseType&branchID=$task->branch&moduleID=" . (empty($moduleID) ? '' : $moduleID)): null, + $canView ? array('class' => 'ghost', 'icon' => 'list-alt', 'text' => $lang->testtask->view, 'url' => inlink('view', "taskID=$task->id")) : null, + array('class' => 'ghost', 'icon' => 'back', 'text' => $lang->goback, 'url' => $this->session->testtaskList) + ) + ) ); -$canBatchEdit = common::hasPriv('testtask', 'batchEdit'); -$canBatchUnlinkCases = common::hasPriv('testtask', 'batchUnlinkCases'); -$canBatchAssign = common::hasPriv('testtask', 'batchAssign'); -$canBatchRun = common::hasPriv('testtask', 'batchRun'); -$footToolbar = array(); -if($canBatchEdit && $canBatchUnlinkCases) +$footToolbar = null; +if($canBatchAction) { - $footToolbar['items'][] = array('type' => 'btn-group', 'items' => array - ( - array('text' => $lang->edit, 'className' => 'batch-btn secondary', 'data-url' => createLink('testcase', 'batchEdit', "productID={$productID}&branch=all")), - array('caret' => 'up', 'className' => 'secondary', 'url' => '#navActions', 'data-toggle' => 'dropdown', 'data-placement' => 'top-start') - )); -} -else -{ - if($canBatchEdit) $footToolbar['items'][] = array('text' => $lang->edit, 'className' => 'batch-btn', 'data-url' => createLink('testcase', 'batchEdit', "productID={$productID}&branch=all")); - if($canBatchUnlinkCases) $footToolbar['items'][] = array('text' => $lang->testtask->unlinkCase, 'className' => 'batch-btn ajax-btn', 'data-url' => helper::createLink('testtask', 'batchUnlinkCases', "taskID={$task->id}")); -} -if($canBatchAssign) $footToolbar['items'][] = array('caret' => 'up', 'text' => $lang->testtask->assignedTo, 'url' => '#navAssignedTo', 'data-toggle' => 'dropdown', 'data-placement' => 'top-start'); -if($canBatchRun) $footToolbar['items'][] = array('text' => $lang->testtask->runCase, 'className' => 'batch-btn batch-run', 'data-url' => helper::createLink('testtask', 'batchRun', "productID={$productID}&orderBy=id_desc&from=testtask&taskID={$taskID}&confirm=yes")); -$footToolbar['btnProps'] = array('size' => 'sm', 'btnType' => 'secondary'); - -if($canBatchEdit && $canBatchUnlinkCases) -{ - menu - ( - set::id('navActions'), - set::class('menu dropdown-menu'), - set::items(array + $footToolbar = array('items' => array()); + if($canBatchEdit && $canBatchUnlink) + { + zui::menu ( - array('text' => $lang->testtask->unlinkCase, 'class' => 'batch-btn ajax-btn', 'data-url' => helper::createLink('testtask', 'batchUnlinkCases', "taskID={$task->id}")), - )) - ); + set::id('navActions'), + set::class('menu dropdown-menu'), + set::items(array + ( + array('text' => $lang->unlink, 'class' => 'batch-btn ajax-btn', 'data-url' => inlink('batchUnlinkCases', "taskID=$task->id")) + )) + ); + $footToolbar['items'][] = array('type' => 'btn-group', 'items' => array + ( + array('text' => $lang->edit, 'className' => 'batch-btn secondary', 'data-url' => helper::createLink('testcase', 'batchEdit', "productID=$productID&branch=all")), + array('caret' => 'up', 'className' => 'secondary', 'url' => '#navActions', 'data-toggle' => 'dropdown', 'data-placement' => 'top-start') + )); + } + if($canBatchEdit && !$canBatchUnlink) $footToolbar['items'][] = array('text' => $lang->edit, 'className' => 'batch-btn', 'btnType' => 'secondary', 'data-url' => $this->createLink('testcase', 'batchEdit', "productID=$productID&branch=all")); + if(!$canBatchEdit && $canBatchUnlink) $footToolbar['items'][] = array('text' => $lang->unlink, 'className' => 'batch-btn', 'btnType' => 'secondary', 'data-url' => inlink('batchUnlinkCases', "taskID=$task->id")); + if($canBatchAssign) + { + $userItems = array(); + foreach($assignedToList as $account => $realname) $userItems[] = array('text' => $realname, 'class' => 'batch-btn ajax-btn', 'data-url' => inlink('batchAssign', "taskID=$task->id")); + + zui::menu + ( + set::id('navUser'), + set::class('dropdown-menu'), + set::items($userItems) + ); + + $footToolbar['items'][] = array('text' => $lang->testtask->assign, 'caret' => 'up', 'btnType' => 'secondary', 'url' => '#navUser', 'data-toggle' => 'dropdown', 'data-placement' => 'top-start'); + } + if($canBatchRun) $footToolbar['items'][] = array('text' => $lang->testtask->runCase, 'className' => 'batch-btn batch-run', 'btnType' => 'secondary', 'data-url' => inlink('batchRun', "productID=$productID&orderBy=id_desc&from=testtask&taskID=$task->id&confirm=yes")); } -if($canBatchAssign) +$cols = $this->loadModel('datatable')->getSetting('testtask'); +if(!empty($cols['actions']['list']['createBug']['url'])) { - $assignedToItems = array(); - foreach($assignedToList as $key => $value) $assignedToItems[] = array('text' => $value, 'class' => 'batch-btn ajax-btn', 'data-url' => helper::createLink('testtask', 'batchAssign', "taskID={$task->id}")); - - menu - ( - set::id('navAssignedTo'), - set::class('dropdown-menu'), - set::items($assignedToItems) - ); + $url = $cols['actions']['list']['createBug']['url']; + $cols['actions']['list']['createBug']['url'] = str_replace(array('%execution%', '%build%', '%testtask%'), array((string)$task->execution, (string)$task->build, (string)$task->id), $url); } -$config->testtask->testcase->dtable->fieldList['story']['map'] = $stories; - -$runs = initTableData($runs, $config->testtask->testcase->dtable->fieldList, $this->testcase); -$data = array_values($runs); +$runs = initTableData($runs, $cols); dtable ( set::customCols(true), - set::data($data), - set::cols($config->testtask->testcase->dtable->fieldList), set::userMap($users), - set::checkable(true), + set::cols($cols), + set::data($runs), + set::checkable($canBatchAction), set::fixedLeftWidth('44%'), set::footToolbar($footToolbar), - set::footPager(usePager()), + set::footPager(usePager()) ); render();