Skip to content

Commit

Permalink
Refactor app/gui/queryresults/queryresultsservice.js (#317)
Browse files Browse the repository at this point in the history
* refactor `src/app/gui/queryresults/queryresultsservice.js`

- add FIXME comments (eg. please "add function description")
- code cleanup (eg. tons of weird ternary conditions, short-circuiting logic and missing brackets!)
- full function rewrite `QueryResultsService::updateLayerResultFeatures(layer)`
- notable function rewrite `QueryResultsService::_digestFeaturesForLayers (featuresForLayers)`

* Fix misspelling and properties position declaration

* Add comments

* Closes #59

* wrong parameter

* add geometry check within `QueryResultsService::showGeometry(geometry)`

* extract function `QueryResultsService::_handleFeatureForLayer(featuresForLayer)`

* remove undefined action `QueryResultsService.zoomToElement`

* clean up some code

* convert `QueryResultsService` to ES6 class

* update @SInCE tags

* update @param tag

* 🐛 Fix bugs due refactoring

* wrong merge

* 🐛 Fix undefined check and change layer.selection.features to empty array instead empty object

* code readability

- slim down function  `updateLayerResultFeatures()`
- alias long variable name `this._addFeaturesLayerResultInteraction`
- slim down function `downloadFeatures()`
- extract function `_handleExternalVectorLayerSelection()`
- extract function `_handleProjectLayerSelection()`

* 🐛 Ensure that find array method return undefined (not found). Add extenal parameter into _getFeaturesIds

* slim down `unRegisterCustomComponent`

* 🐛 Fix add feature to a external layer. fix add settimeout to querycontrol

* code readability

- slim down comments
- alias long variable name `this.state.currentactiontools`
- alias long variable name `this.state.currentactionfeaturelayer`
- alias long variable name ` this.state.layersFeaturesBoxes`
- extract function `_clearActions`
- alias prototype function `QueryResultsService.init`
- alias prototype function `QueryResultsService.reset`

* refactor function `QueryControl.setMap()`

* refactor `_handleFeatureForLayer`

* ♻️ Set right event 'picked' on queryControl

* comments

* 🐛 Fix setCurrentActionLayerFeatureTool

* Check and correct some refactoring code

* ✨ Create common downloadApplicationWrapper to run download

* ♻️ Move downloadApplicationWrapper from queryresultsservice.js to index.prod.js as GUI method

* move application wrapper

* extract `_hasLayerObjGeometry` and `_parseLayerObjFeatures`

* params destrcuturing: `featuresForLayer`

* simplify condition

* refactor `setQueryResponse`

- remove function
 `_digestFeaturesForLayers()`
- rename function
 `_handleFeatureForLayer()` into `_responseToLayer()`
- extract function `_hasLayerObjGeometry()`
- extract function `_hasLayerObjImageField()`
- refactor function `_parseLayerObjFormStructure()`

* alias `_changeLayerResult`

* remove `_orderResponseByProjectLayers`

* apply some fixme and todos

- remove nested if-else in: `getVectorLayerFeaturesFromQueryRequest()`
- incorporate function `_addVectorLayersDataToQueryResponse()` into `*/
  setQueryResponse()` setter
- simplify destructuring assignment within `_printSingleAtlas()` function
- remove function `_addComponent()`

* wrong variable reference

* wrong variable name

* 🐛 Fix case when click to add feature to layer result and no current mapcontrol is active (undefined). Need to be set null to align default value and evaluation.

* `console.warn`

* wrong comments

* 🐛 In case of no features for a specific layer, return undefind, so layer is not add to query results state layers array

* simplify conditions

* 🐛 Need to refer to instance and not to "class"

* 🐛 Handle selection feature action when add new feature to layer result

* 🐛 Add custom drawpolygon type for query by drw polygon otherwise it conflict to download action to get all attributes of polygon query (query by polygon)

* 🐛 fix download action

* boolean logic

---------

Co-authored-by: volterra79 <[email protected]>
  • Loading branch information
Raruto and volterra79 authored Aug 25, 2023
1 parent e458fc2 commit 3d44a21
Show file tree
Hide file tree
Showing 7 changed files with 2,387 additions and 1,691 deletions.
5 changes: 4 additions & 1 deletion src/app/g3w-ol/controls/querybydrawpolygoncontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ proto.runSpatialQuery = async function() {
filterConfig: {
spatialMethod: this.getSpatialMethod()
},
multilayers: ProjectsRegistry.getCurrentProject().isQueryMultiLayers(this.name)
multilayers: ProjectsRegistry.getCurrentProject().isQueryMultiLayers(this.name),
/**@since 3.9.0**/
//add a custom type
type: 'drawpolygon',
},
outputs: {
show({error = false}) {
Expand Down
17 changes: 8 additions & 9 deletions src/app/g3w-ol/controls/querycontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@ const proto = QueryControl.prototype;
/**
* @param {ol.Map} map
*
* @fires picked fired after map `singleclick` ?
* @listens InteractionControl~toggled
*/
proto.setMap = function(map) {
let eventSingleClickKey = null;

this.on('toggled', ({toggled}) => {
let key = null;

this.on('toggled', ({ toggled }) => {
if (true !== toggled) {
ol.Observable.unByKey(eventSingleClickKey);
eventSingleClickKey = null;
} else if (null === eventSingleClickKey && map) {
// register click on map event. It use to dispatch picked event by control
eventSingleClickKey = map
.on('singleclick', throttle(evt => this.dispatchEvent({ type: 'picked', coordinates:evt.coordinate })));
ol.Observable.unByKey(key);
key = null;
} else if (null === key && map) {
key = this.getInteraction().on('picked', throttle(evt => this.runQuery({coordinates: evt.coordinate })));
}
});

Expand All @@ -56,6 +54,7 @@ proto.setMap = function(map) {

/**
* @since 3.8.0
*
* @param event
*/
proto.runQuery = async function({coordinates}) {
Expand Down
Loading

0 comments on commit 3d44a21

Please sign in to comment.