marmelab / ng-admin

Add an AngularJS admin GUI to any RESTful API
http://ng-admin-book.marmelab.com/
MIT License
3.95k stars 725 forks source link

Feature: Possibility to add custom actions #1348

Closed mrded closed 7 years ago

mrded commented 7 years ago

Hi there,

It will be great if it's possible to add custom actions, next to existing ma-view-actions on showView view.

Use case

We have several ways to delete users. By default users can delete them self by sending DELETE /user/{id}. However, we also have possibility to ban spammers by sending DELETE /user/{id}?spam=true. Currently there is no way, I can ban spammers.

It's just one example, but you may also have several end points which you want to trigger from showView.

As I see, currently these buttons are hardcoded.

Kmaschta commented 7 years ago

You can do such a custom button by inserting a directive like:

entity.showView()
    .actions(['list', 'delete', '<custom-directive></custom-directive>']);

You just have to add you directive to the angular app:

app.directive('customDirective', require('./path/to/directive'));

If you have some issue to implement a custom list action, you can ask on StackOverflow with the tag ng-admin.

mrded commented 7 years ago

@Kmaschta thank you for your reply, it was quick :) I've updated my issue. There is no problem with adding a custom directive on listView you're right. It's in the doc.

The problem is with showView. These action buttons are hardcoded in the template, look here.

Kmaschta commented 7 years ago

Yup, sorry I wrote a little fast.

Look at this Plunkr: http://plnkr.co/edit/YbWetcmzBQ4qaI3qFuK3?p=preview, go to User List > Show a user

You can do a custom action in the showView.

mrded commented 7 years ago

Thanks a lot! :)