diff --git a/Gruntfile.js b/Gruntfile.js index 25569ecb..9e00deae 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -183,7 +183,7 @@ module.exports = function (grunt) { }, javascripts: { files: ['src/javascripts/ng-admin.js', 'src/javascripts/ng-admin/**/**/*.js', 'src/javascripts/ng-admin/**/**/*.html'], - tasks: ['ngconfig', 'requirejs:dev', 'copy:js_dev', 'copy:es6_dev', 'copy:es6_devmap'], + tasks: ['ngconfig', 'requirejs:dev', 'ngAnnotate', 'copy:js_dev', 'copy:es6_dev', 'copy:es6_devmap'], options: { atBegin: true, livereload: true @@ -250,7 +250,7 @@ module.exports = function (grunt) { grunt.registerTask('test:local', ['mochaTest', 'karma', 'build:dev', 'copy_build:dev', 'test:local:e2e']); grunt.registerTask('test:local:e2e', ['json_server', 'connect', 'protractor']); - grunt.registerTask('build:dev', ['ngconfig', 'requirejs:dev', 'compass:dev', 'concat:css']); + grunt.registerTask('build:dev', ['ngconfig', 'requirejs:dev', 'ngAnnotate', 'compass:dev', 'concat:css']); grunt.registerTask('copy_build:dev', ['copy:es6_dev', 'copy:es6_devmap', 'copy:js_dev', 'copy:angular', 'copy:css_dev', 'copy:fonts_dev', 'clean']); // register default task diff --git a/README.md b/README.md index 1e2ffc26..691f272e 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Check out the [online demo](http://ng-admin.marmelab.com/) ([source](https://git * [Installation](#installation) * [Example Configuration](#example-configuration) +* [Application Configuration](#application-configuration) * [Entity Configuration](#entity-configuration) * [View Configuration](#view-configuration) * [Menu Configuration](#menu-configuration) @@ -71,6 +72,17 @@ Your application should use a `ui-view`:
``` +### Production ready + +You can enable `ng-strict-di` angular mode to boost your application performance: +```html + +``` + +Ng-admin library is already compatible, but you have to explicitly declare dependencies on your custom application code. + +See [Angular documentation](https://docs.angularjs.org/guide/production) for more details about this tweak. + ## Example Configuration We chose to define the entities & views directly in JavaScript to allow greater freedom in the configuration. @@ -83,7 +95,7 @@ var app = angular.module('myApp', ['ng-admin']); app.config(function (NgAdminConfigurationProvider) { var nga = NgAdminConfigurationProvider; - var app = nga.application('ng-admin backend demo') // application main title + var app = nga.application('ng-admin backend demo', false) // application main title and debug disabled .baseApiUrl('http://localhost:3000/'); // main API endpoint // define all entities at the top to allow references between them @@ -160,6 +172,32 @@ app.config(function (NgAdminConfigurationProvider) { You can find a more detailed configuration in the [blog demo configuration](examples/blog/config.js). +## Application Configuration + +Application is the base of your admin. + +Create a new application: + +```js +// set the title and disable debug for this admin +var app = nga.application('My backend', false); +``` + +* `title()` +Defines the title + + var app = nga.application().title('My backend') + +* `baseApiUrl()` +Defines the main API endpoint + + var app = nga.application().baseApiUrl('http://localhost:3000/') + +* `debug()` +Enable or disable debug (enabled by default) + + var app = nga.application().debug(false) + ## Entity Configuration Each entity maps to a different API endpoint. The name of the entity, defines the endpoint: diff --git a/examples/blog/config.js b/examples/blog/config.js index 554a7030..b72528cd 100644 --- a/examples/blog/config.js +++ b/examples/blog/config.js @@ -4,7 +4,7 @@ var app = angular.module('myApp', ['ng-admin']); - app.config(function (NgAdminConfigurationProvider, RestangularProvider) { + app.config(['NgAdminConfigurationProvider', 'RestangularProvider', function (NgAdminConfigurationProvider, RestangularProvider) { var nga = NgAdminConfigurationProvider; function truncate(value) { @@ -42,6 +42,7 @@ }); var admin = nga.application('ng-admin backend demo') // application main title + .debug(false) // debug disabled .baseApiUrl('http://localhost:3000/'); // main API endpoint // define all entities at the top to allow references between them @@ -276,7 +277,7 @@ ); nga.configure(admin); - }); + }]); app.directive('postLink', ['$location', function ($location) { return { @@ -333,7 +334,7 @@ '
Send
' + ''; - app.config(function ($stateProvider) { + app.config(['$stateProvider', function ($stateProvider) { $stateProvider.state('send-post', { parent: 'main', url: '/sendPost/:id', @@ -342,7 +343,7 @@ controllerAs: 'controller', template: sendPostControllerTemplate }); - }); + }]); // custom page with menu item var customPageTemplate = '
' + @@ -352,12 +353,12 @@ '

You can add custom pages, too

' + '
' + '
'; - app.config(function ($stateProvider) { + app.config(['$stateProvider', function ($stateProvider) { $stateProvider.state('stats', { parent: 'main', url: '/stats', template: customPageTemplate }); - }); + }]); }()); diff --git a/examples/blog/index.html b/examples/blog/index.html index 200e1bcc..3f950748 100644 --- a/examples/blog/index.html +++ b/examples/blog/index.html @@ -9,7 +9,7 @@ - +
diff --git a/src/javascripts/ng-admin.js b/src/javascripts/ng-admin.js index 1945ac73..8772256d 100644 --- a/src/javascripts/ng-admin.js +++ b/src/javascripts/ng-admin.js @@ -62,7 +62,7 @@ define(function (require) { factory.constant('AdminDescription', new AdminDescription()); var ngadmin = angular.module('ng-admin', ['main', 'crud', 'AdminDescriptionModule']); - ngadmin.config(function(NgAdminConfigurationProvider, AdminDescription) { + ngadmin.config(['NgAdminConfigurationProvider', 'AdminDescription', function(NgAdminConfigurationProvider, AdminDescription) { NgAdminConfigurationProvider.setAdminDescription(AdminDescription); - }); + }]); }); diff --git a/src/javascripts/ng-admin/Main/component/provider/NgAdminConfiguration.js b/src/javascripts/ng-admin/Main/component/provider/NgAdminConfiguration.js index 77bd12f1..38bd226e 100644 --- a/src/javascripts/ng-admin/Main/component/provider/NgAdminConfiguration.js +++ b/src/javascripts/ng-admin/Main/component/provider/NgAdminConfiguration.js @@ -3,9 +3,10 @@ define(function () { 'use strict'; - function NgAdminConfiguration() { + function NgAdminConfiguration($compileProvider) { this.config = null; this.adminDescription = null; + this.$compileProvider = $compileProvider; } NgAdminConfiguration.prototype.setAdminDescription = function(adminDescription) { @@ -14,6 +15,8 @@ define(function () { NgAdminConfiguration.prototype.configure = function (config) { this.config = config; + + this.$compileProvider.debugInfoEnabled(this.config.debug()); }; NgAdminConfiguration.prototype.$get = function () { @@ -23,8 +26,8 @@ define(function () { }; }; - NgAdminConfiguration.prototype.application = function(name) { - return this.adminDescription.application(name); + NgAdminConfiguration.prototype.application = function(name, debug) { + return this.adminDescription.application(name, debug); }; NgAdminConfiguration.prototype.entity = function(name) { @@ -43,7 +46,7 @@ define(function () { return this.adminDescription.menu(entity); }; - NgAdminConfiguration.$inject = []; + NgAdminConfiguration.$inject = ['$compileProvider']; return NgAdminConfiguration; }); diff --git a/src/javascripts/ng-admin/es6/lib/Application.js b/src/javascripts/ng-admin/es6/lib/Application.js index d2677b9a..390be133 100644 --- a/src/javascripts/ng-admin/es6/lib/Application.js +++ b/src/javascripts/ng-admin/es6/lib/Application.js @@ -1,7 +1,7 @@ import Menu from './Menu/Menu'; class Application { - constructor(title='ng-admin') { + constructor(title='ng-admin', debug=true) { this._baseApiUrl = ''; this._customTemplate = function(viewName) {}; this._title = title; @@ -10,6 +10,7 @@ class Application { this._header = false; this._entities = []; this._errorMessage = this.defaultErrorMessage; + this._debug = debug; } defaultErrorMessage(response) { @@ -49,6 +50,12 @@ class Application { return url; } + debug(debug) { + if (!arguments.length) return this._debug; + this._debug = debug; + return this; + } + layout(layout) { if (!arguments.length) return this._layout; this._layout = layout; diff --git a/src/javascripts/test/protractor.conf.js b/src/javascripts/test/protractor.conf.js index 1b07ad1b..12479f3f 100644 --- a/src/javascripts/test/protractor.conf.js +++ b/src/javascripts/test/protractor.conf.js @@ -20,5 +20,9 @@ exports.config = { showColors: true, includeStackTrace: true, defaultTimeoutInterval: 360000 + }, + + onPrepare: function () { + browser.executeScript('window.name = "NG_ENABLE_DEBUG_INFO"'); } };