* Refactor batch stages creation page.

This commit is contained in:
chentao
2023-07-14 17:36:23 +08:00
parent 9c8de46bfa
commit 8cf8f8786c
6 changed files with 262 additions and 4 deletions
+21
View File
@@ -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' => '');
+1 -1
View File
@@ -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);
+1
View File
@@ -0,0 +1 @@
.panel-actions {display: flex; width: 100%; flex-direction: row-reverse; justify-content: space-between;}
+6
View File
@@ -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();
};
+3 -3
View File
@@ -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');
+230
View File
@@ -0,0 +1,230 @@
<?php
declare(strict_types=1);
/**
* Create view of program plan 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 chen.tao <chentao@easycorp.ltd>
* @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&section={$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())
);