-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] fieldservice_geoengine: Migration to 16.0
- Loading branch information
Showing
11 changed files
with
224 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
from . import fsm_location | ||
from . import fsm_order | ||
from . import vector_layer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2011-2012 Nicolas Bessi (Camptocamp SA) | ||
# Copyright 2016 Yannick Payot (Camptocamp SA) | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import ValidationError | ||
|
||
NUMBER_ATT = ["float", "integer", "integer_big"] | ||
|
||
|
||
class GeoVectorLayer(models.Model): | ||
_inherit = "geoengine.vector.layer" | ||
|
||
@api.constrains("geo_repr", "attribute_field_id") | ||
def _check_geo_repr(self): | ||
for rec in self: | ||
if ( | ||
rec.attribute_field_id | ||
and rec.attribute_field_id.ttype not in NUMBER_ATT | ||
and rec.model_id.name not in ["fsm.order", "fsm.location"] | ||
and rec.geo_field_id.model not in ["fsm.order", "fsm.location"] | ||
): | ||
if ( | ||
rec.geo_repr == "colored" | ||
and rec.classification != "unique" | ||
or rec.geo_repr == "proportion" | ||
): | ||
raise ValidationError( | ||
_( | ||
"You need to select a numeric field", | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
...vice_geoengine/static/src/js/views/geoengine/geoengine_renderer/geoengine_renderer.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/** @odoo-module */ | ||
|
||
/** | ||
* Copyright 2024 APSL-Nagarro | ||
*/ | ||
|
||
/* global chroma, geostats */ | ||
|
||
import {GeoengineRenderer} from "@base_geoengine/js/views/geoengine/geoengine_renderer/geoengine_renderer.esm"; | ||
import {patch} from "@web/core/utils/patch"; | ||
|
||
/* CONSTANTS */ | ||
const DEFAULT_BEGIN_COLOR = "#FFFFFF"; | ||
const DEFAULT_END_COLOR = "#000000"; | ||
const LEGEND_MAX_ITEMS = 10; | ||
const DEFAULT_NUM_CLASSES = 5; | ||
|
||
patch(GeoengineRenderer.prototype, "geoengine_renderer_view_patch", { | ||
styleVectorLayerColored(cfg, data) { | ||
var indicator = cfg.attribute_field_id[1]; | ||
var values = this.extractLayerValues(cfg, data); | ||
var nb_class = cfg.nb_class || DEFAULT_NUM_CLASSES; | ||
var opacity = cfg.layer_opacity; | ||
var begin_color_hex = cfg.begin_color || DEFAULT_BEGIN_COLOR; | ||
var end_color_hex = cfg.end_color || DEFAULT_END_COLOR; | ||
var begin_color = chroma(begin_color_hex).alpha(opacity).css(); | ||
var end_color = chroma(end_color_hex).alpha(opacity).css(); | ||
// Function that maps numeric values to a color palette. | ||
// This scale function is only used when geo_repr is basic | ||
var scale = chroma.scale([begin_color, end_color]); | ||
var serie = new geostats(values); | ||
var vals = null; | ||
switch (cfg.classification) { | ||
case "unique": | ||
case "custom": | ||
vals = serie.getClassUniqueValues(); | ||
// "RdYlBu" is a set of colors | ||
scale = chroma.scale("RdYlBu").domain([0, vals.length], vals.length); | ||
break; | ||
case "quantile": | ||
serie.getClassQuantile(nb_class); | ||
vals = serie.getRanges(); | ||
scale = scale.domain([0, vals.length], vals.length); | ||
break; | ||
case "interval": | ||
serie.getClassEqInterval(nb_class); | ||
vals = serie.getRanges(); | ||
scale = scale.domain([0, vals.length], vals.length); | ||
break; | ||
} | ||
let colors = []; | ||
if (cfg.classification === "custom") { | ||
colors = vals | ||
.filter((val) => val) | ||
.map((val) => chroma(val).alpha(opacity).css()); | ||
} else { | ||
colors = scale | ||
.colors(vals.length) | ||
.map((color) => chroma(color).alpha(opacity).css()); | ||
} | ||
const styles_map = this.createStylesWithColors(colors); | ||
let legend = null; | ||
if (vals.length <= LEGEND_MAX_ITEMS) { | ||
legend = serie.getHtmlLegend(colors, cfg.name, 1); | ||
for (let i = 0; i < data.length; i++) { | ||
legend = legend.replace( | ||
data[i]._values[cfg.attribute_field_id[1]], | ||
data[i]._values.stage_name | ||
); | ||
} | ||
} | ||
return { | ||
style: (feature) => { | ||
const value = feature.get("attributes")[indicator]; | ||
const color_idx = this.getClass(value, vals); | ||
var label_text = feature.values_.attributes.label; | ||
if (label_text === false) { | ||
label_text = ""; | ||
} else if (label_text !== "") { | ||
label_text = feature.values_.attributes.stage_name; | ||
} | ||
styles_map[colors[color_idx]][0].text_.text_ = label_text.toString(); | ||
return styles_map[colors[color_idx]]; | ||
}, | ||
legend, | ||
}; | ||
}, | ||
async onLayerChanged(vector, layer) { | ||
layer.setSource(null); | ||
const element = document.getElementById(`legend-${vector.resId}`); | ||
if (element !== null) { | ||
element.remove(); | ||
} | ||
if (vector.model) { | ||
this.cfg_models.push(vector.model); | ||
const fields_to_read = [vector.geo_field_id[1]]; | ||
if (vector.attribute_field_id) { | ||
fields_to_read.push(vector.attribute_field_id[1]); | ||
} | ||
const data = await this.getModelData(vector, fields_to_read); | ||
this.styleVectorLayerAndLegend(vector, data, layer); | ||
this.useRelatedModel(vector, layer, data); | ||
} else { | ||
const data = []; | ||
for (const record of this.props.data.records) { | ||
if ( | ||
vector.attribute_field_id[1] === "custom_color" && | ||
typeof record.data[vector.attribute_field_id[1]] === "string" | ||
) { | ||
record.data[vector.attribute_field_id[1]] = parseInt( | ||
record.data[vector.attribute_field_id[1]].split("#")[1], | ||
16 | ||
); | ||
} | ||
data.push(record); | ||
} | ||
this.styleVectorLayerAndLegend(vector, data, layer); | ||
this.addSourceToLayer(data, vector, layer); | ||
} | ||
}, | ||
styleVectorLayerAndLegend(cfg, data, lv) { | ||
const aux = []; | ||
for (var i = 0; i < data.length; i++) { | ||
if ( | ||
cfg.attribute_field_id[1] === "custom_color" && | ||
typeof data[i]._values[cfg.attribute_field_id[1]] === "string" | ||
) { | ||
data[i]._values[cfg.attribute_field_id[1]] = parseInt( | ||
data[i]._values[cfg.attribute_field_id[1]].split("#")[1], | ||
16 | ||
); | ||
} | ||
aux.push(data[i]); | ||
} | ||
const styleInfo = this.styleVectorLayer(cfg, aux); | ||
this.initLegend(styleInfo, cfg); | ||
lv.setStyle(styleInfo.style); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.