* Adjust actions map for program browse page.

This commit is contained in:
wangyidong
2023-06-20 14:05:05 +08:00
parent 8d7c6ef781
commit 469b490039
6 changed files with 201 additions and 176 deletions
+18 -18
View File
@@ -431,24 +431,24 @@ $config->program->browse->dtable->fieldList['actions']['type'] = 'actions'
$config->program->browse->dtable->fieldList['actions']['fixed'] = 'right';
$config->program->browse->dtable->fieldList['actions']['actionsMap'] = array
(
'program_start' => array('icon' => 'icon-start', 'hint' => $lang->program->start),
'program_suspend' => array('icon' => 'icon-pause', 'hint' => $lang->program->suspend),
'program_close' => array('icon' => 'icon-off', 'hint' => $lang->program->close),
'program_activate' => array('icon' => 'icon-active', 'hint' => $lang->program->activate),
'program_other' => array('caret' => true, 'hint' => $lang->other, 'type' => 'dropdown'),
'program_edit' => array('icon' => 'icon-edit', 'hint' => $lang->program->edit),
'program_create' => array('icon' => 'icon-split', 'hint' => $lang->program->create),
'program_start' => array('icon' => 'icon-start', 'hint' => $lang->program->start, 'url' => helper::createLink('program', 'start', "programID={id}"), 'data-toggle' => 'modal'),
'program_suspend' => array('icon' => 'icon-pause', 'hint' => $lang->program->suspend, 'url' => helper::createLink('program', 'suspend', "programID={id}"), 'data-toggle' => 'modal'),
'program_close' => array('icon' => 'icon-off', 'hint' => $lang->program->close, 'url' => helper::createLink('program', 'close', "programID={id}"), 'data-toggle' => 'modal'),
'program_activate' => array('icon' => 'icon-active', 'hint' => $lang->program->activate, 'url' => helper::createLink('program', 'activate', "programID={id}"), 'data-toggle' => 'modal'),
'program_other' => array('caret' => true, 'hint' => $lang->other, 'type' => 'dropdown'),
'program_edit' => array('icon' => 'icon-edit', 'hint' => $lang->program->edit, 'url' => helper::createLink('program', 'edit', "programID={id}")),
'program_create' => array('icon' => 'icon-split', 'hint' => $lang->program->create, 'url' => helper::createLink('program', 'create', "programID={id}")),
'program_delete' => array('icon' => 'icon-trash', 'hint' => $lang->program->delete),
'project_start' => array('icon' => 'icon-start', 'hint' => $lang->project->start),
'project_suspend' => array('icon' => 'icon-pause', 'hint' => $lang->project->suspend),
'project_close' => array('icon' => 'icon-off', 'hint' => $lang->project->close),
'project_activate' => array('icon' => 'icon-active', 'hint' => $lang->project->activate),
'project_other' => array('caret' => true, 'hint' => $lang->project->other, 'type' => 'dropdown'),
'project_edit' => array('icon' => 'icon-edit', 'hint' => $lang->project->edit),
'project_team' => array('icon' => 'icon-groups', 'hint' => $lang->project->manageMembers),
'project_group' => array('icon' => 'icon-lock', 'hint' => $lang->project->group),
'project_more' => array('icon' => 'icon-ellipsis-v', 'hint' => $lang->project->moreActions, 'type' => 'dropdown', 'caret' => false),
'project_link' => array('icon' => 'icon-link', 'hint' => $lang->project->manageProducts),
'project_whitelist' => array('icon' => 'icon-shield-check', 'hint' => $lang->project->whitelist),
'project_start' => array('icon' => 'icon-start', 'hint' => $lang->project->start, 'url' => helper::createLink('project', 'start', "projectID={id}"), 'data-toggle' => 'modal'),
'project_suspend' => array('icon' => 'icon-pause', 'hint' => $lang->project->suspend, 'url' => helper::createLink('project', 'suspend', "projectID={id}"), 'data-toggle' => 'modal'),
'project_close' => array('icon' => 'icon-off', 'hint' => $lang->project->close, 'url' => helper::createLink('project', 'close', "projectID={id}"), 'data-toggle' => 'modal'),
'project_activate' => array('icon' => 'icon-active', 'hint' => $lang->project->activate, 'url' => helper::createLink('project', 'activate', "projectID={id}"), 'data-toggle' => 'modal'),
'project_other' => array('caret' => true, 'hint' => $lang->project->other, 'type' => 'dropdown'),
'project_edit' => array('icon' => 'icon-edit', 'hint' => $lang->project->edit, 'url' => helper::createLink('project', 'edit', "projectID={id}")),
'project_team' => array('icon' => 'icon-groups', 'hint' => $lang->project->manageMembers, 'url' => helper::createLink('project', 'team', "projectID={id}")),
'project_group' => array('icon' => 'icon-lock', 'hint' => $lang->project->group, 'url' => helper::createLink('project', 'group', "projectID={id}")),
'project_more' => array('icon' => 'icon-ellipsis-v', 'hint' => $lang->project->moreActions, 'type' => 'dropdown', 'caret' => false),
'project_link' => array('icon' => 'icon-link', 'hint' => $lang->project->manageProducts, 'url' => helper::createLink('project', 'manageProducts', "projectID={id}")),
'project_whitelist' => array('icon' => 'icon-shield-check', 'hint' => $lang->project->whitelist, 'url' => helper::createLink('project', 'whitelist', "projectID={id}")),
'project_delete' => array('icon' => 'icon-trash', 'hint' => $lang->project->delete)
);
+11
View File
@@ -28,6 +28,17 @@ window.renderCell = function(result, {col, row})
return result;
}
window.confirmDelete = function(projectID, module, projectName)
{
var deleteURL = $.createLink(module, 'delete', "projectID=" + projectID);
if(module == 'program') deleteURL = $.createLink('program', 'delete', "programID=" + projectID + '&confirm=yes');
zui.Modal.confirm({message: confirmDeleteLang[module].replace('%s', projectName), icon:'icon-info-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) =>
{
if(res) $.get(deleteURL, function(){loadCurrentPage();});
});
}
$(document).on('click', '.batch-btn', function()
{
const $this = $(this);
+1 -1
View File
@@ -113,7 +113,7 @@ $lang->program->dateExceedChild = "项目集的起止日期已不包含子项
$lang->program->closeErrorMessage = "存在子项目集或{$lang->projectCommon}为未关闭状态";
$lang->program->hasChildren = "该项目集有子项目集或{$lang->projectCommon}存在,不能删除。";
$lang->program->hasProduct = "该项目集有{$lang->productCommon}存在,不能删除。";
$lang->program->confirmDelete = '您确定要删除\“%s\”项目集吗?';
$lang->program->confirmDelete = '您确定要删除“%s”项目集吗?';
$lang->program->confirmUnlink = '您确定要移除干系人吗?';
$lang->program->readjustTime = '重新调整项目集起止时间';
$lang->program->accessDenied = '你无权访问该项目集';
+6 -155
View File
@@ -1236,8 +1236,9 @@ class programModel extends model
if(!isset($program->type)) return true;
if($action == 'close') return $program->status != 'closed';
if($action == 'activate') return $program->status == 'done' or $program->status == 'closed';
if($action == 'suspend') return $program->status == 'wait' or $program->status == 'doing';
if($action == 'activate') return $program->status == 'done' || $program->status == 'closed';
if($action == 'suspend') return $program->status == 'wait' || $program->status == 'doing';
if($action == 'start') return $program->status == 'wait' || $program->status == 'suspended';
return true;
}
@@ -1732,158 +1733,8 @@ class programModel extends model
*/
public function buildActions($program)
{
$this->loadModel('project');
$actionsMap = array();
$canStartProgram = common::hasPriv('program', 'start');
$canSuspendProgram = common::hasPriv('program', 'suspend');
$canCloseProgram = common::hasPriv('program', 'close');
$canActivateProgram = common::hasPriv('program', 'activate');
$canStartProject = common::hasPriv('project', 'start');
$canSuspendProject = common::hasPriv('project', 'suspend');
$canCloseProject = common::hasPriv('project', 'close');
$canActivateProject = common::hasPriv('project', 'activate');
if($program->type == 'program' && strpos(",{$this->app->user->view->programs},", ",$program->id,") !== false)
{
$normalActions = array('start', 'close', 'activate');
foreach($normalActions as $action)
{
if($action == 'start' and (!$canStartProgram or ($program->status != 'wait' and $program->status != 'suspended'))) continue;
if($action == 'close' and (!$canCloseProgram or $program->status != 'doing')) continue;
if($action == 'activate' and (!$canActivateProgram or $program->status != 'closed')) continue;
$item = new stdclass();
$item->name = $action;
$item->hint = $this->lang->program->$action;
$actionsMap[] = $item;
}
$canCloseCurrentProgram = $canCloseProgram && $program->status != 'doing';
$canActivateCurrentProgram = $canActivateProgram && $program->status != 'closed';
if($canSuspendProgram or $canCloseCurrentProgram or $canActivateCurrentProgram)
{
$other = new stdclass();
$other->name = 'other';
$other->items = array();
$otherActions = array('suspend', 'close', 'activate');
foreach($otherActions as $action)
{
if($action == 'close' and $program->status == 'doing') continue;
if(!common::hasPriv('program', $action)) continue;
$item = new stdclass();
$item->name = $action;
$item->text = $this->lang->program->$action;
if(!$this->isClickable($program, $action)) $item->disabled = true;
if($action == 'close' and $program->status == 'closed') $item->hint = $this->lang->program->tip->closed;
if($action == 'suspend' and $program->status == 'closed') $item->hint = $this->lang->program->tip->notSuspend;
if($action == 'suspend' and $program->status == 'suspended') $item->hint = $this->lang->program->tip->suspended;
if($action == 'activate' and $program->status == 'doing') $item->hint = $this->lang->program->tip->actived;
$other->items[] = $item;
}
$actionsMap[] = $other;
}
$normalActions = array('edit', 'create', 'delete');
foreach($normalActions as $action)
{
if(!common::hasPriv('program', $action)) continue;
$item = new stdclass();
$item->name = $action;
$item->hint = $this->lang->program->$action;
if($action == 'create' and $program->status == 'closed')
{
$item->disabled = true;
$item->hint = $this->lang->program->tip->notCreate;
}
$actionsMap[] = $item;
}
}
elseif($program->type == 'project')
{
$normalActions = array('start', 'close', 'activate');
foreach($normalActions as $action)
{
if($action == 'start' and (!$canStartProject or ($program->status != 'wait' and $program->status != 'suspended'))) continue;
if($action == 'close' and (!$canCloseProject or $program->status != 'doing')) continue;
if($action == 'activate' and (!$canActivateProgram or $program->status != 'closed')) continue;
$item = new stdclass();
$item->name = $action;
$item->hint = $this->lang->project->$action;
$actionsMap[] = $item;
}
if($canSuspendProject or ($canCloseProject and $program->status != 'doing') or ($canActivateProject and $program->status != 'closed'))
{
$other = new stdclass();
$other->name = 'other';
$other->items = array();
$otherActions = array('suspend', 'close', 'activate');
foreach($otherActions as $action)
{
if($action == 'close' and $program->status == 'doing') continue;
if(!common::hasPriv('project', $action)) continue;
$item = new stdclass();
$item->name = $action;
$item->text = $this->lang->project->$action;
if(!$this->project->isClickable($program, $action)) $item->disabled = true;
if($action == 'close' and $program->status == 'closed') $item->hint = $this->lang->project->tip->closed;
if($action == 'suspend' and $program->status == 'closed') $item->hint = $this->lang->project->tip->notSuspend;
if($action == 'suspend' and $program->status == 'suspended') $item->hint = $this->lang->project->tip->suspended;
if($action == 'activate' and $program->status == 'doing') $item->hint = $this->lang->project->tip->actived;
$other->items[] = $item;
}
$actionsMap[] = $other;
}
if(common::hasPriv('project', 'edit')) $actionsMap[] = 'edit';
if(common::hasPriv('project', 'team')) $actionsMap[] = 'team';
if(common::hasPriv('project', 'manageProducts') || common::hasPriv('project', 'whitelist') || common::hasPriv('project', 'delete'))
{
$more = new stdclass();
$more->name = 'more';
$more->items = array();
$moreActions = array('group', 'manageProducts', 'whitelist', 'delete');
foreach($moreActions as $action)
{
if($aciton == 'group' && common::hasPriv('project', 'group'))
{
$item = new stdclass();
$item->name = 'group';
if($program->model == 'kanban')
{
$item->disabled = true;
$item->hint = $this->lang->project->tip->group;
}
$more->items[] = $item;
continue;
}
if(!common::hasPriv('project', $action)) continue;
$item = new stdclass();
$item->name = $action == 'manageProducts' ? 'link' : $action;
$item->text = $this->lang->project->$action;
if($action == 'whitelist' and $program->acl == 'open')
{
$item->disabled = true;
$item->hint = $this->lang->project->tip->whitelist;
}
$more->items[] = $item;
}
$actionsMap[] = $more;
}
}
return $actionsMap;
if($program->type == 'program') return $this->programTao->buildProgramActionsMap($program);
if($program->type == 'project') return $this->programTao->buildProjectActionsMap($program);
return array();
}
}
+159
View File
@@ -47,5 +47,164 @@ class programTao extends programModel
->orderBy('order_asc')
->fetchAll();
}
/**
* 构建项目视图的项目集的操作数据。
* Build actions map for program.
*
* @param object $program
* @access protected
* @return array
*/
protected function buildProgramActionsMap(object $program): array
{
if($program->type == 'program' && !str_contains(",{$this->app->user->view->programs},", ",$program->id,")) return array();
$actionsMap = array();
$canStartProgram = common::hasPriv('program', 'start');
$canSuspendProgram = common::hasPriv('program', 'suspend');
$canCloseProgram = common::hasPriv('program', 'close');
$canActivateProgram = common::hasPriv('program', 'activate');
$normalActions = array('start', 'close', 'activate');
foreach($normalActions as $action)
{
if($action == 'start' && (!$canStartProgram || ($program->status != 'wait' && $program->status != 'suspended'))) continue;
if($action == 'close' && (!$canCloseProgram || $program->status != 'doing')) continue;
if($action == 'activate' && (!$canActivateProgram || $program->status != 'closed')) continue;
$actionsMap[] = $action;
break;
}
if($canSuspendProgram || ($canCloseProgram && $program->status != 'doing') || ($canActivateProgram && $program->status != 'closed'))
{
$other = new stdclass();
$other->name = 'other';
$other->items = array();
$otherActions = array('suspend', 'close', 'activate');
foreach($otherActions as $action)
{
if($action == 'close' && $program->status == 'doing') continue;
if(!common::hasPriv('program', $action)) continue;
$item = new stdclass();
$item->name = $action;
if(!static::isClickable($program, $action)) $item->disabled = true;
if($action == 'close' && $program->status == 'closed') $item->hint = $this->lang->program->tip->closed;
if($action == 'suspend' && $program->status == 'closed') $item->hint = $this->lang->program->tip->notSuspend;
if($action == 'suspend' && $program->status == 'suspended') $item->hint = $this->lang->program->tip->suspended;
if($action == 'activate' && $program->status == 'doing') $item->hint = $this->lang->program->tip->actived;
$other->items[] = $item;
}
$actionsMap[] = $other;
}
$normalActions = array('edit', 'create', 'delete');
foreach($normalActions as $action)
{
if(!common::hasPriv('program', $action)) continue;
$item = new stdclass();
$item->name = $action;
if($action == 'delete') $item->url = "javascript:confirmDelete({$program->id}, 'program', '{$program->name}')";
if($action == 'create' and $program->status == 'closed')
{
$item->disabled = true;
$item->hint = $this->lang->program->tip->notCreate;
}
$actionsMap[] = $item;
}
return $actionsMap;
}
/**
* 构建项目视角中项目的操作数据。
* Build actions map for project.
*
* @param object $project
* @access protected
* @return array
*/
protected function buildProjectActionsMap(object $project): array
{
$this->loadModel('project');
$actionsMap = array();
$canStartProject = common::hasPriv('project', 'start');
$canSuspendProject = common::hasPriv('project', 'suspend');
$canCloseProject = common::hasPriv('project', 'close');
$canActivateProject = common::hasPriv('project', 'activate');
$normalActions = array('start', 'close', 'activate');
foreach($normalActions as $action)
{
if($action == 'start' && (!$canStartProject || ($project->status != 'wait' && $project->status != 'suspended'))) continue;
if($action == 'close' && (!$canCloseProject || $project->status != 'doing')) continue;
if($action == 'activate' && (!$canActivateProject || $project->status != 'closed')) continue;
$actionsMap[] = $action;
break;
}
if($canSuspendProject || ($canCloseProject && $project->status != 'doing') || ($canActivateProject && $project->status != 'closed'))
{
$other = new stdclass();
$other->name = 'other';
$other->items = array();
$otherActions = array('suspend', 'close', 'activate');
foreach($otherActions as $action)
{
if($action == 'close' and $project->status == 'doing') continue;
if(!common::hasPriv('project', $action)) continue;
$item = new stdclass();
$item->name = $action;
if(!projectModel::isClickable($project, $action)) $item->disabled = true;
if($action == 'close' && $project->status == 'closed') $item->hint = $this->lang->project->tip->closed;
if($action == 'suspend' && $project->status == 'closed') $item->hint = $this->lang->project->tip->notSuspend;
if($action == 'suspend' && $project->status == 'suspended') $item->hint = $this->lang->project->tip->suspended;
if($action == 'activate' && $project->status == 'doing') $item->hint = $this->lang->project->tip->actived;
$other->items[] = $item;
}
$actionsMap[] = $other;
}
if(common::hasPriv('project', 'edit')) $actionsMap[] = 'edit';
if(common::hasPriv('project', 'team')) $actionsMap[] = 'team';
if(common::hasPriv('project', 'manageProducts') || common::hasPriv('project', 'whitelist') || common::hasPriv('project', 'delete'))
{
$more = new stdclass();
$more->name = 'more';
$more->items = array();
$moreActions = array('group', 'manageProducts', 'whitelist', 'delete');
foreach($moreActions as $action)
{
if(!common::hasPriv('project', $action)) continue;
$item = new stdclass();
$item->name = $action == 'manageProducts' ? 'link' : $action;
if($action == 'delete') $item->url = "javascript:confirmDelete({$project->id}, 'project', '{$project->name}')";
if($action == 'whitelist' and $project->acl == 'open')
{
$item->disabled = true;
$item->hint = $this->lang->project->tip->whitelist;
}
if($action == 'group' && $project->model == 'kanban')
{
$item->disabled = true;
$item->hint = $this->lang->project->tip->group;
}
$more->items[] = $item;
}
$actionsMap[] = $more;
}
return $actionsMap;
}
}
+6 -2
View File
@@ -1,6 +1,10 @@
<?php
namespace zin;
$confirmDeleteLang['program'] = $lang->program->confirmDelete;
$confirmDeleteLang['project'] = $lang->project->confirmDelete;
jsVar('confirmDeleteLang', $confirmDeleteLang);
$cols = $this->loadModel('datatable')->getSetting('program');
$data = array();
foreach($programs as $program)
@@ -45,8 +49,8 @@ foreach($programs as $program)
$actions = $this->program->buildActions($program);
foreach($actions as $action)
{
if(is_object($action)) $action->name = $program->type . '_' . $action->name;
else $action = $program->type . '_' . $action;
if(is_object($action)) $action->name = $program->type . '_' . $action->name;
if(!is_object($action)) $action = $program->type . '_' . $action;
if(isset($action->items)) foreach($action->items as $idx => $item) $action->items[$idx]->name = $program->type . '_' . $item->name;
$program->actions[] = $action;