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

[BC BREAK] [RFR] Rename main view to ng-admin #759

Merged
merged 1 commit into from
Sep 19, 2016
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ If you don't have a module bundler, don't worry: you can still include `ng-admin

## Bootstraping your Admin

Just add a `<div ui-view>` into your HTML, add a `ng-app` attribute on your `body`, and configure the admin:
Add the `ng-admin.min.css` and `ng-admin.min.js` to the HTML, add a `<div ui-view="ng-admin">`, and configure the admin:

``` html
<!doctype html>
Expand All @@ -84,7 +84,7 @@ Just add a `<div ui-view>` into your HTML, add a `ng-app` attribute on your `bod
<link rel="stylesheet" href="node_modules/ng-admin/build/ng-admin.min.css">
</head>
<body ng-app="myApp">
<div ui-view></div>
<div ui-view="nh-admin"></div>
<script src="node_modules/ng-admin/build/ng-admin.min.js"></script>
<script type="text/javascript">
var myApp = angular.module('myApp', ['ng-admin']);
Expand Down
46 changes: 46 additions & 0 deletions UPGRADE-1.0.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
# Upgrade to 1.0

## [BC Break] ng-admin now attaches to a named view

Ng-admin used to attach to the following element in your main `index.html`:

```js
<div ui-view></div>
```

Starting with 1.0, you now have to name the ui-view of ng-admin:

```js
<div ui-view="ng-admin">
```

Not upgrading your `index.html` will result in a blank page.

## [BC Break] Custom pages must use declare 'ng-admin' as parent instead of 'main'

If you added [custom pages](doc/Custom-pages.md), you probably declared a route with a `parent: 'main'`. The main view isn't named 'parent' anymore, but 'ng-admin'. Therefore, all the state definitions for custom pages must be updated:

```js
// from
myApp.config(function ($stateProvider) {
$stateProvider.state('send-post', {
parent: 'main',
url: '/sendPost/:id',
params: { id: null },
controller: sendPostController,
controllerAs: 'controller',
template: sendPostControllerTemplate
});
});

// to
myApp.config(function ($stateProvider) {
$stateProvider.state('send-post', {
parent: 'ng-admin', // <= this has changed
url: '/sendPost/:id',
params: { id: null },
controller: sendPostController,
controllerAs: 'controller',
template: sendPostControllerTemplate
});
});
```

## Angular 1.4

Previous versions of ng-admin relied on Angular 1.3. Version 1.0 bumps the angular version requirement to 1.4.
Expand Down
4 changes: 2 additions & 2 deletions doc/Custom-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ng-admin uses [AngularUI Router](https://github.com/angular-ui/ui-router) to def
```js
myApp.config(function ($stateProvider) {
$stateProvider.state('send-post', {
parent: 'main',
parent: 'ng-admin',
url: '/sendPost/:id',
params: { id: null },
controller: sendPostController,
Expand All @@ -19,7 +19,7 @@ myApp.config(function ($stateProvider) {
});
```

Here the `controllerAs` property defines the name of the controller in the template. Also worth noting: `parent: 'main'` means that the "send-post" page will be displayed inside the main layout.
Here the `controllerAs` property defines the name of the controller in the template. Also worth noting: `parent: 'ng-admin'` means that the "send-post" page will be displayed inside the main ng-admin layout.

## Page Controller and Template

Expand Down
6 changes: 3 additions & 3 deletions examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@

app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('send-post', {
parent: 'main',
parent: 'ng-admin',
url: '/sendPost/:id',
params: { id: null },
controller: sendPostController,
Expand All @@ -590,15 +590,15 @@

// custom page with menu item
var customPageTemplate = '<div class="row"><div class="col-lg-12">' +
'<ma-view-actions><ma-back-button></ma-back-button></ma-view-actions>' +
'<div class="page-header">' +
'<ma-view-actions><ma-back-button></ma-back-button></ma-view-actions>' +
'<h1>Stats</h1>' +
'<p class="lead">You can add custom pages, too</p>' +
'</div>' +
'</div></div>';
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('stats', {
parent: 'main',
parent: 'ng-admin',
url: '/stats',
template: customPageTemplate
});
Expand Down
2 changes: 1 addition & 1 deletion examples/blog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</style>
</head>
<body ng-app="myApp" ng-strict-di>
<div ui-view></div>
<div ui-view="ng-admin"></div>
<script src="build/fakerest.js" type="text/javascript"></script>
<script src="build/sinon-server.js" type="text/javascript"></script>
<script src="data.js" type="text/javascript"></script>
Expand Down
12 changes: 6 additions & 6 deletions src/javascripts/ng-admin/Crud/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function routing($stateProvider) {
params: {
entity: null
},
parent: 'main',
parent: 'ng-admin',
controller: 'ListLayoutController',
controllerAs: 'llCtrl',
templateProvider: templateProvider('ListView', listLayoutTemplate),
Expand Down Expand Up @@ -146,7 +146,7 @@ function routing($stateProvider) {

$stateProvider
.state('show', {
parent: 'main',
parent: 'ng-admin',
url: '/:entity/show/:id?sortField&sortDir',
controller: 'ShowController',
controllerAs: 'showController',
Expand Down Expand Up @@ -241,7 +241,7 @@ function routing($stateProvider) {

$stateProvider
.state('create', {
parent: 'main',
parent: 'ng-admin',
url: '/:entity/create?{defaultValues:json}',
controller: 'FormController',
controllerAs: 'formController',
Expand Down Expand Up @@ -296,7 +296,7 @@ function routing($stateProvider) {

$stateProvider
.state('edit', {
parent: 'main',
parent: 'ng-admin',
url: '/:entity/edit/:id?sortField&sortDir',
controller: 'FormController',
controllerAs: 'formController',
Expand Down Expand Up @@ -409,7 +409,7 @@ function routing($stateProvider) {

$stateProvider
.state('delete', {
parent: 'main',
parent: 'ng-admin',
url: '/:entity/delete/:id',
controller: 'DeleteController',
controllerAs: 'deleteController',
Expand Down Expand Up @@ -448,7 +448,7 @@ function routing($stateProvider) {

$stateProvider
.state('batchDelete', {
parent: 'main',
parent: 'ng-admin',
url: '/:entity/batch-delete/{ids:json}',
controller: 'BatchDeleteController',
controllerAs: 'batchDeleteController',
Expand Down
20 changes: 12 additions & 8 deletions src/javascripts/ng-admin/Main/config/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ function entryConstructorProvider() {

function routing($stateProvider, $urlRouterProvider) {

$stateProvider.state('main', {
$stateProvider.state('ng-admin', {
abstract: true,
controller: 'AppController',
controllerAs: 'appController',
templateProvider: ['NgAdminConfiguration', function(Configuration) {
return Configuration().layout() || layoutTemplate;
}]
views: {
'ng-admin': {
controller: 'AppController',
controllerAs: 'appController',
templateProvider: ['NgAdminConfiguration', function(Configuration) {
return Configuration().layout() || layoutTemplate;
}]
}
}
});

$stateProvider.state('dashboard', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that we can also use dotted notation for parent views: ng-admin.dashboard for instance.

parent: 'main',
parent: 'ng-admin',
url: '/dashboard?sortField&sortDir',
params: {
sortField: null,
Expand Down Expand Up @@ -112,7 +116,7 @@ function routing($stateProvider, $urlRouterProvider) {
});

$stateProvider.state('ma-404', {
parent: 'main',
parent: 'ng-admin',
template: errorTemplate
});

Expand Down