From d671cd644cbfd496c73888a02a4fd79c90c3ba54 Mon Sep 17 00:00:00 2001 From: leiyong <1549684884@qq.com> Date: Tue, 22 Sep 2020 13:08:17 +0800 Subject: [PATCH] * Adjust project creation logic. --- module/common/lang/zh-cn.php | 2 +- module/program/config.php | 8 ++- module/program/control.php | 73 ++++++++++++++++++-------- module/program/css/prjcreate.css | 10 ++++ module/program/js/prjcreate.js | 20 +++++++ module/program/model.php | 36 +++++++++---- module/program/view/prjcreate.html.php | 40 ++++---------- 7 files changed, 125 insertions(+), 64 deletions(-) create mode 100644 module/program/css/prjcreate.css create mode 100644 module/program/js/prjcreate.js diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 5e9a4885be..1df83f794f 100755 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -123,7 +123,7 @@ $lang->common->common = '公有模块'; $lang->mainNav = new stdclass(); $lang->mainNav->my = ' 地盘|my|index|'; $lang->mainNav->program = ' 项目集|program|pgmindex|'; -$lang->mainNav->product = ' 产品|product|productlist|'; +$lang->mainNav->product = ' 产品|product|all|'; $lang->mainNav->project = ' 项目|program|prjbrowse|'; $lang->mainNav->system = ' 组织|custom|estimate|'; $lang->mainNav->admin = ' 后台|admin|index|'; diff --git a/module/program/config.php b/module/program/config.php index fd2425e388..e0fb96fdb9 100644 --- a/module/program/config.php +++ b/module/program/config.php @@ -9,8 +9,12 @@ $config->program->editor->pgmactivate = array('id' => 'comment', 'tools' => 'sim $config->program->editor->pgmfinish = array('id' => 'comment', 'tools' => 'simpleTools'); $config->program->editor->pgmsuspend = array('id' => 'comment', 'tools' => 'simpleTools'); -$config->program->editor->prjcreate = array('id' => 'desc', 'tools' => 'simpleTools'); -$config->program->editor->prjedit = array('id' => 'desc', 'tools' => 'simpleTools'); +$config->program->editor->prjcreate = array('id' => 'desc', 'tools' => 'simpleTools'); +$config->program->editor->prjedit = array('id' => 'desc', 'tools' => 'simpleTools'); +$config->program->editor->prjclose = array('id' => 'comment', 'tools' => 'simpleTools'); +$config->program->editor->prjsuspend = array('id' => 'comment', 'tools' => 'simpleTools'); +$config->program->editor->prjstart = array('id' => 'comment', 'tools' => 'simpleTools'); +$config->program->editor->prjactivate = array('id' => 'comment', 'tools' => 'simpleTools'); $config->program->list = new stdclass(); $config->program->list->exportFields = 'id,name,code,template,category,status,begin,end,budget,PM,end,desc'; diff --git a/module/program/control.php b/module/program/control.php index d99713f54d..f8e855a0fe 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -915,12 +915,12 @@ class program extends control * * @param string $template * @param int $programID - * @param int $parentProgramID - * @param int $copyProgramID + * @param string $from PRJ|PGM + * @param int $copyProjectID * @access public * @return void */ - public function PRJCreate($template = 'waterfall', $programID = 0, $from = 'PRJ', $parentProgramID = 0, $copyProgramID = '') + public function PRJCreate($template = 'waterfall', $programID = 0, $from = 'PRJ', $copyProjectID = '') { if($from == 'PRJ') { @@ -952,21 +952,9 @@ class program extends control $acl = 'open'; $privway = 'extend'; - if($parentProgramID) + if($copyProjectID) { - $parentProgram = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($parentProgramID)->fetch(); - if($this->program->checkHasContent($parentProgramID)) - { - echo js::alert($this->lang->program->cannotCreateChild); - die(js::locate('back')); - } - - if(empty($template)) $template = $parentProgram->template; - } - - if($copyProgramID) - { - $copyProgram = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($copyProgramID)->fetch(); + $copyProgram = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($copyProjectID)->fetch(); $name = $copyProgram->name; $code = $copyProgram->code; $team = $copyProgram->team; @@ -981,7 +969,8 @@ class program extends control $this->view->groups = $this->loadModel('group')->getPairs(); $this->view->pmUsers = $this->loadModel('user')->getPairs('noclosed|nodeleted|pmfirst'); - $this->view->programs = array('' => '') + $this->program->getPairsByTemplate($template); + $this->view->programs = array('' => '') + $this->program->getPRJPairsByTemplate($template, $programID); + $this->view->programID = $programID; $this->view->template = $template; $this->view->name = $name; $this->view->code = $code; @@ -989,10 +978,10 @@ class program extends control $this->view->acl = $acl; $this->view->privway = $privway; $this->view->whitelist = $whitelist; - $this->view->parentProgram = $parentProgramID ? $parentProgram : ''; - $this->view->copyProgramID = $copyProgramID; - $this->view->programID = $programID; + $this->view->copyProjectID = $copyProjectID; + $this->view->from = $from; $this->view->programList = $this->program->getParentPairs(); + $this->view->parentProgram = $this->program->getPGMByID($programID); $this->display(); } @@ -1384,4 +1373,46 @@ class program extends control $this->view->actions = $this->loadModel('action')->getList('project', $projectID); $this->display('project', 'close'); } + + /** + * Activate a project. + * + * @param int $projectID + * @access public + * @return void + */ + public function PRJActivate($projectID) + { + $project = $this->program->getPRJByID($projectID); + + if(!empty($_POST)) + { + $this->loadModel('action'); + $changes = $this->project->activate($projectID); + if(dao::isError()) die(js::error(dao::getError())); + + if($this->post->comment != '' or !empty($changes)) + { + $actionID = $this->action->create('program', $projectID, 'Activated', $this->post->comment); + $this->action->logHistory($actionID, $changes); + } + $this->executeHooks($projectID); + die(js::reload('parent.parent')); + } + + $newBegin = date('Y-m-d'); + $dateDiff = helper::diffDate($newBegin, $project->begin); + $newEnd = date('Y-m-d', strtotime($project->end) + $dateDiff * 24 * 3600); + + $this->view->title = $this->lang->project->activate; + $this->view->position[] = $this->lang->project->activate; + + $this->view->project = $project; + $this->view->users = $this->loadModel('user')->getPairs('noletter'); + $this->view->actions = $this->loadModel('action')->getList('project', $projectID); + $this->view->newBegin = $newBegin; + $this->view->newEnd = $newEnd; + $this->view->project = $project; + $this->display('project', 'activate'); + } } diff --git a/module/program/css/prjcreate.css b/module/program/css/prjcreate.css new file mode 100644 index 0000000000..6400101703 --- /dev/null +++ b/module/program/css/prjcreate.css @@ -0,0 +1,10 @@ +#copyProjectModal {padding: 0} +#copyProjectModal {padding: 0 2px} +#copyProjectModal > div {position: relative;} +#copyProjectModal a {display: block; min-height: 30px; line-height: 30px; padding: 5px 15px; border: 1px solid #e5e5e5; color: #333; margin: 5px 0; border-radius: 3px;} +#copyProjectModal a > i {display: inline-block; margin-right: 5px;} +#copyProjectModal a:hover {border:1px solid #00a9fc; background-color: #E9F2FB; text-decoration: none} +#copyProjectModal a.active {border-color: #00da88; color: #00da88; background-color: #E5FFE6} +#copyProjectModal a.active:after {position: absolute; content: '\e92f'; font-family: ZentaoIcon; font-size: 20px; right: 25px;} +#copyProjectModal a.cancel {color: #ff5d5d} +#budget {border-right:0px;} diff --git a/module/program/js/prjcreate.js b/module/program/js/prjcreate.js new file mode 100644 index 0000000000..7ae0d41625 --- /dev/null +++ b/module/program/js/prjcreate.js @@ -0,0 +1,20 @@ +$(function() +{ + $('#copyProjects a').click(function(){setCopyProject($(this).data('id')); $('#copyProjectModal').modal('hide')}); + $('#longTime').change(function() + { + if($(this).prop('checked')) + { + $('#end').val('').attr('disabled', 'disabled'); + } + else + { + $('#end').removeAttr('disabled'); + } + }); +}); + +function setCopyProject(copyProjectID) +{ + location.href = createLink('program', 'PRJCreate', 'template=' + template + '&programID=' + programID + '&from=' + from + '©ProjectID=' + copyProjectID); +} diff --git a/module/program/model.php b/module/program/model.php index 95be4163fd..931e5b95dd 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -62,7 +62,7 @@ class programModel extends model /** * Get program pairs by template. * - * @param varchar $template + * @param string $model * @access public * @return void */ @@ -829,7 +829,7 @@ class programModel extends model if($action == 'prjfinish') return $program->status == 'wait' or $program->status == 'doing'; if($action == 'prjclose') return $program->status != 'closed'; if($action == 'prjsuspend') return $program->status == 'wait' or $program->status == 'doing'; - if($action == 'prjactivate') return $program->status == 'done'; + if($action == 'prjactivate') return $program->status == 'done' or $program->status == 'closed'; return true; } @@ -1077,14 +1077,11 @@ class programModel extends model * @access public * @return object */ - public function buildPRJMenuQuery($projectID) + public function buildPRJMenuQuery($projectID = 0) { - $rootProject = $this->getPRJByID($projectID); - $path = ''; - if($rootProject) - { - $path = $rootProject->path; - } + $path = ''; + $program = $this->getPRJByID($projectID); + if($program) $path = $program->path; return $this->dao->select('*')->from(TABLE_PROJECT) ->beginIF($projectID > 0)->where('path')->like($path . '%')->fi() @@ -1092,6 +1089,26 @@ class programModel extends model ->get(); } + /** + * Get project pairs by template. + * + * @param string $model + * @param int $programID + * @access public + * @return void + */ + public function getPRJPairsByTemplate($model, $programID = 0) + { + return $this->dao->select('id, name')->from(TABLE_PROGRAM) + ->where('type')->eq('project') + ->beginIF($programID)->andWhere('parent')->eq($programID)->fi() + ->andWhere('model')->eq($model) + ->andWhere('deleted')->eq(0) + ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->programs)->fi() + ->orderBy('id_desc') + ->fetchPairs(); + } + /** * Get the treemenu of project. * @@ -1161,6 +1178,7 @@ class programModel extends model $project = fixer::input('post') ->setDefault('status', 'wait') ->add('type', 'project') + ->add('lifetime', 'short') ->setIF($this->post->acl != 'custom', 'whitelist', '') ->setDefault('openedBy', $this->app->user->account) ->setDefault('end', '') diff --git a/module/program/view/prjcreate.html.php b/module/program/view/prjcreate.html.php index 4e227ac9d2..89201379fd 100644 --- a/module/program/view/prjcreate.html.php +++ b/module/program/view/prjcreate.html.php @@ -10,30 +10,12 @@ * @link http://www.zentao.net */ ?> - - createLink('project', 'task', 'projectID=' . $projectID);?> - -
- - -