Skip to content

Commit 905d4ab

Browse files
committed
[16.0][IMP] fieldservice_geoengie: Fix vector Layer related Errors
Notifying user to define selected attribute_field_id of supported type from vector layer in infoBox template to avoid JS error. Addressed JS Error when supported data type even defined in geoengine view as well. When a field from attribute_field_id values selected from vector layer is not suitable for "custom" classification, it is notified to the user to avoid JS Error.Similarly for interval classification is also taken care. Domain for attribute_field_id is filter based on classification selection in vector layer to avoid JS Error.
1 parent 729aa20 commit 905d4ab

3 files changed

Lines changed: 110 additions & 4 deletions

File tree

fieldservice_geoengine/models/vector_layer.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
from odoo.exceptions import ValidationError
88

99
NUMBER_ATT = ["float", "integer", "integer_big"]
10+
SUPPORTED_ATT = [
11+
"float",
12+
"integer",
13+
"integer_big",
14+
"related",
15+
"function",
16+
"date",
17+
"datetime",
18+
"char",
19+
"text",
20+
"selection",
21+
]
1022

1123

1224
class GeoVectorLayer(models.Model):
@@ -31,3 +43,27 @@ def _check_geo_repr(self):
3143
"You need to select a numeric field",
3244
)
3345
)
46+
47+
@api.depends("geo_field_id", "classification", "geo_repr")
48+
def _compute_attribute_field_id_domain(self):
49+
for rec in self:
50+
if rec.geo_field_id:
51+
if (
52+
rec.geo_repr == "colored"
53+
and (
54+
rec.classification != "unique"
55+
and rec.classification != "custom"
56+
)
57+
or rec.geo_repr == "proportion"
58+
):
59+
rec.attribute_field_id_domain = [
60+
("ttype", "in", NUMBER_ATT),
61+
("model", "=", rec.geo_field_id.model_id.model),
62+
]
63+
else:
64+
rec.attribute_field_id_domain = [
65+
("ttype", "in", SUPPORTED_ATT),
66+
("model", "=", rec.geo_field_id.model_id.model),
67+
]
68+
else:
69+
rec.attribute_field_id_domain = [("ttype", "in", SUPPORTED_ATT)]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
geospatial https://github.com/OCA/geospatial refs/pull/417/head 9825f67d128918294b67b74d324d1e6d3259399b

fieldservice_geoengine/static/src/js/views/geoengine/geoengine_renderer/geoengine_renderer.esm.js

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ patch(GeoengineRenderer.prototype, "geoengine_renderer_view_patch", {
3434
case "unique":
3535
case "custom":
3636
vals = serie.getClassUniqueValues();
37+
if (
38+
cfg.classification === "custom" &&
39+
vals.some((item) => item === 0)
40+
) {
41+
this.notification.add(
42+
this.env._t(
43+
"Could not generate " +
44+
cfg.classification +
45+
" range for selected Attribute Field: " +
46+
indicator
47+
),
48+
{
49+
type: "warning",
50+
}
51+
);
52+
return false;
53+
}
3754
// "RdYlBu" is a set of colors
3855
scale = chroma.scale("RdYlBu").domain([0, vals.length], vals.length);
3956
break;
@@ -45,6 +62,18 @@ patch(GeoengineRenderer.prototype, "geoengine_renderer_view_patch", {
4562
case "interval":
4663
serie.getClassEqInterval(nb_class);
4764
vals = serie.getRanges();
65+
if (vals.some((item) => item === "0 - 0")) {
66+
this.notification.add(
67+
this.env._t(
68+
"Could not generate interval range for selected Attribute Field: " +
69+
indicator
70+
),
71+
{
72+
type: "warning",
73+
}
74+
);
75+
return false;
76+
}
4877
scale = scale.domain([0, vals.length], vals.length);
4978
break;
5079
}
@@ -81,7 +110,13 @@ patch(GeoengineRenderer.prototype, "geoengine_renderer_view_patch", {
81110
} else if (label_text !== "") {
82111
label_text = feature.values_.attributes.stage_name;
83112
}
84-
styles_map[colors[color_idx]][0].text_.text_ = label_text.toString();
113+
try {
114+
styles_map[colors[color_idx]][0].text_.text_ =
115+
label_text.toString();
116+
} catch (error) {
117+
// Do nothing to restore history
118+
return;
119+
}
85120
return styles_map[colors[color_idx]];
86121
},
87122
legend,
@@ -134,8 +169,42 @@ patch(GeoengineRenderer.prototype, "geoengine_renderer_view_patch", {
134169
}
135170
aux.push(data[i]);
136171
}
137-
const styleInfo = this.styleVectorLayer(cfg, aux);
138-
this.initLegend(styleInfo, cfg);
139-
lv.setStyle(styleInfo.style);
172+
if (this.checkAttributeFieldUsage(cfg, aux)) {
173+
const styleInfo = this.styleVectorLayer(cfg, aux);
174+
if (styleInfo) {
175+
this.initLegend(styleInfo, cfg);
176+
lv.setStyle(styleInfo.style);
177+
}
178+
}
179+
},
180+
/**
181+
* Allows you to find the index of the color to be used according to its value.
182+
* @param {*} val
183+
* @param {*} a
184+
* @returns {Number}
185+
*/
186+
getClass(val, a) {
187+
if (a.some((item) => item === 0)) {
188+
return false;
189+
}
190+
// Classification uniqueValues
191+
var idx = a.indexOf(val);
192+
if (idx > -1) {
193+
return idx;
194+
}
195+
// Range classification
196+
var separator = " - ";
197+
for (var i = 0; i < a.length; i++) {
198+
// All classification except uniqueValues
199+
if (typeof val !== "object" && a[i].indexOf(separator) !== -1) {
200+
var item = a[i].split(separator);
201+
if (val <= parseFloat(item[1])) {
202+
return i;
203+
}
204+
} else if (val === a[i]) {
205+
// Classification uniqueValues
206+
return i;
207+
}
208+
}
140209
},
141210
});

0 commit comments

Comments
 (0)