定制 geniv/nette-admin-element 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

geniv/nette-admin-element

Composer 安装命令:

composer require geniv/nette-admin-element

包简介

Admin element extension for Nette Framework

README 文档

README

Installation

$ composer require geniv/nette-admin-element

or

"geniv/nette-admin-element": ">=1.0.0"

require:

"php": ">=7.0.0",
"nette/nette": ">=2.4.0",
"dibi/dibi": ">=3.0.0",
"geniv/nette-thumbnail": ">=1.0.0"

Include in application

neon configure:

# admin element
adminElement:
    elements: [...]

neon configure extension:

extensions:
    adminElement: AdminElement\Bridges\Nette\Extension

presenters - startup:

$this->template->formRendererPath = IWrapperSection::RENDERER_FORM;

presenters - grid table component:

$visualPaginator->setTemplatePath(__DIR__ . '/templates/visualPaginator.latte');
$gridTable->setSortable((bool) $this->getParameter('sortable'));
$gridTable->setVisualPaginator($visualPaginator);
$gridTable->setItemPerPage($this->wrapperSection->getDatabaseLimit());

$gridTable->setTemplatePath(__DIR__ . '/templates/gridTable.latte');
$gridTable->setSource($this->wrapperSection->getSource());
$pk = $this->wrapperSection->getDatabasePk();
$gridTable->setPrimaryKey($pk);
$gridTable->setDefaultOrder($this->wrapperSection->getDatabaseOrderDefault());

$elements = $this->wrapperSection->getElements();

$gridTable->addColumn($pk, '#');

$items = $this->wrapperSection->getItemsByShow(WrapperSection::ACTION_LIST);
foreach ($items as $idItem => $configure) {
    $elem = $elements[$idItem]; // load element
    $column = $gridTable->addColumn($idItem, $elem->getTranslateNameContent());
    $column->setOrdering($configure['ordering']);
    $column->setData($configure);

    $column->setCallback(function ($data) use ($elem) { return $elem->getRenderRow($data); });
    switch ($configure['type']) {
        case 'checkbox':
        case 'foreigncheckbox':
            $column->setTemplatePath(__DIR__ . '/templates/gridTableCheckbox.latte');
            break;

        case  'foreignfkwhere':
            $column->setTemplatePath(__DIR__ . '/templates/gridTableForeignFkWhere.latte');
            break;
    }
}

presenters - action default:

$this->wrapperSection->getById($idSection, WrapperSection::ACTION_LIST);

$this->template->sectionName = $this->wrapperSection->getSectionName();
$this->template->subSectionName = $this->wrapperSection->getSubsectionName($idSubSection);

$this->template->idSubSection = $this->idSubSection = $idSubSection;
if ($idSubSection) {
    $this->wrapperSection->setSubSectionId($idSubSection);
}

$this->template->page = $page;
$this->template->sortable = $sortable;
$this->template->isSortable = $this->wrapperSection->isSortableConfigure();
$this['gridTable']->setPage((int) $page);

presenters - action detail:

$this->wrapperSection->getById($idSection, WrapperSection::ACTION_DETAIL);

$this->template->sectionId = $id;
$this->template->sectionName = $this->wrapperSection->getSectionName();
$this->template->subSectionName = $this->wrapperSection->getSubsectionName($idSubSection);

$this->template->idSubSection = $this->idSubSection = $idSubSection;
if ($idSubSection) {
    $this->wrapperSection->setSubSectionId($idSubSection);
}

$this->template->detail = $this->wrapperSection->getDetailContainerContent($id);

$this->template->page = $page;

presenters - add edit component:

$form = new Form($this, $name);
$form->setTranslator($this->translator);
$this->wrapperSection->getFormContainerContent($form);
// internal add id element
$form->addHidden('id');
$form->addSubmit('send', 'content-form-' . $this->action . '-send');
$form->addSubmit('ajaxSend', 'content-form-' . $this->action . '-ajax-send')
    ->setOption('class', 'ajax-send hidden');

presenters - action add:

$this->wrapperSection->getById($idSection, WrapperSection::ACTION_ADD);

$this->template->sectionName = $this->wrapperSection->getSectionName();
$this->template->subSectionName = $this->wrapperSection->getSubsectionName($idSubSection);

$this->template->idSubSection = $this->idSubSection = $idSubSection;
if ($idSubSection) {
    $this->wrapperSection->setSubSectionId($idSubSection);
}

$this->template->page = $page;
$this->template->listItems = $this->wrapperSection->getItems();

// define form success
$this->setOnSuccessAdd();

presenters - callback add:

// define form success
$this['formAddEdit']->onSuccess[] = function (Form $form, array $values) {
    try {
        $result = $this->wrapperSection->onSuccessInsert($values);
        if ($result > 0) {
            $this->flashMessage($this->translator->translate('content-form-add-onsuccess', [$result]), 'success');
        } else {
            $this->flashMessage($this->translator->translate('content-form-add-onsuccess-fail', [$result]), 'danger');
        }
        $this->redirect('default', [$this->getParameter('idSection'), $this->wrapperSection->getSubSectionId(), $this->getParameter('page')]);
    } catch (Exception $e) {
        $this->flashMessage($e->getMessage(), 'danger');
        $this->redirect('this');
    }
};

presenters - action edit:

$this->wrapperSection->getById($idSection, WrapperSection::ACTION_EDIT);

