Skip to content

Commit

Permalink
Fix sonar cloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TIL-EBP committed Dec 4, 2024
1 parent 6670268 commit 618d58a
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 91 deletions.
165 changes: 84 additions & 81 deletions ui/src/query/objectInformation.ts
Original file line number Diff line number Diff line change
@@ -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];
}
22 changes: 12 additions & 10 deletions ui/src/toolbox/ngm-geometries-simple-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ export default class NgmGeometriesSimpleList extends LitElementI18n {

actionMenuTemplate(geom: NgmGeometry) {
if (this.viewMode) return '';
const editButton = this.noEditMode ? '' : html`
<div class="item ${classMap({'disabled': !geom.editable})}"
@click=${() => ToolboxStore.setOpenedGeometryOptions({id: geom.id!, editing: true})}>
${i18next.t('tbx_edit_btn')}
</div>`;
const copyButton = this.noEditMode ? '' : html`
<div class="item ${classMap({'disabled': !geom.copyable})}"
@click=${() => ToolboxStore.nextGeometryAction({id: geom.id!, action: 'copy'})}>
${i18next.t('tbx_copy_btn')}
</div>`;
return html`
<div class="menu">
${this.hideMapInteractionButtons ? '' : html`
Expand All @@ -85,17 +95,9 @@ export default class NgmGeometriesSimpleList extends LitElementI18n {
@click=${() => ToolboxStore.setOpenedGeometryOptions({id: geom.id!})}>
${i18next.t('tbx_info_btn')}
</div>
${this.noEditMode ? '' : html`
<div class="item ${classMap({'disabled': !geom.editable})}"
@click=${() => ToolboxStore.setOpenedGeometryOptions({id: geom.id!, editing: true})}>
${i18next.t('tbx_edit_btn')}
</div>`}
${editButton}
`}
${this.noEditMode ? '' : html`
<div class="item ${classMap({'disabled': !geom.copyable})}"
@click=${() => ToolboxStore.nextGeometryAction({id: geom.id!, action: 'copy'})}>
${i18next.t('tbx_copy_btn')}
</div>`}
${copyButton}
${(geom.type === 'line') ? html`
<div class="item"
@click=${() => ToolboxStore.nextGeometryAction({id: geom.id!, action: 'profile'})}>
Expand Down

0 comments on commit 618d58a

Please sign in to comment.