Skip to content

Commit babd669

Browse files
#693 Support default/preset filters for vector layers (#698)
1 parent 7b2f870 commit babd669

File tree

6 files changed

+238
-59
lines changed

6 files changed

+238
-59
lines changed

API/Backend/Geodatasets/routes/geodatasets.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function get(reqtype, req, res, next) {
7171
const filterSplit = req.query.filters.split(",");
7272
filters = [];
7373
filterSplit.forEach((f) => {
74-
if (f === "OR" || f === "AND" || f === "NOT") {
74+
if (f === "OR" || f === "AND" || f === "NOT_AND" || f === "NOT_OR") {
7575
filters.push({
7676
isGroup: true,
7777
op: f,
@@ -257,9 +257,17 @@ function get(reqtype, req, res, next) {
257257
) {
258258
filterSQL.push(
259259
`${
260-
currentGroupOp == "NOT" ? "NOT " : ""
260+
currentGroupOp == "NOT_AND" || currentGroupOp == "NOT_OR"
261+
? "NOT "
262+
: ""
261263
}(${currentGroup.join(
262-
` ${currentGroupOp == "NOT" ? "AND" : f.op} `
264+
` ${
265+
currentGroupOp == "NOT_AND"
266+
? "AND"
267+
: currentGroupOp == "NOT_OR"
268+
? "OR"
269+
: currentGroupOp
270+
} `
263271
)})`
264272
);
265273
currentGroup = [];
@@ -286,6 +294,12 @@ function get(reqtype, req, res, next) {
286294
case "<":
287295
op = "<";
288296
break;
297+
case ">=":
298+
op = ">=";
299+
break;
300+
case "<=":
301+
op = "<=";
302+
break;
289303
case "in":
290304
op = "IN";
291305
break;
@@ -294,6 +308,9 @@ function get(reqtype, req, res, next) {
294308
case "endswith":
295309
op = "LIKE";
296310
break;
311+
case "!=":
312+
op = "!=";
313+
break;
297314
case "=":
298315
default:
299316
break;
@@ -342,9 +359,17 @@ function get(reqtype, req, res, next) {
342359
// Final group
343360
if (currentGroup.length > 0) {
344361
filterSQL.push(
345-
`${currentGroupOp == "NOT" ? "NOT " : ""}(${currentGroup.join(
362+
`${
363+
currentGroupOp == "NOT_AND" || currentGroupOp == "NOT_OR"
364+
? "NOT "
365+
: ""
366+
}(${currentGroup.join(
346367
` ${
347-
currentGroupOp === "NOT" ? "AND" : currentGroupOp || "AND"
368+
currentGroupOp === "NOT_AND"
369+
? "AND"
370+
: currentGroupOp === "NOT_OR"
371+
? "OR"
372+
: currentGroupOp || "AND"
348373
} `
349374
)})`
350375
);

configure/src/metaconfigs/layer-vector-config.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,82 @@
555555
}
556556
]
557557
},
558+
{
559+
"name": "Filter",
560+
"rows": [
561+
{
562+
"name": "Filters",
563+
"components": [
564+
{
565+
"field": "variables.initialFilters",
566+
"name": "Initial Filters",
567+
"description": "Configures the layer's filters for displaying an initial custom subset of the data.",
568+
"type": "objectarray",
569+
"width": 12,
570+
"object": [
571+
{
572+
"field": "type",
573+
"name": "Type of Property",
574+
"description": "If not a Group, whether the property's value should be treated as a string or as a number.",
575+
"type": "dropdown",
576+
"width": 2,
577+
"options": ["string", "number"]
578+
},
579+
{
580+
"field": "key",
581+
"name": "Property",
582+
"description": "If not a Group, a field name from the properties object of each feature of this layer to be to construct a filter. Supports dot.notation for nested properties.",
583+
"type": "text",
584+
"width": 4
585+
},
586+
{
587+
"field": "op",
588+
"name": "Operator",
589+
"description": "If not a Group, the operator to use between the 'Property' and 'Value'.",
590+
"type": "dropdown",
591+
"width": 2,
592+
"options": [
593+
"=",
594+
"!=",
595+
",",
596+
"<",
597+
">",
598+
"<=",
599+
">=",
600+
"contains",
601+
"beginswith",
602+
"endswith"
603+
]
604+
},
605+
{
606+
"field": "value",
607+
"name": "Value",
608+
"description": "If not a Group, a value for the equation to operate on.",
609+
"type": "text",
610+
"width": 4
611+
},
612+
{
613+
"field": "isGroup",
614+
"name": "Is A Group",
615+
"description": "A group contains all property-value rows beneath this row and up until the next Group row or up until the end. Groups themselves are always ANDed together but enables member rows within them to abide by a different operator. If this entry 'Is A Group', then the type, property, operator and values fields are ignored.",
616+
"type": "switch",
617+
"width": 6,
618+
"defaultChecked": false
619+
},
620+
{
621+
"field": "groupOp",
622+
"name": "Group Operator",
623+
"description": "If 'Is A Group', the operator to use for members within the group. 'AND' ands all the group members together. 'OR' ors all the group members together. 'NOT_AND' ands all the group members together and then negates the evaluation. 'NOT_OR' ors all the group members together and then negates the evaluation.",
624+
"type": "dropdown",
625+
"width": 6,
626+
"options": ["AND", "OR", "NOT_AND", "NOT_OR"]
627+
}
628+
]
629+
}
630+
]
631+
}
632+
]
633+
},
558634
{
559635
"name": "Interface",
560636
"rows": [

src/essence/Ancillary/LocalFilterer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,10 @@ const LocalFilterer = {
318318
let result
319319
if (group.op === 'OR') {
320320
result = group.matches.some(Boolean)
321-
} else if (group.op === 'NOT') {
321+
} else if (group.op === 'NOT_AND') {
322322
result = !group.matches.every(Boolean)
323+
} else if (group.op === 'NOT_OR') {
324+
result = !group.matches.some(Boolean)
323325
} else {
324326
// default to AND
325327
result = group.matches.every(Boolean)

src/essence/Basics/Layers_/Filtering/Filtering.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
font-size: 13px;
169169
}
170170
.layersTool_filtering_group_operator {
171-
width: 190px;
171+
width: 231px;
172172
text-align: center;
173173
}
174174

@@ -257,7 +257,10 @@
257257
.layersTool_filtering_group_operator_select.op_or {
258258
background: var(--color-c2);
259259
}
260-
.layersTool_filtering_group_operator_select.op_not {
260+
.layersTool_filtering_group_operator_select.op_not_and {
261+
background: var(--color-orange2);
262+
}
263+
.layersTool_filtering_group_operator_select.op_not_or {
261264
background: var(--color-p4);
262265
}
263266
.layersTool_filtering_group_operator_select .dropy__title span {

0 commit comments

Comments
 (0)