diff --git a/Gruntfile.js b/Gruntfile.js
index ad616223..aed32f17 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -8,6 +8,26 @@ module.exports = function (grunt) {
requirejs: grunt.file.readJSON('grunt/grunt-requirejs.json'),
compass: grunt.file.readJSON('grunt/grunt-compass.json'),
+ ngAnnotate: {
+ ngadmin: {
+ files: {
+ 'src/build/ng-admin.min.js': ['src/build/ng-admin.min.js']
+ }
+ }
+ },
+
+ uglify: {
+ ngadmin: {
+ files: {
+ 'src/build/ng-admin.min.js': ['src/build/ng-admin.min.js']
+ }
+ }
+ },
+
+ clean: {
+ build: ["src/build/app", "src/build/bower_components", "src/build/*.js", "!src/build/*.min.js"]
+ },
+
connect: {
server: {
options: {
@@ -72,6 +92,9 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
+ grunt.loadNpmTasks('grunt-contrib-clean');
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.loadNpmTasks('grunt-ng-annotate');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-karma');
@@ -79,6 +102,7 @@ module.exports = function (grunt) {
grunt.registerTask('assets:js', ['requirejs:dev']);
grunt.registerTask('assets:css', ['compass:dev']);
grunt.registerTask('test', ['karma']);
+ grunt.registerTask('build', ['requirejs:prod', 'ngAnnotate', 'uglify']);
// register default task
grunt.registerTask('default', ['concurrent:assets_all_dev', 'concurrent:connect_watch']);
diff --git a/bower.json b/bower.json
index 04e0fb31..0e0d9656 100644
--- a/bower.json
+++ b/bower.json
@@ -13,7 +13,6 @@
"jquery": "~1.11.0",
"requirejs": "~2.1.14",
"requirejs-text": "~2.0.12",
- "requirejs-domready": "~2.0.1",
"bootstrap-sass-official": "~3.1.0",
"restangular": "~1.4.0",
"angular-ui-router": "~0.2.10",
@@ -24,7 +23,8 @@
},
"devDependencies": {
"angular-mocks": "1.2.15",
- "angular-scenario": "1.2.15"
+ "angular-scenario": "1.2.15",
+ "almond": "~0.3.0"
},
"resolutions": {
"angular": "~1.2.16"
diff --git a/grunt/grunt-requirejs.json b/grunt/grunt-requirejs.json
index ba28a029..9b7dce50 100644
--- a/grunt/grunt-requirejs.json
+++ b/grunt/grunt-requirejs.json
@@ -10,29 +10,27 @@
"generateSourceMaps": true,
"skipDirOptimize": true,
"removeCombined": true,
-
- "mainConfigFile": [
- "src/scripts/common.js",
- "src/scripts/ng-admin.js"
- ]
+ "mainConfigFile": "src/scripts/app.js"
}
},
"prod": {
"options": {
- "appDir": "src/scripts",
- "fileExclusionRegExp": "^(build)",
- "baseUrl": "./",
- "dir": "src/require",
- "optimize": "uglify2",
+ "baseUrl": "src/scripts",
+ "mainConfigFile": "src/scripts/app.js",
+ "include": ["app"],
+ "name": "bower_components/almond/almond",
+ "out": "./src/build/ng-admin.min.js",
+
+ "optimize": "none",
"preserveLicenseComments": false,
+ "findNestedDependencies": true,
"generateSourceMaps": false,
"skipDirOptimize": true,
"removeCombined": true,
-
- "mainConfigFile": [
- "src/scripts/common.js",
- "src/scripts/ng-admin.js"
- ]
+ "wrap": {
+ "startFile": "build/start.frag",
+ "endFile": "build/end.frag"
+ }
}
}
}
diff --git a/package.json b/package.json
index 135c2d3a..f2f73bc8 100644
--- a/package.json
+++ b/package.json
@@ -15,8 +15,10 @@
"requirejs": "~2.1.14"
},
"devDependencies": {
+ "grunt-contrib-clean": "^0.6.0",
"grunt-contrib-watch": "~0.5.2",
"grunt-karma": "^0.8.3",
+ "grunt-ng-annotate": "^0.3.2",
"jshint-stylish": "~0.1.3",
"karma": "~0.12.14",
"karma-chrome-launcher": "^0.1.4",
@@ -24,7 +26,8 @@
"karma-ng-html2js-preprocessor": "~0.1.0",
"karma-ng-scenario": "~0.1.0",
"karma-phantomjs-launcher": "^0.1.4",
- "karma-requirejs": "~0.2.2"
+ "karma-requirejs": "~0.2.2",
+ "grunt-contrib-uglify": "~0.6.0"
},
"engines": {
"node": ">=0.10.0"
diff --git a/sass/screen.scss b/sass/screen.scss
index 8d9bb160..21b2c735 100644
--- a/sass/screen.scss
+++ b/sass/screen.scss
@@ -3,6 +3,9 @@ $icon-font-path: "/scripts/bower_components/bootstrap-sass-official/vendor/asset
// bower:scss
@import "../src/scripts/bower_components/bootstrap-sass-official/vendor/assets/stylesheets/bootstrap.scss";
@import "/scripts/bower_components/nprogress/nprogress.css";
+@import "/scripts/bower_components/fontawesome/css/font-awesome.css";
+@import "/scripts/bower_components/humane/themes/flatty.css";
+@import "/scripts/bower_components/bootstrap/dist/css/bootstrap.css";
// endbower
@import "sb-admin.scss";
diff --git a/src/index.html b/src/index.html
index a7aeadae..5c20babd 100644
--- a/src/index.html
+++ b/src/index.html
@@ -1,20 +1,16 @@
-
+
Angular admin
-
-
-
-
-
+
+
-
+
-
diff --git a/src/scripts/app.js b/src/scripts/app.js
index 826ac57f..9a6abb90 100644
--- a/src/scripts/app.js
+++ b/src/scripts/app.js
@@ -1,19 +1,61 @@
require.config({
- waitSeconds: 30
+ paths: {
+ 'angular': 'bower_components/angular/angular',
+ 'angular-resource': 'bower_components/angular-resource/angular-resource',
+ 'angular-sanitize': 'bower_components/angular-sanitize/angular-sanitize',
+ 'angular-route': 'bower_components/angular-route/angular-route',
+ 'angular-ui-router': 'bower_components/angular-ui-router/release/angular-ui-router',
+ 'lodash': 'bower_components/lodash/dist/lodash.min',
+ 'text' : 'bower_components/requirejs-text/text',
+ 'angular-bootstrap': 'bower_components/angular-bootstrap/ui-bootstrap.min',
+ 'angular-bootstrap-tpls': 'bower_components/angular-bootstrap/ui-bootstrap-tpls.min',
+ 'restangular': 'bower_components/restangular/dist/restangular',
+ 'humane': 'bower_components/humane/humane',
+ 'nprogress': 'bower_components/nprogress/nprogress',
+
+ 'MainModule': 'app/Main/MainModule',
+ 'CrudModule': 'app/Crud/CrudModule'
+ },
+ shim: {
+ 'angular': {
+ exports: 'angular'
+ },
+ 'restangular': {
+ deps: ['angular', 'lodash']
+ },
+ 'angular-ui-router': {
+ deps: ['angular']
+ },
+ 'angular-bootstrap': {
+ deps: ['angular']
+ },
+ 'angular-bootstrap-tpls': {
+ deps: ['angular', 'angular-bootstrap']
+ },
+ 'jquery': {
+ exports: '$'
+ },
+ 'angular-resource': {
+ deps: ['angular']
+ },
+ 'angular-sanitize': {
+ deps: ['angular']
+ },
+ 'angular-route': {
+ deps: ['angular']
+ },
+ 'nprogress': {
+ exports: 'NProgress'
+ }
+ }
});
-require(['common', 'ng-admin'], function () {
+define(function(require) {
"use strict";
- require(['angular', 'MainModule', 'CrudModule'], function (angular) {
-
- angular.module('ng-admin', ['main', 'crud']);
-
- // we add the ng-app attribute for pure debugging purposes
- // historically, it was needed in case angular scenario was used for e2e tests
- document.body.setAttribute('ng-app', 'ng-admin');
+ var angular = require('angular');
+ require('MainModule');
+ require('CrudModule');
- // async resource download implies async angular app bootstrap
- angular.bootstrap(document.body, ['ng-admin']);
- });
+ angular.module('ng-admin', ['main', 'crud']);
});
diff --git a/src/scripts/app/Crud/CrudModule.js b/src/scripts/app/Crud/CrudModule.js
index 4ecde959..94d38ce8 100644
--- a/src/scripts/app/Crud/CrudModule.js
+++ b/src/scripts/app/Crud/CrudModule.js
@@ -1,68 +1,51 @@
-define(
- [
- 'angular',
- 'config',
+define(function (require) {
+ "use strict";
- 'app/Crud/component/controller/ListController',
- 'app/Crud/component/controller/FormController',
- 'app/Crud/component/controller/DeleteController',
+ var angular = require('angular'),
+ ListController = require('app/Crud/component/controller/ListController'),
+ FormController = require('app/Crud/component/controller/FormController'),
+ DeleteController = require('app/Crud/component/controller/DeleteController'),
- 'app/Crud/component/directive/InfinitePagination',
+ InfinitePagination = require('app/Crud/component/directive/InfinitePagination'),
- 'app/Crud/component/service/CrudManager',
+ CrudManager = require('app/Crud/component/service/CrudManager'),
- 'app/Crud/config/routing',
+ routing = require('app/Crud/config/routing');
- 'angular-ui-router', 'angular-sanitize', 'angular-bootstrap-tpls'
- ],
- function (
- angular,
- config,
+ require('angular-ui-router');
+ require('angular-sanitize');
+ require('angular-bootstrap-tpls');
- ListController,
- FormController,
- DeleteController,
+ var CrudModule = angular.module('crud', ['ui.router', 'ui.bootstrap', 'ngSanitize']);
- InfinitePagination,
+ CrudModule.controller('ListController', ListController);
+ CrudModule.controller('FormController', FormController);
+ CrudModule.controller('DeleteController', DeleteController);
- CrudManager,
+ CrudModule.service('CrudManager', CrudManager);
- routing
- ) {
- "use strict";
+ CrudModule.directive('infinitePagination', InfinitePagination);
- var CrudModule = angular.module('crud', ['ui.router', 'ui.bootstrap', 'ngSanitize']);
- CrudModule.constant('config', config);
+ /**
+ * Date Picker patch
+ * https://github.com/angular-ui/bootstrap/commit/42cc3f269bae020ba17b4dcceb4e5afaf671d49b
+ */
+ CrudModule.config(function($provide){
+ $provide.decorator('dateParser', function($delegate){
- CrudModule.controller('ListController', ListController);
- CrudModule.controller('FormController', FormController);
- CrudModule.controller('DeleteController', DeleteController);
+ var oldParse = $delegate.parse;
+ $delegate.parse = function(input, format) {
+ if ( !angular.isString(input) || !format ) {
+ return input;
+ }
+ return oldParse.apply(this, arguments);
+ };
- CrudModule.service('CrudManager', CrudManager);
-
- CrudModule.directive('infinitePagination', InfinitePagination);
-
- /**
- * Date Picker patch
- * https://github.com/angular-ui/bootstrap/commit/42cc3f269bae020ba17b4dcceb4e5afaf671d49b
- */
- CrudModule.config(function($provide){
- $provide.decorator('dateParser', function($delegate){
-
- var oldParse = $delegate.parse;
- $delegate.parse = function(input, format) {
- if ( !angular.isString(input) || !format ) {
- return input;
- }
- return oldParse.apply(this, arguments);
- };
-
- return $delegate;
- });
+ return $delegate;
});
+ });
- CrudModule.config(routing);
+ CrudModule.config(routing);
- return CrudModule;
- }
-);
+ return CrudModule;
+});
diff --git a/src/scripts/app/Crud/component/controller/DeleteController.js b/src/scripts/app/Crud/component/controller/DeleteController.js
index fac18839..4c3d87e4 100644
--- a/src/scripts/app/Crud/component/controller/DeleteController.js
+++ b/src/scripts/app/Crud/component/controller/DeleteController.js
@@ -1,4 +1,4 @@
-define([], function() {
+define(function() {
'use strict';
var DeleteController = function($scope, $location, CrudManager, params) {
diff --git a/src/scripts/app/Crud/component/controller/FormController.js b/src/scripts/app/Crud/component/controller/FormController.js
index 89511ebb..2163a1b5 100644
--- a/src/scripts/app/Crud/component/controller/FormController.js
+++ b/src/scripts/app/Crud/component/controller/FormController.js
@@ -1,9 +1,9 @@
-define([
- 'humane',
- 'nprogress'
-], function(humane, NProgress) {
+define(function() {
'use strict';
+ var humane = require('humane'),
+ NProgress = require('nprogress');
+
var FormController = function($scope, $location, $filter, CrudManager, Validator, data) {
var isNew = typeof(data.entityId) === 'undefined';
this.$scope = $scope;
diff --git a/src/scripts/app/Crud/component/controller/ListController.js b/src/scripts/app/Crud/component/controller/ListController.js
index c11fb326..b41150e7 100644
--- a/src/scripts/app/Crud/component/controller/ListController.js
+++ b/src/scripts/app/Crud/component/controller/ListController.js
@@ -1,8 +1,8 @@
-define([
- 'nprogress'
-], function(NProgress) {
+define(function(require) {
'use strict';
+ var NProgress = require('nprogress');
+
var ListController = function($scope, $location, $anchorScroll, data, CrudManager) {
this.$scope = $scope;
this.$location = $location;
diff --git a/src/scripts/app/Crud/component/directive/InfinitePagination.js b/src/scripts/app/Crud/component/directive/InfinitePagination.js
index 35390b33..1ee7d8d6 100644
--- a/src/scripts/app/Crud/component/directive/InfinitePagination.js
+++ b/src/scripts/app/Crud/component/directive/InfinitePagination.js
@@ -1,8 +1,8 @@
-define([
- 'angular'
-], function(angular) {
+define(function(require) {
'use strict';
+ var angular = require('angular');
+
function InfinitePagination($window, $document) {
return {
link:function (scope, element, attrs) {
diff --git a/src/scripts/app/Crud/component/service/CrudManager.js b/src/scripts/app/Crud/component/service/CrudManager.js
index 15c30e74..92266d3a 100644
--- a/src/scripts/app/Crud/component/service/CrudManager.js
+++ b/src/scripts/app/Crud/component/service/CrudManager.js
@@ -1,20 +1,19 @@
-define([
- 'angular',
- 'config'
-], function(angular, ApplicationConfig) {
+define(function(require) {
'use strict';
+ var angular = require('angular');
+
/**
*
* @param {$q} $q
* @param {Restangular} Restangular
- * @param {Application} config
+ * @param {Application} Configuration
* @constructor
*/
- function CrudManager($q, Restangular, config) {
+ function CrudManager($q, Restangular, Configuration) {
this.$q = $q;
this.Restangular = Restangular;
- this.config = config || ApplicationConfig;
+ this.config = Configuration();
this.Restangular.setBaseUrl(this.config.baseApiUrl());
this.Restangular.setFullResponse(true); // To get also the headers
@@ -459,7 +458,7 @@ define([
return values;
};
- CrudManager.$inject = ['$q', 'Restangular'];
+ CrudManager.$inject = ['$q', 'Restangular', 'NgAdminConfiguration'];
return CrudManager;
});
diff --git a/src/scripts/app/Crud/config/routing.js b/src/scripts/app/Crud/config/routing.js
index fe4d1861..bfbe7e81 100644
--- a/src/scripts/app/Crud/config/routing.js
+++ b/src/scripts/app/Crud/config/routing.js
@@ -1,11 +1,11 @@
-define([
- 'text!../view/list.html',
- 'text!../view/create.html',
- 'text!../view/edit.html',
- 'text!../view/delete.html'
-], function (listTemplate, createTemplate, editTemplate, deleteTemplate) {
+define(function (require) {
"use strict";
+ var listTemplate = require('text!../view/list.html'),
+ createTemplate = require('text!../view/create.html'),
+ editTemplate = require('text!../view/edit.html'),
+ deleteTemplate = require('text!../view/delete.html');
+
var routing = function ($stateProvider) {
$stateProvider
diff --git a/src/scripts/app/Main/MainModule.js b/src/scripts/app/Main/MainModule.js
index 887206df..7d3a04a5 100644
--- a/src/scripts/app/Main/MainModule.js
+++ b/src/scripts/app/Main/MainModule.js
@@ -1,58 +1,55 @@
-define(
- [
- 'angular',
- 'config',
+define(function (require) {
+ var angular = require('angular'),
+ AppController = require('app/Main/component/controller/AppController'),
+ DashboardController = require('app/Main/component/controller/DashboardController'),
+ SidebarController = require('app/Main/component/controller/SidebarController'),
- 'app/Main/component/controller/AppController',
- 'app/Main/component/controller/DashboardController',
- 'app/Main/component/controller/SidebarController',
+ PanelBuilder = require('app/Main/component/service/PanelBuilder'),
+ Validator = require('app/Main/component/service/Validator'),
- 'app/Main/component/service/PanelBuilder',
- 'app/Main/component/service/Validator',
+ Application = require('app/Main/component/service/config/Application'),
+ Entity = require('app/Main/component/service/config/Entity'),
+ Field = require('app/Main/component/service/config/Field'),
+ Reference = require('app/Main/component/service/config/Reference'),
+ ReferencedList = require('app/Main/component/service/config/ReferencedList'),
+ ReferenceMany = require('app/Main/component/service/config/ReferenceMany'),
- 'app/Main/component/filter/OrderElement',
+ NgAdminConfiguration = require('app/Main/component/provider/NgAdminConfiguration'),
- 'app/Main/config/routing',
+ OrderElement = require('app/Main/component/filter/OrderElement'),
- 'app/Main/run/Loader',
+ routing = require('app/Main/config/routing'),
- 'angular-ui-router', 'restangular'
- ],
- function (
- angular,
- config,
+ loader = require('app/Main/run/Loader');
- AppController,
- DashboardController,
- SidebarController,
+ require('angular-ui-router');
+ require('restangular');
- PanelBuilder,
- Validator,
+ "use strict";
- OrderElement,
+ var MainModule = angular.module('main', ['ui.router', 'restangular']);
- routing,
+ MainModule.controller('AppController', AppController);
+ MainModule.controller('DashboardController', DashboardController);
+ MainModule.controller('SidebarController', SidebarController);
- loader
- ) {
- "use strict";
+ MainModule.service('PanelBuilder', PanelBuilder);
+ MainModule.service('Validator', Validator);
- var MainModule = angular.module('main', ['ui.router', 'restangular']);
- MainModule.constant('config', config);
+ MainModule.constant('Application', Application);
+ MainModule.constant('Entity', Entity);
+ MainModule.constant('Field', Field);
+ MainModule.constant('Reference', Reference);
+ MainModule.constant('ReferencedList', ReferencedList);
+ MainModule.constant('ReferenceMany', ReferenceMany);
- MainModule.controller('AppController', AppController);
- MainModule.controller('DashboardController', DashboardController);
- MainModule.controller('SidebarController', SidebarController);
+ MainModule.provider('NgAdminConfiguration', NgAdminConfiguration);
- MainModule.service('PanelBuilder', PanelBuilder);
- MainModule.service('Validator', Validator);
+ MainModule.filter('orderElement', OrderElement);
- MainModule.filter('orderElement', OrderElement);
+ MainModule.config(routing);
- MainModule.config(routing);
+ MainModule.run(loader);
- MainModule.run(loader);
-
- return MainModule;
- }
-);
+ return MainModule;
+});
diff --git a/src/scripts/app/Main/component/controller/AppController.js b/src/scripts/app/Main/component/controller/AppController.js
index e1faab53..61d576d9 100644
--- a/src/scripts/app/Main/component/controller/AppController.js
+++ b/src/scripts/app/Main/component/controller/AppController.js
@@ -1,6 +1,4 @@
-define([
- 'config'
-], function(config) {
+define(function() {
'use strict';
/**
@@ -8,9 +6,9 @@ define([
* @param {$scope} $scope
* @constructor
*/
- var AppController = function ($scope) {
+ var AppController = function ($scope, Configuration) {
this.$scope = $scope;
- this.applicationName = config.title();
+ this.applicationName = Configuration().title();
$scope.$on('$destroy', this.destroy.bind(this));
};
@@ -19,7 +17,7 @@ define([
this.$scope = undefined;
};
- AppController.$inject = ['$scope'];
+ AppController.$inject = ['$scope', 'NgAdminConfiguration'];
return AppController;
});
diff --git a/src/scripts/app/Main/component/controller/DashboardController.js b/src/scripts/app/Main/component/controller/DashboardController.js
index 458a1b89..b121c9fc 100644
--- a/src/scripts/app/Main/component/controller/DashboardController.js
+++ b/src/scripts/app/Main/component/controller/DashboardController.js
@@ -1,4 +1,4 @@
-define([], function() {
+define(function() {
'use strict';
/**
diff --git a/src/scripts/app/Main/component/controller/SidebarController.js b/src/scripts/app/Main/component/controller/SidebarController.js
index 0558a05c..13113b8e 100644
--- a/src/scripts/app/Main/component/controller/SidebarController.js
+++ b/src/scripts/app/Main/component/controller/SidebarController.js
@@ -1,12 +1,10 @@
-define([
- 'config'
-], function(config) {
+define(function() {
'use strict';
- var SidebarController = function($scope, $location) {
+ var SidebarController = function($scope, $location, Configuration) {
this.$scope = $scope;
this.$location = $location;
- this.entities = config.getEntities();
+ this.entities = Configuration().getEntities();
this.computeCurrentEntity();
$scope.$on('$locationChangeSuccess', this.computeCurrentEntity.bind(this));
@@ -37,7 +35,7 @@ define([
this.$location = undefined;
};
- SidebarController.$inject = ['$scope', '$location'];
+ SidebarController.$inject = ['$scope', '$location', 'NgAdminConfiguration'];
return SidebarController;
});
diff --git a/src/scripts/app/Main/component/filter/OrderElement.js b/src/scripts/app/Main/component/filter/OrderElement.js
index ec75df81..11262f05 100644
--- a/src/scripts/app/Main/component/filter/OrderElement.js
+++ b/src/scripts/app/Main/component/filter/OrderElement.js
@@ -1,4 +1,4 @@
-define([], function() {
+define(function() {
'use strict';
function OrderElement() {
diff --git a/src/scripts/app/Main/component/provider/NgAdminConfiguration.js b/src/scripts/app/Main/component/provider/NgAdminConfiguration.js
new file mode 100644
index 00000000..b90b40ac
--- /dev/null
+++ b/src/scripts/app/Main/component/provider/NgAdminConfiguration.js
@@ -0,0 +1,23 @@
+define(function() {
+ 'use strict';
+
+ function NgAdminConfiguration() {
+ this.config = null;
+ }
+
+ NgAdminConfiguration.prototype.configure = function(config) {
+ this.config = config;
+ };
+
+ NgAdminConfiguration.prototype.$get = function() {
+ var self = this;
+
+ return function() {
+ return self.config;
+ }
+ };
+
+ NgAdminConfiguration.$inject = [];
+
+ return NgAdminConfiguration;
+});
diff --git a/src/scripts/app/Main/component/service/PanelBuilder.js b/src/scripts/app/Main/component/service/PanelBuilder.js
index bd0885fb..fcb015f8 100644
--- a/src/scripts/app/Main/component/service/PanelBuilder.js
+++ b/src/scripts/app/Main/component/service/PanelBuilder.js
@@ -1,16 +1,16 @@
-define([
- 'config'
-], function(config) {
+define(function() {
'use strict';
/**
* @param {$q} $q
* @param {CrudManager} CrudManager
+ * @param {Configuration} Configuration
* @constructor
*/
- function PanelBuilder($q, CrudManager) {
+ function PanelBuilder($q, CrudManager, Configuration) {
this.$q = $q;
this.CrudManager = CrudManager;
+ this.Configuration = Configuration();
}
/**
@@ -24,8 +24,8 @@ define([
limit,
self = this;
- angular.forEach(config.getEntityNames(), function(entityName) {
- entity = config.getEntity(entityName);
+ angular.forEach(this.Configuration.getEntityNames(), function(entityName) {
+ entity = self.Configuration.getEntity(entityName);
limit = entity.dashboard();
if (limit) {
@@ -36,7 +36,7 @@ define([
return this.$q.all(promises);
};
- PanelBuilder.$inject = ['$q', 'CrudManager'];
+ PanelBuilder.$inject = ['$q', 'CrudManager', 'NgAdminConfiguration'];
return PanelBuilder;
});
diff --git a/src/scripts/app/Main/component/service/Validator.js b/src/scripts/app/Main/component/service/Validator.js
index be50787e..4f1ec05e 100644
--- a/src/scripts/app/Main/component/service/Validator.js
+++ b/src/scripts/app/Main/component/service/Validator.js
@@ -1,11 +1,12 @@
-define(['config'], function(config) {
+define(function() {
'use strict';
- function Validator() {
+ function Validator(Configuration) {
+ this.Configuration = Configuration();
}
Validator.prototype.validate = function(entityName, entity) {
- var entityConfig = config.getEntity(entityName);
+ var entityConfig = this.Configuration.getEntity(entityName);
if (typeof(entityConfig) === 'undefined') {
return false;
@@ -20,5 +21,7 @@ define(['config'], function(config) {
});
};
+ Validator.$inject = ['NgAdminConfiguration'];
+
return Validator;
});
diff --git a/src/scripts/lib/config/Application.js b/src/scripts/app/Main/component/service/config/Application.js
similarity index 94%
rename from src/scripts/lib/config/Application.js
rename to src/scripts/app/Main/component/service/config/Application.js
index 36c53985..176fd763 100644
--- a/src/scripts/lib/config/Application.js
+++ b/src/scripts/app/Main/component/service/config/Application.js
@@ -1,10 +1,12 @@
-define(['lib/config/Configurable'], function (Configurable) {
+define(function (require) {
"use strict";
function defaultHeaders() {
return {};
}
+ var Configurable = require('app/Main/component/service/config/Configurable');
+
return function(title) {
var entities = {};
diff --git a/src/scripts/lib/config/Configurable.js b/src/scripts/app/Main/component/service/config/Configurable.js
similarity index 95%
rename from src/scripts/lib/config/Configurable.js
rename to src/scripts/app/Main/component/service/config/Configurable.js
index d93686af..94341cd4 100644
--- a/src/scripts/lib/config/Configurable.js
+++ b/src/scripts/app/Main/component/service/config/Configurable.js
@@ -1,6 +1,6 @@
// @see: https://github.com/marmelab/gremlins.js/blob/master/src/utils/configurable.js
-define([], function () {
+define(function () {
"use strict";
function configurable(targetFunction, config) {
diff --git a/src/scripts/lib/config/Entity.js b/src/scripts/app/Main/component/service/config/Entity.js
similarity index 97%
rename from src/scripts/lib/config/Entity.js
rename to src/scripts/app/Main/component/service/config/Entity.js
index a00947f6..bb55b2ee 100644
--- a/src/scripts/lib/config/Entity.js
+++ b/src/scripts/app/Main/component/service/config/Entity.js
@@ -1,6 +1,8 @@
-define(['lib/config/Configurable'], function (Configurable) {
+define(function (require) {
'use strict';
+ var Configurable = require('app/Main/component/service/config/Configurable');
+
/**
* Return the title depending if the config is a string or a function
* @param {Function} config
diff --git a/src/scripts/lib/config/Field.js b/src/scripts/app/Main/component/service/config/Field.js
similarity index 95%
rename from src/scripts/lib/config/Field.js
rename to src/scripts/app/Main/component/service/config/Field.js
index 70f26047..67f06109 100644
--- a/src/scripts/lib/config/Field.js
+++ b/src/scripts/app/Main/component/service/config/Field.js
@@ -1,6 +1,8 @@
-define(['lib/config/Configurable'], function (Configurable) {
+define(function (require) {
'use strict';
+ var Configurable = require('app/Main/component/service/config/Configurable');
+
return function(fieldName) {
var availableTypes = ['number', 'string', 'text', 'email', 'date'];
var availableEditions = ['read-only', 'editable'];
diff --git a/src/scripts/lib/config/Reference.js b/src/scripts/app/Main/component/service/config/Reference.js
similarity index 94%
rename from src/scripts/lib/config/Reference.js
rename to src/scripts/app/Main/component/service/config/Reference.js
index e5c7ab51..afd271c1 100644
--- a/src/scripts/lib/config/Reference.js
+++ b/src/scripts/app/Main/component/service/config/Reference.js
@@ -1,6 +1,8 @@
-define(['lib/config/Configurable'], function (Configurable) {
+define(function (require) {
'use strict';
+ var Configurable = require('app/Main/component/service/config/Configurable');
+
return function(fieldName) {
var availableTypes = ['number', 'text', 'email', 'date'];
var availableEditions = ['read-only', 'editable'];
diff --git a/src/scripts/lib/config/ReferenceMany.js b/src/scripts/app/Main/component/service/config/ReferenceMany.js
similarity index 94%
rename from src/scripts/lib/config/ReferenceMany.js
rename to src/scripts/app/Main/component/service/config/ReferenceMany.js
index 2a32d9a6..1e2af833 100644
--- a/src/scripts/lib/config/ReferenceMany.js
+++ b/src/scripts/app/Main/component/service/config/ReferenceMany.js
@@ -1,6 +1,8 @@
-define(['lib/config/Configurable'], function (Configurable) {
+define(function (require) {
'use strict';
+ var Configurable = require('app/Main/component/service/config/Configurable');
+
return function(fieldName) {
var availableTypes = ['number', 'text', 'email', 'date'];
var availableEditions = ['read-only', 'editable'];
diff --git a/src/scripts/lib/config/ReferencedList.js b/src/scripts/app/Main/component/service/config/ReferencedList.js
similarity index 94%
rename from src/scripts/lib/config/ReferencedList.js
rename to src/scripts/app/Main/component/service/config/ReferencedList.js
index a8b43e2c..8a254c3a 100644
--- a/src/scripts/lib/config/ReferencedList.js
+++ b/src/scripts/app/Main/component/service/config/ReferencedList.js
@@ -1,6 +1,8 @@
-define(['lib/config/Configurable'], function (Configurable) {
+define(function (require) {
'use strict';
+ var Configurable = require('app/Main/component/service/config/Configurable');
+
return function(fieldName) {
var name = fieldName || 'reference';
var items = [];
diff --git a/src/scripts/app/Main/config/routing.js b/src/scripts/app/Main/config/routing.js
index ebf232c2..fb35d94d 100644
--- a/src/scripts/app/Main/config/routing.js
+++ b/src/scripts/app/Main/config/routing.js
@@ -1,9 +1,9 @@
-define([
- 'text!../view/layout.html',
- 'text!../view/dashboard.html'
-], function (layoutTemplate, dashboardTemplate) {
+define(function (require) {
"use strict";
+ var layoutTemplate = require('text!../view/layout.html'),
+ dashboardTemplate = require('text!../view/dashboard.html');
+
function routing($stateProvider, $urlRouterProvider) {
$stateProvider.state('main', {
diff --git a/src/scripts/app/Main/run/Loader.js b/src/scripts/app/Main/run/Loader.js
index ef604450..0fb2bd71 100644
--- a/src/scripts/app/Main/run/Loader.js
+++ b/src/scripts/app/Main/run/Loader.js
@@ -1,8 +1,8 @@
-define([
- 'nprogress'
-], function(NProgress) {
+define(function(require) {
"use strict";
+ var NProgress = require('nprogress');
+
/**
* Display loader on each route change
*
diff --git a/src/scripts/common.js b/src/scripts/common.js
deleted file mode 100644
index bde0a052..00000000
--- a/src/scripts/common.js
+++ /dev/null
@@ -1,65 +0,0 @@
-require.config({
- paths: {
- 'jquery': 'bower_components/jquery/dist/jquery',
- 'angular': 'bower_components/angular/angular',
- 'angular-resource': 'bower_components/angular-resource/angular-resource',
- 'angular-sanitize': 'bower_components/angular-sanitize/angular-sanitize',
- 'angular-route': 'bower_components/angular-route/angular-route',
- 'angular-ui-router': 'bower_components/angular-ui-router/release/angular-ui-router',
- 'lodash': 'bower_components/lodash/dist/lodash.min',
- 'text' : 'bower_components/requirejs-text/text',
- 'angular-bootstrap': 'bower_components/angular-bootstrap/ui-bootstrap.min',
- 'angular-bootstrap-tpls': 'bower_components/angular-bootstrap/ui-bootstrap-tpls.min',
- 'restangular': 'bower_components/restangular/dist/restangular',
- 'humane': 'bower_components/humane/humane',
- 'nprogress': 'bower_components/nprogress/nprogress'
- },
- shim: {
- 'angular': {
- exports: 'angular'
- },
- 'restangular': {
- deps: ['angular', 'lodash']
- },
- 'angular-ui-router': {
- deps: ['angular']
- },
- 'angular-bootstrap': {
- deps: ['angular']
- },
- 'angular-bootstrap-tpls': {
- deps: ['angular', 'angular-bootstrap']
- },
- 'jquery': {
- exports: '$'
- },
- 'angular-resource': {
- deps: ['angular']
- },
- 'angular-sanitize': {
- deps: ['angular']
- },
- 'angular-route': {
- deps: ['angular']
- },
- 'nprogress': {
- exports: 'NProgress'
- }
- },
- modules: [
- {
- name: 'common',
- include: [
- 'lodash',
- 'angular',
- 'restangular',
- 'angular-ui-router',
- 'angular-bootstrap-tpls'
- ],
- override: {
- generateSourceMaps: false,
- optimize: 'none'
- }
- }
- ]
-});
diff --git a/src/scripts/config-dist.js b/src/scripts/config-dist.js
index f5c24471..4cbe909a 100644
--- a/src/scripts/config-dist.js
+++ b/src/scripts/config-dist.js
@@ -1,129 +1,132 @@
-define([
- 'lib/config/Application',
- 'lib/config/Entity',
- 'lib/config/Field',
- 'lib/config/Reference',
- 'lib/config/ReferencedList',
- 'lib/config/ReferenceMany'
-], function (Application, Entity, Field, Reference, ReferencedList, ReferenceMany) {
+(function() {
"use strict";
- var post = Entity('posts'),
- commentBody = Field('body'),
- postId = Field('id'),
- postCreatedAt = Field('created_at'),
- commentTags = ReferenceMany('tags');
+ var app = angular.module('myApp', ['ng-admin']);
- var tag = Entity('tags')
- .label('Tags')
- .dashboard(10)
- .pagination(function(page, maxPerPage) {
- return {
- _start: (page - 1) * maxPerPage,
- _end: (page) * maxPerPage
- };
- })
- .infinitePagination(false)
- .addField(Field('id')
- .order(1)
- .label('ID')
- .type('number')
- .identifier(true)
- .edition('read-only')
- )
- .addField(Field('name')
- .order(2)
- .label('Name')
- .edition('editable')
- .validation({
- "required": true,
- "max-length" : 150
- })
- );
+ app.config(function(NgAdminConfigurationProvider, Application, Entity, Field, Reference, ReferencedList, ReferenceMany) {
+ function truncate(value) {
+ return value.length > 50 ? value.substr(0, 50) + '...' : value;
+ }
- var comment = Entity('comments')
- .label('Comments')
- .dashboard(10)
- .pagination(function(page, maxPerPage) {
+ function pagination(page, maxPerPage) {
return {
- _start: (page - 1) * maxPerPage,
- _end: (page) * maxPerPage
- };
- })
- .infinitePagination(true)
- .addField(postId
- .order(1)
- .label('ID')
- .type('number')
- .identifier(true)
- .edition('read-only')
- )
- .addField(Reference('post_id')
- .targetEntity(post)
- .targetLabel('title')
- )
- .addField(commentBody
- .order(2)
- .type('text')
- .label('Comment')
- .edition('editable')
- .validation({
- "required": true,
- "max-length" : 150,
- "validator" : function(value) {
- return value.indexOf('chat') > -1;
- }
- })
- )
- .addField(postCreatedAt
+ offset: (page - 1) * maxPerPage,
+ limit: maxPerPage
+ }
+ }
+
+ var post = Entity('posts'),
+ commentBody = Field('body'),
+ postId = Field('id'),
+ postCreatedAt = Field('created_at');
+
+ var tag = Entity('tags')
.order(3)
- .label('Creation Date')
- .type('date')
- .edition('editable')
- .validation({
- "required": true
- })
- )
- .addField(commentTags
.label('Tags')
- .targetEntity(tag)
- .targetLabel('name')
+ .dashboard(10)
+ .pagination(pagination)
+ .infinitePagination(false)
+ .addField(Field('id')
+ .order(1)
+ .label('ID')
+ .type('number')
+ .identifier(true)
+ .edition('read-only')
+ )
+ .addField(Field('name')
+ .order(2)
+ .label('Name')
+ .edition('editable')
+ .validation({
+ "required": true,
+ "max-length" : 150
+ })
);
- post
- .label('Posts')
- .dashboard(null)
- .pagination(false)
- .addField(Field('id')
- .label('ID')
- .type('number')
- .identifier(true)
- .edition('read-only')
- )
- .addField(Field('title')
- .label('Title')
- .edition('editable')
- )
- .addField(Field('body')
- .label('Body')
- .type('text')
- .edition('editable')
- )
- .addField(ReferencedList('comments')
+ var comment = Entity('comments')
+ .order(2)
.label('Comments')
- .targetEntity(comment)
- .targetField('post_id')
- .targetFields([postId, commentBody, commentTags])
- )
- .addField(ReferenceMany('tags')
- .label('Tags')
- .targetEntity(tag)
- .targetLabel('name')
- );
+ .description('Lists all the blog comments with an infinite pagination')
+ .dashboard(10)
+ .pagination(pagination)
+ .infinitePagination(true)
+ .addField(postId
+ .order(1)
+ .label('ID')
+ .type('number')
+ .identifier(true)
+ .edition('read-only')
+ )
+ .addField(Reference('post_id')
+ .dashboard(false)
+ .targetEntity(post)
+ .targetLabel('title')
+ )
+ .addField(commentBody
+ .order(2)
+ .type('text')
+ .label('Comment')
+ .edition('editable')
+ .truncateList(truncate)
+ .validation({
+ "required": true,
+ "max-length" : 150
+ })
+ )
+ .addField(postCreatedAt
+ .order(3)
+ .label('Creation Date')
+ .type('date')
+ .edition('editable')
+ .validation({
+ "required": true
+ })
+ );
+
+ post
+ .label('Posts')
+ .order(1)
+ .dashboard(null)
+ .perPage(10)
+ .pagination(pagination)
+ .titleCreate('Create a post')
+ .titleEdit('Edit a post')
+ .description('Lists all the blog posts with a simple pagination')
+ .addField(Field('id')
+ .label('ID')
+ .type('number')
+ .identifier(true)
+ .edition('read-only')
+ )
+ .addField(Field('title')
+ .label('Title')
+ .edition('editable')
+ .truncateList(truncate)
+ )
+ .addField(Field('body')
+ .label('Body')
+ .type('text')
+ .edition('editable')
+ .truncateList(truncate)
+ )
+ .addField(ReferencedList('comments')
+ .label('Comments')
+ .targetEntity(comment)
+ .targetField('post_id')
+ .targetFields([postId, commentBody])
+ )
+ .addField(ReferenceMany('tags')
+ .label('Tags')
+ .targetEntity(tag)
+ .targetLabel('name')
+ );
+
+ var app = Application('ng-admin backend demo')
+ .baseApiUrl('http://localhost:3000/')
+ .addEntity(post)
+ .addEntity(comment)
+ .addEntity(tag);
- return Application('My backend')
- .baseApiUrl('http://localhost:3000/')
- .addEntity(post)
- .addEntity(comment)
- .addEntity(tag);
-});
+ NgAdminConfigurationProvider.configure(app);
+ })
+})();
diff --git a/src/scripts/ng-admin.js b/src/scripts/ng-admin.js
deleted file mode 100644
index f4f80876..00000000
--- a/src/scripts/ng-admin.js
+++ /dev/null
@@ -1,17 +0,0 @@
-require.config({
- paths: {
- 'MainModule': 'app/Main/MainModule',
- 'CrudModule': 'app/Crud/CrudModule'
- },
- modules: [
- {
- name: 'ng-admin',
- include: [
- 'text',
- 'MainModule',
- 'CrudModule'
- ],
- exclude: ['common']
- }
- ]
-});
diff --git a/test/app-test.js b/test/app-test.js
index a9d0573f..61284812 100644
--- a/test/app-test.js
+++ b/test/app-test.js
@@ -15,10 +15,58 @@ requirejs.config({
'angular-mocks': 'bower_components/angular-mocks/angular-mocks',
'mixins': '/base/test/mock/mixins',
'mock/q': '/base/test/mock/q',
- 'mock/Restangular': '/base/test/mock/Restangular'
+ 'mock/Restangular': '/base/test/mock/Restangular',
+
+ 'angular': 'bower_components/angular/angular',
+ 'angular-resource': 'bower_components/angular-resource/angular-resource',
+ 'angular-sanitize': 'bower_components/angular-sanitize/angular-sanitize',
+ 'angular-route': 'bower_components/angular-route/angular-route',
+ 'angular-ui-router': 'bower_components/angular-ui-router/release/angular-ui-router',
+ 'lodash': 'bower_components/lodash/dist/lodash.min',
+ 'text' : 'bower_components/requirejs-text/text',
+ 'angular-bootstrap': 'bower_components/angular-bootstrap/ui-bootstrap.min',
+ 'angular-bootstrap-tpls': 'bower_components/angular-bootstrap/ui-bootstrap-tpls.min',
+ 'restangular': 'bower_components/restangular/dist/restangular',
+ 'humane': 'bower_components/humane/humane',
+ 'nprogress': 'bower_components/nprogress/nprogress',
+
+ 'MainModule': 'app/Main/MainModule',
+ 'CrudModule': 'app/Crud/CrudModule'
},
shim: {
- 'angular-mocks': ['angular']
+ 'angular': {
+ exports: 'angular'
+ },
+ 'angular-mocks': {
+ deps: ['angular']
+ },
+ 'restangular': {
+ deps: ['angular', 'lodash']
+ },
+ 'angular-ui-router': {
+ deps: ['angular']
+ },
+ 'angular-bootstrap': {
+ deps: ['angular']
+ },
+ 'angular-bootstrap-tpls': {
+ deps: ['angular', 'angular-bootstrap']
+ },
+ 'jquery': {
+ exports: '$'
+ },
+ 'angular-resource': {
+ deps: ['angular']
+ },
+ 'angular-sanitize': {
+ deps: ['angular']
+ },
+ 'angular-route': {
+ deps: ['angular']
+ },
+ 'nprogress': {
+ exports: 'NProgress'
+ }
},
// ask Require.js to load these files (all our tests)
diff --git a/test/karma.conf.js b/test/karma.conf.js
index f7744d2e..9459f8fa 100644
--- a/test/karma.conf.js
+++ b/test/karma.conf.js
@@ -10,18 +10,12 @@ module.exports = function(config) {
{pattern: 'src/scripts/bower_components/angular-mocks/angular-mocks.js', included: false},
// ng-admin application files
- {pattern: 'src/scripts/lib/**/*.js', included: false},
{pattern: 'src/scripts/app/**/component/**/*.js', included: false},
{pattern: 'src/scripts/app/**/config/**/*.js', included: false},
{pattern: 'src/scripts/app/**/view/**/*.html', included: false},
- // require configuration files
- 'src/scripts/common.js',
- 'src/scripts/ng-admin.js',
-
// Test files
{pattern: 'test/unit/**/**/*.js', included: false},
- {pattern: 'test/unit/lib/**/*.js', included: false},
{pattern: 'test/mock/*.js', included: false},
// Test bootstrap
diff --git a/test/unit/Crud/component/service/CrudManagerSpec.js b/test/unit/Crud/component/service/CrudManagerSpec.js
index 0c006f84..d54b2487 100644
--- a/test/unit/Crud/component/service/CrudManagerSpec.js
+++ b/test/unit/Crud/component/service/CrudManagerSpec.js
@@ -1,19 +1,17 @@
/*global require,describe,module,beforeEach,inject,it,expect*/
-define('config', null);
-
-define([
- 'app/Crud/component/service/CrudManager',
- 'lib/config/Application',
- 'lib/config/Entity',
- 'lib/config/Field',
- 'lib/config/Reference',
- 'mixins',
- 'mock/q',
- 'mock/Restangular'
-], function(CrudManager, Application, Entity, Field, Reference, mixins, $q, Restangular) {
+define(function(require) {
'use strict';
+ var CrudManager = require('app/Crud/component/service/CrudManager'),
+ Application = require('app/Main/component/service/config/Application'),
+ Entity = require('app/Main/component/service/config/Entity'),
+ Field = require('app/Main/component/service/config/Field'),
+ Reference = require('app/Main/component/service/config/Reference'),
+ mixins = require('mixins'),
+ $q = require('mock/q'),
+ Restangular = require('mock/Restangular');
+
describe("Service: CrudManager", function() {
var crudManager,
catEntity,
@@ -47,10 +45,14 @@ define([
}))
.addField(Reference('human_id').targetEntity(humanEntity).targetLabel('name'));
- var config = Application('test')
+ var rawConfig = Application('test')
.addEntity(catEntity)
.addEntity(humanEntity);
+ var config = function() {
+ return rawConfig;
+ };
+
crudManager = new CrudManager($q, Restangular, config);
});
diff --git a/test/unit/lib/config/ApplicationSpec.js b/test/unit/lib/config/ApplicationSpec.js
deleted file mode 100644
index e69de29b..00000000