Skip to content

Commit

Permalink
Merge pull request #655 from marmelab/referenced_list_actions
Browse files Browse the repository at this point in the history
[RFR] (re)-add listActions support on referencedList
  • Loading branch information
fzaninotto committed Sep 3, 2015
2 parents e179a5b + e2b1536 commit 30b520e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 20 deletions.
3 changes: 2 additions & 1 deletion examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
nga.field('body').label('Comment')
])
.sortField('created_at')
.sortDir('DESC'),
.sortDir('DESC')
.listActions(['edit']),
nga.field('', 'template').label('')
.template('<span class="pull-right"><ma-filtered-list-button entity-name="comments" filter="{ post_id: entry.values.id }" size="sm"></ma-filtered-list-button></span>')
]);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "git://github.com/marmelab/ng-admin.git"
},
"devDependencies": {
"admin-config": "^0.2.15",
"admin-config": "^0.2.16",
"angular": "~1.3.15",
"angular-bootstrap": "^0.12.0",
"angular-mocks": "1.3.14",
Expand Down
12 changes: 11 additions & 1 deletion src/javascripts/ng-admin/Crud/button/maCreateButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ define(function () {
scope.label = scope.label || 'Create';

scope.gotoCreate = function () {
$state.go($state.get('create'), angular.extend({entity: scope.entity().name()}, $state.params));
if ($state.params.entity == scope.entity().name()) {
// link to the same entity, so preserve active filters
$state.go($state.get('create'), angular.extend({
entity: scope.entity().name(),
}, $state.params));
} else {
// link to anoter entity, so forget filters
$state.go($state.get('create'), {
entity: scope.entity().name(),
});
}
};
},
template:
Expand Down
19 changes: 14 additions & 5 deletions src/javascripts/ng-admin/Crud/button/maDeleteButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ define(function () {
},
link: function (scope) {
scope.label = scope.label || 'Delete';

scope.gotoDelete = function () {
$state.go($state.get('delete'), angular.extend({
entity: scope.entity().name(),
id: scope.entry().identifierValue
}, $state.params));
if ($state.params.entity == scope.entity().name()) {
// link to the same entity, so preserve active filters
$state.go($state.get('delete'), angular.extend({
entity: scope.entity().name(),
id: scope.entry().identifierValue
}, $state.params));
} else {
// link to anoter entity, so forget filters
$state.go($state.get('delete'), {
entity: scope.entity().name(),
id: scope.entry().identifierValue
});
}

};
},
template:
Expand Down
18 changes: 13 additions & 5 deletions src/javascripts/ng-admin/Crud/button/maEditButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ define(function () {
link: function (scope) {
scope.label = scope.label || 'Edit';
scope.gotoEdit = function () {
$state.go($state.get('edit'),
angular.extend({
entity: scope.entity().name(),
id: scope.entry().identifierValue
}, $state.params));
if ($state.params.entity == scope.entity().name()) {
// link to the same entity, so preserve active filters
$state.go($state.get('edit'), angular.extend({
entity: scope.entity().name(),
id: scope.entry().identifierValue
}, $state.params));
} else {
// link to anoter entity, so forget filters
$state.go($state.get('edit'), {
entity: scope.entity().name(),
id: scope.entry().identifierValue
});
}
};
},
template:
Expand Down
19 changes: 13 additions & 6 deletions src/javascripts/ng-admin/Crud/button/maShowButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ define(function () {
},
link: function (scope) {
scope.label = scope.label || 'Show';

scope.gotoShow = function () {
$state.go($state.get('show'),
angular.extend({
entity: scope.entity().name(),
id: scope.entry().identifierValue
}, $state.params));
if ($state.params.entity == scope.entity().name()) {
// link to the same entity, so preserve active filters
$state.go($state.get('show'), angular.extend({
entity: scope.entity().name(),
id: scope.entry().identifierValue
}, $state.params));
} else {
// link to anoter entity, so forget filters
$state.go($state.get('show'), {
entity: scope.entity().name(),
id: scope.entry().identifierValue
});
}
};
},
template:
Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/test/e2e/ShowViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ShowView', function () {
describe('ReferencedListField', function() {
it('should render as a datagrid', function () {
$$('.ng-admin-field-comments th').then(function (inputs) {
expect(inputs.length).toBe(3);
expect(inputs.length).toBe(4);

expect(inputs[0].getAttribute('class')).toBe('ng-scope ng-admin-column-id');
expect(inputs[1].getAttribute('class')).toBe('ng-scope ng-admin-column-created_at');
Expand Down

0 comments on commit 30b520e

Please sign in to comment.