-
Notifications
You must be signed in to change notification settings - Fork 726
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[RFR] Document the way to define nested entity urls for relationships #711
Conversation
[RFR] Document the way to define nested entity urls for relationships
I have come up with another solution. myApp.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push(function() {
return {
request: function(config) {
// Check if any filter is present
try {
config.params._filter['try'];
} catch (err) {
return config;
}
// Get only pathname not full url
var a = document.createElement('a');
a.href = config.url;
// Find keys starting with ":"
var matches = a.pathname.match(/(\:[^\/]*)/g);
if (matches) {
// Remove ":" from keys
matches = matches.map(function(match) {
return match.replace(':', '');
});
// Find if all keys present in filters
if (matches.every(function(match) { return !!config.params._filter[match]; })) {
// Perform url manipulation
matches.forEach(function(match) {
// Replace key with value
a.pathname = a.pathname.replace(":" + match, config.params._filters[match]);
// Delete filter
delete config.params._filters[match];
});
// Update url
config.url = a.href;
}
}
return config;
}
};
});
}]); myApp.config(['NgAdminConfigurationProvider', function(nga) {
admin = nga.application('My ngAdmin App');
client = nga.entity('clients').identifier(nga.field('personal_id'));
// set the fields of the user entity list view
client.listView()
.fields([
nga.field('personal_id').label('Personal ID'),
nga.field('first_name').label('First name'),
nga.field('last_name').label('Last name')
])
.batchActions([])
.listActions(['show'])
client.showView()
.title 'Client detailed info for #{{ entry.values.personal_id }}'
.fields([
nga.field('personal_id').label('Personal ID'),
nga.field('first_name').label('First name'),
nga.field('last_name').label('Last name'),
nga.field('companies', 'referenced_list')
.targetEntity(
nga.entity('companies')
.identifier(nga.field('reg_no')) // Unique field returned by API
.url("/clients/:personal_id/companies"); // Resource URL including parent resource id
)
.targetReferenceField('personal_id') // Field to be replaced in URL
.targetFields([
nga.field('reg_no').label('Reg. number'),
nga.field('name').label('Name'),
nga.field('created_at', 'datetime').label('Created at')
])
])
}]); |
How can I show nested object? Currently I can't pass post's ID to url of comment detail. Please help!!! |
I have found a solution by reference to issue 627 |
Attention that, maybe it's because change of codes, configuration parameters have changed:
@fzaninotto Maybe should update in the wiki as well.
|
By default, ng-admin uses filters to fetch entities related to another one. For instance, to fetch all the
comments
related to thepost
entity #123, ng-admin calls the following url:Some API servers only support a special type of URL for that case:
Restangular doesn't allow to modify the URL of an outgoing request (see Restangular issue #603), so in order to achieve that you must use an interceptor on the
$http
Angular service.