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

dynamic permanent filters #1350

Open
saimirg opened this issue Jun 23, 2017 · 1 comment
Open

dynamic permanent filters #1350

saimirg opened this issue Jun 23, 2017 · 1 comment

Comments

@saimirg
Copy link

saimirg commented Jun 23, 2017

Hi,
i read that i should ask on StackOverflow and Gitter and some time ago I published the same question on both but got no answer.

Here is my question:
The following link is clicked at some point during the workflow to add a subscription record.
http://example.com/admin/#/Subscriptions/create?defaultValues={"login_id":1234}

This is part of the creationView code:

.fields([
            nga.field('login_id', 'reference')
		.targetEntity(admin.getEntity('LoginData'))
                .targetField(nga.field('username'))
		.attributes({ placeholder: 'Select Account' })
		.validation({ required: true })
		.label('Username'),

...which when loads, calls the API to the LoginData entity. Our problem is that the response is bringing back all the records and we're not finding a way to pass the login_id parameter as query parameter so we can filter records on the backend; (or as a permanent filter ?)

So API to LoginData should call http://example.com/api/LoginData?login_id=1234

@emresebat
Copy link

Hi

I have small hack for this, using the addFullRequestInterceptor, but I wish we had a better solution.

So for your case it would be something like:

RestangularProvider.addFullRequestInterceptor(function(element, operation, what, url, headers, params) {
  if (operation == 'getList') {
    //WARN: intercept only for specific view
    if (what === 'LoginData') {
      const hash = location.hash;
      if (hash.includes('Subscriptions/create')) {
        const search = 'defaultValues=';
        const defaultValuesStr = decodeURIComponent(hash.substring(hash.indexOf(search) + search.length));
        const defaultValues = JSON.parse(defaultValuesStr);
        params['login_id'] = defaultValues.login_id;
      }
    }
  }
  return {
    params: params
  };
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants