From bd4000dcbec42627dbf4b91c2c0b800e797670a7 Mon Sep 17 00:00:00 2001 From: oeni2023 <141681986+oeni2023@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:04:55 +0100 Subject: [PATCH 1/8] SonarCloud: mark as readonly SonarCloud: mark as readonly SonarCloud: mark as readonly --- ui/src/LimitCameraHeightToDepth.ts | 4 ++-- ui/src/MapChooser.ts | 4 ++-- ui/src/NavigableVolumeLimiter.ts | 4 ++-- ui/src/draw/CesiumDraw.ts | 8 +++---- .../elements/dashboard/ngm-add-member-form.ts | 4 ++-- ui/src/elements/dashboard/ngm-dashboard.ts | 2 +- ui/src/elements/hide-overflow.ts | 2 +- ui/src/elements/ngm-coordinate-popup.ts | 4 ++-- ui/src/elements/ngm-cursor-information.ts | 2 +- ui/src/elements/ngm-map-configuration.ts | 2 +- ui/src/elements/ngm-nav-tools.ts | 14 +++++------ ui/src/elements/ngm-side-bar.ts | 2 +- ui/src/layers/ngm-layers-item.ts | 10 ++++---- ui/src/measure/MeasureTool.ts | 4 ++-- ui/src/ngm-app-boot.ts | 2 +- ui/src/query/ObjectSelector.ts | 4 ++-- ui/src/slicer/SlicerArrows.ts | 24 +++++++++---------- ui/src/store/auth.ts | 2 +- ui/src/store/dashboard.ts | 12 +++++----- ui/src/store/draw.ts | 4 ++-- ui/src/store/main.ts | 18 +++++++------- ui/src/store/navTools.ts | 10 ++++---- ui/src/store/query.ts | 2 +- ui/src/store/toolbox.ts | 16 ++++++------- ui/src/toolbox/GeometryController.ts | 10 ++++---- ui/src/toolbox/ngm-draw-section.ts | 2 +- ui/src/toolbox/ngm-geometry-edit.ts | 10 ++++---- ui/src/toolbox/ngm-gst-interaction.ts | 4 ++-- ui/src/toolbox/ngm-measure.ts | 2 +- ui/src/toolbox/ngm-point-edit.ts | 2 +- ui/src/toolbox/ngm-toolbox.ts | 2 +- ui/src/toolbox/ngm-topo-profile-modal.ts | 6 ++--- 32 files changed, 99 insertions(+), 99 deletions(-) diff --git a/ui/src/LimitCameraHeightToDepth.ts b/ui/src/LimitCameraHeightToDepth.ts index f5ecaeee1..9dd033e76 100644 --- a/ui/src/LimitCameraHeightToDepth.ts +++ b/ui/src/LimitCameraHeightToDepth.ts @@ -3,8 +3,8 @@ import type {Scene} from 'cesium'; export default class LimitCameraHeightToDepth { - private scene: Scene; - private depth: number; + private readonly scene: Scene; + private readonly depth: number; constructor(scene: Scene, depth: number) { this.scene = scene; diff --git a/ui/src/MapChooser.ts b/ui/src/MapChooser.ts index f314bb926..5c2406cb1 100644 --- a/ui/src/MapChooser.ts +++ b/ui/src/MapChooser.ts @@ -6,8 +6,8 @@ import type {BaseLayerConfig} from './viewer'; import MainStore from './store/main'; export default class MapChooser { - private viewer: Viewer; - private config: BaseLayerConfig[]; + private readonly viewer: Viewer; + private readonly config: BaseLayerConfig[]; public selectedMap: BaseLayerConfig; public elements: NgmMapChooser[] = []; diff --git a/ui/src/NavigableVolumeLimiter.ts b/ui/src/NavigableVolumeLimiter.ts index 3996d7a84..ba2368f59 100644 --- a/ui/src/NavigableVolumeLimiter.ts +++ b/ui/src/NavigableVolumeLimiter.ts @@ -7,8 +7,8 @@ import type {Scene, Rectangle} from 'cesium'; */ export default class NavigableVolumeLimiter { private blockLimiter = false; - private boundingSphere: BoundingSphere; - private ratioFunction: (height: number) => number; + private readonly boundingSphere: BoundingSphere; + private readonly ratioFunction: (height: number) => number; constructor(scene: Scene, rectangle: Rectangle, height: number, ratioFunction: (height: number) => number) { this.boundingSphere = BoundingSphere.fromRectangle3D(rectangle, Ellipsoid.WGS84, height); diff --git a/ui/src/draw/CesiumDraw.ts b/ui/src/draw/CesiumDraw.ts index 6e5411c9f..2c8aa9f4c 100644 --- a/ui/src/draw/CesiumDraw.ts +++ b/ui/src/draw/CesiumDraw.ts @@ -61,10 +61,10 @@ export type DrawEndDetails = { } export class CesiumDraw extends EventTarget { - private viewer_: Viewer; - private strokeColor_: Color; - private strokeWidth_: number; - private fillColor_: Color; + private readonly viewer_: Viewer; + private readonly strokeColor_: Color; + private readonly strokeWidth_: number; + private readonly fillColor_: Color; private eventHandler_: ScreenSpaceEventHandler | undefined; private activePoints_: Cartesian3[] = []; private activePoint_: Cartesian3 | undefined; diff --git a/ui/src/elements/dashboard/ngm-add-member-form.ts b/ui/src/elements/dashboard/ngm-add-member-form.ts index ada09a3e9..0e49d80b4 100644 --- a/ui/src/elements/dashboard/ngm-add-member-form.ts +++ b/ui/src/elements/dashboard/ngm-add-member-form.ts @@ -29,7 +29,7 @@ export class NgmAddMemberForm extends LitElementI18n { accessor email: string | undefined; @state() accessor roleNotSelected = false; - private roleDropdownItems: DropdownItem[] = [ + private readonly roleDropdownItems: DropdownItem[] = [ {title: i18next.t('dashboard_project_viewer'), value: 'viewer'}, {title: i18next.t('dashboard_project_editor'), value: 'editor'}, ]; @@ -105,4 +105,4 @@ export class NgmAddMemberForm extends LitElementI18n { return this; } -} \ No newline at end of file +} diff --git a/ui/src/elements/dashboard/ngm-dashboard.ts b/ui/src/elements/dashboard/ngm-dashboard.ts index 6f01a184b..c3ab86e00 100644 --- a/ui/src/elements/dashboard/ngm-dashboard.ts +++ b/ui/src/elements/dashboard/ngm-dashboard.ts @@ -127,7 +127,7 @@ export class NgmDashboard extends LitElementI18n { private geometries: NgmGeometry[] = []; private recentlyViewedIds: Array = []; private userEmail: string | undefined; - private tempKmlDataSource = new CustomDataSource('tempKmlDataSource'); + private readonly tempKmlDataSource = new CustomDataSource('tempKmlDataSource'); @consume({context: apiClientContext}) accessor apiClient!: ApiClient; diff --git a/ui/src/elements/hide-overflow.ts b/ui/src/elements/hide-overflow.ts index 7cfd3dfec..24db986d6 100644 --- a/ui/src/elements/hide-overflow.ts +++ b/ui/src/elements/hide-overflow.ts @@ -4,7 +4,7 @@ import {customElement} from 'lit/decorators.js'; @customElement('hide-overflow') export class HideOverflow extends LitElement { - private observer: IntersectionObserver; + private readonly observer: IntersectionObserver; constructor() { super(); diff --git a/ui/src/elements/ngm-coordinate-popup.ts b/ui/src/elements/ngm-coordinate-popup.ts index 1756c4b12..e2513a8a1 100644 --- a/ui/src/elements/ngm-coordinate-popup.ts +++ b/ui/src/elements/ngm-coordinate-popup.ts @@ -20,7 +20,7 @@ export class NgmCoordinatePopup extends LitElementI18n { @state() accessor terrainDistance = ''; private eventHandler: ScreenSpaceEventHandler | undefined; - private integerFormat = new Intl.NumberFormat('de-CH', { + private readonly integerFormat = new Intl.NumberFormat('de-CH', { maximumFractionDigits: 1 }); @@ -98,4 +98,4 @@ export class NgmCoordinatePopup extends LitElementI18n { createRenderRoot() { return this; } -} \ No newline at end of file +} diff --git a/ui/src/elements/ngm-cursor-information.ts b/ui/src/elements/ngm-cursor-information.ts index 6ac6f702b..ec909c66c 100644 --- a/ui/src/elements/ngm-cursor-information.ts +++ b/ui/src/elements/ngm-cursor-information.ts @@ -22,7 +22,7 @@ export class NgmCursorInformation extends LitElementI18n { private unlistenMoveStart: any; private unlistenMoveEnd: any; // always use the 'de-CH' locale to always have the simple tick as thousands separator - private integerFormat = new Intl.NumberFormat('de-CH', { + private readonly integerFormat = new Intl.NumberFormat('de-CH', { maximumFractionDigits: 1 }); diff --git a/ui/src/elements/ngm-map-configuration.ts b/ui/src/elements/ngm-map-configuration.ts index fc9d0d5c6..0bd72df6e 100644 --- a/ui/src/elements/ngm-map-configuration.ts +++ b/ui/src/elements/ngm-map-configuration.ts @@ -31,7 +31,7 @@ export class NgmMapConfiguration extends LitElementI18n { accessor baseMapId = 'ch.swisstopo.pixelkarte-grau'; @query('ngm-map-chooser') accessor mapChooserElement; - private debouncedOpacityUpdate = debounce((evt: Event) => this.updateOpacity(Number((evt.target).value)), 250); + private readonly debouncedOpacityUpdate = debounce((evt: Event) => this.updateOpacity(Number((evt.target).value)), 250); private prevExaggeration: number = 1; constructor() { diff --git a/ui/src/elements/ngm-nav-tools.ts b/ui/src/elements/ngm-nav-tools.ts index 462c7b4af..f2ba11549 100644 --- a/ui/src/elements/ngm-nav-tools.ts +++ b/ui/src/elements/ngm-nav-tools.ts @@ -58,7 +58,7 @@ export class NgmNavTools extends LitElementI18n { private zoomingOut = false; private unlistenFromPostRender: Event.RemoveCallback | null = null; private eventHandler: ScreenSpaceEventHandler | undefined; - private stopZoomFunction: () => void = () => this.stopZoom(); + private readonly stopZoomFunction: () => void = () => this.stopZoom(); private refIcon: Entity = new Entity({ position: Cartesian3.ZERO, show: false, @@ -70,14 +70,14 @@ export class NgmNavTools extends LitElementI18n { } }); private moveRef = false; - private julianDate = new JulianDate(); + private readonly julianDate = new JulianDate(); private axisDataSource: CustomDataSource | undefined; private axisCenter: Cartesian3 | undefined; - private oldPolylineUpdate: any = PolylineCollection.prototype.update; - private xyAxisCalculation = (axis, side) => [this.axisCenter, positionFromPxDistance(this.viewer!.scene, this.axisCenter!, AXIS_LENGTH, axis, side)]; - private xAxisCallback = new CallbackProperty(() => this.xyAxisCalculation('x', -1), false); - private yAxisCallback = new CallbackProperty(() => this.xyAxisCalculation('y', 1), false); - private zAxisCallback = new CallbackProperty(() => this.xyAxisCalculation('z', -1), false); + private readonly oldPolylineUpdate: any = PolylineCollection.prototype.update; + private readonly xyAxisCalculation = (axis, side) => [this.axisCenter, positionFromPxDistance(this.viewer!.scene, this.axisCenter!, AXIS_LENGTH, axis, side)]; + private readonly xAxisCallback = new CallbackProperty(() => this.xyAxisCalculation('x', -1), false); + private readonly yAxisCallback = new CallbackProperty(() => this.xyAxisCalculation('y', 1), false); + private readonly zAxisCallback = new CallbackProperty(() => this.xyAxisCalculation('z', -1), false); private exaggeration = 1; constructor() { diff --git a/ui/src/elements/ngm-side-bar.ts b/ui/src/elements/ngm-side-bar.ts index 2fc3952a9..01daac880 100644 --- a/ui/src/elements/ngm-side-bar.ts +++ b/ui/src/elements/ngm-side-bar.ts @@ -91,7 +91,7 @@ export class SideBar extends LitElementI18n { private zoomedToPosition = false; private accordionInited = false; private shareListenerAdded = false; - private shareDownListener = evt => { + private readonly shareDownListener = evt => { if (!evt.composedPath().includes(this)) this.activePanel = null; }; diff --git a/ui/src/layers/ngm-layers-item.ts b/ui/src/layers/ngm-layers-item.ts index e23fe9cbd..9bed758b3 100644 --- a/ui/src/layers/ngm-layers-item.ts +++ b/ui/src/layers/ngm-layers-item.ts @@ -38,8 +38,8 @@ export class NgmLayersItem extends LitElementI18n { accessor movable = false; @query('.menu') accessor actionMenu!: HTMLElement; - private toggleItemSelection = () => this.movable ? Sortable.utils.select(this) : Sortable.utils.deselect(this); - private debouncedOpacityChange = debounce(() => this.changeOpacity(), 250, true); + private readonly toggleItemSelection = () => this.movable ? Sortable.utils.select(this) : Sortable.utils.deselect(this); + private readonly debouncedOpacityChange = debounce(() => this.changeOpacity(), 250, true); firstUpdated() { $(this.querySelector('.ui.dropdown')!).dropdown(); @@ -166,9 +166,9 @@ export class NgmLayersItem extends LitElementI18n { ${i18next.t('dtd_legend')} ` : ''} ${this.config?.geocatId ? html` - Geocat.ch ` : ''} diff --git a/ui/src/measure/MeasureTool.ts b/ui/src/measure/MeasureTool.ts index 939aef444..e5dbd92b7 100644 --- a/ui/src/measure/MeasureTool.ts +++ b/ui/src/measure/MeasureTool.ts @@ -28,7 +28,7 @@ export default class MeasureTool { private readonly measureDataSource = new CustomDataSource('measure'); private readonly measureOptions: MeasureOptions; private measureToolActive = false; - private screenSpaceEventHandler: ScreenSpaceEventHandler | undefined; + private readonly screenSpaceEventHandler: ScreenSpaceEventHandler | undefined; private measurePositions: Cartesian3[] = []; private highlightEntity: Entity | undefined; private points: Entity[] = []; @@ -164,4 +164,4 @@ export default class MeasureTool { this.measureDataSource.entities.removeAll(); this.viewer?.scene.render(); } -} \ No newline at end of file +} diff --git a/ui/src/ngm-app-boot.ts b/ui/src/ngm-app-boot.ts index fa4618c9d..7c13451e5 100644 --- a/ui/src/ngm-app-boot.ts +++ b/ui/src/ngm-app-boot.ts @@ -10,7 +10,7 @@ import {ConfigService} from './api/config.service'; @customElement('ngm-app-boot') export class NgmAppBoot extends LitElement { - private viewerInitialization = new Task(this, { + private readonly viewerInitialization = new Task(this, { task: async () => { const clientConfig = await new ConfigService().getConfig() as ClientConfig; if (!clientConfig) { diff --git a/ui/src/query/ObjectSelector.ts b/ui/src/query/ObjectSelector.ts index 6febb133b..6a06ea921 100644 --- a/ui/src/query/ObjectSelector.ts +++ b/ui/src/query/ObjectSelector.ts @@ -27,8 +27,8 @@ function isTemplateResult(value) { } export default class ObjectSelector { - private viewer: Viewer; - private scene: Scene; + private readonly viewer: Viewer; + private readonly scene: Scene; selectedObj: any | null = null; // todo improve types savedColor: Color | null = null; diff --git a/ui/src/slicer/SlicerArrows.ts b/ui/src/slicer/SlicerArrows.ts index eb88680ed..5e419ee24 100644 --- a/ui/src/slicer/SlicerArrows.ts +++ b/ui/src/slicer/SlicerArrows.ts @@ -69,18 +69,18 @@ export default class SlicerArrows { private enableInputs = true; - private scratchBoundingSphere_ = new BoundingSphere(); - private scratchArrowPosition2d_ = new Cartesian2(); - private scratchOppositeArrowPosition2d_ = new Cartesian2(); - private scratchAxisVector2d_ = new Cartesian2(); - private scratchMouseMoveVector_ = new Cartesian2(); - private scratchObjectMoveVector2d_ = new Cartesian2(); - private scratchNewArrowPosition2d_ = new Cartesian2(); - private axisVector3d = new Cartesian3(); - private scratchLeft = new Cartesian3(); - private scratchRight = new Cartesian3(); - private scratchTop = new Cartesian3(); - private scratchBottom = new Cartesian3(); + private readonly scratchBoundingSphere_ = new BoundingSphere(); + private readonly scratchArrowPosition2d_ = new Cartesian2(); + private readonly scratchOppositeArrowPosition2d_ = new Cartesian2(); + private readonly scratchAxisVector2d_ = new Cartesian2(); + private readonly scratchMouseMoveVector_ = new Cartesian2(); + private readonly scratchObjectMoveVector2d_ = new Cartesian2(); + private readonly scratchNewArrowPosition2d_ = new Cartesian2(); + private readonly axisVector3d = new Cartesian3(); + private readonly scratchLeft = new Cartesian3(); + private readonly scratchRight = new Cartesian3(); + private readonly scratchTop = new Cartesian3(); + private readonly scratchBottom = new Cartesian3(); private eventHandler: (ScreenSpaceEventHandler | null) = null; highlightedArrow: Entity | undefined = undefined; diff --git a/ui/src/store/auth.ts b/ui/src/store/auth.ts index c1ba6a919..802aac782 100644 --- a/ui/src/store/auth.ts +++ b/ui/src/store/auth.ts @@ -2,7 +2,7 @@ import {BehaviorSubject} from 'rxjs'; import type {AuthUser} from '../authService'; export default class AuthStore { - private static userSubject = new BehaviorSubject(null); + private static readonly userSubject = new BehaviorSubject(null); static get user(): BehaviorSubject { return this.userSubject; diff --git a/ui/src/store/dashboard.ts b/ui/src/store/dashboard.ts index be2a97f32..5f5dcee7c 100644 --- a/ui/src/store/dashboard.ts +++ b/ui/src/store/dashboard.ts @@ -24,12 +24,12 @@ export type ProjectParamSubject = { export type ProjectMode = 'edit' | 'viewEdit' | 'viewOnly' | undefined export default class DashboardStore { - private static selectedTopicOrProjectSubject = new BehaviorSubject(undefined); - private static viewIndexSubject = new Subject(); - private static topicOrProjectParamSubject = new BehaviorSubject(undefined); - private static projectModeSubject = new BehaviorSubject(undefined); - private static geometriesSubject = new Subject(); - private static showSaveOrCancelWarningSubject = new Subject(); + private static readonly selectedTopicOrProjectSubject = new BehaviorSubject(undefined); + private static readonly viewIndexSubject = new Subject(); + private static readonly topicOrProjectParamSubject = new BehaviorSubject(undefined); + private static readonly projectModeSubject = new BehaviorSubject(undefined); + private static readonly geometriesSubject = new Subject(); + private static readonly showSaveOrCancelWarningSubject = new Subject(); static get selectedTopicOrProject(): BehaviorSubject { return this.selectedTopicOrProjectSubject; diff --git a/ui/src/store/draw.ts b/ui/src/store/draw.ts index 01a137b54..15facd146 100644 --- a/ui/src/store/draw.ts +++ b/ui/src/store/draw.ts @@ -2,8 +2,8 @@ import {BehaviorSubject} from 'rxjs'; import type {CesiumDraw} from '../draw/CesiumDraw'; export default class DrawStore { - private static drawSubject = new BehaviorSubject(undefined); - private static drawStateSubject = new BehaviorSubject(false); + private static readonly drawSubject = new BehaviorSubject(undefined); + private static readonly drawStateSubject = new BehaviorSubject(false); static measureState = new BehaviorSubject(false); static setDrawState(value: boolean): void { diff --git a/ui/src/store/main.ts b/ui/src/store/main.ts index 66ee92b85..d49fad30a 100644 --- a/ui/src/store/main.ts +++ b/ui/src/store/main.ts @@ -5,21 +5,21 @@ import {getIonToken, setIonToken} from '../permalink'; import {IonAsset} from '../api-ion'; export default class MainStore { - private static viewerSubject = new BehaviorSubject(null); - private static mapChooserSubject = new BehaviorSubject(null); - private static layersRemovedSubject = new Subject(); - private static syncMapSubject = new Subject(); - private static voxelLayerCountSubject = new BehaviorSubject([]); - private static ionTokenSubject = new BehaviorSubject(getIonToken()); - private static ionAssetSubject = new Subject(); - private static removeIonAssetsSubject = new Subject(); + private static readonly viewerSubject = new BehaviorSubject(null); + private static readonly mapChooserSubject = new BehaviorSubject(null); + private static readonly layersRemovedSubject = new Subject(); + private static readonly syncMapSubject = new Subject(); + private static readonly voxelLayerCountSubject = new BehaviorSubject([]); + private static readonly ionTokenSubject = new BehaviorSubject(getIonToken()); + private static readonly ionAssetSubject = new Subject(); + private static readonly removeIonAssetsSubject = new Subject(); static setUrlLayersSubject = new Subject(); static syncLayerParams = new Subject(); /** * List of uploaded KML dataSource names. Required to get list of uploaded layers and update properties in batch (e.g. exaggeration) * @private */ - private static uploadedKmlListSubject = new BehaviorSubject([]); + private static readonly uploadedKmlListSubject = new BehaviorSubject([]); static get viewer(): BehaviorSubject { return this.viewerSubject; diff --git a/ui/src/store/navTools.ts b/ui/src/store/navTools.ts index 482dab6ba..6b0affb5f 100644 --- a/ui/src/store/navTools.ts +++ b/ui/src/store/navTools.ts @@ -3,11 +3,11 @@ import type {LockType} from '../elements/ngm-cam-configuration'; import type {Cartesian3} from 'cesium'; export default class NavToolsStore { - private static syncTargetPointSubject = new Subject(); - private static cameraHeightSubject = new Subject(); - private static hideTargetPointSubject = new Subject(); - private static navLockTypeSubject = new BehaviorSubject(''); - private static targetPointPositionSubject = new BehaviorSubject(undefined); + private static readonly syncTargetPointSubject = new Subject(); + private static readonly cameraHeightSubject = new Subject(); + private static readonly hideTargetPointSubject = new Subject(); + private static readonly navLockTypeSubject = new BehaviorSubject(''); + private static readonly targetPointPositionSubject = new BehaviorSubject(undefined); static exaggerationChanged = new Subject(); static get syncTargetPoint() { diff --git a/ui/src/store/query.ts b/ui/src/store/query.ts index df294f6f4..1ee3eee15 100644 --- a/ui/src/store/query.ts +++ b/ui/src/store/query.ts @@ -2,7 +2,7 @@ import {Subject} from 'rxjs'; import type {QueryResult} from '../query/types'; export default class QueryStore { - private static objectInfoSubject = new Subject(); + private static readonly objectInfoSubject = new Subject(); static setObjectInfo(attributes: QueryResult | undefined): void { if (attributes && !Object.getOwnPropertyNames(attributes).length) diff --git a/ui/src/store/toolbox.ts b/ui/src/store/toolbox.ts index 25301a222..2c5e79d66 100644 --- a/ui/src/store/toolbox.ts +++ b/ui/src/store/toolbox.ts @@ -20,14 +20,14 @@ export interface GeometryAction { export type GeometryCreateOptions = {geometry: NgmGeometry, slice?: boolean}; export default class ToolboxStore { - private static slicerSubject = new BehaviorSubject(null); - private static rtcSubject = new Subject(); - private static geometriesSubject = new BehaviorSubject([]); - private static noEditGeometriesSubject = new BehaviorSubject([]); - private static openedGeometryOptionsSubject = new BehaviorSubject(null); - private static sliceGeometrySubject = new BehaviorSubject(null); - private static geomActionSubject = new Subject(); - private static syncSliceSubject = new Subject(); + private static readonly slicerSubject = new BehaviorSubject(null); + private static readonly rtcSubject = new Subject(); + private static readonly geometriesSubject = new BehaviorSubject([]); + private static readonly noEditGeometriesSubject = new BehaviorSubject([]); + private static readonly openedGeometryOptionsSubject = new BehaviorSubject(null); + private static readonly sliceGeometrySubject = new BehaviorSubject(null); + private static readonly geomActionSubject = new Subject(); + private static readonly syncSliceSubject = new Subject(); static get slicer(): BehaviorSubject { return this.slicerSubject; diff --git a/ui/src/toolbox/GeometryController.ts b/ui/src/toolbox/GeometryController.ts index 9508feb39..fcecadc13 100644 --- a/ui/src/toolbox/GeometryController.ts +++ b/ui/src/toolbox/GeometryController.ts @@ -47,11 +47,11 @@ import {saveAs} from 'file-saver'; export class GeometryController { private draw: CesiumDraw | undefined; - private toastPlaceholder: HTMLElement; + private readonly toastPlaceholder: HTMLElement; private viewer: Viewer | null = null; - private unlistenEditPostRender: Event.RemoveCallback | undefined; - private geometriesDataSource: CustomDataSource; - private julianDate = new JulianDate(); + private readonly unlistenEditPostRender: Event.RemoveCallback | undefined; + private readonly geometriesDataSource: CustomDataSource; + private readonly julianDate = new JulianDate(); private selectedArea: Entity | undefined; private screenSpaceEventHandler: ScreenSpaceEventHandler | undefined; private geometriesCounter: AreasCounter = { @@ -60,7 +60,7 @@ export class GeometryController { rectangle: 0, polygon: 0 }; - private noEdit: boolean; + private readonly noEdit: boolean; constructor(geometriesDataSource: CustomDataSource, toastPlaceholder: HTMLElement, noEdit = false) { this.geometriesDataSource = geometriesDataSource; diff --git a/ui/src/toolbox/ngm-draw-section.ts b/ui/src/toolbox/ngm-draw-section.ts index a47bd2a84..512961ff9 100644 --- a/ui/src/toolbox/ngm-draw-section.ts +++ b/ui/src/toolbox/ngm-draw-section.ts @@ -24,7 +24,7 @@ export class NgmDrawSection extends LitElementI18n { accessor hidden = true; @state() accessor lineInfo: DrawInfo | undefined; - private draw: CesiumDraw | undefined; + private readonly draw: CesiumDraw | undefined; private drawGeometries = [ {label: () => i18next.t('tbx_add_point_btn_label'), type: 'point', icon: 'ngm-point-draw-icon'}, {label: () => i18next.t('tbx_add_line_btn_label'), type: 'line', icon: 'ngm-line-draw-icon'}, diff --git a/ui/src/toolbox/ngm-geometry-edit.ts b/ui/src/toolbox/ngm-geometry-edit.ts index 6fd79bbd8..fd7db8610 100644 --- a/ui/src/toolbox/ngm-geometry-edit.ts +++ b/ui/src/toolbox/ngm-geometry-edit.ts @@ -42,11 +42,11 @@ export class NgmGeometryEdit extends LitElementI18n { accessor validLowerLimit = true; private editingEntity: Entity | undefined; private viewer: Viewer | null | undefined; - private minVolumeHeight = 1; - private maxVolumeHeight = 30000; - private minVolumeLowerLimit = -30000; - private maxVolumeLowerLimit = 30000; - private julianDate = new JulianDate(); + private readonly minVolumeHeight = 1; + private readonly maxVolumeHeight = 30000; + private readonly minVolumeLowerLimit = -30000; + private readonly maxVolumeLowerLimit = 30000; + private readonly julianDate = new JulianDate(); private draw: CesiumDraw | undefined; private unsubscribeFromChanges: Event.RemoveCallback | undefined; private geometriesDataSource: CustomDataSource | undefined; diff --git a/ui/src/toolbox/ngm-gst-interaction.ts b/ui/src/toolbox/ngm-gst-interaction.ts index 3e1a89bc0..7de8eff90 100644 --- a/ui/src/toolbox/ngm-gst-interaction.ts +++ b/ui/src/toolbox/ngm-gst-interaction.ts @@ -31,8 +31,8 @@ export class NgmGstInteraction extends LitElementI18n { @state() accessor selectedId: string | undefined; private viewer: Viewer | null = null; - private minDepth_ = -6000; - private maxDepth_ = 1000; + private readonly minDepth_ = -6000; + private readonly maxDepth_ = 1000; private outputFormat: OutputFormat = 'pdf'; private abortController = new AbortController(); private extentInited = false; diff --git a/ui/src/toolbox/ngm-measure.ts b/ui/src/toolbox/ngm-measure.ts index 7ccf0037c..1d6a796c2 100644 --- a/ui/src/toolbox/ngm-measure.ts +++ b/ui/src/toolbox/ngm-measure.ts @@ -17,7 +17,7 @@ export class NgmMeasure extends LitElementI18n { @state() accessor lineInfo: DrawInfo | undefined; private measure: MeasureTool | undefined; - private integerFormat = new Intl.NumberFormat('de-CH', { + private readonly integerFormat = new Intl.NumberFormat('de-CH', { maximumFractionDigits: 1 }); diff --git a/ui/src/toolbox/ngm-point-edit.ts b/ui/src/toolbox/ngm-point-edit.ts index c72c4a250..4e2de070b 100644 --- a/ui/src/toolbox/ngm-point-edit.ts +++ b/ui/src/toolbox/ngm-point-edit.ts @@ -29,7 +29,7 @@ export class NgmPointEdit extends LitElementI18n { maxHeight = 30000; minDepth = -30000; maxDepth = 30000; - private julianDate: JulianDate = new JulianDate(); + private readonly julianDate: JulianDate = new JulianDate(); private viewer: Viewer | null = null; @query('.dropdown') diff --git a/ui/src/toolbox/ngm-toolbox.ts b/ui/src/toolbox/ngm-toolbox.ts index de85b4837..dcc51845d 100644 --- a/ui/src/toolbox/ngm-toolbox.ts +++ b/ui/src/toolbox/ngm-toolbox.ts @@ -44,7 +44,7 @@ export class NgmToolbox extends LitElementI18n { geometriesDataSource: CustomDataSource = new CustomDataSource(GEOMETRY_DATASOURCE_NAME); noEditGeometriesDataSource: CustomDataSource = new CustomDataSource(NO_EDIT_GEOMETRY_DATASOURCE_NAME); private viewer: Viewer | null = null; - private julianDate = new JulianDate(); + private readonly julianDate = new JulianDate(); private draw: CesiumDraw | undefined; private geometryController: GeometryController | undefined; private geometryControllerNoEdit: GeometryController | undefined; diff --git a/ui/src/toolbox/ngm-topo-profile-modal.ts b/ui/src/toolbox/ngm-topo-profile-modal.ts index d1ea07751..16d9dbe14 100644 --- a/ui/src/toolbox/ngm-topo-profile-modal.ts +++ b/ui/src/toolbox/ngm-topo-profile-modal.ts @@ -48,15 +48,15 @@ export class NgmTopoProfileModal extends LitElementI18n { @query('.ngm-profile-tooltip') accessor profileTooltip; private viewer: Viewer | null | undefined; - private bisect = bisector((d) => d.domainDist).left; + private readonly bisect = bisector((d) => d.domainDist).left; private linestring: number[][] | undefined; private data: ProfileData[] = []; private name: string | undefined; private profileInfo: any | undefined; private domain: any; private distInKM = false; - private highlightPointPosition: Cartesian3 = new Cartesian3(); - private highlightPoint = new Entity({ + private readonly highlightPointPosition: Cartesian3 = new Cartesian3(); + private readonly highlightPoint = new Entity({ position: new CallbackProperty(() => this.highlightPointPosition, false), point: { show: new CallbackProperty(() => this.showTooltip, false), From b9142b3ac72beade9b52f5ac8a36282c42204e72 Mon Sep 17 00:00:00 2001 From: oeni2023 <141681986+oeni2023@users.noreply.github.com> Date: Fri, 29 Nov 2024 10:51:59 +0100 Subject: [PATCH 2/8] readyonly removed based on github action Check ui job --- ui/src/toolbox/ngm-draw-section.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/toolbox/ngm-draw-section.ts b/ui/src/toolbox/ngm-draw-section.ts index 512961ff9..a47bd2a84 100644 --- a/ui/src/toolbox/ngm-draw-section.ts +++ b/ui/src/toolbox/ngm-draw-section.ts @@ -24,7 +24,7 @@ export class NgmDrawSection extends LitElementI18n { accessor hidden = true; @state() accessor lineInfo: DrawInfo | undefined; - private readonly draw: CesiumDraw | undefined; + private draw: CesiumDraw | undefined; private drawGeometries = [ {label: () => i18next.t('tbx_add_point_btn_label'), type: 'point', icon: 'ngm-point-draw-icon'}, {label: () => i18next.t('tbx_add_line_btn_label'), type: 'line', icon: 'ngm-line-draw-icon'}, From 316fabb1c94695038457f332e5072d3f437a6414 Mon Sep 17 00:00:00 2001 From: oeni2023 <141681986+oeni2023@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:53:51 +0100 Subject: [PATCH 3/8] sonarCloud connected to sonarLint --- .vscode/settings.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 313e4917a..b899df801 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,8 @@ { "javascript.preferences.quoteStyle": "single", - "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false + "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false, + "sonarlint.connectedMode.project": { + "connectionId": "swisstopo", + "projectKey": "swisstopo_swissgeol-viewer-app" + } } From e128b5a7fb0a75e4508d59c2b6d6cf056bcfde2b Mon Sep 17 00:00:00 2001 From: oeni2023 <141681986+oeni2023@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:14:23 +0100 Subject: [PATCH 4/8] SonarCloud: mark as readonly --- ui/src/cesium-toolbar.ts | 2 +- ui/src/store/draw.ts | 2 +- ui/src/store/main.ts | 4 ++-- ui/src/store/navTools.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/src/cesium-toolbar.ts b/ui/src/cesium-toolbar.ts index 745a99e80..f93a77b87 100644 --- a/ui/src/cesium-toolbar.ts +++ b/ui/src/cesium-toolbar.ts @@ -135,7 +135,7 @@ export class CesiumToolbar extends LitElement { super.updated(changedProperties); } - static styles = css` + static readonly styles = css` :host { position: absolute; background-color: #0000005c; diff --git a/ui/src/store/draw.ts b/ui/src/store/draw.ts index 15facd146..a77a83d9e 100644 --- a/ui/src/store/draw.ts +++ b/ui/src/store/draw.ts @@ -4,7 +4,7 @@ import type {CesiumDraw} from '../draw/CesiumDraw'; export default class DrawStore { private static readonly drawSubject = new BehaviorSubject(undefined); private static readonly drawStateSubject = new BehaviorSubject(false); - static measureState = new BehaviorSubject(false); + static readonly measureState = new BehaviorSubject(false); static setDrawState(value: boolean): void { this.drawStateSubject.next(value); diff --git a/ui/src/store/main.ts b/ui/src/store/main.ts index d49fad30a..a299de6e6 100644 --- a/ui/src/store/main.ts +++ b/ui/src/store/main.ts @@ -13,8 +13,8 @@ export default class MainStore { private static readonly ionTokenSubject = new BehaviorSubject(getIonToken()); private static readonly ionAssetSubject = new Subject(); private static readonly removeIonAssetsSubject = new Subject(); - static setUrlLayersSubject = new Subject(); - static syncLayerParams = new Subject(); + static readonly setUrlLayersSubject = new Subject(); + static readonly syncLayerParams = new Subject(); /** * List of uploaded KML dataSource names. Required to get list of uploaded layers and update properties in batch (e.g. exaggeration) * @private diff --git a/ui/src/store/navTools.ts b/ui/src/store/navTools.ts index 6b0affb5f..af905bf78 100644 --- a/ui/src/store/navTools.ts +++ b/ui/src/store/navTools.ts @@ -8,7 +8,7 @@ export default class NavToolsStore { private static readonly hideTargetPointSubject = new Subject(); private static readonly navLockTypeSubject = new BehaviorSubject(''); private static readonly targetPointPositionSubject = new BehaviorSubject(undefined); - static exaggerationChanged = new Subject(); + static readonly exaggerationChanged = new Subject(); static get syncTargetPoint() { return this.syncTargetPointSubject; From a2b81b6fe09e4b3174e1b42e7962810915db72de Mon Sep 17 00:00:00 2001 From: oeni2023 <141681986+oeni2023@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:48:10 +0100 Subject: [PATCH 5/8] SonarCloud: nullish coalescing --- ui/src/authService.ts | 6 +++--- .../elements/dashboard/ngm-add-member-form.ts | 12 +++++------ .../dashboard/ngm-project-topic-overview.ts | 4 ++-- ui/src/elements/ngm-ion-modal.ts | 4 ++-- ui/src/elements/ngm-side-bar.ts | 8 ++++---- ui/src/layers/helpers.ts | 8 ++++---- ui/src/layers/ngm-layers-item.ts | 2 +- ui/src/ngm-app.ts | 2 +- ui/src/permalink.ts | 4 ++-- ui/src/swisstopoImagery.ts | 12 +++++------ ui/src/toolbox/GeometryController.ts | 20 +++++++++---------- ui/src/toolbox/ngm-geometry-info.ts | 14 ++++++------- ui/src/viewer.ts | 2 +- 13 files changed, 49 insertions(+), 49 deletions(-) diff --git a/ui/src/authService.ts b/ui/src/authService.ts index cea5f1c91..480f4bce7 100644 --- a/ui/src/authService.ts +++ b/ui/src/authService.ts @@ -1,4 +1,4 @@ -import type { + import type { CognitoIdentityCredentialProvider, CognitoIdentityCredentials } from '@aws-sdk/credential-provider-cognito-identity'; @@ -47,11 +47,11 @@ export default class AuthService { if (params.has('access_token') && params.has('id_token') && params.get('token_type') === 'Bearer' && params.get('state') === this.state()) { localStorage.setItem('rawCognitoResponse', response); - const token = params.get('access_token') || ''; + const token = params.get('access_token') ?? ''; const payload = atob(token.split('.')[1]); const claims = JSON.parse(payload); this.setUser(claims); - this.setAccessToken(params.get('id_token') || ''); + this.setAccessToken(params.get('id_token') ?? ''); } } else if (this.getUser()) { // this strange line sets up observable and autologout diff --git a/ui/src/elements/dashboard/ngm-add-member-form.ts b/ui/src/elements/dashboard/ngm-add-member-form.ts index 0e49d80b4..8e589d5fc 100644 --- a/ui/src/elements/dashboard/ngm-add-member-form.ts +++ b/ui/src/elements/dashboard/ngm-add-member-form.ts @@ -36,9 +36,9 @@ export class NgmAddMemberForm extends LitElementI18n { onAdd() { if (!this.name || !this.surname || !isEmail(this.email) || !this.memberRole) { - this.name = this.name || ''; - this.surname = this.surname || ''; - this.email = this.email || ''; + this.name = this.name ?? ''; + this.surname = this.surname ?? ''; + this.email = this.email ?? ''; this.roleNotSelected = !this.memberRole; return; } @@ -63,21 +63,21 @@ export class NgmAddMemberForm extends LitElementI18n { return html`
- { this.name = evt.target.value; }}/> ${i18next.t('project_member_name')}
- { this.surname = evt.target.value; }}/> ${i18next.t('project_member_surname')}
- { this.email = evt.target.value; }}/> diff --git a/ui/src/elements/dashboard/ngm-project-topic-overview.ts b/ui/src/elements/dashboard/ngm-project-topic-overview.ts index 2733fcb7b..4ab1b095f 100644 --- a/ui/src/elements/dashboard/ngm-project-topic-overview.ts +++ b/ui/src/elements/dashboard/ngm-project-topic-overview.ts @@ -51,7 +51,7 @@ export class NgmProjectTopicOverview extends LitElementI18n { if (!this.topicOrProject) return ''; const project = isProject(this.topicOrProject) ? this.topicOrProject : undefined; const ownerEmail = project?.owner?.email; - const owner = ownerEmail || i18next.t('swisstopo'); + const owner = ownerEmail ?? i18next.t('swisstopo'); const date = this.topicOrProject?.modified ? this.topicOrProject?.modified : this.topicOrProject?.created; const backgroundImage = this.topicOrProject.image?.length ? `url('${this.topicOrProject.image}')` : 'none'; const editorEmails = project?.editors?.map(m => m.email) || []; @@ -161,7 +161,7 @@ export class NgmProjectTopicOverview extends LitElementI18n { @click=${() => this.duplicateToProject()}> ${i18next.t('duplicate_to_project')}
- + ${i18next.t('dashboard_share_topic_email')} ${isProject(this.topicOrProject) && this.topicOrProject.owner.email !== this.userEmail ? '' : html` diff --git a/ui/src/elements/ngm-ion-modal.ts b/ui/src/elements/ngm-ion-modal.ts index 82010b377..02fc1c132 100644 --- a/ui/src/elements/ngm-ion-modal.ts +++ b/ui/src/elements/ngm-ion-modal.ts @@ -86,7 +86,7 @@ export class NgmIonModal extends LitElementI18n {
- { this.token = evt.target.value; }}/> @@ -133,4 +133,4 @@ export class NgmIonModal extends LitElementI18n { // no shadow dom return this; } -} \ No newline at end of file +} diff --git a/ui/src/elements/ngm-side-bar.ts b/ui/src/elements/ngm-side-bar.ts index 01daac880..5e80d2e40 100644 --- a/ui/src/elements/ngm-side-bar.ts +++ b/ui/src/elements/ngm-side-bar.ts @@ -378,7 +378,7 @@ export class SideBar extends LitElementI18n { } layer.visible = urlLayer.visible; layer.opacity = urlLayer.opacity; - layer.wmtsCurrentTime = urlLayer.timestamp || layer.wmtsCurrentTime; + layer.wmtsCurrentTime = urlLayer.timestamp ?? layer.wmtsCurrentTime; layer.setOpacity && layer.setOpacity(layer.opacity); layer.displayed = true; layer.setVisibility && layer.setVisibility(layer.visible); @@ -395,7 +395,7 @@ export class SideBar extends LitElementI18n { type: LayerType.tiles3d, assetId: Number(assetId), ionToken: ionToken, - label: ionAsset?.name || assetId, + label: ionAsset?.name ?? assetId, layer: assetId, visible: true, displayed: true, @@ -607,12 +607,12 @@ export class SideBar extends LitElementI18n { config = searchLayer; config.visible = true; config.origin = 'layer'; - config.label = searchLayer.title || searchLayer.label; + config.label = searchLayer.title ?? searchLayer.label; config.legend = config.type === LayerType.swisstopoWMTS ? config.layer : undefined; } else { config = { type: LayerType.swisstopoWMTS, - label: searchLayer.title || searchLayer.label, + label: searchLayer.title ?? searchLayer.label, layer: searchLayer.layer, visible: true, displayed: true, diff --git a/ui/src/layers/helpers.ts b/ui/src/layers/helpers.ts index acc99b648..79e900629 100644 --- a/ui/src/layers/helpers.ts +++ b/ui/src/layers/helpers.ts @@ -61,13 +61,13 @@ export async function create3DVoxelsTilesetFromConfig(viewer: Viewer, config: La }); const searchParams = new URLSearchParams(location.search); - const stepSize = parseFloat(searchParams.get('stepSize') || '1'); + const stepSize = parseFloat(searchParams.get('stepSize') ?? '1'); primitive.nearestSampling = true; primitive.stepSize = stepSize; primitive.depthTest = true; primitive.show = !!config.visible; - primitive.pickable = config.pickable !== undefined ? config.pickable : false; + primitive.pickable = config.pickable ?? false; primitive.layer = config.layer; viewer.scene.primitives.add(primitive); @@ -114,7 +114,7 @@ export async function create3DTilesetFromConfig(viewer: Viewer, config: LayerCon tileset.style = new Cesium3DTileStyle(config.style); } - tileset.pickable = config.pickable !== undefined ? config.pickable : false; + tileset.pickable = config.pickable ?? false; viewer.scene.primitives.add(tileset); config.setVisibility = visible => { @@ -180,7 +180,7 @@ export async function createSwisstopoWMTSImageryLayer(viewer: Viewer, config: La }, 100); }; viewer.scene.imageryLayers.add(layer); - layer.alpha = config.opacity || 1; + layer.alpha = config.opacity ?? 1; layer.show = !!config.visible; return layer; } diff --git a/ui/src/layers/ngm-layers-item.ts b/ui/src/layers/ngm-layers-item.ts index 9bed758b3..82bf63770 100644 --- a/ui/src/layers/ngm-layers-item.ts +++ b/ui/src/layers/ngm-layers-item.ts @@ -240,7 +240,7 @@ export class NgmLayersItem extends LitElementI18n { this.changeOrderActive && e.preventDefault()}>
diff --git a/ui/src/ngm-app.ts b/ui/src/ngm-app.ts index 1ad9e76bb..ceb696737 100644 --- a/ui/src/ngm-app.ts +++ b/ui/src/ngm-app.ts @@ -228,7 +228,7 @@ export class NgmApp extends LitElementI18n { // Temporarily increasing the maximum screen space error to load low LOD tiles. const searchParams = new URLSearchParams(document.location.search); - globe.maximumScreenSpaceError = parseFloat(searchParams.get('initialScreenSpaceError') || '2000'); + globe.maximumScreenSpaceError = parseFloat(searchParams.get('initialScreenSpaceError') ?? '2000'); let currentStep = 1; const unlisten = globe.tileLoadProgressEvent.addEventListener(queueLength => { diff --git a/ui/src/permalink.ts b/ui/src/permalink.ts index daacf2717..4a6c7a3ff 100644 --- a/ui/src/permalink.ts +++ b/ui/src/permalink.ts @@ -143,7 +143,7 @@ export function syncLayersParam(activeLayers: LayerConfig[]) { const transparency = !l.opacity || isNaN(l.opacity) ? 0 : (1 - l.opacity); layersTransparency.push(transparency.toFixed(2)); layersVisibility.push(!!l.visible); - layersTimestamps.push(l.wmtsCurrentTime || ''); + layersTimestamps.push(l.wmtsCurrentTime ?? ''); } }); @@ -329,7 +329,7 @@ export function getPermalink() { export function getExaggeration() { const params = getURLSearchParams(); - let zExaggeration = parseFloat(params.get(EXAGGERATION_PARAM) || '1'); + let zExaggeration = parseFloat(params.get(EXAGGERATION_PARAM) ?? '1'); if (zExaggeration < 1) zExaggeration = 1; if (zExaggeration > 20) zExaggeration = 20; return zExaggeration; diff --git a/ui/src/swisstopoImagery.ts b/ui/src/swisstopoImagery.ts index 0ba82836f..8d9663c7f 100644 --- a/ui/src/swisstopoImagery.ts +++ b/ui/src/swisstopoImagery.ts @@ -53,7 +53,7 @@ export function getSwisstopoImagery( .replace('{format}', swisstopoConfig.format); imageryProvider = new UrlTemplateImageryProvider({ url: url, - maximumLevel: localConfig.maximumLevel || swisstopoConfig.maximumLevel, + maximumLevel: localConfig.maximumLevel ?? swisstopoConfig.maximumLevel, rectangle: SWITZERLAND_RECTANGLE, credit: new Credit(swisstopoConfig.attribution), customTags: { @@ -84,7 +84,7 @@ export function getSwisstopoImagery( return; } const imageryLayer = new ImageryLayer(imageryProvider, { - alpha: localConfig.opacity !== undefined ? localConfig.opacity : 1 + alpha: localConfig.opacity ?? 1 }); resolve(imageryLayer); } else { @@ -137,7 +137,7 @@ async function parseWMTSCapabilities(wmtsCapabilities: Document): Promise { if (!layerConfigs) { const params = getURLSearchParams(); - const lang = params.get('lang') || 'en'; + const lang = params.get('lang') ?? 'en'; const wmsConfig = await fetchWMSCapabilities(lang); const wmtsConfig = await fetchWMTSCapabilities(lang); layerConfigs = {...wmsConfig, ...wmtsConfig}; diff --git a/ui/src/toolbox/GeometryController.ts b/ui/src/toolbox/GeometryController.ts index fcecadc13..dd289442d 100644 --- a/ui/src/toolbox/GeometryController.ts +++ b/ui/src/toolbox/GeometryController.ts @@ -457,8 +457,8 @@ export class GeometryController { const type = attributes.type; const name = type.charAt(0).toUpperCase() + type.slice(1); const entityAttrs: Entity.ConstructorOptions = { - id: attributes.id || undefined, - name: attributes.name || `${name} ${this.geometriesCounter[type]}`, + id: attributes.id ?? undefined, + name: attributes.name ?? `${name} ${this.geometriesCounter[type]}`, show: attributes.show, properties: { area: attributes.area, @@ -468,11 +468,11 @@ export class GeometryController { type: type, volumeShowed: !!attributes.volumeShowed, volumeHeightLimits: attributes.volumeHeightLimits || null, - description: attributes.description || '', - image: attributes.image || '', - website: attributes.website || '', - editable: attributes.editable === undefined ? true : attributes.editable, - copyable: attributes.copyable === undefined ? true : attributes.copyable, + description: attributes.description ?? '', + image: attributes.image ?? '', + website: attributes.website ?? '', + editable: attributes.editable ?? attributes.editable, + copyable: attributes.copyable ?? attributes.copyable, } }; const color = attributes.color; @@ -484,7 +484,7 @@ export class GeometryController { entityAttrs.position = Cartographic.toCartesian(cartPosition); } entityAttrs.billboard = { - image: attributes.pointSymbol || `./images/${POINT_SYMBOLS[0]}`, + image: attributes.pointSymbol ?? `./images/${POINT_SYMBOLS[0]}`, color: color ? new Color(color.red, color.green, color.blue) : DEFAULT_AOI_COLOR, scale: 0.5, verticalOrigin: VerticalOrigin.BOTTOM, @@ -492,9 +492,9 @@ export class GeometryController { heightReference: HeightReference.RELATIVE_TO_GROUND }; entityAttrs.properties!.swissforagesId = attributes.swissforagesId; - attributes.depth = attributes.depth || 400; + attributes.depth = attributes.depth ?? 400; entityAttrs.properties!.depth = attributes.depth; - attributes.diameter = attributes.diameter || 40; + attributes.diameter = attributes.diameter ?? 40; entityAttrs.properties!.diameter = attributes.diameter; const height = Cartographic.fromCartesian(entityAttrs.position).height; entityAttrs.ellipse = { diff --git a/ui/src/toolbox/ngm-geometry-info.ts b/ui/src/toolbox/ngm-geometry-info.ts index b7ba3d750..37098d35b 100644 --- a/ui/src/toolbox/ngm-geometry-info.ts +++ b/ui/src/toolbox/ngm-geometry-info.ts @@ -142,7 +142,7 @@ export class NgmGeometryInfo extends LitElementI18n {
${i18next.t('obj_info_description_label')}
-
${geom.description || ''}
+
${geom.description ?? ''}
${i18next.t('obj_info_image_label')}
@@ -157,7 +157,7 @@ export class NgmGeometryInfo extends LitElementI18n {
${i18next.t('tbx_volume_lower_limit_label')}
-
${geom.volumeHeightLimits?.lowerLimit.toFixed(1) || '-'} m
+
${geom.volumeHeightLimits?.lowerLimit.toFixed(1) ?? '-'} m
${i18next.t('tbx_volume_height_label')}
@@ -165,28 +165,28 @@ export class NgmGeometryInfo extends LitElementI18n {
${i18next.t('tbx_point_depth_label')}
-
${geom.depth?.toFixed(1) || '-'} m
+
${geom.depth?.toFixed(1) ?? '-'} m
${i18next.t('tbx_point_diameter_label')}
-
${geom.diameter?.toFixed(1) || '-'} m
+
${geom.diameter?.toFixed(1) ?? '-'} m
${i18next.t('obj_info_area_label')}
-
${geom.area || '-'} km²
+
${geom.area ?? '-'} km²
${geom.type === 'line' ? i18next.t('obj_info_length_label') : i18next.t('obj_info_perimeter_label')}
-
${geom.perimeter || '-'} km
+
${geom.perimeter ?? '-'} km
${i18next.t('obj_info_number_segments_label')}
-
${geom.numberOfSegments || ''}
+
${geom.numberOfSegments ?? ''}
${geom.pointSymbol ? diff --git a/ui/src/viewer.ts b/ui/src/viewer.ts index 140f7c65c..90f2c2a1b 100644 --- a/ui/src/viewer.ts +++ b/ui/src/viewer.ts @@ -179,7 +179,7 @@ export async function setupViewer(container: Element, rethrowRenderErrors: boole // Position the sun the that shadows look nice let sunDate = new Date('2018-06-21T10:00:00.000Z'); if (searchParams.has('date')) { - const betterDate = new Date(searchParams.get('date') || ''); + const betterDate = new Date(searchParams.get('date') ?? ''); if (Number.isNaN(betterDate.getDate())) { console.error(`Provided date is wrong: ${searchParams.get('date')}`); } else { From c2d6e234c37faea53b34ec6815697fb84a4fb0e8 Mon Sep 17 00:00:00 2001 From: oeni2023 <141681986+oeni2023@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:48:43 +0100 Subject: [PATCH 6/8] SonarCloud: Modify tsconfig for nullish coalescing --- ui/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/tsconfig.json b/ui/tsconfig.json index efa71687d..957b1dd39 100644 --- a/ui/tsconfig.json +++ b/ui/tsconfig.json @@ -7,6 +7,7 @@ "outDir": "./types", "rootDir": "./src", "strict": true, + "strictNullChecks": true, "skipLibCheck": true, "noUnusedLocals": true, "noUnusedParameters": true, From 6670268a68c88b7fc098fc4010f014532cbb6011 Mon Sep 17 00:00:00 2001 From: oeni2023 <141681986+oeni2023@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:49:01 +0100 Subject: [PATCH 7/8] settings.json modified --- .vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b899df801..a63d968c2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,6 @@ "sonarlint.connectedMode.project": { "connectionId": "swisstopo", "projectKey": "swisstopo_swissgeol-viewer-app" - } + }, + "makefile.configureOnOpen": false } From 618d58ab194941926dab4d041772d8038474b48b Mon Sep 17 00:00:00 2001 From: till_schuetze Date: Wed, 4 Dec 2024 07:55:46 +0100 Subject: [PATCH 8/8] Fix sonar cloud issues --- ui/src/query/objectInformation.ts | 165 ++++++++++--------- ui/src/toolbox/ngm-geometries-simple-list.ts | 22 +-- 2 files changed, 96 insertions(+), 91 deletions(-) diff --git a/ui/src/query/objectInformation.ts b/ui/src/query/objectInformation.ts index 61ec17c2e..c5cfc4102 100644 --- a/ui/src/query/objectInformation.ts +++ b/ui/src/query/objectInformation.ts @@ -1,81 +1,84 @@ -import {JulianDate, VoxelCell} from 'cesium'; -import {PickableVoxelPrimitive} from '../layers/helpers'; -import {getValueOrUndefined} from '../cesiumutils'; -import i18next from 'i18next'; -import {formatCartesian3AsLv95} from '../projection'; -import {voxelLayerToFilter} from '../layertree'; - -export function extractPrimitiveAttributes(primitive): [string, number][] { - const data: [string, number][] = []; - let propertyNames: string[] = primitive.getPropertyIds(); - const length = propertyNames.length; - const properties = primitive.tileset.properties; - const propsOrder = properties && properties.propsOrder ? properties.propsOrder : []; - propertyNames = sortPropertyNames(propertyNames, propsOrder); - for (let i = 0; i < length; ++i) { - const key = propertyNames[i]; - const value = primitive.getProperty(key); - if (typeof value === 'number' || !!value) { - data.push([key, value]); - } - } - return data; -} - -export function extractVoxelAttributes(voxelCell: VoxelCell): [string, number | string][] { - const cellCenter = voxelCell.orientedBoundingBox.center; - const propertyNames: string[] = voxelCell.getNames(); - const primitive: PickableVoxelPrimitive = voxelCell.primitive; - const layer = primitive.layer; - const attributes: [string, number][] = propertyNames.map(name => { - const value = voxelCell.getProperty(name); - if (layer && voxelLayerToFilter[layer]) { - const filters = voxelLayerToFilter[layer]; - if (name === filters.lithologyDataName) { - const label = filters.lithology.find(f => f.index === value[0])?.label; - return [ - i18next.t('vox_filter_lithology'), - label ? i18next.t(label) : i18next.t('vox_filter_undefined_lithology') - ]; - } - if (name === filters.conductivityDataName) { - const valueOrUndefined = value[0] <= -9999 ? i18next.t('vox_filter_undefined_lithology') : value; - return [i18next.t('vox_filter_hydraulic_conductivity'), valueOrUndefined]; - } - } - if (name === 'Temp_C') { - return [i18next.t('vox_temperature'), value]; - } - return [name, value]; - }); - return [...attributes, [i18next.t('vox_cell_center'), formatCartesian3AsLv95(cellCenter).join(', ')]]; -} - -export function isPickable(object) { - if (object.tileset) { - return object.tileset.pickable; - } else if (!(object instanceof VoxelCell) && object.primitive && object.primitive.allowPicking !== undefined) { - return object.primitive.allowPicking; - } else if (object instanceof VoxelCell) { - const voxelPrimitive: PickableVoxelPrimitive = object.primitive; - return voxelPrimitive && voxelPrimitive.pickable; - } else { - return object.id && getValueOrUndefined(object.id?.properties?.type) === 'point'; - } -} - -export function extractEntitiesAttributes(entity) { - if (!entity.properties) return; - return {id: entity.id, ...entity.properties.getValue(JulianDate.fromDate(new Date()))}; -} - -export function sortPropertyNames(propertyNames: string[], propertiesOrder: string[] = []): string[] { - const lowerPriorityProps = propertyNames - .filter(prop => !propertiesOrder.includes(prop)) - .sort((left, right) => { - const titleLeft = left.toLowerCase(); - const titleRight = right.toLowerCase(); - return titleLeft > titleRight ? 1 : titleLeft < titleRight ? -1 : 0; - }); - return [...propertiesOrder, ...lowerPriorityProps]; -} +import {JulianDate, VoxelCell} from 'cesium'; +import {PickableVoxelPrimitive} from '../layers/helpers'; +import {getValueOrUndefined} from '../cesiumutils'; +import i18next from 'i18next'; +import {formatCartesian3AsLv95} from '../projection'; +import {voxelLayerToFilter} from '../layertree'; + +export function extractPrimitiveAttributes(primitive): [string, number][] { + const data: [string, number][] = []; + let propertyNames: string[] = primitive.getPropertyIds(); + const length = propertyNames.length; + const properties = primitive.tileset.properties; + const propsOrder = properties && properties.propsOrder ? properties.propsOrder : []; + propertyNames = sortPropertyNames(propertyNames, propsOrder); + for (let i = 0; i < length; ++i) { + const key = propertyNames[i]; + const value = primitive.getProperty(key); + if (typeof value === 'number' || !!value) { + data.push([key, value]); + } + } + return data; +} + +export function extractVoxelAttributes(voxelCell: VoxelCell): [string, number | string][] { + const cellCenter = voxelCell.orientedBoundingBox.center; + const propertyNames: string[] = voxelCell.getNames(); + const primitive: PickableVoxelPrimitive = voxelCell.primitive; + const layer = primitive.layer; + const attributes: [string, number][] = propertyNames.map(name => { + const value = voxelCell.getProperty(name); + if (layer && voxelLayerToFilter[layer]) { + const filters = voxelLayerToFilter[layer]; + if (name === filters.lithologyDataName) { + const label = filters.lithology.find(f => f.index === value[0])?.label; + return [ + i18next.t('vox_filter_lithology'), + label ? i18next.t(label) : i18next.t('vox_filter_undefined_lithology') + ]; + } + if (name === filters.conductivityDataName) { + const valueOrUndefined = value[0] <= -9999 ? i18next.t('vox_filter_undefined_lithology') : value; + return [i18next.t('vox_filter_hydraulic_conductivity'), valueOrUndefined]; + } + } + if (name === 'Temp_C') { + return [i18next.t('vox_temperature'), value]; + } + return [name, value]; + }); + return [...attributes, [i18next.t('vox_cell_center'), formatCartesian3AsLv95(cellCenter).join(', ')]]; +} + +export function isPickable(object) { + if (object.tileset) { + return object.tileset.pickable; + } else if (!(object instanceof VoxelCell) && object.primitive && object.primitive.allowPicking !== undefined) { + return object.primitive.allowPicking; + } else if (object instanceof VoxelCell) { + const voxelPrimitive: PickableVoxelPrimitive = object.primitive; + return voxelPrimitive && voxelPrimitive.pickable; + } else { + return object.id && getValueOrUndefined(object.id?.properties?.type) === 'point'; + } +} + +export function extractEntitiesAttributes(entity) { + if (!entity.properties) return; + return {id: entity.id, ...entity.properties.getValue(JulianDate.fromDate(new Date()))}; +} + +export function sortPropertyNames(propertyNames: string[], propertiesOrder: string[] = []): string[] { + const lowerPriorityProps = propertyNames + .filter(prop => !propertiesOrder.includes(prop)) + .sort((left, right) => { + const titleLeft = left.toLowerCase(); + const titleRight = right.toLowerCase(); + if (titleLeft === titleRight) { + return 0; + } + return titleLeft > titleRight ? 1 : -1; + }); + return [...propertiesOrder, ...lowerPriorityProps]; +} diff --git a/ui/src/toolbox/ngm-geometries-simple-list.ts b/ui/src/toolbox/ngm-geometries-simple-list.ts index 73563a3be..24b14a714 100644 --- a/ui/src/toolbox/ngm-geometries-simple-list.ts +++ b/ui/src/toolbox/ngm-geometries-simple-list.ts @@ -74,6 +74,16 @@ export default class NgmGeometriesSimpleList extends LitElementI18n { actionMenuTemplate(geom: NgmGeometry) { if (this.viewMode) return ''; + const editButton = this.noEditMode ? '' : html` +
ToolboxStore.setOpenedGeometryOptions({id: geom.id!, editing: true})}> + ${i18next.t('tbx_edit_btn')} +
`; + const copyButton = this.noEditMode ? '' : html` +
ToolboxStore.nextGeometryAction({id: geom.id!, action: 'copy'})}> + ${i18next.t('tbx_copy_btn')} +
`; return html` - ${this.noEditMode ? '' : html` -
ToolboxStore.setOpenedGeometryOptions({id: geom.id!, editing: true})}> - ${i18next.t('tbx_edit_btn')} -
`} + ${editButton} `} - ${this.noEditMode ? '' : html` -
ToolboxStore.nextGeometryAction({id: geom.id!, action: 'copy'})}> - ${i18next.t('tbx_copy_btn')} -
`} + ${copyButton} ${(geom.type === 'line') ? html`
ToolboxStore.nextGeometryAction({id: geom.id!, action: 'profile'})}>