From 8cf8f8786ce559c8d3827e48356f66ffaa12b2e1 Mon Sep 17 00:00:00 2001 From: chentao Date: Fri, 14 Jul 2023 17:35:46 +0800 Subject: [PATCH] * Refactor batch stages creation page. --- module/programplan/config/form.php | 21 +++ module/programplan/control.php | 2 +- module/programplan/css/create.ui.css | 1 + module/programplan/js/create.ui.js | 6 + module/programplan/model.php | 6 +- module/programplan/ui/create.html.php | 230 ++++++++++++++++++++++++++ 6 files changed, 262 insertions(+), 4 deletions(-) create mode 100644 module/programplan/css/create.ui.css create mode 100644 module/programplan/js/create.ui.js create mode 100644 module/programplan/ui/create.html.php diff --git a/module/programplan/config/form.php b/module/programplan/config/form.php index a92c92ab69..9153d69863 100644 --- a/module/programplan/config/form.php +++ b/module/programplan/config/form.php @@ -20,3 +20,24 @@ $config->programplan->ajaxCustom->form['zooming'] = array('required' => fals $config->programplan->ajaxCustom->form['stageCustom'] = array('required' => false, 'type' => 'array'); $config->programplan->ajaxCustom->form['ganttFields'] = array('required' => false, 'type' => 'array'); +/* Batch stages creation. */ +global $app, $lang; +$app->loadLang('execution'); +$app->loadLang('stage'); +!isset($config->programplan->form) && $config->programplan->form = new stdClass(); +$config->programplan->form->create = common::formConfig('programplan', 'create'); +$config->programplan->form->create['planIDList'] = array('type' => 'array', 'control' => 'text', 'required' => false, 'default' => ''); +$config->programplan->form->create['orders'] = array('type' => 'array', 'control' => 'text', 'required' => false, 'default' => ''); +$config->programplan->form->create['type'] = array('label' => $lang->execution->method, 'type' => 'array', 'control' => 'select', 'required' => true, 'default' => '', 'options' => $lang->execution->typeList); +$config->programplan->form->create['name'] = array('label' => $lang->nameAB, 'type' => 'array', 'control' => 'text', 'required' => true, 'default' => '', 'base' => true); +$config->programplan->form->create['code'] = array('label' => $lang->code, 'type' => 'array', 'control' => 'select', 'required' => false, 'default' => '', 'options' => array()); +$config->programplan->form->create['PM'] = array('label' => $lang->programplan->PMAB, 'type' => 'array', 'control' => 'select', 'required' => false, 'default' => '', 'options' => array()); +$config->programplan->form->create['percent'] = array('label' => $lang->programplan->percent, 'type' => 'array', 'control' => 'number', 'required' => false, 'default' => 0, 'options' => array()); +$config->programplan->form->create['attribute'] = array('label' => $lang->programplan->attribute, 'type' => 'array', 'control' => 'select', 'required' => false, 'default' => 0, 'options' => $lang->stage->typeList); +$config->programplan->form->create['acl'] = array('label' => $lang->programplan->acl, 'type' => 'array', 'control' => 'select', 'required' => false, 'default' => 'open', 'options' => $lang->execution->aclList); +$config->programplan->form->create['milestone'] = array('label' => $lang->programplan->milestone, 'type' => 'array', 'control' => 'select', 'required' => false, 'default' => 0, 'options' => $lang->programplan->milestoneList); +$config->programplan->form->create['begin'] = array('label' => $lang->programplan->begin, 'type' => 'array', 'control' => 'text', 'required' => true, 'default' => ''); +$config->programplan->form->create['end'] = array('label' => $lang->programplan->end, 'type' => 'array', 'control' => 'text', 'required' => true, 'default' => ''); +$config->programplan->form->create['realBegan'] = array('label' => $lang->programplan->realBegan, 'type' => 'array', 'control' => 'text', 'required' => false, 'default' => ''); +$config->programplan->form->create['realEnd'] = array('label' => $lang->programplan->realEnd, 'type' => 'array', 'control' => 'text', 'required' => false, 'default' => ''); +$config->programplan->form->create['desc'] = array('label' => $lang->programplan->desc, 'type' => 'array', 'control' => 'textarea', 'required' => false, 'default' => ''); diff --git a/module/programplan/control.php b/module/programplan/control.php index 9457bf8a6c..cc22cfcd59 100644 --- a/module/programplan/control.php +++ b/module/programplan/control.php @@ -82,7 +82,7 @@ class programplan extends control $this->productID = $this->commonAction($projectID, $productID); if($_POST) { - $formData = form::data($this->config->programplan->create->form); + $formData = form::data($this->config->programplan->form->create); $formData = $this->programplanZen->beforeCreate($formData); $this->programplan->create($formData, $projectID, $this->productID, $planID); diff --git a/module/programplan/css/create.ui.css b/module/programplan/css/create.ui.css new file mode 100644 index 0000000000..d27f39e859 --- /dev/null +++ b/module/programplan/css/create.ui.css @@ -0,0 +1 @@ +.panel-actions {display: flex; width: 100%; flex-direction: row-reverse; justify-content: space-between;} diff --git a/module/programplan/js/create.ui.js b/module/programplan/js/create.ui.js new file mode 100644 index 0000000000..9013da1835 --- /dev/null +++ b/module/programplan/js/create.ui.js @@ -0,0 +1,6 @@ +window.onRenderRow = function(row, rowIdx, data) +{ + if(!data || !data.planIDList) return; + + row.children('.form-batch-row-actions').children('[data-type=delete]').remove(); +}; diff --git a/module/programplan/model.php b/module/programplan/model.php index c7cf1e847a..e0d4719e07 100755 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -515,10 +515,10 @@ class programplanModel extends model { /* Get every value from formData without use extract(). */ $planIDList = $formData->get('planIDList'); - $names = $formData->get('names'); + $names = $formData->get('name'); $projectManager = $formData->get('PM'); - $percents = $formData->get('percents'); - $attributes = $formData->get('attributes'); + $percents = $formData->get('percent'); + $attributes = $formData->get('attribute'); $acl = $formData->get('acl'); $milestone = $formData->get('milestone'); $begin = $formData->get('begin'); diff --git a/module/programplan/ui/create.html.php b/module/programplan/ui/create.html.php new file mode 100644 index 0000000000..7efe51d5fb --- /dev/null +++ b/module/programplan/ui/create.html.php @@ -0,0 +1,230 @@ + + * @package programplan + * @link https://www.zentao.net + */ + +namespace zin; + +$fields = $this->config->programplan->form->create; + +/* Generate title that is tailored to specific situation. */ +$title = $lang->programplan->create; +if($planID) $title = $programPlan->name . $lang->project->stage . '(' . $programPlan->begin . $lang->project->to . $programPlan->end . ')'; + +/* Generate product list dropdown menu while stage by product. */ +$fnGenerateStageByProductList = function() use ($productID, $productList, $project) +{ + if(empty($productList) || $project->stageBy != 'product') return null; + + $defaultName = $productID != 0 ? zget($productList,$productID) : current($productList); + + $items = array(); + foreach($productList as $key => $product) + { + $items[] = array('text' => $product, 'active' => $productID == $key, 'data-url' => createLink('programplan', 'create', "projectID=$project->id&productID=$key")); + } + + return dropdown + ( + $defaultName, + span(setClass('caret')), + set::items($items) + ); +}; + +/* Generate customized fields. */ +$fnGenerateCustomizedFields = function() use ($defaultFields, $customFields, $showFields, $custom) +{ + $items = array(); + + foreach($customFields as $name => $text) + { + $items[] = array + ( + 'name' => $name, + 'text' => $text, + 'show' => str_contains($showFields, $name), + 'default' => str_contains($defaultFields, $name) + ); + } + + return array('items' => $items, 'urlParams' => "module=programplan§ion={$custom}&key=createFields"); +}; + +/* Generate checkboxes for sub-stage management. */ +$fnGenerateSubPlanManageFields = function() use ($lang, $planID, $project, $executionType) +{ + if(empty($planID) || $project->model != 'waterfallplus') return div(); + + $typeList = $lang->programplan->typeList; + + $items = array(); + if(count($typeList) > 1) + { + foreach($typeList as $key => $value) + { + // TODO implements click event + $items[] = checkbox + ( + set::type('radio'), + set::name('executionType'), + set::text($value), + set::value($key), + //on::change('window.onChangeExecutionType'), + set::checked($key == $executionType) + ); + } + $items[] = icon(setClass('icon-help')); + } + else + { + $items[] = zget($typeList, $executionType); + } + + return div + ( + setClass('flex w-1/2'), + $lang->programplan->subPlanManage . ':', + $items + ); +}; + +/* Generate form fields. */ +$fnGenerateFields = function() use ($lang, $requiredFields, $showFields, $fields, $PMUsers) +{ + $items = array(); + $items[] = array('name' => 'id', 'label' => $lang->idAB, 'control' => 'index', 'width' => '32px'); + + $renderFields = implode(',', array_keys($requiredFields)); + $renderFields = ",$renderFields,$showFields,"; + + foreach($fields as $name => $field) + { + $field['name'] = $name; + + /* Convert 'options' to 'items'. */ + if(!empty($field['options'])) + { + $field['items'] = $field['options']; + } + unset($field['options']); + + /* Assgn item data to PM field. */ + if($name == 'PM') + { + $field['items'] = $PMUsers; + } + + /* Form field name is plural nouns, so remove the suffix 's' */ + $name = trim($name, 's'); + /* Set hidden attribute. */ + if(!str_contains($renderFields, ",$name,")) + { + $field['hidden'] = true; + } + + $items[] = $field; + } + + return $items; +}; + +/* Generate default rendering data. */ +$fnGenerateDefaultData = function() use ($config, $plans, $planID, $stages, $executionType) +{ + /* If the $planID variable is not empty, then the user is on the sub-stages creation page and no default values should be used. */ + if(!empty($planID)) return array(); + + $items = array(); + + /* Created a new project witho no stages. */ + if(empty($plans)) + { + foreach($stages as $stage) + { + $item = new stdClass(); + + $item->name = $stage->name; + if(isset($config->setCode) && $config->setCode == 1) + { + $item->code = isset($stage->code) ? $stage->code : ''; + } + $item->percent = $stage->percent; + $item->attribute = $stage->type; + $item->acl = 'open'; + $item->milestone = 0; + + $items[] = $item; + } + + return $items; + } + + /* Create stages for exist project. */ + foreach($plans as $plan) + { + $item = new stdClass(); + + $item->disabled = !isset($plan->setMilestone); + $item->planIDList = $plan->id; + $item->type = $plan->type; + $item->name = $plan->name; + if(isset($config->setCode) && $config->setCode == 1) + { + $item->code = $plan->code; + } + $item->PM = $plan->PM; + $item->percent = $plan->percent; + $item->attribute = $plan->attribute; + $item->acl = $plan->acl; + $item->milestone = $plan->milestone; + $item->begin = $plan->begin; + $item->end = $plan->end; + $item->realBegan = $plan->realBegan; + $item->realEnd = $plan->realEnd; + $item->desc = $plan->desc; + if($config->edition == 'max' && $executionType == 'stage') + { + $item->output = empty($plan->output) ? 0 : explode(',', $plan->output); + } + $item->order = $plan->order; + + $items[] = $item; + } + + return $items; +}; + +/* ZIN: layout. */ +featureBar(li +( + setClass('nav-item'), + a + ( + setClass('active'), + $title + ), + $fnGenerateStageByProductList() +)); + +toolbar +( + btn(setClass('btn primary open-url'), set::icon('back'), set('data-back', 'APP'), $lang->goback) +); + +formBatchPanel +( + set::id('dataform'), + set::onRenderRow(jsRaw('window.onRenderRow')), + to::headingActions(array($fnGenerateSubPlanManageFields())), + set::customFields($fnGenerateCustomizedFields()), + set::items($fnGenerateFields()), + set::data($fnGenerateDefaultData()) +);