3
votes

After reading http://www.jhipster.tech/entities-filtering/, I can get my jhipster generated applicaiton filter work on postman.

For example I can get right result on postman with: http://localhost:8080/api/requests?page=0&size=20&sort=model,asc&sort=id&id.in=20000,20001

my questions how can make it work on the generated angular client side app?

I saw that in the ../shared folder it has "request-util.ts". Inside it, there is parameter named "query" and "filter".

export const createRequestOption = (req?: any): BaseRequestOptions => {
const options: BaseRequestOptions = new BaseRequestOptions();
if (req) {
    const params: URLSearchParams = new URLSearchParams();
    params.set('page', req.page);
    params.set('size', req.size);
    if (req.sort) {
        params.paramsMap.set('sort', req.sort);
    }
    params.set('query', req.query);
    params.set('filter', req.filter);

    options.params = params;
}
return options;

};

After reading JHipster: Filtering entities with criteria - intended Angular client-side approach I tried serveral ways to either pass a {} or [] to query or fitler. However, I cannot make it to work.

In the server side, log says: RequestResource.getAllRequests() with argument[s] = [RequestCriteria{}, Page request [number: 0, size 21, sort: happenDate: DESC]]

The "RequestCriteria{}" cound not get anything I passed in.

Anyone has idear how can I make it work? Thanks a lot.

1
I also had an issue with the filtering and enums (see stackoverflow.com/questions/47111866/…). It's true that JHipster filtering seems powerful, but it's sometimes difficult to use it on the Angular part using request-utils.ts - agoncal
Thanks, I read your post. So you use the url to path the criteria, like I test on postman. I still want to use the generated service instead use http directly. Anyway, if cannot find a way, that will be the choice. - Maosheng Wang
A PR just arrived on JHipster testing request-util.ts. That helps quite a lot actually : github.com/jhipster/generator-jhipster/pull/6972/files#diff-1 - agoncal
I have had a look of your code just. It take one step further. Actaully, I am wondering what the actually pupose of the original authur delare fitler, query and search on that method but not implement them? - Maosheng Wang

1 Answers

2
votes

as a temp way, here is my current way to pass the filter from client to server:

compose a filter property for the paramater req object pass to model some.service.ts query(req?:any) function like this

 req.filter =  {
        'contactName.contains': "Smith"
        'contactNumber.contains':"186"
    };

and then change the ../shared folder request-util.ts file

if (req.filter) {
        for (const k in req.filter) {
            if (k) {
              params.append(k, req.filter[k]);
           }
        }

    }
    // params.set('filter', req.filter);