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

Make it easier to use backend filters #48

Open
SpaceK33z opened this issue Jun 29, 2017 · 3 comments
Open

Make it easier to use backend filters #48

SpaceK33z opened this issue Jun 29, 2017 · 3 comments

Comments

@SpaceK33z
Copy link
Contributor

SpaceK33z commented Jun 29, 2017

Sometimes you want to fetch a store from the backend but with some filters applied.

Our Django-Binder stack has a lot of auto-generated filters. To filter a store on a customer id we can do something like this:

const store = new Store();

store.params = {'.customer': customer.id };
store.fetch();

For a customer filter the backend has defined it looks about the same;

const store = new Store();

store.params = {'.leaves_for_customer': customer.id };
store.fetch();

The syntax for defining this is a bit weird + doesn't use camelCasing. We can perhaps fix it to look like this;

store.addFilter('leavesForCustomer', customer.id);
store.removeFilter('leavesForCustomer');
@SpaceK33z
Copy link
Contributor Author

Note: think about how to implement filters like '.customer:isnull': true

@SpaceK33z
Copy link
Contributor Author

SpaceK33z commented Jul 14, 2017

Some other notes:

  • how to implement '.start_date:range': '2017-01-01,2017-02-01'? I think addFilter('startDate', ['2017-01-01', '2017-02-01']) makes sense.
  • add something like store.getFilter('startDate'), because in the frontend you need to show this data.
  • how to handle ?deleted=true, since it doesn't have a leading . (+ there can be other custom filters)
  • add tests for nested filters like '.customer.location.city': 'Eindhoven'
  • for Make it easier to use backend sorting #53 we also need a similar solution (backend sorting)

@SpaceK33z
Copy link
Contributor Author

Another idea, taking into account the notes above:

store.setParam(Params.FILTER_RANGE, 'startDate', [moment(), moment()]);
store.setParam(Params.FILTER_CUSTOM, 'deleted', true);
store.setParam(Params.SORT_ASC, 'pastOwner.lastName');

Problem with this;

  • how to read the value of a param? you can't do store.getParam('pastOwner.lastName') because that can either be an sorthing or a filter or whatevs.

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

1 participant