Skip to content

Commit

Permalink
Fix eslint errors and some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Oct 30, 2024
1 parent 45d390f commit 4cd7c66
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
/** @odoo-module */

class Popover {
/**
* The base element
* @param {HTMLElement} element
*/
element = undefined;
/**
* The jQuery base element
*/
jqueryElement = undefined;
/**
* The map
* @param {ol.Map} map
*/
map = undefined;
/**
* The popup overlay
* @param {ol.Overlay} popup
*/
popup = undefined;
/**
* The popover
* @param {jQuery} popover
*/
popover = undefined;

constructor(element, map) {
/**
* The popover
* @param {jQuery} popover
*/
this.popover = undefined;
/**
* The map
* @param {ol.Map} map
*/
this.map = map;
/**
* The base element
* @param {HTMLElement} element
*/
this.element = element;
/**
* The jQuery base element
* @type {jQuery}
*/
this.jqueryElement = $(element);
/**
* The popup overlay
* @param {ol.Overlay} popup
*/
this.popup = new ol.Overlay({
element: this.element,
positioning: "bottom-center",
Expand All @@ -52,11 +48,10 @@ class Popover {
}
}

mapOnMove(event) {
mapOnMove() {
if (!this.feature) {
return;
}
//this.popup.setPosition(this.feature.getGeometry().getFirstCoordinate());
$(this.element).popover("show");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @odoo-module **/

//import rpc from "web.rpc";
import session from "web.session";

/**
Expand Down Expand Up @@ -43,7 +42,7 @@ function buildCanvas(
const alpha = radius < height ? Math.acos(radius / height) : 0;
const circleCenter = [
canvas.width / 2,
alpha == 0 ? canvas.width / 2 : radius + strokeWidth / 2,
alpha === 0 ? canvas.width / 2 : radius + strokeWidth / 2,
];
const linesStart = [canvas.width / 2, radius + height + strokeWidth / 2];
const linesWeight = Math.sin(alpha) * radius;
Expand All @@ -57,7 +56,10 @@ function buildCanvas(
context.lineJoin = "round";

context.beginPath();
if (alpha != 0) {
if (alpha === 0) {
context.moveTo(circleCenter[0] + radius, circleCenter[1]);
context.arc(circleCenter[0], circleCenter[1], radius, 0, Math.PI * 2);
} else {
context.moveTo(line2End[0], line2End[1]);
context.lineTo(linesStart[0], linesStart[1]);
context.lineTo(line1End[0], line1End[1]);
Expand All @@ -69,9 +71,6 @@ function buildCanvas(
Math.PI / 2 - alpha
);
context.lineTo(line2End[0], line2End[1]);
} else {
context.moveTo(circleCenter[0] + radius, circleCenter[1]);
context.arc(circleCenter[0], circleCenter[1], radius, 0, Math.PI * 2);
}
context.stroke();
context.moveTo(circleCenter[0] + centerRadius, circleCenter[1]);
Expand Down Expand Up @@ -166,58 +165,56 @@ function buildIcon(
}

class Search {
/**
* The search input element
* @type {HTMLInputElement}
*/
element = undefined;
/**
* The search input JQuery element
* @type {JQuery<HTMLElement>}
*/
jquery_element = undefined;
/**
* The map
* @type {ol.Map}
*/
map = undefined;
/**
* The stores layer
* @type {ol.layer.Vector}
*/
stores = undefined;
/**
* The format to read the features
* @type {ol.format.GeoJSON}
*/
format = undefined;
/**
* The language of the user
* @type {string}
*/
lang = undefined;
/**
* The input element of the flexdatalist
* @type {HTMLInputElement}
*/
jquery_input_element = undefined;
/**
* The last search text
* @type {string}
*/
last_search_text = "";

constructor(element, map, mapElement, stores, maxResults = 200, mapZoom = -1) {
/**
* The search input element
* @type {HTMLInputElement}
*/
this.element = element;
/**
* The search input JQuery element
* @type {JQuery<HTMLElement>}
*/
this.jquery_element = $(element);
this.jquery_element.val("");

/**
* The map
* @type {ol.Map}
*/
this.map = map;
/**
* The stores layer
* @type {ol.layer.Vector}
*/
this.stores = stores;
/**
* The last search text
* @type {string}
*/
this.last_search_text = "";

/**
* The search input element
* @type {HTMLInputElement}
*/
this.mapElement = mapElement;
/**
* The maximum number of results
* @type {number}
*/
this.maxResults = maxResults;
/**
* The zoom level of the map
* @type {number}
*/
this.mapZoom = mapZoom;
this.stores = stores;
/**
* The message element
* @type {JQuery<HTMLElement>}
*/
this.message = null;

this.stores.setStyle(
new ol.style.Style({
image: buildIcon(
Expand All @@ -233,11 +230,20 @@ class Search {
),
})
);

/**
* The format to read the features
* @type {ol.format.GeoJSON}
*/
this.format = new ol.format.GeoJSON({
dataProjection: "EPSG:4326",
featureProjection: "EPSG:3857",
});

/**
* The language of the user
* @type {string}
*/
this.lang = (document.documentElement.getAttribute("lang") || "en_US").replace(
"-",
"_"
Expand All @@ -249,27 +255,32 @@ class Search {
focusFirstResult: true,
maxShownResults: 10,
searchIn: ["value"],
// combo box
// Combo box
visibleProperties: ["text"],
// tag list in field
// Tag list in field
textProperty: "text",
// the managed value
// The managed value
valueProperty: "text",
cache: false,
});

/**
* The input element of the flexdatalist
* @type {HTMLInputElement}
*/
this.jquery_input_element = element.querySelector("ul input");
this.jquery_element.on("before:flexdatalist.search", this.loadDatas.bind(this));
this.jquery_element.on("change:flexdatalist", () => {
const value = this.jquery_element.flexdatalist("value");
if (value.length == 0) {
if (value.length === 0) {
// Initial state
this.loadPartners([], true);
return;
}
const arg = [];
for (let item of value) {
for (const item of value) {
const value_split = item.split(":");
if (value_split.length == 2) {
if (value_split.length === 2) {
arg.push({field: value_split[0], value: value_split[1].trim()});
}
}
Expand All @@ -281,7 +292,7 @@ class Search {
}

loadPartners(tags, firstTime = false) {
if (this.message != null) {
if (this.message !== null) {
this.mapElement.removeChild(this.message[0]);
this.message = null;
}
Expand Down Expand Up @@ -314,17 +325,17 @@ class Search {
this.map.getView().setZoom(this.mapZoom);
return;
}
for (let feature of result) {
for (const feature of result) {
console.log(this.format.readFeature(feature));
storesSource.addFeature(this.format.readFeature(feature));
}
if (storesSource.getFeatures().length == 0) {
if (storesSource.getFeatures().length === 0) {
return;
}
const extent = storesSource.getExtent();
const addWidth = (extent[2] - extent[0]) / 10;
const addHeight = (extent[3] - extent[1]) / 10;
if (addWidth == 0 && addHeight == 0) {
if (addWidth === 0 && addHeight === 0) {
this.map.getView().setCenter([extent[0], extent[1]]);
} else {
this.map
Expand All @@ -344,12 +355,12 @@ class Search {
}

loadDatas(event, text) {
if (text == this.last_search_text) {
if (text === this.last_search_text) {
return;
}
this.last_search_text = text;

if (this.message != null) {
if (this.message !== null) {
this.mapElement.removeChild(this.message[0]);
this.message = null;
}
Expand All @@ -364,7 +375,7 @@ class Search {
session.rpc("/website-geoengine/tags", args).then(
(result) => {
const data = [];
for (let item of result) {
for (const item of result) {
data.push({
value: item[1],
text: `${item[0]}: ${item[1]}`,
Expand Down

0 comments on commit 4cd7c66

Please sign in to comment.