zin 转换工具
zin 辅助工具用于将禅道传统的 view 视图实现方式转换为 zin 的方式。
使用步骤
- 修改
config/my.php配置文件:
php
$config->debug = true; // 使用 DEBUG 模式
$config->zinTool = true; // 使用 zin 转换工具- 完整刷新禅道首页,并在应用标签内打开待转换的传统视图。调试模式下,传统页头会加载
www/js/zui3/zintool.js。 - 点击首页全局栏的 zin() 按钮,工具读取当前应用 iframe 中的页面并显示转换结果。
- 对话框内容为 zin 视图辅助文件,点击 Copy to clipboard 按钮并粘贴至对应文件。
提示
禅道 zin 转换工具不会生成新的视图文件覆盖之前的文件。需要注意的是当从一个 zin 页面转到传统页面时,zin 工具可能无法正常工作,这时只需要使用浏览器重新刷新一下页面即可。
zin 视图辅助文件
工具根据旧页面生成 PHP 草稿,其中包含页面结构、数据变量和迁移提示。在 module/<模块>/ui/ 中补齐草稿里的数据、事件和权限判断。生成器会在末尾附上 render();,当前框架由控制器调用 renderPage() 完成输出,迁移后可省略这行。
下面为通过 zin 转换工具生成的视图辅助文件示例,包括 bug 列表页面和创建 bug 页面:
php
<?php
declare(strict_types=1);
/**
* The browse view file of bug 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 yourname<yourname@easycorp.ltd>
* @package bug
* @link http://www.zentao.net
*/
/*
======= Attention ======
This file is generated by zin-tool, you should check the following to-do list.
+ Familiar with the use of these widgets in zin: featureBar, sidebar, dtable.
+ Check the following variables which used in widgets: $dtableCols, $dtableRows, $dtableToolbar.
+ Check the undefined items definition in featureBar widget.
+ Check the 3 items definition in toolbar widget.
+ Check the origin code in module/bug/view/browse.html.php, and ensure that all features have been implemented.
+ Check the origin js code in module/bug/js/common.js and module/bug/js/browse.js
+ Check the origin css code in module/bug/css/common.css and module/bug/css/browse.css
+ Remove the comments which start with "zin:"
+ Test according to the new design draft and the original implementation
*/
namespace zin;
/* ====== Preparing and processing page data ====== */
/* zin: Set variables to define columns and rows data for dtable */
$dtableCols = array();
$dtableRows = array();
$dtableToolbar = array();
/* ====== Define the page structure with zin widgets ====== */
/* zin: Define the feature bar on main menu */
featureBar
(
set::current($browseType),
li(searchToggle())
);
/* zin: Define the toolbar on main menu */
toolbar
(
item(set(array
(
'icon' => $lang->icons->report,
'text' => $lang->story->report->common,
'class' => "ghost"
))),
item(set(array
(
'type' => "btnGroup",
'items' => array(array
(
'icon' => $lang->icons->export,
'text' => $lang->project->export,
'class' => "ghost dropdown-toggle",
'type' => "dropdown",
'items' => array($lang->product->export)
))
))),
item(set(array
(
'type' => "btnGroup",
'items' => array(array
(
'icon' => $lang->icons->create,
'text' => $lang->bug->create,
'class' => "primary create-bug-btn"
), array
(
'text' => "",
'class' => "primary dropdown-toggle",
'type' => "dropdown",
'items' => array($lang->bug->create, $lang->bug->batchCreate)
))
)))
);
/* zin: Define the sidebar in main content */
sidebar
(
moduleMenu()
);
/* zin: Define the dtable in main content */
dtable
(
set::className('shadow rounded'),
set::cols($dtableCols),
set::data($dtableRows),
set::plugins(array("checkable")),
set::checkable(true),
set::toolbar($dtableToolbar),
set::footPager(usePager()),
set::footer(array("checkbox", "divider", "toolbar", "toolbar", "本页共 14 个Bug,未解决 14。", "flex", "pager"))
);
/* ====== Render page ====== */
render();php
<?php
declare(strict_types=1);
/**
* The create view file of bug 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 yourname<yourname@easycorp.ltd>
* @package bug
* @link http://www.zentao.net
*/
/*
======= Attention ======
This file is generated by zin-tool, you should check the following to-do list.
+ Familiar with the use of these widgets in zin: formPanel, formRow, inputGroup, input, control.
+ Check the following variables which used in widgets: $productOptions, $moduleOptions, $projectOptions, $openedBuildOptions, $assignedToOptions, $typeOptions, $storyOptions, $taskOptions, $mailtoOptions, $contactListMenuOptions.
+ Check the origin code in module/bug/view/create.html.php, and ensure that all features have been implemented.
+ Check the origin js code in module/bug/js/common.js and module/bug/js/create.js
+ Check the origin css code in module/bug/css/common.css and module/bug/css/create.css
+ Remove the comments which starts with "zin:"
+ Test according to the new design draft and the original implementation
*/
namespace zin;
/* ====== Preparing and processing page data ====== */
/* zin: Set variables to define picker options for form */
$formTitle = $lang->bug->create;
$productOptions = array();
$moduleOptions = array();
$projectOptions = array(array('value' => $moduleID, 'text' => ""), array('value' => "1334", 'text' => $productName));
$openedBuildOptions = array();
$assignedToOptions = array();
$typeOptions = array(array('value' => "", 'text' => ""), array('value' => $type, 'text' => "代码错误"), array('value' => "config", 'text' => "配置相关"), array('value' => "install", 'text' => "安装部署"), array('value' => "security", 'text' => "安全相关"));
$storyOptions = array();
$taskOptions = array(array('value' => $moduleID, 'text' => ""));
$mailtoOptions = array();
$contactListMenuOptions = array();
/* ====== Define the page structure with zin widgets ====== */
/* zin: Define the form in main content */
formPanel
(
set::title($formTitle), // The form title is diffrent from the page title,
formRow
(
formGroup
(
set::width("1/3"),
set::label($lang->todo->product),
inputGroup
(
control(set(array
(
'name' => $lang->program->menuOrder[5],
'id' => $lang->program->menuOrder[5],
'value' => $productID,
'disabled' => $stepsRequired,
'type' => "picker",
'onchange' => "loadAll",
'items' => $productOptions
)))
)
),
formGroup
(
set::width("1/3"),
inputGroup
(
$lang->story->module,
control(set(array
(
'name' => "module",
'id' => "module",
'value' => $moduleID,
'disabled' => $stepsRequired,
'type' => "picker",
'onchange' => "loadModuleRelated",
'items' => $moduleOptions
)))
)
)
),
formRow
(
formGroup
(
set::width("1/3"),
set::name("project"),
set::label($lang->my->projects),
set::value("0"),
set::control("picker"),
set::items($projectOptions)
),
formGroup
(
set::width("1/3"),
inputGroup
(
$lang->bug->openedBuild,
control(set(array
(
'name' => "openedBuild[]",
'id' => $field,
'value' => NULL,
'disabled' => $stepsRequired,
'type' => "picker",
'items' => $openedBuildOptions,
'multiple' => $isStepsTemplate
))),
"",
btn(set(array
(
'type' => "btn",
'text' => $lang->product->allStory,
'class' => "input-group-btn"
)))
)
)
),
formRow
(
formGroup
(
set::width("1/3"),
set::label($lang->story->report->storysPerAssignedTo->graph->xAxisName),
inputGroup
(
control(set(array
(
'name' => "assignedTo",
'id' => "assignedTo",
'value' => $assignedTo,
'disabled' => $stepsRequired,
'type' => "picker",
'items' => $assignedToOptions
))),
btn(set(array
(
'type' => "btn",
'text' => $lang->bug->allUsers,
'class' => "input-group-btn"
)))
)
),
formGroup
(
set::width("1/3"),
inputGroup
(
$lang->task->deadline
)
)
),
formRow
(
formGroup
(
set::width("1/3"),
set::name("feedbackBy"),
set::label($lang->story->feedbackBy),
set::control("text")
),
formGroup
(
set::width("1/3"),
inputGroup
(
$lang->story->notifyEmail
)
)
),
formGroup
(
set::width("1/3"),
set::name("type"),
set::label($lang->bug->type),
set::value("codeerror"),
set::control("picker"),
set::items($typeOptions)
),
formGroup
(
set::width("2/3"),
set::label($lang->bug->title),
inputGroup
(
$lang->bug->severity,
btn(set(array
(
'type' => "btn",
'text' => "1\n2\n3\n4\n1234",
'class' => "input-group-btn pri-selector"
))),
$lang->my->pri,
btn(set(array
(
'type' => "btn",
'text' => "3 \n \n \n \n1\n2\n3\n4\n1234",
'class' => "input-group-btn pri-selector"
)))
)
),
formGroup
(
set::width("2/3"),
set::label($lang->bug->steps),
inputGroup
(
control(set(array
(
'id' => "title",
'value' => "",
'disabled' => $stepsRequired,
'type' => "text"
))),
$lang->public,
btn(set(array
(
'type' => "btn",
'text' => $lang->save,
'class' => "input-group-btn"
)))
)
),
formRow
(
formGroup
(
set::width("1/3"),
set::name("story"),
set::label($lang->bug->story),
set::value("0"),
set::control("picker"),
set::items($storyOptions)
),
formGroup
(
set::width("1/3"),
inputGroup
(
$lang->story->tasks,
control(set(array
(
'name' => $lang->my->menu->work->subModule,
'id' => $lang->my->menu->work->subModule,
'value' => $moduleID,
'disabled' => $stepsRequired,
'type' => "picker",
'items' => $taskOptions
)))
)
)
),
formRow
(
formGroup
(
set::width("1/3"),
set::label($lang->product->mailto),
inputGroup
(
control(set(array
(
'name' => "mailto[]",
'id' => "mailto",
'value' => NULL,
'disabled' => $stepsRequired,
'type' => "picker",
'items' => $mailtoOptions,
'multiple' => $isStepsTemplate
))),
control(set(array
(
'name' => "contactListMenu",
'id' => "contactListMenu",
'value' => "",
'disabled' => $stepsRequired,
'type' => "picker",
'onchange' => "setMailto",
'items' => $contactListMenuOptions
)))
)
),
formGroup
(
set::width("1/3"),
inputGroup
(
$lang->story->keywords,
control(set(array
(
'name' => "keywords",
'id' => "keywords",
'value' => "",
'disabled' => $stepsRequired,
'type' => "text"
)))
)
)
),
formGroup
(
set::width("2/3"),
set::name("files[]"),
set::label($lang->story->files),
set::control("file")
)
);
/* ====== Render page ====== */
render();以 Bug 列表页为例,先补齐列定义、行数据和工具栏配置,再对照原视图逐项检查搜索、筛选和列表操作。核对 module/bug/js/ 和 module/bug/css/ 中的模块公共文件、方法专用文件,把页面仍需的交互和样式迁入对应的 .ui.js、.ui.css。验证通过后,可以移除已处理的 zin: 注释。
实现原理
禅道 zin 转换工具会读取原始页面中的内容,然后做如下处理:
- 提取页面关键特征,包括模块名、方法名、页面内元素 ID、类名、特定的 JS 函数调用、ZUI 组件的使用情况等
- 根据关键特征确定页面布局,包括列表页、详情页、表单页、批量表单页等
- 根据页面布局,进一步检查页面内用到的组件,包括侧边栏、导航、工具栏、表格、表单等
- 生成使用 zin 来实现此页面的结构,并定义相关数据变量
- 输出视图辅助文件并增加必要注释