Skip to content
Snippets Groups Projects
Commit c9166174 authored by Dimitri DI GUSTO's avatar Dimitri DI GUSTO
Browse files

Round float to 2 decimal on dataset details

parent f5b2448d
No related branches found
No related tags found
1 merge request!159Sollicit 10 02 2022
...@@ -41,10 +41,10 @@ ...@@ -41,10 +41,10 @@
</div> </div>
<!-- Display the value. If it is url, display a link --> <!-- Display the value. If it is url, display a link -->
<div *ngSwitchDefault class="property-value"> <div *ngSwitchDefault class="property-value">
<span <span *ngIf="isFloat(properties[key]) && !isUrl(properties[key])">{{ roundTo(properties[key], 2) }}</span>
*ngIf="!isUrl(properties[key])">{{ (properties[key] && properties[key] !== '') ? properties[key] : '-' }}</span> <span *ngIf="!isFloat(properties[key]) && !isUrl(properties[key])">{{ (properties[key] && properties[key] !== '') ? properties[key] : '-' }}</span>
<a [href]="properties[key]" target="_blank" *ngIf="isUrl(properties[key])">{{ properties[key] }}</a> <a [href]="properties[key]" target="_blank" *ngIf="isUrl(properties[key])">{{ properties[key] }}</a>
</div> </div>
</ng-container> </ng-container>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -94,4 +94,13 @@ export class DatasetDataDetailPropertiesComponent implements OnInit { ...@@ -94,4 +94,13 @@ export class DatasetDataDetailPropertiesComponent implements OnInit {
const isStringAndNotNull = value ? typeof value === 'string' : false; const isStringAndNotNull = value ? typeof value === 'string' : false;
return isStringAndNotNull ? value.match(regex) : false; return isStringAndNotNull ? value.match(regex) : false;
} }
isFloat(n: any) {
return Number(n) === n && n % 1 !== 0;
}
roundTo(num: number, places: number) {
const factor = 10 ** places;
return Math.round(num * factor) / factor;
}
} }
...@@ -20,12 +20,9 @@ ...@@ -20,12 +20,9 @@
*ngFor="let key of displayedProperties; let indexRow=index;" (click)="emitSelectedData(element)" [attr.role]="'cell'"> *ngFor="let key of displayedProperties; let indexRow=index;" (click)="emitSelectedData(element)" [attr.role]="'cell'">
<ng-container *ngIf="!isPropertyComplex(element,key)"> <ng-container *ngIf="!isPropertyComplex(element,key)">
<span *ngIf="!isUrl(element.properties[key]); else urlPropTemplate" <span *ngIf="isFloat(element.properties[key]) && !isUrl(element.properties[key])" class="data-property-value">{{ roundTo(element.properties[key], 2) }}</span>
class="data-property-value">{{ element.properties[key] }}</span> <span *ngIf="!isFloat(element.properties[key]) && !isUrl(element.properties[key])" class="data-property-value">{{ element.properties[key] }}</span>
<ng-template #urlPropTemplate> <a *ngIf="isUrl(element.properties[key])" [href]="element.properties[key]" target="_blank" class="data-property-value">{{ element.properties[key] }}</a>
<a class="data-property-value" target="_blank"
[href]="element.properties[key]">{{ element.properties[key] }}</a>
</ng-template>
</ng-container> </ng-container>
<span *ngIf="isPropertyComplex(element,key)"> <span *ngIf="isPropertyComplex(element,key)">
<span i18n-data-tooltip="@@dataset.data.tooltip" <span i18n-data-tooltip="@@dataset.data.tooltip"
......
...@@ -166,4 +166,13 @@ export class DatasetTableComponent implements OnInit, OnDestroy { ...@@ -166,4 +166,13 @@ export class DatasetTableComponent implements OnInit, OnDestroy {
// Make there are no duplicates in the array // Make there are no duplicates in the array
this.visitedFeatures = [...new Set(this.visitedFeatures)] this.visitedFeatures = [...new Set(this.visitedFeatures)]
} }
isFloat(n: any) {
return Number(n) === n && n % 1 !== 0;
}
roundTo(num: number, places: number) {
const factor = 10 ** places;
return Math.round(num * factor) / factor;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment