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

Allow costum stores + make operators configurable in manifest.json #73

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class EditableQueryBuilderWidgetFactory {
model.getDistinctValues(args.value, args.selectedField, vm.selectedStoreId);
});
this.#queryBuilderWidgetModelBinding = Binding.for(vm, model)
.syncAll("replaceOpenedTables")
.syncAll("replaceOpenedTables", "operators")
.enable()
.syncToLeftNow();

Expand Down
80 changes: 24 additions & 56 deletions src/main/js/bundles/dn_querybuilder/FieldWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@
showFieldInfos: {
type: Boolean,
default: false
},
operators: {
type: Object,
default: () => {
return {default:{default: []}};
}
}
},
data() {
Expand Down Expand Up @@ -388,13 +394,12 @@
const selectedField = this.selectedField;
this.getDistinctValues(value, selectedField);
if (selectedField.type === "date") {
fieldQuery.value = null;
fieldQuery.relationalOperator = "$lte";
fieldQuery.value = new Date();
} else {
fieldQuery.value = (selectedField.codedValues[0]
&& selectedField.codedValues[0].code) || selectedField.distinctValues[0] || "";
fieldQuery.relationalOperator = "$eq";
}
fieldQuery.relationalOperator = this.getRelationalOperators(selectedField)[0].value;
if (fieldQuery.relationalOperator === "$exists") {
fieldQuery.value = true;
}
Expand All @@ -408,7 +413,7 @@
fieldQuery.value = true;
} else {
if (selectedField.type === "date") {
fieldQuery.value = "";
fieldQuery.value = new Date();
} else {
fieldQuery.value = (selectedField.codedValues[0]
&& selectedField.codedValues[0].code) || selectedField.distinctValues[0] || "";
Expand All @@ -426,59 +431,22 @@
if (!field) {
return [];
}
const type = field.type;
switch (type) {
case "codedvalue":
return [
{value: "$eq", text: this.i18n.relationalOperators.is},
{value: "!$eq", text: this.i18n.relationalOperators.is_not},
{value: "$gt", text: this.i18n.relationalOperators.is_greater_than},
{value: "$gte", text: this.i18n.relationalOperators.is_greater_or_equal},
{value: "$lt", text: this.i18n.relationalOperators.is_less_than},
{value: "$lte", text: this.i18n.relationalOperators.is_less_or_equal},
{value: "$exists", text: this.i18n.relationalOperators.exists}
];
case "boolean":
return [
{value: "$eq", text: this.i18n.relationalOperators.is},
{value: "!$eq", text: this.i18n.relationalOperators.is_not},
{value: "$exists", text: this.i18n.relationalOperators.exists}
];
case "string":
case "guid":
case "global-id":
return [
{value: "$eq", text: this.i18n.relationalOperators.is},
{value: "!$eq", text: this.i18n.relationalOperators.is_not},
{value: "$eqw", text: this.i18n.relationalOperators.eqw},
{value: "$suggest", text: this.i18n.relationalOperators.suggest},
{value: "$exists", text: this.i18n.relationalOperators.exists},
{value: "$in", text: this.i18n.relationalOperators.in}
];
case "number":
return [
{value: "$eq", text: this.i18n.relationalOperators.is},
{value: "!$eq", text: this.i18n.relationalOperators.is_not},
{value: "$gt", text: this.i18n.relationalOperators.is_greater_than},
{value: "$gte", text: this.i18n.relationalOperators.is_greater_or_equal},
{value: "$lt", text: this.i18n.relationalOperators.is_less_than},
{value: "$lte", text: this.i18n.relationalOperators.is_less_or_equal},
{value: "$exists", text: this.i18n.relationalOperators.exists},
{value: "$in", text: this.i18n.relationalOperators.in}
];
case "date":
return [
{value: "$lte", text: this.i18n.relationalOperators.before},
{value: "$gte", text: this.i18n.relationalOperators.after},
{value: "$exists", text: this.i18n.relationalOperators.exists}
];
default:
return [
{value: "$eq", text: this.i18n.relationalOperators.is},
{value: "!$eq", text: this.i18n.relationalOperators.is_not},
{value: "$exists", text: this.i18n.relationalOperators.exists}
];
let type = field.type;
let operators = [];
if (type === "guid" || type === "global-id"){
type = "string";
}
if(field.operatorClass && this.operators[field.operatorClass]){
operators = this.operators[field.operatorClass][type];
}
else{
operators = this.operators.default[type];
}
if(!operators){
operators = this.operators.default.default;
}
return operators;

},
getDistinctValues(value, selectedField) {
this.$root.$emit("getDistinctValues", {value, selectedField});
Expand Down
3 changes: 2 additions & 1 deletion src/main/js/bundles/dn_querybuilder/MetadataAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export default class MetadataAnalyzer {
type: field.type,
codedValues: codedValues,
distinctValues: [],
loading: false
loading: false,
operatorClass: field.operatorClass
});
}
});
Expand Down
4 changes: 3 additions & 1 deletion src/main/js/bundles/dn_querybuilder/QueryBuilderWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
:enable-distinct-values="enableDistinctValues"
:show-field-infos="visibleElements.fieldInfos"
:i18n="i18n"
:operators="operators"
@remove="removeField"
@add="addField"
/>
Expand Down Expand Up @@ -421,7 +422,8 @@
linkOperatorsDisabled: true,
ariaLabelAdded: false,
textToRead: "",
replaceOpenedTables: false
replaceOpenedTables: false,
operators: {default:{default:[]}}
};
},
computed: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class QueryBuilderWidgetFactory {
"activeSpatialInputAction", "allowMultipleSpatialInputs", "negateSpatialInput", "replaceOpenedTables")
.syncAllToLeft("locale", "storeData", "sortFieldData", "enableDistinctValues",
"spatialInputActions", "activeSpatialInputActionDescription",
"loading", "processing", "activeTool")
"loading", "processing", "activeTool", "operators")
.enable()
.syncToLeftNow();
}
Expand Down
82 changes: 82 additions & 0 deletions src/main/js/bundles/dn_querybuilder/QueryBuilderWidgetModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,63 @@ export default declare({
replaceOpenedTables: false,
metadataQuery: null,
metadataDelay: 500,
operators: {},
defaultOperators: {
default : {
codedvalue: [
{value: "$eq", text: "is"},
{value: "!$eq", text: "is_not"},
{value: "$gt", text: "is_greater_than"},
{value: "$gte", text: "is_greater_or_equal"},
{value: "$lt", text: "is_less_than"},
{value: "$lte", text: "is_less_or_equal"},
{value: "$exists", text: "exists"}
],
boolean: [
{value: "$eq", text: "is"},
{value: "!$eq", text: "is_not"},
{value: "$exists", text: "exists"}
],
string: [
{value: "$eq", text: "is"},
{value: "!$eq", text: "is_not"},
{value: "$eqw", text: "eqw"},
{value: "$suggest", text: "suggest"},
{value: "$exists", text: "exists"},
{value: "$in", text: "in"}
],
number: [
{value: "$eq", text: "is"},
{value: "!$eq", text: "is_not"},
{value: "$gt", text: "is_greater_than"},
{value: "$gte", text: "is_greater_or_equal"},
{value: "$lt", text: "is_less_than"},
{value: "$lte", text: "is_less_or_equal"},
{value: "$exists", text: "exists"},
{value: "$in", text: "in"}
],
date: [
{value: "$lte", text: "before"},
{value: "$gte", text: "after"},
{value: "$exists", text: "exists"}
],
default: [
{value: "$eq", text: "is"},
{value: "!$eq", text: "is_not"},
{value: "$exists", text: "exists"}
]
}
},

activate() {
this.locale = Locale.getCurrent().getLanguage();
this.getStoreDataFromMetadata();
this.linkOperator = this.defaultLinkOperator;
this.spatialRelation = this.defaultSpatialRelation;
this.fieldQueries = [];
this.i18n = this._i18n.get();
this.loadi18nText(this.defaultOperators);
this.prepareOperators(this.operators);

const connect = this.connect = new Connect();
connect.connect(this._tool, "onActivate", () => {
Expand Down Expand Up @@ -568,5 +618,37 @@ export default declare({

_selectedStoreStillAvailable(stores) {
return stores.find((store) => store.id === this.selectedStoreId);
},

loadi18nText(operators) {
if (typeof operators === 'object' && operators !== null) {
if (Array.isArray(operators)) {
operators.forEach(item => this.loadi18nText(item));
} else {
Object.keys(operators).forEach(key => {
if (typeof operators[key] === 'object' && operators[key] !== null) {
this.loadi18nText(operators[key]);
} else if (key === "text") {
const replacement = this.i18n.ui.relationalOperators[operators[key]];
if (replacement) {
operators[key] = replacement;
}
}
});
}
}
return;
},

prepareOperators(operators){
const completeOperators = {...this.defaultOperators};
Object.keys(operators).forEach(configuration => {
completeOperators[configuration] = {...this.defaultOperators.default};
Object.keys(operators[configuration]).forEach(type => {
completeOperators[configuration][type] = operators[configuration][type];
});
});
this.operators = completeOperators;
return;
}
});
9 changes: 7 additions & 2 deletions src/main/js/bundles/dn_querybuilder/QueryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ export default class QueryController {
}

let query = this.#query = countFilter.query({}, { count: 0 });
return apprt_when(query.total, async (total) => {
if (total) {
let totalInQuery = true;
if(!query.total){
query.total= query;
totalInQuery = false;
}
return apprt_when(query.total, async (res) => {
if (res && totalInQuery || res.total ) {
// smartfinder
if (this._smartfinderComplexQueryHandler && store.coreName) {
this._smartfinderComplexQueryHandler.setComplexQuery(complexQuery);
Expand Down
48 changes: 47 additions & 1 deletion src/main/js/bundles/dn_querybuilder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,52 @@ To use a store with the Query Builder bundle, add the value _querybuilder_ to th
],
"width": "2px"
}
}
},
"operators": {
"default" : {
"codedvalue": [
{"value": "$eq", "text": "${ui.relationalOperators.is}"},
{"value": "!$eq", "text": "${ui.relationalOperators.is_not}"},
{"value": "$gt", "text": "${ui.relationalOperators.is_greater_than}"},
{"value": "$gte", "text": "${ui.relationalOperators.is_greater_or_equal}"},
{"value": "$lt", "text": "${ui.relationalOperators.is_less_than}"},
{"value": "$lte", "text": "${ui.relationalOperators.is_less_or_equal}"},
{"value": "$exists", "text": "${ui.relationalOperators.exists}"}
],
"boolean": [
{"value": "$eq", "text": "${ui.relationalOperators.is}"},
{"value": "!$eq", "text": "${ui.relationalOperators.is_not}"},
{"value": "$exists", "text": "${ui.relationalOperators.exists}"}
],
"string": [
{"value": "$eq", "text": "${ui.relationalOperators.is}"},
{"value": "!$eq", "text": "${ui.relationalOperators.is_not}"},
{"value": "$eqw", "text": "${ui.relationalOperators.eqw}"},
{"value": "$suggest", "text": "${ui.relationalOperators.suggest}"},
{"value": "$exists", "text": "${ui.relationalOperators.exists}"},
{"value": "$in", "text": "${ui.relationalOperators.in}"}
],
"number": [
{"value": "$eq", "text": "${ui.relationalOperators.is}"},
{"value": "!$eq", "text": "${ui.relationalOperators.is_not}"},
{"value": "$gt", "text": "${ui.relationalOperators.is_greater_than}"},
{"value": "$gte", "text": "${ui.relationalOperators.is_greater_or_equal}"},
{"value": "$lt", "text": "is_less_than"},
{"value": "$lte", "text": "${ui.relationalOperators.is_less_or_equal}"},
{"value": "$exists", "text": "${ui.relationalOperators.exists}"},
{"value": "$in", "text": "${ui.relationalOperators.in}"}
],
"date": [
{"value": "$lte", "text": "${ui.relationalOperators.before}"},
{"value": "$gte", "text": "${ui.relationalOperators.after}"},
{"value": "$exists", "text": "${ui.relationalOperators.exists}"}
],
"default": [
{"value": "$eq", "text": "${ui.relationalOperators.is}"},
{"value": "!$eq", "text": "${ui.relationalOperators.is_not}"},
{"value": "$exists", "text": "${ui.relationalOperators.exists}"}
]
}
}
}
```
Expand All @@ -236,6 +281,7 @@ To use a store with the Query Builder bundle, add the value _querybuilder_ to th
| hiddenFields | Array | | ```[]``` | Names of fields that should be hidden in the field select |
| hiddenSortFields | Array | | ```[]``` | Names of fields that should be hidden in the sort field select |
| symbols | Object | | | Symbols that will be used for the presentation of geometries that are selected via the spatial input actions. |
| operators | Object | | | Specify the allowed operators when formulating a costum query. All provided information is option, if no information is given the default will be chosen. You could also provide additional field types. Further, you can add a specififc `operatorClass` to the fieds ans specify the opertors here like: `{"operators": {default {...}, operatorClass: {...}}}`

### QueryTools:
```
Expand Down
Loading