From 6569f3bb1e2696cb4a974cf7fbf9cbb7675d9239 Mon Sep 17 00:00:00 2001 From: tianshujie Date: Thu, 29 Jun 2023 13:59:01 +0800 Subject: [PATCH] * Refactor edit execution page interaction. --- module/execution/js/common.ui.js | 2 +- module/execution/js/edit.ui.js | 132 +++++++++++++++++++++++++++- module/execution/ui/create.html.php | 10 ++- module/execution/ui/edit.html.php | 33 ++++--- 4 files changed, 159 insertions(+), 18 deletions(-) diff --git a/module/execution/js/common.ui.js b/module/execution/js/common.ui.js index 152ef46113..598718036e 100644 --- a/module/execution/js/common.ui.js +++ b/module/execution/js/common.ui.js @@ -221,7 +221,7 @@ function addNewLine(e) newLine.find("select[name^='branch']").on('change', "loadPlan('#products" + index + "', this)"); newLine.addClass('newLine'); - newLine.find('.linkProduct > .form-label').html(''); + newLine.find('.linkProduct > .form-label').html('').removeClass('required'); newLine.find('.removeLine').removeClass('hidden'); newLine.find("select[name^='products']").attr('name', 'products[' + index + ']').attr('id', 'products' + index).val(''); newLine.find("select[name^='plans']").attr('name', 'plans[' + index + '][' + 0 + '][]'); diff --git a/module/execution/js/edit.ui.js b/module/execution/js/edit.ui.js index c215dc54c5..1c5dbdaabc 100644 --- a/module/execution/js/edit.ui.js +++ b/module/execution/js/edit.ui.js @@ -1,4 +1,134 @@ $(function() { if($('#typeHover').length) new zui.Tooltip('#typeHover', {title: typeTip, trigger: 'hover', placement: 'right', type: 'white', 'className': 'text-gray border border-light'}); -}) + + $(document).on('click', 'button[type=submit]', function() + { + let products = new Array(); + let existedBranch = false; + + /* Determine whether the products of the same branch are linked. */ + $(".productsBox select[name^='products']").each(function() + { + let productID = $(this).val(); + if(typeof(products[productID]) == 'undefined') products[productID] = new Array(); + if(multiBranchProducts[productID]) + { + let branchID = $(this).closest('.form-row').find("select[name^=branch]").val(); + if(products[productID][branchID]) + { + existedBranch = true; + } + else + { + products[productID][branchID] = branchID; + } + if(existedBranch) return false; + } + }); + + if(existedBranch) + { + zui.Modal.alert(errorSameBranches); + return false; + } + }); + + if(isWaterfall) hidePlanBox(executionAttr); +}); + +/** + * Change product interaction. + * + * @access public + * @return void + */ +function productChange(e) +{ + loadBranches(e); + + let $product = $(e.target); + let current = $product.val(); + let last = $product.attr('last'); + let lastBranch = $product.attr('lastBranch'); + + $product.attr('data-last', current); + + let $branch = $product.closest('.productBox').find("[name^='branch']"); + if($branch.val()) + { + $product.attr('lastBranch', $branch.val()); + } + else + { + $product.removeAttr('lastBranch'); + } + + if(current != last && unmodifiableProducts.includes(Number(last))) + { + if(lastBranch != 0) + { + if(unmodifiableBranches.includes(Number(lastBranch))) + { + if(linkedStoryIDList[last][lastBranch]) zui.Modal.alert(unLinkProductTip.replace("%s", allProducts[last] + branchGroups[last][lastBranch])); + } + } + else + { + zui.Modal.alert(unLinkProductTip.replace("%s", allProducts[last])); + } + } +} + +/** + * Change branch interaction. + * + * @access public + * @return void + */ +function branchChange(e) +{ + let $branch = $(e.target); + let current = $branch.val(); + let last = $branch.attr('data-last'); + $branch.attr('data-last', current); + + let $product = $branch.closest('.form-row').find("[name^='products']"); + $product.attr('lastBranch', current); + loadPlans($product, $branch); + + if(unmodifiableBranches.includes(last)) + { + let productID = $product.val(); + if(unmodifiableBranches.includes(productID) && linkedStoryIDList[productID][last]) + { + zui.Modal.alert(tip.replace('%s', linkedStoryIDList[productID][last])); + } + } +} + +/** + * Change project interaction. + * + * @access public + * @return void + */ +function changeProject(e) +{ + let projectID = $(e.target).val(); + if($('#syncStories').length == 0) $('button[type=submit]').after(""); + + zui.Modal.confirm(confirmSync).then((res) => + { + if(res) + { + $("#syncStories").val('yes'); + lastProjectID = projectID; + } + else + { + $("#syncStories").val('no'); + $('#project').val(lastProjectID); + } + }); +}; diff --git a/module/execution/ui/create.html.php b/module/execution/ui/create.html.php index bc5745029c..b7c1f129d8 100644 --- a/module/execution/ui/create.html.php +++ b/module/execution/ui/create.html.php @@ -107,6 +107,7 @@ if(isset($project->hasProduct) && !empty($project->hasProduct) && $products) ( set::width($hasBranch ? '1/4' : '1/2'), setClass('linkProduct'), + set::required(true), $i == 0 ? set::label($lang->project->manageProducts) : set::label(''), inputGroup ( @@ -169,13 +170,13 @@ if(isset($project->hasProduct) && !empty($project->hasProduct) && $products) setClass('pl-2 flex self-center line-btn'), btn ( - setClass('btn btn-link addLine'), + setClass('btn btn-link text-gray addLine'), on::click('addNewLine'), icon('plus') ), btn ( - setClass('btn btn-link removeLine'), + setClass('btn btn-link text-gray removeLine'), setClass($i == 0 ? 'hidden' : ''), icon('trash'), on::click('removeLine'), @@ -217,6 +218,7 @@ else ( set::width('1/2'), setClass('linkProduct'), + set::required(true), set::label($lang->project->manageProducts), select ( @@ -263,13 +265,13 @@ else setClass('pl-2 flex self-center line-btn'), btn ( - setClass('btn btn-link addLine'), + setClass('btn btn-link text-gray addLine'), on::click('addNewLine'), icon('plus') ), btn ( - setClass('btn btn-link removeLine'), + setClass('btn btn-link text-gray removeLine'), setClass('hidden'), icon('trash'), on::click('removeLine'), diff --git a/module/execution/ui/edit.html.php b/module/execution/ui/edit.html.php index 9625c60d77..4f9567d52b 100644 --- a/module/execution/ui/edit.html.php +++ b/module/execution/ui/edit.html.php @@ -16,12 +16,16 @@ jsVar('errorSameBranches', $lang->execution->errorSameBranches); jsVar('unmodifiableProducts',$unmodifiableProducts); jsVar('unmodifiableBranches', $unmodifiableBranches); jsVar('multiBranchProducts', $multiBranchProducts); +jsVar('linkedStoryIDList', $linkedStoryIDList); jsVar('confirmSync', $lang->execution->confirmSync); jsVar('unLinkProductTip', $lang->project->unLinkProductTip); jsVar('typeTip', $lang->execution->typeTip); jsVar('projectID', $execution->project); jsVar('allProducts', $allProducts); jsVar('branchGroups', $branchGroups); +jsVar('isWaterfall', isset($project) && ($project->model == 'waterfall' || $project->model == 'waterfallplus')); +jsVar('executionAttr', $execution->attribute); +jsVar('window.lastProjectID', $execution->project); $projectBox = null; if(isset($project)) @@ -145,6 +149,7 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') ( set::width($hasBranch ? '1/4' : '1/2'), setClass('linkProduct'), + set::required(true), $i == 0 ? set::label($lang->project->manageProducts) : set::label(''), inputGroup ( @@ -158,9 +163,10 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') set::value($product->id), set::items($allProducts), set::last($product->id), + $hasBranch ? set::lastBranch(join(',', $product->branches)) : null, set::disabled($execution->type == 'stage' && $project->stageBy == 'project'), set::required(true), - on::change('loadBranches'), + on::change('productChange'), $execution->type == 'stage' && $project->stageBy == 'project' ? formHidden("products[$i]", $product->id) : null, ) ), @@ -181,7 +187,7 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') set::items($branches), set::value(implode(',', $product->branches)), set::multiple(true), - on::change("loadPlans('#products{$i}', this)") + on::change("branchChange") ) ), ), @@ -203,16 +209,16 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') ), $isStage && $project->stageBy == 'project' ? null : div ( - setClass('pl-2 flex self-center line-btn'), + setClass('pl-2 flex self-center text-gray line-btn'), btn ( - setClass('btn btn-link addLine'), + setClass('btn btn-link text-gray addLine'), on::click('addNewLine'), icon('plus') ), btn ( - setClass('btn btn-link removeLine'), + setClass('btn btn-link text-gray removeLine'), setClass($i == 0 ? 'hidden' : ''), icon('trash'), on::click('removeLine'), @@ -254,6 +260,7 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') ( set::width('1/2'), setClass('linkProduct'), + set::required(true), set::label($lang->project->manageProducts), select ( @@ -261,7 +268,7 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') set::name('products[0]'), set::items($allProducts), set::required(true), - on::change('loadBranches') + on::change('productChange') ) ), formGroup @@ -277,7 +284,7 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') set::name('branch[0][]'), set::control('select'), set::multiple(true), - on::change("loadPlans('#products0', this)") + on::change('branchChange') ) ), ), @@ -301,13 +308,13 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') setClass('pl-2 flex self-center line-btn'), btn ( - setClass('btn btn-link addLine'), + setClass('btn btn-link text-gray addLine'), on::click('addNewLine'), icon('plus') ), btn ( - setClass('btn btn-link removeLine'), + setClass('btn btn-link text-gray removeLine'), setClass('hidden'), icon('trash'), on::click('removeLine'), @@ -331,6 +338,7 @@ else ( set::width($hasBranch ? '1/4' : '1/2'), setClass('linkProduct'), + set::required(true), $i == 0 ? set::label($lang->project->manageProducts) : set::label(''), inputGroup ( @@ -344,9 +352,10 @@ else set::value($product->id), set::items($allProducts), set::last($product->id), + $hasBranch ? set::lastBranch(join(',', $product->branches)) : null, set::disabled($project->model == 'waterfall' || $project->model == 'waterfallplus'), set::required(true), - on::change('loadBranches'), + on::change('productChange'), $project->model == 'waterfall' || $project->model == 'waterfallplus' ? formHidden("products[$i]", $product->id) : null, ) ), @@ -368,7 +377,7 @@ else set::value(isset($product->branches) ? implode(',', $product->branches) : ''), set::disabled($project->model == 'waterfall' || $project->model == 'waterfallplus'), set::multiple(true), - on::change("loadPlans('#products{$i}', this)") + on::change('branchChange') ) ), ), @@ -456,7 +465,7 @@ formPanel set::name('delta'), set::inline(true), set::items($lang->execution->endList), - set::value((strtotime($project->end) - strtotime($project->begin)) / 3600 / 24 + 1), + set::value((strtotime($execution->end) - strtotime($execution->begin)) / 3600 / 24 + 1), on::change('computeEndDate'), ) ),