From 201285215bf888b7e115bf9bd2c3d01c25edc1e8 Mon Sep 17 00:00:00 2001 From: tianshujie98 Date: Wed, 11 Aug 2021 15:04:29 +0800 Subject: [PATCH] * Finish task #41244. --- module/execution/control.php | 23 ++++++++ module/execution/js/create.js | 12 ++++ module/execution/lang/de.php | 3 + module/execution/lang/en.php | 3 + module/execution/lang/fr.php | 3 + module/execution/lang/vi.php | 3 + module/execution/lang/zh-cn.php | 3 + module/execution/model.php | 83 +++++++++++++++++++-------- module/execution/view/create.html.php | 23 +++++--- 9 files changed, 124 insertions(+), 32 deletions(-) diff --git a/module/execution/control.php b/module/execution/control.php index 0d0cb3c83d..2b21f5e3b0 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -1340,6 +1340,7 @@ class execution extends control $this->view->name = $name; $this->view->code = $code; $this->view->team = $team; + $this->view->teams = array(0 => '') + $this->execution->getTeamPairsByProject((int)$projectID); $this->view->allProjects = array(0 => '') + $this->project->getPairsByModel(); $this->view->executionID = $executionID; $this->view->productID = $productID; @@ -2635,6 +2636,28 @@ class execution extends control } } + /** + * AJAX: get team members by projectID/executionID. + * + * @param int $objectID + * @access public + * @return string + */ + public function ajaxGetTeamMembers($objectID) + { + $type = 'execution'; + if($this->config->systemMode == 'new') + { + $type = $this->dao->findById($objectID)->from(TABLE_PROJECT)->fetch('type'); + $type = $type == 'project' ? $type : 'execution'; + } + + $users = $this->loadModel('user')->getPairs('nodeleted|noclosed'); + $members = $this->user->getTeamMemberPairs($objectID, $type); + + die(html::select('teamMembers[]', $users, array_keys($members), "class='form-control chosen' multiple")); + } + /** * When create a execution, help the user. * diff --git a/module/execution/js/create.js b/module/execution/js/create.js index e3290b67ff..1f703868a5 100644 --- a/module/execution/js/create.js +++ b/module/execution/js/create.js @@ -42,6 +42,18 @@ $(function() }; adjustMainCol(); $(window).on('resize', adjustMainCol); + + $('#teams').change(function() + { + var objectID = $(this).val(); + $.get(createLink('execution', 'ajaxGetTeamMembers', 'objectID=' + objectID), function(data) + { + $('#teamMembers').parent().html(data); + $('#teamMembers').chosen(); + }); + }) + + $('#teams').change(); }); function showLifeTimeTips() diff --git a/module/execution/lang/de.php b/module/execution/lang/de.php index a5e1c34fdd..292b6d7885 100644 --- a/module/execution/lang/de.php +++ b/module/execution/lang/de.php @@ -99,6 +99,9 @@ $lang->execution->recent = 'Recent visits: '; $lang->execution->copyNoExecution = 'There are no ' . $lang->executionCommon . 'available to copy.'; $lang->execution->noTeam = 'No team members at the moment'; +if($this->config->systemMode == 'new') $lang->execution->copyTeamTip = "select Project/{$lang->execution->common} to copy its members"; +if($this->config->systemMode == 'classic') $lang->execution->copyTeamTip = "select Project/{$lang->executionCommon} to copy its members"; + $lang->execution->start = 'Start'; $lang->execution->activate = 'Aktivieren'; $lang->execution->putoff = 'Zurückstellen'; diff --git a/module/execution/lang/en.php b/module/execution/lang/en.php index 20ec31ed80..3f6eb9ceb1 100644 --- a/module/execution/lang/en.php +++ b/module/execution/lang/en.php @@ -100,6 +100,9 @@ $lang->execution->recent = 'Recent visits: '; $lang->execution->copyNoExecution = 'There are no ' . $lang->executionCommon . 'available to copy.'; $lang->execution->noTeam = 'No team members at the moment'; +if($this->config->systemMode == 'new') $lang->execution->copyTeamTip = "select Project/{$lang->execution->common} to copy its members"; +if($this->config->systemMode == 'classic') $lang->execution->copyTeamTip = "select Project/{$lang->executionCommon} to copy its members"; + $lang->execution->start = 'Start'; $lang->execution->activate = 'Activate'; $lang->execution->putoff = 'Delay'; diff --git a/module/execution/lang/fr.php b/module/execution/lang/fr.php index 53f323b89c..9490560780 100644 --- a/module/execution/lang/fr.php +++ b/module/execution/lang/fr.php @@ -99,6 +99,9 @@ $lang->execution->recent = 'Recent visits: '; $lang->execution->copyNoExecution = 'There are no ' . $lang->executionCommon . 'available to copy.'; $lang->execution->noTeam = 'No team members at the moment'; +if($this->config->systemMode == 'new') $lang->execution->copyTeamTip = "select Project/{$lang->execution->common} to copy its members"; +if($this->config->systemMode == 'classic') $lang->execution->copyTeamTip = "select Project/{$lang->executionCommon} to copy its members"; + $lang->execution->start = 'Démarrer'; $lang->execution->activate = 'Activer'; $lang->execution->putoff = 'Ajourner'; diff --git a/module/execution/lang/vi.php b/module/execution/lang/vi.php index 2a3e9ba2d5..85b67cc35c 100644 --- a/module/execution/lang/vi.php +++ b/module/execution/lang/vi.php @@ -100,6 +100,9 @@ $lang->execution->recent = 'Recent visits: '; $lang->execution->copyNoExecution = 'There are no ' . $lang->executionCommon . 'available to copy.'; $lang->execution->noTeam = 'No team members at the moment'; +if($this->config->systemMode == 'new') $lang->execution->copyTeamTip = "select Project/{$lang->execution->common} to copy its members"; +if($this->config->systemMode == 'classic') $lang->execution->copyTeamTip = "select Project/{$lang->executionCommon} to copy its members"; + $lang->execution->start = 'Bắt đầu'; $lang->execution->activate = 'Kích hoạt'; $lang->execution->putoff = 'Tạm ngưng'; diff --git a/module/execution/lang/zh-cn.php b/module/execution/lang/zh-cn.php index fe2371889f..9a23d3c856 100644 --- a/module/execution/lang/zh-cn.php +++ b/module/execution/lang/zh-cn.php @@ -100,6 +100,9 @@ $lang->execution->recent = '近期访问:'; $lang->execution->copyNoExecution = '没有可用的' . $lang->executionCommon . '来复制'; $lang->execution->noTeam = '暂时没有团队成员'; +if($this->config->systemMode == 'new') $lang->execution->copyTeamTip = "可以选择复制项目或{$lang->execution->common}团队的成员"; +if($this->config->systemMode == 'classic') $lang->execution->copyTeamTip = "可以选择复制{$lang->executionCommon}团队的成员"; + $lang->execution->start = "开始"; $lang->execution->activate = "激活"; $lang->execution->putoff = "延期"; diff --git a/module/execution/model.php b/module/execution/model.php index 0e416d6bb5..e00b7e35cb 100644 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -325,7 +325,7 @@ class executionModel extends model ->join('whitelist', ',') ->add('type', $type) ->stripTags($this->config->execution->editor->create['id'], $this->config->allowedTags) - ->remove('products, workDays, delta, branch, uid, plans') + ->remove('products, workDays, delta, branch, uid, plans, teams, teamMembers') ->get(); /* Check the workload format and total. */ @@ -368,6 +368,7 @@ class executionModel extends model $executionID = $this->dao->lastInsertId(); $today = helper::today(); $creatorExists = false; + $teamMembers = array(); /* Save order. */ $this->dao->update(TABLE_EXECUTION)->set('`order`')->eq($executionID * 5)->where('id')->eq($executionID)->exec(); @@ -376,39 +377,42 @@ class executionModel extends model /* Update the path. */ if($this->config->systemMode == 'new') $this->setTreePath($executionID); - /* Copy team of execution. */ - if($copyExecutionID != '') + /* Set team of execution. */ + $members = isset($_POST['teamMembers']) ? $_POST['teamMembers'] : array(); + $roles = $this->loadModel('user')->getUserRoles(array_keys($members)); + foreach($members as $account) { - $members = $this->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($copyExecutionID)->andWhere('type')->eq('execution')->fetchAll(); - foreach($members as $member) - { - unset($member->id); - $member->root = $executionID; - $member->join = $today; - $member->days = $sprint->days; - $member->type = 'execution'; - $this->dao->insert(TABLE_TEAM)->data($member)->exec(); - if($member->account == $this->app->user->account) $creatorExists = true; - } - } + if(empty($account)) continue; - /* Add the creator to team. */ - if($copyExecutionID == '' or !$creatorExists) - { - $this->app->loadLang('user'); - $member = new stdclass(); + $member = new stdClass(); $member->root = $executionID; - $member->account = $this->app->user->account; - $member->role = zget($this->lang->user->roleList, $this->app->user->role, ''); - $member->join = $today; $member->type = 'execution'; + $member->account = $account; + $member->role = zget($roles, $account, ''); + $member->join = $today; $member->days = $sprint->days; $member->hours = $this->config->execution->defaultWorkhours; $this->dao->insert(TABLE_TEAM)->data($member)->exec(); - - if($this->config->systemMode == 'new') $this->addProjectMembers($sprint->project, array($member)); + if($member->account == $this->app->user->account) $creatorExists = true; + $teamMembers[$account] = $member; } + if(!$creatorExists) + { + $member = new stdClass(); + $member->root = $executionID; + $member->type = 'execution'; + $member->account = $this->app->user->account; + $member->role = zget($this->lang->user->roleList, $this->app->user->role, ''); + $member->join = $today; + $member->days = $sprint->days; + $member->hours = $this->config->execution->defaultWorkhours; + $this->dao->insert(TABLE_TEAM)->data($member)->exec(); + $teamMembers[$member->account] = $member; + } + + if($this->config->systemMode == 'new') $this->addProjectMembers($sprint->project, $teamMembers); + /* Create doc lib. */ $this->app->loadLang('doc'); $lib = new stdclass(); @@ -2439,6 +2443,35 @@ class executionModel extends model ->fetchAll('account'); } + /** + * Get the project and execution the team through the projectID. + * + * @param int $projectID + * @access public + * @return array + */ + public function getTeamPairsByProject($projectID = 0) + { + $teams = $this->dao->select('id,team,type')->from(TABLE_PROJECT) + ->where('deleted')->eq(0) + ->andWhere('project')->eq($projectID) + ->orWhere('id')->eq($projectID) + ->fetchAll('id'); + + if(empty($teams)) return array(); + + $teamPairs = array(); + foreach($teams as $id => $team) + { + if(empty($team->team)) continue; + + $object = $team->type == 'project' ? $this->lang->project->common . '-' : $this->lang->execution->common . '-'; + $teamPairs[$id] = $object . $team->team; + } + + return $teamPairs; + } + /** * Manage team members. * diff --git a/module/execution/view/create.html.php b/module/execution/view/create.html.php index 707b4290f0..df69b0c8b1 100644 --- a/module/execution/view/create.html.php +++ b/module/execution/view/create.html.php @@ -50,13 +50,13 @@ execution->project;?> - + systemMode == 'new')) ? $lang->execution->execName : $lang->execution->name;?> - + systemMode == 'new')) ? $lang->execution->execCode : $lang->execution->code;?> @@ -82,13 +82,9 @@ - - execution->teamname;?> - - systemMode == 'new')) ? $lang->execution->execType : $lang->execution->type;?> - execution->lifeTimeList, '', "class='form-control' onchange='showLifeTimeTips()'"); ?> + execution->lifeTimeList, '', "class='form-control chosen' onchange='showLifeTimeTips()'"); ?>
execution->typeDesc;?>
@@ -144,6 +140,19 @@ + + execution->teamname;?> + + + + + execution->copyTeam;?> + execution->copyTeamTip}'"); ?> + + + execution->team;?> + + systemMode == 'new')) ? $lang->execution->execDesc : $lang->execution->desc;?>