$this->template->sectionId = $id;
$this->template->sectionName = $this->wrapperSection->getSectionName();
$this->template->subSectionName = $this->wrapperSection->getSubsectionName($idSubSection);

$this->template->idSubSection = $this->idSubSection = $idSubSection;
if ($idSubSection) {
    $this->wrapperSection->setSubSectionId($idSubSection);
}

$this->template->page = $page;
$this->template->listItems = $this->wrapperSection->getItems();

// define form success
$this->setOnSuccessEdit();

presenters - callback edit:

$pk = $this->wrapperSection->getDatabasePk();

$result = $this->wrapperSection->onSuccessUpdate($values);

// load #id value
$id = $values[$pk];
if ($result > 0) {  // change values
    $this->flashMessage($this->translator->translate('content-form-edit-onsuccess', [$id]), 'success');
} else if ($result === 0) { // no change values
    $this->flashMessage($this->translator->translate('content-form-edit-onsuccess-no-change', [$id]), 'info');
} else {
    $this->flashMessage($this->translator->translate('content-form-edit-onsuccess-fail', [$id]), 'danger');
}

// redirect only for send button
if ($form['send']->isSubmittedBy()) {
    $this->redirect('default', [$this->getParameter('idSection'), $this->wrapperSection->getSubSectionId(), $this->getParameter('page')]);
}

presenters - action delete:

$this->wrapperSection->getById($idSection, WrapperSection::ACTION_DELETE);

if ($idSubSection) {
    $this->wrapperSection->setSubSectionId($idSubSection);
}

$result = $this->wrapperSection->onSuccessDelete($id);
if ($result > 0) {
    $this->flashMessage($this->translator->translate('content-form-delete-onsuccess', [$id]), 'success');
} else if ($result === 0) { // no change values
    $this->flashMessage($this->translator->translate('content-form-delete-onsuccess-no-change', [$id]), 'info');
} else {
    $this->flashMessage($this->translator->translate('content-form-delete-onsuccess-fail', [$id]), 'danger');
}
$this->redirect('default', [$this->getParameter('idSection'), $this->wrapperSection->getSubSectionId(), $page]);

presenters - handle sortable:

if ($this->isAjax()) {
    if ($this->wrapperSection->saveSortablePosition($values)) {
        $this->flashMessage($this->translator->translate('content-form-sortable-onsuccess'), 'success');
    }
    $this->redirect('default', [$this->getParameter('idSection'), $this->wrapperSection->getSubSectionId()]);
}

presenters - action add - foreign:

$this->wrapperSection->getById($idSection, WrapperSection::ACTION_ADD);

$this->template->sectionName = $this->wrapperSection->getSectionName();
$this->template->subSectionName = $this->wrapperSection->getSubsectionName($idSubSection);

$this->template->idSubSection = $this->idSubSection = $idSubSection;
if ($idSubSection) {
    $this->wrapperSection->setSubSectionId($idSubSection);
}

$this->template->page = $page;
$this->template->listItems = $this->wrapperSection->getItems();

// remove ajaxSend submit button for ADD
unset($this['formAddEdit']['ajaxSend']);

// set FkId
$this->wrapperSection->setFkId($fkId);

// define form success
$this->setOnSuccessAdd();

presenters - action edit - foreign:

$this->wrapperSection->getById($idSection, WrapperSection::ACTION_EDIT);

$this->template->sectionId = $id;
$this->template->sectionName = $this->wrapperSection->getSectionName();
$this->template->subSectionName = $this->wrapperSection->getSubsectionName($idSubSection);

$this->template->idSubSection = $this->idSubSection = $idSubSection;
if ($idSubSection) {
    $this->wrapperSection->setSubSectionId($idSubSection);
}

$this->template->page = $page;
$this->template->listItems = $this->wrapperSection->getItems();

// set FkId
$this->wrapperSection->setFkId($fkId);
$this['switchFkId']->addVariableTemplate('hasLocale', $this->wrapperSection->getMByIdN($id));

$defaults = $this->wrapperSection->setDefaults($this->wrapperSection->getDataById($id));

// define form success
$this->setOnSuccessEdit();

presenters - handle delete switch fkId:

if ($this->wrapperSection->deleteForeignSection($id, $fkIdDelete)) {
    $this->flashMessage($this->translator->translate('content-foreign-delete-switch-fkid-onsuccess', [$fkIdDelete]), 'success');
}
$this->redirect('this', $this->getParameter('idSection'));

presenters - switch fkId component:

$htmlSelect->setTemplatePath(__DIR__ . '/templates/ContentForeign/switchFkId.latte');
$htmlSelect->setRoute('SwitchFkId!');
$htmlSelect->setItems($this->wrapperSection->getForeignItems());
$htmlSelect->setActiveValue($this->wrapperSection->getFkId());

presenter - menu

// get list group
$this->template->listMenuGroup = $this->configureGroup->getListGroup();
// get list menu item
$this->template->listMenuItem = Callback::closure($this->wrapperSection, 'getListMenuItem');
// get presenter name for each menu
$this->template->getMenuItemPresenter = Callback::closure($this->wrapperSection, 'getMenuItemPresenter');

geniv/nette-admin-element 适用场景与选型建议

geniv/nette-admin-element 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 414 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「admin」 「nette」 「geniv」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 geniv/nette-admin-element 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 geniv/nette-admin-element 我们能提供哪些服务?
定制开发 / 二次开发

基于 geniv/nette-admin-element 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 414
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-25