From 6c1f05f7302b5c494d3b3e45a0ad510ac8fbad1e Mon Sep 17 00:00:00 2001 From: Nick Jakuschona Date: Fri, 13 Sep 2024 10:14:50 +0200 Subject: [PATCH] resolve types and its domains --- package.json | 3 ++ src/main/js/apps/sample/app.json | 6 +-- .../HierarchicalSearchController.ts | 48 +++++++++++++++++-- .../HierarchicalSearchWidget.vue | 2 + .../bundles/dn_hierarchicalsearch/README.md | 7 ++- .../dn_hierarchicalsearch/manifest.json | 3 +- 6 files changed, 58 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 6c71dea..0d4c89b 100644 --- a/package.json +++ b/package.json @@ -32,5 +32,8 @@ "typescript": "5.4.5", "vue": "2.7.15", "vue-template-compiler": "2.7.15" + }, + "dependencies": { + "mapapps-4-developers": "file:" } } diff --git a/src/main/js/apps/sample/app.json b/src/main/js/apps/sample/app.json index f0e4edb..09f92e6 100644 --- a/src/main/js/apps/sample/app.json +++ b/src/main/js/apps/sample/app.json @@ -45,15 +45,15 @@ "storeId": "flurstuecke_store", "fields": [ { - "name": "NAMGMK", + "name": "namgmk", "label": "Gemarkung" }, { - "name": "FLN", + "name": "fln", "label": "Flur" }, { - "name": "ZAE", + "name": "zae", "label": "Flurstück" } ], diff --git a/src/main/js/bundles/dn_hierarchicalsearch/HierarchicalSearchController.ts b/src/main/js/bundles/dn_hierarchicalsearch/HierarchicalSearchController.ts index 22956d4..710203c 100644 --- a/src/main/js/bundles/dn_hierarchicalsearch/HierarchicalSearchController.ts +++ b/src/main/js/bundles/dn_hierarchicalsearch/HierarchicalSearchController.ts @@ -40,12 +40,16 @@ export default class HierarchicalSearchController { private mapActions: any; private mapActionsConfig: any; private widget: any; + private types: any; + private domains: any; + private resolveTypes: boolean; activate(componentContext: InjectedReference): void { const bundleContext = this.bundleContext = componentContext.getBundleContext(); const serviceResolver = this.serviceResolver = new ServiceResolver({}); serviceResolver.setBundleCtx(bundleContext); } + /** * Method that enables the hierarchical search function of the bundle * @param event emitted by clickHandler, on click, use to access clicked tool @@ -59,11 +63,15 @@ export default class HierarchicalSearchController { const fields = tool.fields; this.mapActions = tool.mapActions; this.mapActionsConfig = tool.mapActionsConfig; + this.resolveTypes = tool.resolveTypes; + this.types = {}; + this.domains = {}; const model = this._hierarchicalSearchModel; const envs = this.bundleContext.getCurrentExecutionEnvironment(); model.isMobile = envs.some((env) => env.name === "Mobile"); model.fields = this.getFields(fields); + this.setUpSelect(0); let widget; @@ -82,10 +90,10 @@ export default class HierarchicalSearchController { const window: any = ct_util.findEnclosingWindow(widget); if (window) { window.set("title", tool.title); - window.on("Close", () => { + window.onHide = () => { this.hideWidget(); this.resetSearch(); - }); + }; } }, 100); } @@ -154,8 +162,10 @@ export default class HierarchicalSearchController { } } - private queryDistinctValues(field: Field, index: number): void { + private async queryDistinctValues(field: Field, index: number): void { + const queryUrl = this.store.target; + const model = this._hierarchicalSearchModel; if (!queryUrl) { console.error("Store has no target!"); return; @@ -170,13 +180,41 @@ export default class HierarchicalSearchController { }); if (index === 0) { queryObject.where = "1=1"; + if(this.resolveTypes && this.store.layer.types && this.store.layer.typeIdField === fieldName) { + this.store.layer.types.forEach((type) => { + this.types[type.id] = type; + }); + } } else { const complexQuery = this.getComplexQuery(); queryObject.where = toSQLWhere(complexQuery, {}); + if(this.resolveTypes && this.types && this.types[model.fields[0].value.value] && this.types[model.fields[0].value.value].domains[fieldName]) { + this.domains = {}; + this.types[model.fields[0].value.value].domains[fieldName].codedValues.forEach((domain) => { + this.domains[domain.code] = domain.name; + }); + } + else { + this.domains = undefined; + } } + + const layer = this.store.layer; + const types = this.types; + const domains = this.domains; + const resolveTypes = this.resolveTypes; + query.executeQueryJSON(this.store.target, queryObject).then(function (response) { response.features.forEach((feature) => { - field.items.push(feature.attributes[fieldName]); + if (resolveTypes && index === 0 && layer.typeIdField == fieldName) { + field.items.push({value: feature.attributes[fieldName], label: types[feature.attributes[fieldName]].name}); + } + else if (resolveTypes && index !== 0 && domains ) { + field.items.push({value: feature.attributes[fieldName], label: domains[feature.attributes[fieldName]]}); + } + else { + field.items.push({value: feature.attributes[fieldName], label: feature.attributes[fieldName]}); + } }); field.loading = false; }); @@ -247,7 +285,7 @@ export default class HierarchicalSearchController { const searchObj = {}; model.fields.forEach((field: Field) => { if (field && field.value) { - searchObj[field.name] = field.value; + searchObj[field.name] = field.value.value; } }); diff --git a/src/main/js/bundles/dn_hierarchicalsearch/HierarchicalSearchWidget.vue b/src/main/js/bundles/dn_hierarchicalsearch/HierarchicalSearchWidget.vue index 735fdad..73a3a02 100644 --- a/src/main/js/bundles/dn_hierarchicalsearch/HierarchicalSearchWidget.vue +++ b/src/main/js/bundles/dn_hierarchicalsearch/HierarchicalSearchWidget.vue @@ -30,6 +30,8 @@