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

MapFilter Plugin: Build filter string with field inputs only while using predifined filters #570

Open
danceb opened this issue Aug 20, 2024 · 3 comments

Comments

@danceb
Copy link

danceb commented Aug 20, 2024

I am trying to configure a set of predefined filters for the map filter plugin. Here the filtering is not possible, if the filter expressions are chained with "and|or", no default value is set and the user input isn't given yet.

For instance, if I have this configuration:

{
  "id": "flurstuecke",
  "title": "Flurstücke",
  "filter": {
      "Flurstücke": [["ort", "=", "$gemarkung$"], "and", ["flur", "=", "$flur$"]]
  },
  "fields": ["field config here"]
}

this results in this filter:
grafik

But as far as turning the filter switcher it results in an error, as the filter parameter within the map request is as follows:

FILTER=Flurstücke:( "ort" = 'undefined' AND "flur" = 'undefined' )

It works only, if all of the fields are filled in before turning the switch. So if a value is deleted to enter a new one, the filter crashes aswell.

So my suggestion is, that the filter of the respective input field is only active, if the user has filled somethin in.

So for instance:

grafik

results in

FILTER=Flurstücke:( "ort" = 'Jena' AND "flur" = '1' )

and

grafik

results in

FILTER=Flurstücke:( "ort" = 'Jena' )

or
grafik

results in

FILTER=Flurstücke:()

and the empty filters are skipped as nothing is filled in.

In addition showing the error/warning that the filter is not correct result in a frozen app, I have to reload the site after this completely.

grafik

@danceb danceb changed the title MapFilter Plugin: Build filter string not until field input within predifined filters MapFilter Plugin: Build filter string with field inputs only while using predifined filters Aug 20, 2024
@manisandro
Copy link
Member

Not sure if related to the freeze you see, but I could find out one error which I fixed in [1].

Regarding the handling of undefined values: this is not trivial, say

[["field1", ">", "$value1$"], "or", ["field2", ">", "$value2$"]], "and",["field3", ">", "$value3$"]

Cutting of a portion of the expression due to an undefined $value$ would mean replacing the subexpression triplet with true and then evaluating the entire expression to simplify and cut off all the AND TRUE or OR TRUE etc.

[1] qgis/qwc2@0d59ce1

@danceb
Copy link
Author

danceb commented Aug 21, 2024

I do not understand correctly, why the subexpression has to be replaced with true instead of just remove that part with regex or something? There is on special case, if the first subexpression is undefined as the connector afterwards has to be removed and not the one before.

So here some examples:

[["field1", ">", "$value1$"], "or", ["field2", ">", "$value2$"]], "and",["field3", ">", "$value3$"]

case 1, $value1$ is undefined, so remove ["field1", ">", "$value1$"], "or", :

[["field2", ">", "$value2$"]], "and",["field3", ">", "$value3$"]

FILTER=layer:("field2" > 'value2' AND "field3 > 'value3')

case 2, $value2$ is undefined, so remove , "or", ["field2", ">", "$value2$"]:

[["field1", ">", "$value1$"]], "and",["field3", ">", "$value3$"]

FILTER=layer:("field1" > 'value1' AND "field3 > 'value3')

case 3, $value3$ is undefined, so remove , "and",["field3", ">", "$value3$"]:

[["field1", ">", "$value1$"], "or", ["field2", ">", "$value2$"]]

FILTER=layer:("field1" > 'value1' OR "field2 > 'value2')

case 4, $value1$ and $value3$ are undefined, so remove ["field1", ">", "$value1$"], "or", and , "and",["field3", ">", "$value3$"]:

[["field2", ">", "$value2$"]]

FILTER=layer:"field2" > 'value2'

Would this work?

@manisandro
Copy link
Member

What you implicitly did here is replacing the triplet with an undefined value with true, and then resolving the parent boolean operation to simplify the parent triplet. This is the same thing the code would need to do.

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