From 2b77bb6df5a3cdfc3ec935940ecd02a810e73594 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Tue, 16 Sep 2014 08:14:38 +0200 Subject: [PATCH 01/10] Add build process --- Gruntfile.js | 24 ++++++++++++++++++++++++ bower.json | 1 - grunt/grunt-requirejs.json | 10 ++++++---- package.json | 3 +++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index ad616223..0b9200cc 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: { + src: ['src/build/common.js', 'src/build/ng-admin.js', 'src/build/app.js'] + } + }, + + concat: { + options: { + separator: ';' + }, + dist: { + src: ['src/build/common.js', 'src/build/ng-admin.js', 'src/build/app.js'], + dest: '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-concat'); + grunt.loadNpmTasks('grunt-contrib-clean'); + 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', 'concat', 'clean:build']); // register default task grunt.registerTask('default', ['concurrent:assets_all_dev', 'concurrent:connect_watch']); diff --git a/bower.json b/bower.json index 04e0fb31..53314c71 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", diff --git a/grunt/grunt-requirejs.json b/grunt/grunt-requirejs.json index ba28a029..8070505a 100644 --- a/grunt/grunt-requirejs.json +++ b/grunt/grunt-requirejs.json @@ -20,18 +20,20 @@ "prod": { "options": { "appDir": "src/scripts", - "fileExclusionRegExp": "^(build)", "baseUrl": "./", - "dir": "src/require", - "optimize": "uglify2", + "dir": "src/build", + "optimize": "none", "preserveLicenseComments": false, + "findNestedDependencies": true, "generateSourceMaps": false, "skipDirOptimize": true, "removeCombined": true, + "include": "app", "mainConfigFile": [ "src/scripts/common.js", - "src/scripts/ng-admin.js" + "src/scripts/ng-admin.js", + "src/scripts/app.js" ] } } diff --git a/package.json b/package.json index 135c2d3a..4fed06bb 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,11 @@ "requirejs": "~2.1.14" }, "devDependencies": { + "grunt-contrib-clean": "^0.6.0", + "grunt-contrib-concat": "^0.5.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", From 5ceeaca07c95ec80ec9ba6844a341f0c5636409f Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Tue, 16 Sep 2014 08:19:28 +0200 Subject: [PATCH 02/10] wip: add minification --- Gruntfile.js | 11 ++++++++++- grunt/grunt-requirejs.json | 1 - package.json | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 0b9200cc..b17f4c33 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,12 +14,20 @@ module.exports = function (grunt) { } }, + uglify: { + ngadmin: { + files: { + 'src/build/ng-admin.min.js': ['src/build/common.js', 'src/build/ng-admin.js', 'src/build/app.js'] + } + } + }, + concat: { options: { separator: ';' }, dist: { - src: ['src/build/common.js', 'src/build/ng-admin.js', 'src/build/app.js'], + src: [], dest: 'src/build/ng-admin.min.js' } }, @@ -94,6 +102,7 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-ng-annotate'); grunt.loadNpmTasks('grunt-concurrent'); grunt.loadNpmTasks('grunt-karma'); diff --git a/grunt/grunt-requirejs.json b/grunt/grunt-requirejs.json index 8070505a..412253e6 100644 --- a/grunt/grunt-requirejs.json +++ b/grunt/grunt-requirejs.json @@ -22,7 +22,6 @@ "appDir": "src/scripts", "baseUrl": "./", "dir": "src/build", - "optimize": "none", "preserveLicenseComments": false, "findNestedDependencies": true, "generateSourceMaps": false, diff --git a/package.json b/package.json index 4fed06bb..2cde66f2 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "devDependencies": { "grunt-contrib-clean": "^0.6.0", "grunt-contrib-concat": "^0.5.0", + "grunt-contrib-uglify": "^0.5.1", "grunt-contrib-watch": "~0.5.2", "grunt-karma": "^0.8.3", "grunt-ng-annotate": "^0.3.2", From df30da9e7b53f6d5b6003c65f686bc2b15a71341 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Thu, 18 Sep 2014 07:20:10 +0200 Subject: [PATCH 03/10] wip - use ng-admin with another app --- bower.json | 3 +- src/index.html | 8 ++- src/scripts/app.js | 8 --- .../app/Crud/component/service/CrudManager.js | 15 +++-- src/scripts/app/Main/MainModule.js | 9 ++- .../component/controller/AppController.js | 10 ++- .../component/controller/SidebarController.js | 10 ++- .../Main/component/provider/Configuration.js | 23 +++++++ .../Main/component/service/PanelBuilder.js | 14 ++--- .../app/Main/component/service/Validator.js | 9 ++- src/scripts/config-dist.js | 62 +++++++++++-------- 11 files changed, 102 insertions(+), 69 deletions(-) create mode 100644 src/scripts/app/Main/component/provider/Configuration.js diff --git a/bower.json b/bower.json index 53314c71..0e0d9656 100644 --- a/bower.json +++ b/bower.json @@ -23,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/src/index.html b/src/index.html index a7aeadae..49c37e96 100644 --- a/src/index.html +++ b/src/index.html @@ -12,9 +12,13 @@ + + + - +
-
diff --git a/src/scripts/app.js b/src/scripts/app.js index 826ac57f..7dba74e2 100644 --- a/src/scripts/app.js +++ b/src/scripts/app.js @@ -6,14 +6,6 @@ require(['common', 'ng-admin'], function () { "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'); - - // async resource download implies async angular app bootstrap - angular.bootstrap(document.body, ['ng-admin']); }); }); diff --git a/src/scripts/app/Crud/component/service/CrudManager.js b/src/scripts/app/Crud/component/service/CrudManager.js index 15c30e74..20760f71 100644 --- a/src/scripts/app/Crud/component/service/CrudManager.js +++ b/src/scripts/app/Crud/component/service/CrudManager.js @@ -1,22 +1,21 @@ define([ - 'angular', - 'config' -], function(angular, ApplicationConfig) { + 'angular' +], function(angular) { 'use strict'; /** * * @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.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', 'Configuration']; return CrudManager; }); diff --git a/src/scripts/app/Main/MainModule.js b/src/scripts/app/Main/MainModule.js index 887206df..9326146c 100644 --- a/src/scripts/app/Main/MainModule.js +++ b/src/scripts/app/Main/MainModule.js @@ -1,7 +1,6 @@ define( [ 'angular', - 'config', 'app/Main/component/controller/AppController', 'app/Main/component/controller/DashboardController', @@ -10,6 +9,8 @@ define( 'app/Main/component/service/PanelBuilder', 'app/Main/component/service/Validator', + 'app/Main/component/provider/Configuration', + 'app/Main/component/filter/OrderElement', 'app/Main/config/routing', @@ -20,7 +21,6 @@ define( ], function ( angular, - config, AppController, DashboardController, @@ -29,6 +29,8 @@ define( PanelBuilder, Validator, + Configuration, + OrderElement, routing, @@ -38,7 +40,6 @@ define( "use strict"; var MainModule = angular.module('main', ['ui.router', 'restangular']); - MainModule.constant('config', config); MainModule.controller('AppController', AppController); MainModule.controller('DashboardController', DashboardController); @@ -47,6 +48,8 @@ define( MainModule.service('PanelBuilder', PanelBuilder); MainModule.service('Validator', Validator); + MainModule.provider('Configuration', Configuration); + MainModule.filter('orderElement', OrderElement); MainModule.config(routing); diff --git a/src/scripts/app/Main/component/controller/AppController.js b/src/scripts/app/Main/component/controller/AppController.js index e1faab53..50ae5348 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', 'Configuration']; return AppController; }); diff --git a/src/scripts/app/Main/component/controller/SidebarController.js b/src/scripts/app/Main/component/controller/SidebarController.js index 0558a05c..794cf4e6 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', 'Configuration']; return SidebarController; }); diff --git a/src/scripts/app/Main/component/provider/Configuration.js b/src/scripts/app/Main/component/provider/Configuration.js new file mode 100644 index 00000000..8aa35725 --- /dev/null +++ b/src/scripts/app/Main/component/provider/Configuration.js @@ -0,0 +1,23 @@ +define([], function() { + 'use strict'; + + function Configuration() { + this.config = null; + } + + Configuration.prototype.configure = function(config) { + this.config = config; + }; + + Configuration.prototype.$get = function() { + var self = this; + + return function() { + return self.config; + } + }; + + Configuration.$inject = []; + + return Configuration; +}); diff --git a/src/scripts/app/Main/component/service/PanelBuilder.js b/src/scripts/app/Main/component/service/PanelBuilder.js index bd0885fb..d70fc2b1 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', 'Configuration']; return PanelBuilder; }); diff --git a/src/scripts/app/Main/component/service/Validator.js b/src/scripts/app/Main/component/service/Validator.js index be50787e..93ddfc85 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 = ['Configuration']; + return Validator; }); diff --git a/src/scripts/config-dist.js b/src/scripts/config-dist.js index f5c24471..bdccbedf 100644 --- a/src/scripts/config-dist.js +++ b/src/scripts/config-dist.js @@ -8,13 +8,17 @@ define([ ], function (Application, Entity, Field, Reference, ReferencedList, ReferenceMany) { "use strict"; + function truncate(value) { + return value.length > 50 ? value.substr(0, 50) + '...' : value; + } + var post = Entity('posts'), commentBody = Field('body'), postId = Field('id'), - postCreatedAt = Field('created_at'), - commentTags = ReferenceMany('tags'); + postCreatedAt = Field('created_at'); var tag = Entity('tags') + .order(3) .label('Tags') .dashboard(10) .pagination(function(page, maxPerPage) { @@ -30,7 +34,7 @@ define([ .type('number') .identifier(true) .edition('read-only') - ) + ) .addField(Field('name') .order(2) .label('Name') @@ -39,10 +43,12 @@ define([ "required": true, "max-length" : 150 }) - ); + ); var comment = Entity('comments') + .order(2) .label('Comments') + .description('Lists all the blog comments with an infinite pagination') .dashboard(10) .pagination(function(page, maxPerPage) { return { @@ -57,24 +63,23 @@ define([ .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, - "validator" : function(value) { - return value.indexOf('chat') > -1; - } + "max-length" : 150 }) - ) + ) .addField(postCreatedAt .order(3) .label('Creation Date') @@ -83,45 +88,52 @@ define([ .validation({ "required": true }) - ) - .addField(commentTags - .label('Tags') - .targetEntity(tag) - .targetLabel('name') - ); + ); post .label('Posts') + .order(1) .dashboard(null) - .pagination(false) + .perPage(10) + .pagination(function(page, maxPerPage) { + return { + _start: (page - 1) * maxPerPage, + _end: (page) * maxPerPage + }; + }) + .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, commentTags]) - ) + .targetFields([postId, commentBody]) + ) .addField(ReferenceMany('tags') .label('Tags') .targetEntity(tag) .targetLabel('name') - ); + ); - return Application('My backend') + return Application('ng-admin backend demo') .baseApiUrl('http://localhost:3000/') .addEntity(post) .addEntity(comment) From a4b93e6a4bf659128299555ff21fcff100daad4e Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Thu, 18 Sep 2014 18:45:32 +0200 Subject: [PATCH 04/10] Add a provider to configure app from another app --- src/index.html | 7 +- src/scripts/app.js | 60 +++++++++++++++-- .../app/Crud/component/service/CrudManager.js | 4 +- src/scripts/app/Main/MainModule.js | 21 ++++++ .../component/controller/AppController.js | 2 +- .../component/controller/SidebarController.js | 2 +- .../Main/component/service/PanelBuilder.js | 4 +- .../app/Main/component/service/Validator.js | 2 +- .../component/service}/config/Application.js | 2 +- .../component/service}/config/Configurable.js | 0 .../Main/component/service}/config/Entity.js | 2 +- .../Main/component/service}/config/Field.js | 2 +- .../component/service}/config/Reference.js | 2 +- .../service}/config/ReferenceMany.js | 2 +- .../service}/config/ReferencedList.js | 2 +- src/scripts/common.js | 65 ------------------- src/scripts/ng-admin.js | 17 ----- 17 files changed, 91 insertions(+), 105 deletions(-) rename src/scripts/{lib => app/Main/component/service}/config/Application.js (95%) rename src/scripts/{lib => app/Main/component/service}/config/Configurable.js (100%) rename src/scripts/{lib => app/Main/component/service}/config/Entity.js (98%) rename src/scripts/{lib => app/Main/component/service}/config/Field.js (96%) rename src/scripts/{lib => app/Main/component/service}/config/Reference.js (95%) rename src/scripts/{lib => app/Main/component/service}/config/ReferenceMany.js (95%) rename src/scripts/{lib => app/Main/component/service}/config/ReferencedList.js (95%) delete mode 100644 src/scripts/common.js delete mode 100644 src/scripts/ng-admin.js diff --git a/src/index.html b/src/index.html index 49c37e96..c13f2b04 100644 --- a/src/index.html +++ b/src/index.html @@ -12,13 +12,8 @@ - - - - +
diff --git a/src/scripts/app.js b/src/scripts/app.js index 7dba74e2..924d9c69 100644 --- a/src/scripts/app.js +++ b/src/scripts/app.js @@ -2,10 +2,62 @@ require.config({ waitSeconds: 30 }); -require(['common', 'ng-admin'], function () { +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', + + '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(['angular', 'MainModule', 'CrudModule'], function (angular) { "use strict"; - require(['angular', 'MainModule', 'CrudModule'], function (angular) { - angular.module('ng-admin', ['main', 'crud']); - }); + angular.module('ng-admin', ['main', 'crud']); }); diff --git a/src/scripts/app/Crud/component/service/CrudManager.js b/src/scripts/app/Crud/component/service/CrudManager.js index 20760f71..e9d38be7 100644 --- a/src/scripts/app/Crud/component/service/CrudManager.js +++ b/src/scripts/app/Crud/component/service/CrudManager.js @@ -13,9 +13,9 @@ define([ function CrudManager($q, Restangular, Configuration) { this.$q = $q; this.Restangular = Restangular; - this.config = Configuration; + this.config = Configuration(); - this.Restangular.setBaseUrl('' /*this.config.baseApiUrl()*/); + this.Restangular.setBaseUrl(this.config.baseApiUrl()); this.Restangular.setFullResponse(true); // To get also the headers } diff --git a/src/scripts/app/Main/MainModule.js b/src/scripts/app/Main/MainModule.js index 9326146c..096a361a 100644 --- a/src/scripts/app/Main/MainModule.js +++ b/src/scripts/app/Main/MainModule.js @@ -9,6 +9,13 @@ define( 'app/Main/component/service/PanelBuilder', 'app/Main/component/service/Validator', + 'app/Main/component/service/config/Application', + 'app/Main/component/service/config/Entity', + 'app/Main/component/service/config/Field', + 'app/Main/component/service/config/Reference', + 'app/Main/component/service/config/ReferencedList', + 'app/Main/component/service/config/ReferenceMany', + 'app/Main/component/provider/Configuration', 'app/Main/component/filter/OrderElement', @@ -29,6 +36,13 @@ define( PanelBuilder, Validator, + Application, + Entity, + Field, + Reference, + ReferencedList, + ReferenceMany, + Configuration, OrderElement, @@ -48,6 +62,13 @@ define( MainModule.service('PanelBuilder', PanelBuilder); MainModule.service('Validator', Validator); + 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.provider('Configuration', Configuration); MainModule.filter('orderElement', OrderElement); diff --git a/src/scripts/app/Main/component/controller/AppController.js b/src/scripts/app/Main/component/controller/AppController.js index 50ae5348..df8481c4 100644 --- a/src/scripts/app/Main/component/controller/AppController.js +++ b/src/scripts/app/Main/component/controller/AppController.js @@ -8,7 +8,7 @@ define([], function() { */ var AppController = function ($scope, Configuration) { this.$scope = $scope; - this.applicationName = '';//Configuration.title(); + this.applicationName = Configuration().title(); $scope.$on('$destroy', this.destroy.bind(this)); }; diff --git a/src/scripts/app/Main/component/controller/SidebarController.js b/src/scripts/app/Main/component/controller/SidebarController.js index 794cf4e6..e551c1f9 100644 --- a/src/scripts/app/Main/component/controller/SidebarController.js +++ b/src/scripts/app/Main/component/controller/SidebarController.js @@ -4,7 +4,7 @@ define([], function() { var SidebarController = function($scope, $location, Configuration) { this.$scope = $scope; this.$location = $location; - this.entities = []; //Configuration.getEntities(); + this.entities = Configuration().getEntities(); this.computeCurrentEntity(); $scope.$on('$locationChangeSuccess', this.computeCurrentEntity.bind(this)); diff --git a/src/scripts/app/Main/component/service/PanelBuilder.js b/src/scripts/app/Main/component/service/PanelBuilder.js index d70fc2b1..8d0ef1b5 100644 --- a/src/scripts/app/Main/component/service/PanelBuilder.js +++ b/src/scripts/app/Main/component/service/PanelBuilder.js @@ -10,7 +10,7 @@ define([], function() { function PanelBuilder($q, CrudManager, Configuration) { this.$q = $q; this.CrudManager = CrudManager; - this.Configuration = Configuration; + this.Configuration = Configuration(); } /** @@ -24,7 +24,7 @@ define([], function() { limit, self = this; - angular.forEach([] /*this.Configuration.getEntityNames()*/, function(entityName) { + angular.forEach(this.Configuration.getEntityNames(), function(entityName) { entity = self.Configuration.getEntity(entityName); limit = entity.dashboard(); diff --git a/src/scripts/app/Main/component/service/Validator.js b/src/scripts/app/Main/component/service/Validator.js index 93ddfc85..9f91666b 100644 --- a/src/scripts/app/Main/component/service/Validator.js +++ b/src/scripts/app/Main/component/service/Validator.js @@ -2,7 +2,7 @@ define([], function() { 'use strict'; function Validator(Configuration) { - this.Configuration = Configuration; + this.Configuration = Configuration(); } Validator.prototype.validate = function(entityName, entity) { diff --git a/src/scripts/lib/config/Application.js b/src/scripts/app/Main/component/service/config/Application.js similarity index 95% rename from src/scripts/lib/config/Application.js rename to src/scripts/app/Main/component/service/config/Application.js index 36c53985..a8d7fadf 100644 --- a/src/scripts/lib/config/Application.js +++ b/src/scripts/app/Main/component/service/config/Application.js @@ -1,4 +1,4 @@ -define(['lib/config/Configurable'], function (Configurable) { +define(['app/Main/component/service/config/Configurable'], function (Configurable) { "use strict"; function defaultHeaders() { diff --git a/src/scripts/lib/config/Configurable.js b/src/scripts/app/Main/component/service/config/Configurable.js similarity index 100% rename from src/scripts/lib/config/Configurable.js rename to src/scripts/app/Main/component/service/config/Configurable.js diff --git a/src/scripts/lib/config/Entity.js b/src/scripts/app/Main/component/service/config/Entity.js similarity index 98% rename from src/scripts/lib/config/Entity.js rename to src/scripts/app/Main/component/service/config/Entity.js index a00947f6..2c6b025b 100644 --- a/src/scripts/lib/config/Entity.js +++ b/src/scripts/app/Main/component/service/config/Entity.js @@ -1,4 +1,4 @@ -define(['lib/config/Configurable'], function (Configurable) { +define(['app/Main/component/service/config/Configurable'], function (Configurable) { 'use strict'; /** diff --git a/src/scripts/lib/config/Field.js b/src/scripts/app/Main/component/service/config/Field.js similarity index 96% rename from src/scripts/lib/config/Field.js rename to src/scripts/app/Main/component/service/config/Field.js index 70f26047..fdf4917e 100644 --- a/src/scripts/lib/config/Field.js +++ b/src/scripts/app/Main/component/service/config/Field.js @@ -1,4 +1,4 @@ -define(['lib/config/Configurable'], function (Configurable) { +define(['app/Main/component/service/config/Configurable'], function (Configurable) { 'use strict'; return function(fieldName) { diff --git a/src/scripts/lib/config/Reference.js b/src/scripts/app/Main/component/service/config/Reference.js similarity index 95% rename from src/scripts/lib/config/Reference.js rename to src/scripts/app/Main/component/service/config/Reference.js index e5c7ab51..5150029f 100644 --- a/src/scripts/lib/config/Reference.js +++ b/src/scripts/app/Main/component/service/config/Reference.js @@ -1,4 +1,4 @@ -define(['lib/config/Configurable'], function (Configurable) { +define(['app/Main/component/service/config/Configurable'], function (Configurable) { 'use strict'; return function(fieldName) { diff --git a/src/scripts/lib/config/ReferenceMany.js b/src/scripts/app/Main/component/service/config/ReferenceMany.js similarity index 95% rename from src/scripts/lib/config/ReferenceMany.js rename to src/scripts/app/Main/component/service/config/ReferenceMany.js index 2a32d9a6..9bd63a4c 100644 --- a/src/scripts/lib/config/ReferenceMany.js +++ b/src/scripts/app/Main/component/service/config/ReferenceMany.js @@ -1,4 +1,4 @@ -define(['lib/config/Configurable'], function (Configurable) { +define(['app/Main/component/service/config/Configurable'], function (Configurable) { 'use strict'; return function(fieldName) { diff --git a/src/scripts/lib/config/ReferencedList.js b/src/scripts/app/Main/component/service/config/ReferencedList.js similarity index 95% rename from src/scripts/lib/config/ReferencedList.js rename to src/scripts/app/Main/component/service/config/ReferencedList.js index a8b43e2c..b66681a9 100644 --- a/src/scripts/lib/config/ReferencedList.js +++ b/src/scripts/app/Main/component/service/config/ReferencedList.js @@ -1,4 +1,4 @@ -define(['lib/config/Configurable'], function (Configurable) { +define(['app/Main/component/service/config/Configurable'], function (Configurable) { 'use strict'; return function(fieldName) { 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/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'] - } - ] -}); From 5e31beefab81673c78f6afe1b3c01514f1a65f63 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Fri, 19 Sep 2014 10:40:40 +0200 Subject: [PATCH 05/10] WIP - build app --- grunt/grunt-requirejs.json | 27 +++++----- src/index.html | 5 ++ src/scripts/app.js | 108 ++++++++++++++++++++----------------- 3 files changed, 76 insertions(+), 64 deletions(-) diff --git a/grunt/grunt-requirejs.json b/grunt/grunt-requirejs.json index 412253e6..69ea1541 100644 --- a/grunt/grunt-requirejs.json +++ b/grunt/grunt-requirejs.json @@ -10,30 +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", - "baseUrl": "./", - "dir": "src/build", + "baseUrl": "src/scripts", + "mainConfigFile": "src/scripts/app.js", + "include": ["app"], + "name": "bower_components/almond/almond", + "out": "./src/ng-admin.min.js", + + "optimize": "uglify2", "preserveLicenseComments": false, "findNestedDependencies": true, "generateSourceMaps": false, "skipDirOptimize": true, "removeCombined": true, - "include": "app", - - "mainConfigFile": [ - "src/scripts/common.js", - "src/scripts/ng-admin.js", - "src/scripts/app.js" - ] + "wrap": { + "startFile": "build/start.frag", + "endFile": "build/end.frag" + } } } } diff --git a/src/index.html b/src/index.html index c13f2b04..7687672e 100644 --- a/src/index.html +++ b/src/index.html @@ -11,7 +11,12 @@ + + + +
diff --git a/src/scripts/app.js b/src/scripts/app.js index 924d9c69..46e2261b 100644 --- a/src/scripts/app.js +++ b/src/scripts/app.js @@ -1,63 +1,73 @@ -require.config({ - waitSeconds: 30 -}); - 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', - - 'MainModule': 'app/Main/MainModule', - 'CrudModule': 'app/Crud/CrudModule' + 'angular': 'bower_components/angular/angular' }, 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(['angular', 'MainModule', 'CrudModule'], function (angular) { +define(function(require) { "use strict"; - angular.module('ng-admin', ['main', 'crud']); + var angular = require('angular'); + + angular.module('ng-admin', [/*'main', 'crud'*/]); + + //// TMP + //var app = angular.module('myApp', ['ng-admin']); + // + //app.config(function(ConfigurationProvider, Application, Entity, Field, Reference, ReferencedList, ReferenceMany) { + // function truncate(value) { + // return value.length > 50 ? value.substr(0, 50) + '...' : value; + // } + // + // var post = Entity('posts') + // .label('Posts') + // .order(1) + // .dashboard(10) + // .perPage(10) + // .pagination(function(page, maxPerPage) { + // return { + // offset: (page - 1) * maxPerPage, + // limit: maxPerPage + // }; + // }) + // .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) + // ); + // + // var app = Application('ng-admin backend demo') + // .baseApiUrl('http://localhost:3000/') + // .addEntity(post); + // + // ConfigurationProvider.configure(app); + //}); + // + //// 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', 'myApp'); + // + //// async resource download implies async angular app bootstrap + //angular.bootstrap(document.body, ['myApp']); }); From e38e3e57254a282386d767fb5fc852d31c65a77c Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Mon, 22 Sep 2014 08:07:17 +0200 Subject: [PATCH 06/10] Add build process --- Gruntfile.js | 2 +- grunt/grunt-requirejs.json | 4 +- sass/screen.scss | 3 + src/index.html | 14 +- src/scripts/app.js | 102 ++++--- src/scripts/app/Crud/CrudModule.js | 89 +++--- .../component/controller/DeleteController.js | 2 +- .../component/controller/FormController.js | 8 +- .../component/controller/ListController.js | 6 +- .../component/directive/InfinitePagination.js | 6 +- .../app/Crud/component/service/CrudManager.js | 6 +- src/scripts/app/Crud/config/routing.js | 12 +- src/scripts/app/Main/MainModule.js | 103 +++---- .../component/controller/AppController.js | 2 +- .../controller/DashboardController.js | 2 +- .../component/controller/SidebarController.js | 2 +- .../app/Main/component/filter/OrderElement.js | 2 +- .../Main/component/provider/Configuration.js | 2 +- .../Main/component/service/PanelBuilder.js | 2 +- .../app/Main/component/service/Validator.js | 2 +- .../component/service/config/Application.js | 6 +- .../component/service/config/Configurable.js | 2 +- .../Main/component/service/config/Entity.js | 4 +- .../Main/component/service/config/Field.js | 4 +- .../component/service/config/Reference.js | 4 +- .../component/service/config/ReferenceMany.js | 4 +- .../service/config/ReferencedList.js | 4 +- src/scripts/app/Main/config/routing.js | 8 +- src/scripts/app/Main/run/Loader.js | 6 +- src/scripts/config-dist.js | 253 +++++++++--------- 30 files changed, 304 insertions(+), 362 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index b17f4c33..18b41efa 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -111,7 +111,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', 'concat', 'clean:build']); + grunt.registerTask('build', ['requirejs:prod', /*'ngAnnotate', 'concat',*/ 'clean:build']); // register default task grunt.registerTask('default', ['concurrent:assets_all_dev', 'concurrent:connect_watch']); diff --git a/grunt/grunt-requirejs.json b/grunt/grunt-requirejs.json index 69ea1541..9b7dce50 100644 --- a/grunt/grunt-requirejs.json +++ b/grunt/grunt-requirejs.json @@ -19,9 +19,9 @@ "mainConfigFile": "src/scripts/app.js", "include": ["app"], "name": "bower_components/almond/almond", - "out": "./src/ng-admin.min.js", + "out": "./src/build/ng-admin.min.js", - "optimize": "uglify2", + "optimize": "none", "preserveLicenseComments": false, "findNestedDependencies": true, "generateSourceMaps": false, 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 7687672e..5c20babd 100644 --- a/src/index.html +++ b/src/index.html @@ -1,24 +1,16 @@ - + Angular admin - - - - - - - + - +
diff --git a/src/scripts/app.js b/src/scripts/app.js index 46e2261b..9a6abb90 100644 --- a/src/scripts/app.js +++ b/src/scripts/app.js @@ -1,73 +1,61 @@ require.config({ paths: { - 'angular': 'bower_components/angular/angular' + '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' } } }); - define(function(require) { "use strict"; var angular = require('angular'); + require('MainModule'); + require('CrudModule'); - angular.module('ng-admin', [/*'main', 'crud'*/]); - - //// TMP - //var app = angular.module('myApp', ['ng-admin']); - // - //app.config(function(ConfigurationProvider, Application, Entity, Field, Reference, ReferencedList, ReferenceMany) { - // function truncate(value) { - // return value.length > 50 ? value.substr(0, 50) + '...' : value; - // } - // - // var post = Entity('posts') - // .label('Posts') - // .order(1) - // .dashboard(10) - // .perPage(10) - // .pagination(function(page, maxPerPage) { - // return { - // offset: (page - 1) * maxPerPage, - // limit: maxPerPage - // }; - // }) - // .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) - // ); - // - // var app = Application('ng-admin backend demo') - // .baseApiUrl('http://localhost:3000/') - // .addEntity(post); - // - // ConfigurationProvider.configure(app); - //}); - // - //// 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', 'myApp'); - // - //// async resource download implies async angular app bootstrap - //angular.bootstrap(document.body, ['myApp']); + 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 e9d38be7..11163c4c 100644 --- a/src/scripts/app/Crud/component/service/CrudManager.js +++ b/src/scripts/app/Crud/component/service/CrudManager.js @@ -1,8 +1,8 @@ -define([ - 'angular' -], function(angular) { +define(function(require) { 'use strict'; + var angular = require('angular'); + /** * * @param {$q} $q 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 096a361a..42d577f5 100644 --- a/src/scripts/app/Main/MainModule.js +++ b/src/scripts/app/Main/MainModule.js @@ -1,82 +1,55 @@ -define( - [ - 'angular', +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/service/config/Application', - 'app/Main/component/service/config/Entity', - 'app/Main/component/service/config/Field', - 'app/Main/component/service/config/Reference', - 'app/Main/component/service/config/ReferencedList', - 'app/Main/component/service/config/ReferenceMany', + Configuration = require('app/Main/component/provider/Configuration'), - 'app/Main/component/provider/Configuration', + OrderElement = require('app/Main/component/filter/OrderElement'), - 'app/Main/component/filter/OrderElement', + routing = require('app/Main/config/routing'), - 'app/Main/config/routing', + loader = require('app/Main/run/Loader'); - 'app/Main/run/Loader', + require('angular-ui-router'); + require('restangular'); - 'angular-ui-router', 'restangular' - ], - function ( - angular, + "use strict"; - AppController, - DashboardController, - SidebarController, + var MainModule = angular.module('main', ['ui.router', 'restangular']); - PanelBuilder, - Validator, + MainModule.controller('AppController', AppController); + MainModule.controller('DashboardController', DashboardController); + MainModule.controller('SidebarController', SidebarController); - Application, - Entity, - Field, - Reference, - ReferencedList, - ReferenceMany, + MainModule.service('PanelBuilder', PanelBuilder); + MainModule.service('Validator', Validator); - Configuration, + MainModule.constant('Application', Application); + MainModule.constant('Entity', Entity); + MainModule.constant('Field', Field); + MainModule.constant('Reference', Reference); + MainModule.constant('ReferencedList', ReferencedList); + MainModule.constant('ReferenceMany', ReferenceMany); - OrderElement, + MainModule.provider('Configuration', Configuration); - routing, + MainModule.filter('orderElement', OrderElement); - loader - ) { - "use strict"; + MainModule.config(routing); - var MainModule = angular.module('main', ['ui.router', 'restangular']); + MainModule.run(loader); - MainModule.controller('AppController', AppController); - MainModule.controller('DashboardController', DashboardController); - MainModule.controller('SidebarController', SidebarController); - - MainModule.service('PanelBuilder', PanelBuilder); - MainModule.service('Validator', Validator); - - 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.provider('Configuration', Configuration); - - MainModule.filter('orderElement', OrderElement); - - MainModule.config(routing); - - 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 df8481c4..e27359b9 100644 --- a/src/scripts/app/Main/component/controller/AppController.js +++ b/src/scripts/app/Main/component/controller/AppController.js @@ -1,4 +1,4 @@ -define([], function() { +define(function() { 'use strict'; /** 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 e551c1f9..4639402c 100644 --- a/src/scripts/app/Main/component/controller/SidebarController.js +++ b/src/scripts/app/Main/component/controller/SidebarController.js @@ -1,4 +1,4 @@ -define([], function() { +define(function() { 'use strict'; var SidebarController = function($scope, $location, Configuration) { 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/Configuration.js b/src/scripts/app/Main/component/provider/Configuration.js index 8aa35725..d65649c9 100644 --- a/src/scripts/app/Main/component/provider/Configuration.js +++ b/src/scripts/app/Main/component/provider/Configuration.js @@ -1,4 +1,4 @@ -define([], function() { +define(function() { 'use strict'; function Configuration() { diff --git a/src/scripts/app/Main/component/service/PanelBuilder.js b/src/scripts/app/Main/component/service/PanelBuilder.js index 8d0ef1b5..055e9425 100644 --- a/src/scripts/app/Main/component/service/PanelBuilder.js +++ b/src/scripts/app/Main/component/service/PanelBuilder.js @@ -1,4 +1,4 @@ -define([], function() { +define(function() { 'use strict'; /** diff --git a/src/scripts/app/Main/component/service/Validator.js b/src/scripts/app/Main/component/service/Validator.js index 9f91666b..7cd79bad 100644 --- a/src/scripts/app/Main/component/service/Validator.js +++ b/src/scripts/app/Main/component/service/Validator.js @@ -1,4 +1,4 @@ -define([], function() { +define(function() { 'use strict'; function Validator(Configuration) { diff --git a/src/scripts/app/Main/component/service/config/Application.js b/src/scripts/app/Main/component/service/config/Application.js index a8d7fadf..37d71baf 100644 --- a/src/scripts/app/Main/component/service/config/Application.js +++ b/src/scripts/app/Main/component/service/config/Application.js @@ -1,10 +1,12 @@ -define(['app/Main/component/service/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/app/Main/component/service/config/Configurable.js b/src/scripts/app/Main/component/service/config/Configurable.js index d93686af..94341cd4 100644 --- a/src/scripts/app/Main/component/service/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/app/Main/component/service/config/Entity.js b/src/scripts/app/Main/component/service/config/Entity.js index 2c6b025b..bb55b2ee 100644 --- a/src/scripts/app/Main/component/service/config/Entity.js +++ b/src/scripts/app/Main/component/service/config/Entity.js @@ -1,6 +1,8 @@ -define(['app/Main/component/service/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/app/Main/component/service/config/Field.js b/src/scripts/app/Main/component/service/config/Field.js index fdf4917e..67f06109 100644 --- a/src/scripts/app/Main/component/service/config/Field.js +++ b/src/scripts/app/Main/component/service/config/Field.js @@ -1,6 +1,8 @@ -define(['app/Main/component/service/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/app/Main/component/service/config/Reference.js b/src/scripts/app/Main/component/service/config/Reference.js index 5150029f..afd271c1 100644 --- a/src/scripts/app/Main/component/service/config/Reference.js +++ b/src/scripts/app/Main/component/service/config/Reference.js @@ -1,6 +1,8 @@ -define(['app/Main/component/service/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/app/Main/component/service/config/ReferenceMany.js b/src/scripts/app/Main/component/service/config/ReferenceMany.js index 9bd63a4c..1e2af833 100644 --- a/src/scripts/app/Main/component/service/config/ReferenceMany.js +++ b/src/scripts/app/Main/component/service/config/ReferenceMany.js @@ -1,6 +1,8 @@ -define(['app/Main/component/service/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/app/Main/component/service/config/ReferencedList.js b/src/scripts/app/Main/component/service/config/ReferencedList.js index b66681a9..8a254c3a 100644 --- a/src/scripts/app/Main/component/service/config/ReferencedList.js +++ b/src/scripts/app/Main/component/service/config/ReferencedList.js @@ -1,6 +1,8 @@ -define(['app/Main/component/service/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/config-dist.js b/src/scripts/config-dist.js index bdccbedf..ae3480c3 100644 --- a/src/scripts/config-dist.js +++ b/src/scripts/config-dist.js @@ -1,141 +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"; - function truncate(value) { - return value.length > 50 ? value.substr(0, 50) + '...' : value; - } + var app = angular.module('myApp', ['ng-admin']); - var post = Entity('posts'), - commentBody = Field('body'), - postId = Field('id'), - postCreatedAt = Field('created_at'); + app.config(function(ConfigurationProvider, Application, Entity, Field, Reference, ReferencedList, ReferenceMany) { + function truncate(value) { + return value.length > 50 ? value.substr(0, 50) + '...' : value; + } - var tag = Entity('tags') - .order(3) - .label('Tags') - .dashboard(10) - .pagination(function(page, maxPerPage) { + function pagination(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 - }) - ); + offset: (page - 1) * maxPerPage, + limit: maxPerPage + } + } - var comment = Entity('comments') - .order(2) - .label('Comments') - .description('Lists all the blog comments with an infinite pagination') - .dashboard(10) - .pagination(function(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') - .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 + 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 - }) - ); + .label('Tags') + .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') - .order(1) - .dashboard(null) - .perPage(10) - .pagination(function(page, maxPerPage) { - return { - _start: (page - 1) * maxPerPage, - _end: (page) * maxPerPage - }; - }) - .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') + var comment = Entity('comments') + .order(2) .label('Comments') - .targetEntity(comment) - .targetField('post_id') - .targetFields([postId, commentBody]) - ) - .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('ng-admin backend demo') - .baseApiUrl('http://localhost:3000/') - .addEntity(post) - .addEntity(comment) - .addEntity(tag); -}); + ConfigurationProvider.configure(app); + }) +})(); From a7dbef7b6f578f50228b3108e72638cb891f024e Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Mon, 22 Sep 2014 08:14:04 +0200 Subject: [PATCH 07/10] Update test configuration --- .../app/Main/component/service/config/Application.js | 2 +- test/karma.conf.js | 4 +--- test/unit/Crud/component/service/CrudManagerSpec.js | 8 ++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/scripts/app/Main/component/service/config/Application.js b/src/scripts/app/Main/component/service/config/Application.js index 37d71baf..176fd763 100644 --- a/src/scripts/app/Main/component/service/config/Application.js +++ b/src/scripts/app/Main/component/service/config/Application.js @@ -1,6 +1,6 @@ define(function (require) { "use strict"; - + function defaultHeaders() { return {}; } diff --git a/test/karma.conf.js b/test/karma.conf.js index f7744d2e..13bb9b6d 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -10,14 +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', + 'src/scripts/app.js', // Test files {pattern: 'test/unit/**/**/*.js', included: false}, diff --git a/test/unit/Crud/component/service/CrudManagerSpec.js b/test/unit/Crud/component/service/CrudManagerSpec.js index 0c006f84..610f1220 100644 --- a/test/unit/Crud/component/service/CrudManagerSpec.js +++ b/test/unit/Crud/component/service/CrudManagerSpec.js @@ -4,10 +4,10 @@ define('config', null); define([ 'app/Crud/component/service/CrudManager', - 'lib/config/Application', - 'lib/config/Entity', - 'lib/config/Field', - 'lib/config/Reference', + 'app/Main/component/service/config/Application', + 'app/Main/component/service/config/Entity', + 'app/Main/component/service/config/Field', + 'app/Main/component/service/config/Reference', 'mixins', 'mock/q', 'mock/Restangular' From d0af5017c13ce8e80133bc4037162f812dbc7dfb Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Mon, 22 Sep 2014 08:32:15 +0200 Subject: [PATCH 08/10] Rename configuration to NgAdminConfiguration --- .../app/Crud/component/service/CrudManager.js | 2 +- src/scripts/app/Main/MainModule.js | 4 ++-- .../component/controller/AppController.js | 2 +- .../component/controller/SidebarController.js | 2 +- .../Main/component/provider/Configuration.js | 23 ------------------- .../provider/NgAdminConfiguration.js | 23 +++++++++++++++++++ .../Main/component/service/PanelBuilder.js | 2 +- .../app/Main/component/service/Validator.js | 2 +- src/scripts/config-dist.js | 4 ++-- 9 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 src/scripts/app/Main/component/provider/Configuration.js create mode 100644 src/scripts/app/Main/component/provider/NgAdminConfiguration.js diff --git a/src/scripts/app/Crud/component/service/CrudManager.js b/src/scripts/app/Crud/component/service/CrudManager.js index 11163c4c..92266d3a 100644 --- a/src/scripts/app/Crud/component/service/CrudManager.js +++ b/src/scripts/app/Crud/component/service/CrudManager.js @@ -458,7 +458,7 @@ define(function(require) { return values; }; - CrudManager.$inject = ['$q', 'Restangular', 'Configuration']; + CrudManager.$inject = ['$q', 'Restangular', 'NgAdminConfiguration']; return CrudManager; }); diff --git a/src/scripts/app/Main/MainModule.js b/src/scripts/app/Main/MainModule.js index 42d577f5..7d3a04a5 100644 --- a/src/scripts/app/Main/MainModule.js +++ b/src/scripts/app/Main/MainModule.js @@ -14,7 +14,7 @@ define(function (require) { ReferencedList = require('app/Main/component/service/config/ReferencedList'), ReferenceMany = require('app/Main/component/service/config/ReferenceMany'), - Configuration = require('app/Main/component/provider/Configuration'), + NgAdminConfiguration = require('app/Main/component/provider/NgAdminConfiguration'), OrderElement = require('app/Main/component/filter/OrderElement'), @@ -43,7 +43,7 @@ define(function (require) { MainModule.constant('ReferencedList', ReferencedList); MainModule.constant('ReferenceMany', ReferenceMany); - MainModule.provider('Configuration', Configuration); + MainModule.provider('NgAdminConfiguration', NgAdminConfiguration); MainModule.filter('orderElement', OrderElement); diff --git a/src/scripts/app/Main/component/controller/AppController.js b/src/scripts/app/Main/component/controller/AppController.js index e27359b9..61d576d9 100644 --- a/src/scripts/app/Main/component/controller/AppController.js +++ b/src/scripts/app/Main/component/controller/AppController.js @@ -17,7 +17,7 @@ define(function() { this.$scope = undefined; }; - AppController.$inject = ['$scope', 'Configuration']; + AppController.$inject = ['$scope', 'NgAdminConfiguration']; return AppController; }); diff --git a/src/scripts/app/Main/component/controller/SidebarController.js b/src/scripts/app/Main/component/controller/SidebarController.js index 4639402c..13113b8e 100644 --- a/src/scripts/app/Main/component/controller/SidebarController.js +++ b/src/scripts/app/Main/component/controller/SidebarController.js @@ -35,7 +35,7 @@ define(function() { this.$location = undefined; }; - SidebarController.$inject = ['$scope', '$location', 'Configuration']; + SidebarController.$inject = ['$scope', '$location', 'NgAdminConfiguration']; return SidebarController; }); diff --git a/src/scripts/app/Main/component/provider/Configuration.js b/src/scripts/app/Main/component/provider/Configuration.js deleted file mode 100644 index d65649c9..00000000 --- a/src/scripts/app/Main/component/provider/Configuration.js +++ /dev/null @@ -1,23 +0,0 @@ -define(function() { - 'use strict'; - - function Configuration() { - this.config = null; - } - - Configuration.prototype.configure = function(config) { - this.config = config; - }; - - Configuration.prototype.$get = function() { - var self = this; - - return function() { - return self.config; - } - }; - - Configuration.$inject = []; - - return Configuration; -}); 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 055e9425..fcb015f8 100644 --- a/src/scripts/app/Main/component/service/PanelBuilder.js +++ b/src/scripts/app/Main/component/service/PanelBuilder.js @@ -36,7 +36,7 @@ define(function() { return this.$q.all(promises); }; - PanelBuilder.$inject = ['$q', 'CrudManager', 'Configuration']; + 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 7cd79bad..4f1ec05e 100644 --- a/src/scripts/app/Main/component/service/Validator.js +++ b/src/scripts/app/Main/component/service/Validator.js @@ -21,7 +21,7 @@ define(function() { }); }; - Validator.$inject = ['Configuration']; + Validator.$inject = ['NgAdminConfiguration']; return Validator; }); diff --git a/src/scripts/config-dist.js b/src/scripts/config-dist.js index ae3480c3..4cbe909a 100644 --- a/src/scripts/config-dist.js +++ b/src/scripts/config-dist.js @@ -3,7 +3,7 @@ var app = angular.module('myApp', ['ng-admin']); - app.config(function(ConfigurationProvider, Application, Entity, Field, Reference, ReferencedList, ReferenceMany) { + app.config(function(NgAdminConfigurationProvider, Application, Entity, Field, Reference, ReferencedList, ReferenceMany) { function truncate(value) { return value.length > 50 ? value.substr(0, 50) + '...' : value; } @@ -127,6 +127,6 @@ .addEntity(comment) .addEntity(tag); - ConfigurationProvider.configure(app); + NgAdminConfigurationProvider.configure(app); }) })(); From b4d2e4678a094c541fe7794db072ee0315f8509d Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Mon, 22 Sep 2014 22:11:00 +0200 Subject: [PATCH 09/10] Fix tests --- Gruntfile.js | 9 ---- package.json | 1 - test/app-test.js | 52 ++++++++++++++++++- test/karma.conf.js | 4 -- .../Crud/component/service/CrudManagerSpec.js | 28 +++++----- test/unit/lib/config/ApplicationSpec.js | 0 6 files changed, 65 insertions(+), 29 deletions(-) delete mode 100644 test/unit/lib/config/ApplicationSpec.js diff --git a/Gruntfile.js b/Gruntfile.js index 18b41efa..81bab8fa 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,14 +14,6 @@ module.exports = function (grunt) { } }, - uglify: { - ngadmin: { - files: { - 'src/build/ng-admin.min.js': ['src/build/common.js', 'src/build/ng-admin.js', 'src/build/app.js'] - } - } - }, - concat: { options: { separator: ';' @@ -102,7 +94,6 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-clean'); - grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-ng-annotate'); grunt.loadNpmTasks('grunt-concurrent'); grunt.loadNpmTasks('grunt-karma'); diff --git a/package.json b/package.json index 2cde66f2..4fed06bb 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "devDependencies": { "grunt-contrib-clean": "^0.6.0", "grunt-contrib-concat": "^0.5.0", - "grunt-contrib-uglify": "^0.5.1", "grunt-contrib-watch": "~0.5.2", "grunt-karma": "^0.8.3", "grunt-ng-annotate": "^0.3.2", 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 13bb9b6d..9459f8fa 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -14,12 +14,8 @@ module.exports = function(config) { {pattern: 'src/scripts/app/**/config/**/*.js', included: false}, {pattern: 'src/scripts/app/**/view/**/*.html', included: false}, - // require configuration files - 'src/scripts/app.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 610f1220..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', - 'app/Main/component/service/config/Application', - 'app/Main/component/service/config/Entity', - 'app/Main/component/service/config/Field', - 'app/Main/component/service/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 From 000748e2ff1c3005db1045c8c624e73c5dc150a8 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Mon, 22 Sep 2014 23:30:42 +0200 Subject: [PATCH 10/10] Add minification process --- Gruntfile.js | 20 ++++++++++---------- package.json | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 81bab8fa..aed32f17 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -10,17 +10,17 @@ module.exports = function (grunt) { ngAnnotate: { ngadmin: { - src: ['src/build/common.js', 'src/build/ng-admin.js', 'src/build/app.js'] + files: { + 'src/build/ng-admin.min.js': ['src/build/ng-admin.min.js'] + } } }, - concat: { - options: { - separator: ';' - }, - dist: { - src: [], - dest: 'src/build/ng-admin.min.js' + uglify: { + ngadmin: { + files: { + 'src/build/ng-admin.min.js': ['src/build/ng-admin.min.js'] + } } }, @@ -92,8 +92,8 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-compass'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-connect'); - grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-ng-annotate'); grunt.loadNpmTasks('grunt-concurrent'); grunt.loadNpmTasks('grunt-karma'); @@ -102,7 +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', 'concat',*/ 'clean:build']); + grunt.registerTask('build', ['requirejs:prod', 'ngAnnotate', 'uglify']); // register default task grunt.registerTask('default', ['concurrent:assets_all_dev', 'concurrent:connect_watch']); diff --git a/package.json b/package.json index 4fed06bb..f2f73bc8 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ }, "devDependencies": { "grunt-contrib-clean": "^0.6.0", - "grunt-contrib-concat": "^0.5.0", "grunt-contrib-watch": "~0.5.2", "grunt-karma": "^0.8.3", "grunt-ng-annotate": "^0.3.2", @@ -27,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"