Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Backward compatibility #356

Merged
merged 5 commits into from
Mar 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ module.exports = function (grunt) {

grunt.registerTask('test:local', ['mochaTest', 'karma', 'build:dev', 'copy_build:dev', 'test:local:e2e']);
grunt.registerTask('test:local:e2e', ['json_server', 'connect', 'protractor']);
grunt.registerTask('build:dev', ['requirejs:dev', 'compass:dev', 'concat:css']);
grunt.registerTask('build:dev', ['ngconfig', 'requirejs:dev', 'compass:dev', 'concat:css']);
grunt.registerTask('copy_build:dev', ['copy:es6_dev', 'copy:es6_devmap', 'copy:js_dev', 'copy:angular', 'copy:css_dev', 'copy:fonts_dev', 'clean']);

// register default task
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ Here is a full example for a backend that will let you create, update, and delet

var app = angular.module('myApp', ['ng-admin']);

app.config(function (AdminDescription, NgAdminProvider) {
var nga = AdminDescription;
app.config(function (NgAdminConfigurationProvider) {
var nga = NgAdminConfigurationProvider;
var app = nga.application('ng-admin backend demo') // application main title
.baseApiUrl('http://localhost:3000/'); // main API endpoint

Expand All @@ -100,7 +100,7 @@ app.config(function (AdminDescription, NgAdminProvider) {
post.dashboardView() // customize the dashboard panel for this entity
.title('Recent posts')
.order(1) // display the post panel first in the dashboard
.limit(5) // limit the panel to the 5 latest posts
.perPage(5) // limit the panel to the 5 latest posts
.fields([nga.field('title').isDetailLink(true).map(truncate)]); // fields() called with arguments add fields to the view

post.listView()
Expand Down Expand Up @@ -156,7 +156,7 @@ app.config(function (AdminDescription, NgAdminProvider) {
.template('<other-page-link></other-link-link>')
]);

NgAdminProvider.configure(app);
nga.configure(app);
});
```

Expand Down Expand Up @@ -261,7 +261,7 @@ Defines the API endpoint for a view. It can be a string or a function.

The `dashboardView` also defines `sortField` and `sortDir` fields like the `listView`.

* `limit(Number)`
* `perPage(Number)`
Set the number of items.

* `order(Number)`
Expand Down
18 changes: 7 additions & 11 deletions UPGRADE-0.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@

ng-admin 0.7 breaks compatibility with 0.5 and makes the "factories" configuration API compulsory. If your configuration uses `nga.field()`, it will still work woth 0.7. If it uses `new Field()`, you'll need to follow [the 0.6 upgrade guide](https://github.com/marmelab/ng-admin/blob/b3c7b1afc6a52651df6ba4454d8461620339b4da/UPGRADE-0.6.md).

## Configuration factory
## Field type

The configuration is now done through the `AdminDescription` object. You can retrieve it directly from Angular DI. You just have to retrieve your application from this factory instead of the `NgAdminConfigurationProvider` as previously. In addition, `NgAdminConfigurationProvider` was renamed to `NgAdminProvider`:
Method `Field.type()` is no longer supported as a setter. Instead, you should specify the second argument from the field factory.

``` diff
- app.config(function (NgAdminConfigurationProvider, RestangularProvider) {
+ app.config(function (AdminDescription, NgAdminProvider, RestangularProvider) {
- var nga = NgAdminConfigurationProvider;
+ var nga = AdminDescription;
- nga.field('created_at').type('date')
+ nga.field('created_at', 'date')
```

// ...
## perPage instead of limit

- nga.configure(admin);
+ NgAdminProvider.configure(admin);
});
```
Dashboard view `limit()` method has been deprecated. Please use the `perPage` method instead.
12 changes: 6 additions & 6 deletions examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

var app = angular.module('myApp', ['ng-admin']);

app.config(function (AdminDescription, NgAdminProvider, RestangularProvider) {
var nga = AdminDescription;
app.config(function (NgAdminConfigurationProvider, RestangularProvider) {
var nga = NgAdminConfigurationProvider;

function truncate(value) {
if (!value) {
Expand Down Expand Up @@ -66,7 +66,7 @@
post.dashboardView() // customize the dashboard panel for this entity
.title('Recent posts')
.order(1) // display the post panel first in the dashboard
.limit(5) // limit the panel to the 5 latest posts
.perPage(5) // limit the panel to the 5 latest posts
.fields([nga.field('title').isDetailLink(true).map(truncate)]); // fields() called with arguments add fields to the view

post.listView()
Expand Down Expand Up @@ -133,7 +133,7 @@
comment.dashboardView()
.title('Last comments')
.order(2) // display the comment panel second in the dashboard
.limit(5)
.perPage(5)
.fields([
nga.field('id'),
nga.field('body', 'wysiwyg')
Expand Down Expand Up @@ -218,7 +218,7 @@
tag.dashboardView()
.title('Recent tags')
.order(3)
.limit(10)
.perPage(10)
.fields([
nga.field('id'),
nga.field('name'),
Expand Down Expand Up @@ -248,7 +248,7 @@
nga.field('published', 'boolean')
]);

NgAdminProvider.configure(admin);
nga.configure(admin);
});

app.directive('postLink', ['$location', function ($location) {
Expand Down
5 changes: 4 additions & 1 deletion src/javascripts/ng-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ define(function (require) {
var factory = angular.module('AdminDescriptionModule', []);
factory.constant('AdminDescription', new AdminDescription());

angular.module('ng-admin', ['main', 'crud', 'AdminDescriptionModule']);
var ngadmin = angular.module('ng-admin', ['main', 'crud', 'AdminDescriptionModule']);
ngadmin.config(function(NgAdminConfigurationProvider, AdminDescription) {
NgAdminConfigurationProvider.setAdminDescription(AdminDescription);
});
});
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/column/maColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ define(function (require) {
};
}

maColumn.$inject = ['$location', '$anchorScroll', '$compile', 'NgAdmin', 'FieldViewConfiguration'];
maColumn.$inject = ['$location', '$anchorScroll', '$compile', 'NgAdminConfiguration', 'FieldViewConfiguration'];

return maColumn;
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function (require) {
};
}

maReferenceManyLinkColumn.$inject = ['$location', 'NgAdmin'];
maReferenceManyLinkColumn.$inject = ['$location', 'NgAdminConfiguration'];

return maReferenceManyLinkColumn;
});
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/form/FormController.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ define(function () {
this.entity = undefined;
};

FormController.$inject = ['$scope', '$location', '$filter', 'CreateQueries', 'UpdateQueries', 'Validator', 'NgAdmin', 'progression', 'notification', 'view', 'entry'];
FormController.$inject = ['$scope', '$location', '$filter', 'CreateQueries', 'UpdateQueries', 'Validator', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'entry'];

return FormController;
});
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/repository/CreateQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ define(function (require) {
});
};

CreateQueries.$inject = ['$q', 'Restangular', 'NgAdmin'];
CreateQueries.$inject = ['$q', 'Restangular', 'NgAdminConfiguration'];

return CreateQueries;
});
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/repository/DeleteQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function (require) {
.customDELETE();
};

DeleteQueries.$inject = ['$q', 'Restangular', 'NgAdmin'];
DeleteQueries.$inject = ['$q', 'Restangular', 'NgAdminConfiguration'];

return DeleteQueries;
});
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/repository/Queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define(function () {
this.Restangular.setFullResponse(true); // To get also the headers
}

Queries.$inject = ['$q', 'Restangular', 'NgAdmin'];
Queries.$inject = ['$q', 'Restangular', 'NgAdminConfiguration'];

return Queries;
});
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ define(function (require) {
return entry;
};

RetrieveQueries.$inject = ['$q', 'Restangular', 'NgAdmin'];
RetrieveQueries.$inject = ['$q', 'Restangular', 'NgAdminConfiguration'];

return RetrieveQueries;
});
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/repository/UpdateQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ define(function (require) {
});
};

UpdateQueries.$inject = ['$q', 'Restangular', 'NgAdmin'];
UpdateQueries.$inject = ['$q', 'Restangular', 'NgAdminConfiguration'];

return UpdateQueries;
});
4 changes: 2 additions & 2 deletions src/javascripts/ng-admin/Crud/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ define(function (require) {
deleteTemplate = require('text!./delete/delete.html');

function templateProvider(viewName, defaultView) {
return ['$stateParams', 'NgAdmin', function ($stateParams, Configuration) {
return ['$stateParams', 'NgAdminConfiguration', function ($stateParams, Configuration) {
var customTemplate;
var view = Configuration().getViewByEntityAndType($stateParams.entity, viewName);
customTemplate = view.template();
Expand All @@ -22,7 +22,7 @@ define(function (require) {
}

function viewProvider(viewName) {
return ['$stateParams', 'NgAdmin', function ($stateParams, Configuration) {
return ['$stateParams', 'NgAdminConfiguration', function ($stateParams, Configuration) {
var view = Configuration().getViewByEntityAndType($stateParams.entity, viewName);
if (!view.isEnabled()) {
throw new Error('The ' + viewName + ' is disabled for this entity');
Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Main/MainModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define(function (require) {
MainModule.service('PanelBuilder', require('ng-admin/Main/component/service/PanelBuilder'));
MainModule.service('Validator', require('ng-admin/Main/component/service/Validator'));

MainModule.provider('NgAdmin', require('ng-admin/Main/component/provider/NgAdmin'));
MainModule.provider('NgAdminConfiguration', require('ng-admin/Main/component/provider/NgAdminConfiguration'));

MainModule.filter('enabled', require('ng-admin/Main/component/filter/Enabled'));
MainModule.filter('orderElement', require('ng-admin/Main/component/filter/OrderElement'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define(function () {
this.$scope = undefined;
};

AppController.$inject = ['$scope', '$location', 'NgAdmin'];
AppController.$inject = ['$scope', '$location', 'NgAdminConfiguration'];

return AppController;
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ define(function () {
this.$filter = undefined;
};

SidebarController.$inject = ['$scope', '$location', '$sce', '$filter', 'NgAdmin'];
SidebarController.$inject = ['$scope', '$location', '$sce', '$filter', 'NgAdminConfiguration'];

return SidebarController;
});
24 changes: 0 additions & 24 deletions src/javascripts/ng-admin/Main/component/provider/NgAdmin.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*global define*/

define(function () {
'use strict';

function NgAdminConfiguration() {
this.config = null;
this.adminDescription = null;
}

NgAdminConfiguration.prototype.setAdminDescription = function(adminDescription) {
this.adminDescription = adminDescription;
}

NgAdminConfiguration.prototype.configure = function (config) {
this.config = config;
};

NgAdminConfiguration.prototype.$get = function () {
var config = this.config;
return function () {
return config;
};
};

NgAdminConfiguration.prototype.application = function(name) {
return this.adminDescription.application(name);
};

NgAdminConfiguration.prototype.entity = function(name) {
return this.adminDescription.entity(name);
};

NgAdminConfiguration.prototype.field = function(name, type) {
return this.adminDescription.field(name, type);
};

NgAdminConfiguration.prototype.registerFieldType = function(name, type) {
return this.adminDescription.registerFieldType(name, type);
};

NgAdminConfiguration.$inject = [];

return NgAdminConfiguration;
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ define(function () {
});
};

PanelBuilder.$inject = ['$q', '$filter', '$location', 'RetrieveQueries', 'NgAdmin'];
PanelBuilder.$inject = ['$q', '$filter', '$location', 'RetrieveQueries', 'NgAdminConfiguration'];

return PanelBuilder;
});
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Main/config/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define(function (require) {
abstract: true,
controller: 'AppController',
controllerAs: 'appController',
templateProvider: ['NgAdmin', function(Configuration) {
templateProvider: ['NgAdminConfiguration', function(Configuration) {
return Configuration().layout() || layoutTemplate;
}]
});
Expand Down
4 changes: 4 additions & 0 deletions src/javascripts/ng-admin/es6/lib/Factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class Factory {
this._fieldTypes[name] = constructor;
}

getFieldConstructor(name) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to ease inheritance for custom types.

return this._fieldTypes[name];
}

_init() {
this.registerFieldType('boolean', BooleanField);
this.registerFieldType('choice', ChoiceField);
Expand Down
8 changes: 5 additions & 3 deletions src/javascripts/ng-admin/es6/lib/Field/ReferenceField.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class ReferenceField extends ChoiceField {
this._detailLink = true;
}

get perPage() {
return this._perPage;
perPage(perPage) {
if (!arguments.length) return this._perPage;
this._perPage = perPage;
return this;
}

targetEntity(entity) {
Expand Down Expand Up @@ -48,7 +50,7 @@ class ReferenceField extends ChoiceField {
}

getReferencedView() {
return this._referencedView.perPage(this.perPage);
return this._referencedView.perPage(this._perPage);
}

filters(filters) {
Expand Down
Loading