marmelab/ng-admin-generator-bundle
最新稳定版本:0.2.0
Composer 安装命令:
composer require marmelab/ng-admin-generator-bundle
包简介
Bundle to generate easily a ng-admin configuration file based on your LemonRestBundle based API
README 文档
README
| Archived Repository This code is no longer maintained. Feel free to fork it, but use it at your own risks. |
NgAdminGeneratorBundle 
You're a fan of StanLemonRestBundle because it makes REST APIs based on Doctrine entities a piece of cake? You starred ng-admin because you love the idea of a JavaScript-powered administration panel consuming a REST API? Then, you will love NgAdminGeneratorBundle, the Symfony2 bundle that bootstraps ng-admin based on a Doctrine-powered REST API!
Installation
Setting up bundle
Using this bundle in your own project is pretty straightforward, thanks to composer:
composer require marmelab/ng-admin-generator-bundle
Then, register it to your AppKernel.php file. The NgAdminGeneratorBundle should only be used in development:
class AppKernel extends Kernel { public function registerBundles() { // ... if (in_array($this->getEnvironment(), array('dev', 'test'))) { $bundles[] = new \marmelab\NgAdminGeneratorBundle\marmelabNgAdminGeneratorBundle(); } // ... } }
No more configuration, you are now ready to go!
ng-admin template sample
Here is a Twig template to render your favorite administration panel:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Administration Panel</title> <link rel="stylesheet" href="{{ asset('components/ng-admin/build/ng-admin.min.css') }}"/> </head> <body ng-app="myApp"> <script src="{{ asset('components/angular/angular.min.js') }}"></script> <script src="{{ asset('components/ng-admin/build/ng-admin.min.js') }}"></script> <script src="{{ asset('ngadmin.conf.js') }}"></script> <div ui-view></div> </body> </html>
If you got a blank page, ensure you have set correctly the ng-app and ui-view attributes.
Generating your ng-admin configuration
This bundle just adds the ng-admin:configuration:generate command to your application. By default, it outputs a JavaScript configuration based on the REST API defined by StanLemonRestBundle into STDOUT. You are free to redirect STDOUT into the file of your choice:
./app/console ng-admin:configuration:generate > public/js/ng-admin-config.js
Tip: Thanks to the Symfony2 Console component, you can truncate parts of the command name and call the ng-admin:c:g command!
Configuration sample
Here is a sample of an auto-generated configuration, based on the stanlemon/rest-demo-app demo application. This application sets up the same entities as the official ng-admin demo app, i.e. Posts, Comments, and Tags. The generator simply uses entity mapping to better know which fields to use.
var app = angular.module('myApp', ['ng-admin']); // Deal with query parameters expected by StanLemon bundle app.config(function(RestangularProvider) { RestangularProvider.addFullRequestInterceptor(function(element, operation, what, url, headers, params) { if (operation == "getList") { // custom pagination params params._start = (params._page - 1) * params._perPage; params._end = params._page * params._perPage; delete params._page; delete params._perPage; // custom sort params if (params._sortField) { params._orderBy = params._sortField; params._orderDir = params._sortDir; delete params._sortField; delete params._sortDir; } // custom filters if (params._filters) { for (var filter in params._filters) { params[filter] = params._filters[filter]; } delete params._filters; } } return { params: params }; }); }); /* Define a `config` block for each entity, allowing to split configuration across several files. */ app.config(function($provide, NgAdminConfigurationProvider) { $provide.factory("PostAdmin", function() { var nga = NgAdminConfigurationProvider; var post = nga.entity('post'); // Dashboard (as list) won't display referenced list of items. post.dashboardView() .fields([ nga.field('id', 'number'), nga.field('title', 'string'), nga.field('body', 'text'), // We limit to 3 number of fields displayed on dashboard ]); post.listView() .fields([ nga.field('id', 'number'), nga.field('title', 'string'), nga.field('body', 'text'), // Take more meaningful field. Here, use `name` instead of `id` nga.field('tags', 'reference_many') .targetEntity(nga.entity('tag')) .targetField(nga.field('name')), ]) .listActions(['show', 'edit', 'delete']); post.creationView() .fields([ // Do not display id: we don't have any yet nga.field('title', 'string'), nga.field('body', 'text'), nga.field('tags', 'reference_many') .targetEntity(nga.entity('tag')) .targetField(nga.field('name')), // No referenced_list either, as that's a brand new entity ]); post.editionView() .fields([ nga.field('id', 'number').readOnly(), // don't modify id nga.field('title', 'string'), nga.field('body', 'text'), nga.field('tags', 'reference_many') .targetEntity(nga.entity('tag')) .targetField(nga.field('name')), nga.field('comments', 'referenced_list') .targetEntity(nga.entity('comment')) .targetReferenceField('post_id') .targetFields([ nga.field('id', 'number'), nga.field('body', 'text'), nga.field('created_at', 'date'), ]), ]); /* To ease configuration per view, we repeat every field every time. If you want to display same fields across views, you can use for instance `post.editView().fields()` to get edition fields. */ post.showView() .fields([ nga.field('id', 'number'), nga.field('title', 'string'), nga.field('body', 'text'), nga.field('tags', 'reference_many') .targetEntity(nga.entity('tag')) .targetField(nga.field('name')), nga.field('comments', 'referenced_list') .targetEntity(nga.entity('comment')) .targetReferenceField('post_id') .targetFields([ nga.field('id', 'number'), nga.field('body', 'text'), nga.field('created_at', 'date'), ]), ]); return post; }); }); // Same config block for comments // Same config block for tags app.config(function(NgAdminConfigurationProvider, PostAdminProvider, CommentAdminProvider, TagAdminProvider) { var admin = NgAdminConfigurationProvider .application('') .baseApiUrl(location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '') + '/api/') admin .addEntity(PostAdminProvider.$get()) .addEntity(CommentAdminProvider.$get()) .addEntity(TagAdminProvider.$get()) ; NgAdminConfigurationProvider.configure(admin); });
Contributing
Your feedback about the usage of this bundle is valuable: don't hesitate to open GitHub Issues for any problem or question you may have.
All contributions are welcome. New applications or options should be tested with the phpunit command.
License
NgAdminGeneratorBundle is licensed under the MIT Licence, courtesy of marmelab.
marmelab/ng-admin-generator-bundle 适用场景与选型建议
marmelab/ng-admin-generator-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.42k 次下载、GitHub Stars 达 77, 最近一次更新时间为 2015 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「administration」 「ng-admin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 marmelab/ng-admin-generator-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marmelab/ng-admin-generator-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 marmelab/ng-admin-generator-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
Notadd's Administration Module.
Dynamically Laravel CRUD administration with automatic database migrations
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Cpanel Licensing Class
统计信息
- 总下载量: 2.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 78
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-24