[RFR] Document the way to define nested entity urls for relationships#711
Merged
fzaninotto merged 1 commit intomasterfrom Sep 30, 2015
Merged
[RFR] Document the way to define nested entity urls for relationships#711fzaninotto merged 1 commit intomasterfrom
fzaninotto merged 1 commit intomasterfrom
Conversation
This was referenced Sep 30, 2015
Closed
Closed
fzaninotto
added a commit
that referenced
this pull request
Sep 30, 2015
[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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By default, ng-admin uses filters to fetch entities related to another one. For instance, to fetch all the
commentsrelated to thepostentity #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
$httpAngular service.