Skip to content

Commit 27230cd

Browse files
committed
feat: format metadata floats with significant digits
1 parent 154f6c2 commit 27230cd

17 files changed

+377
-66
lines changed

src/app/app-config.service.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ const appConfig: AppConfigInterface = {
5050
thumbnailFetchLimitPerPage: 500,
5151
maxFileUploadSizeInMb: "16mb",
5252
maxDirectDownloadSize: 5000000000,
53+
metadataFloatFormatEnabled: true,
54+
metadataFloatFormat: {
55+
significantDigits: 3,
56+
minCutoff: 0.001,
57+
maxCutoff: 1000,
58+
},
5359
metadataPreviewEnabled: true,
5460
metadataStructure: "",
5561
multipleDownloadAction: "http://localhost:3012/zip",

src/app/app-config.service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export class MainMenuConfiguration {
6464
authenticatedUser: MainMenuOptions;
6565
}
6666

67+
export class MetadataFloatFormat {
68+
significantDigits: number;
69+
minCutoff: number; // using scientific notation below this cutoff
70+
maxCutoff: number; // using scientific notation above this cutoff
71+
}
72+
6773
export interface AppConfigInterface {
6874
skipSciCatLoginPageEnabled?: boolean;
6975
accessTokenPrefix: string;
@@ -102,6 +108,8 @@ export interface AppConfigInterface {
102108
maxDirectDownloadSize: number | null;
103109
metadataPreviewEnabled: boolean;
104110
metadataStructure: string;
111+
metadataFloatFormat?: MetadataFloatFormat;
112+
metadataFloatFormatEnabled?: boolean;
105113
multipleDownloadAction: string | null;
106114
multipleDownloadEnabled: boolean;
107115
multipleDownloadUseAuthToken: boolean;
@@ -232,6 +240,14 @@ export class AppConfigService {
232240
config.dateFormat = "yyyy-MM-dd HH:mm";
233241
}
234242

243+
if (!config.metadataFloatFormat) {
244+
config.metadataFloatFormat = {
245+
significantDigits: 3,
246+
minCutoff: 0.001,
247+
maxCutoff: 1000,
248+
};
249+
}
250+
235251
this.appConfig = config;
236252
}
237253

src/app/datasets/dataset-table/dataset-table.component.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { FileSizePipe } from "shared/pipes/filesize.pipe";
6363
import { actionMenu } from "shared/modules/dynamic-material-table/utilizes/default-table-settings";
6464
import { TableConfigService } from "shared/services/table-config.service";
6565
import { selectInstruments } from "state-management/selectors/instruments.selectors";
66+
import { FormatNumberPipe } from "shared/pipes/format-number.pipe";
6667

6768
export interface SortChangeEvent {
6869
active: string;
@@ -155,6 +156,7 @@ export class DatasetTableComponent implements OnInit, OnDestroy {
155156
private datePipe: DatePipe,
156157
private fileSize: FileSizePipe,
157158
private tableConfigService: TableConfigService,
159+
private formatNumberPipe: FormatNumberPipe,
158160
) {}
159161

160162
private getInstrumentName(row: OutputDatasetObsoleteDto): string {
@@ -480,6 +482,19 @@ export class DatasetTableComponent implements OnInit, OnDestroy {
480482
this.getInstrumentName(row);
481483
}
482484

485+
if (column.name.startsWith("scientificMetadata.")) {
486+
convertedColumn.customRender = (col, row) => {
487+
return String(
488+
this.formatNumberPipe.transform(lodashGet(row, col.name)),
489+
);
490+
};
491+
convertedColumn.toExport = (row) => {
492+
return String(
493+
this.formatNumberPipe.transform(lodashGet(row, column.name)),
494+
);
495+
};
496+
}
497+
483498
return convertedColumn;
484499
});
485500
}

src/app/shared/modules/scientific-metadata-tree/base-classes/metadata-input-base.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { MetadataInputComponent } from "../metadata-input/metadata-input.compone
66
import { FormatNumberPipe } from "shared/pipes/format-number.pipe";
77
import { ScientificMetadataTreeModule } from "../scientific-metadata-tree.module";
88
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
9+
import { AppConfigService } from "app-config.service";
10+
import { provideHttpClient } from "@angular/common/http";
911

1012
describe("MetadataInputBase", () => {
1113
let component: MetadataInputComponent;
@@ -15,11 +17,25 @@ describe("MetadataInputBase", () => {
1517
TestBed.configureTestingModule({
1618
declarations: [MetadataInputComponent],
1719
imports: [ScientificMetadataTreeModule, BrowserAnimationsModule],
18-
providers: [FormBuilder, FormatNumberPipe],
20+
providers: [
21+
FormBuilder,
22+
FormatNumberPipe,
23+
AppConfigService,
24+
provideHttpClient(),
25+
],
1926
}).compileComponents();
2027
}));
2128

2229
beforeEach(() => {
30+
const appConfigService = TestBed.inject(AppConfigService);
31+
(appConfigService as any).appConfig = {
32+
metadataFloatFormatEnabled: true,
33+
metadataFloatFormat: {
34+
significantDigits: 3,
35+
minCutoff: 0.001,
36+
maxCutoff: 1000,
37+
},
38+
};
2339
fixture = TestBed.createComponent(MetadataInputComponent);
2440
component = fixture.componentInstance;
2541
const data = new FlatNodeEdit();

src/app/shared/modules/scientific-metadata-tree/base-classes/tree-base.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { FlatNode, TreeNode } from "../base-classes/tree-base";
77
import { TreeEditComponent } from "../tree-edit/tree-edit.component";
88
import { ScientificMetadataTreeModule } from "../scientific-metadata-tree.module";
99
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
10+
import { AppConfigService } from "app-config.service";
11+
import { provideHttpClient } from "@angular/common/http";
1012

1113
describe("TreeBaseComponent", () => {
1214
let component: TreeEditComponent;
@@ -16,11 +18,26 @@ describe("TreeBaseComponent", () => {
1618
TestBed.configureTestingModule({
1719
declarations: [TreeEditComponent],
1820
imports: [ScientificMetadataTreeModule, BrowserAnimationsModule],
19-
providers: [MatDialog, MatSnackBar, DatePipe],
21+
providers: [
22+
MatDialog,
23+
MatSnackBar,
24+
DatePipe,
25+
AppConfigService,
26+
provideHttpClient(),
27+
],
2028
}).compileComponents();
2129
}));
2230

2331
beforeEach(() => {
32+
const appConfigService = TestBed.inject(AppConfigService);
33+
(appConfigService as any).appConfig = {
34+
metadataFloatFormatEnabled: true,
35+
metadataFloatFormat: {
36+
significantDigits: 3,
37+
minCutoff: 0.001,
38+
maxCutoff: 1000,
39+
},
40+
};
2441
fixture = TestBed.createComponent(TreeEditComponent);
2542
component = fixture.componentInstance;
2643
component.metadata = {

src/app/shared/modules/scientific-metadata-tree/base-classes/tree-base.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { FormatNumberPipe } from "shared/pipes/format-number.pipe";
99
import { PrettyUnitPipe } from "shared/pipes/pretty-unit.pipe";
1010
import { DateTimeService } from "shared/services/date-time.service";
1111
import { UnitsService } from "shared/services/units.service";
12+
import { AppConfigService } from "app-config.service";
1213

1314
export class TreeNode {
1415
children: TreeNode[];
@@ -43,10 +44,10 @@ export class TreeBaseComponent {
4344
prettyUnitPipe: PrettyUnitPipe;
4445
unitsService: UnitsService;
4546
dateTimeService: DateTimeService;
46-
constructor() {
47+
constructor(protected configService: AppConfigService) {
4748
this.unitsService = new UnitsService();
4849
this.prettyUnitPipe = new PrettyUnitPipe(this.unitsService);
49-
this.formatNumberPipe = new FormatNumberPipe();
50+
this.formatNumberPipe = new FormatNumberPipe(this.configService);
5051
this.dateTimeService = new DateTimeService();
5152
}
5253
buildDataTree(obj: { [key: string]: any }, level: number): TreeNode[] {

src/app/shared/modules/scientific-metadata-tree/metadata-input/metadata-input.component.spec.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { ScientificMetadataTreeModule } from "../scientific-metadata-tree.module
99
import { MetadataInputComponent } from "./metadata-input.component";
1010

1111
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
12+
import { AppConfigService } from "app-config.service";
13+
import { provideHttpClient } from "@angular/common/http";
1214

1315
describe("MetadataInputComponent", () => {
1416
let component: MetadataInputComponent;
@@ -18,11 +20,25 @@ describe("MetadataInputComponent", () => {
1820
TestBed.configureTestingModule({
1921
declarations: [MetadataInputComponent],
2022
imports: [ScientificMetadataTreeModule, BrowserAnimationsModule],
21-
providers: [FormBuilder, FormatNumberPipe],
23+
providers: [
24+
FormBuilder,
25+
FormatNumberPipe,
26+
AppConfigService,
27+
provideHttpClient(),
28+
],
2229
}).compileComponents();
2330
}));
2431

2532
beforeEach(() => {
33+
const appConfigService = TestBed.inject(AppConfigService);
34+
(appConfigService as any).appConfig = {
35+
metadataFloatFormatEnabled: true,
36+
metadataFloatFormat: {
37+
significantDigits: 3,
38+
minCutoff: 0.001,
39+
maxCutoff: 1000,
40+
},
41+
};
2642
fixture = TestBed.createComponent(MetadataInputComponent);
2743
component = fixture.componentInstance;
2844
const data = new FlatNodeEdit();
@@ -76,7 +92,7 @@ describe("MetadataInputComponent", () => {
7692
component.addCurrentMetadata(component.data);
7793
expect(component.metadataForm.get("type").value).toEqual("quantity");
7894
expect(component.metadataForm.get("key").value).toEqual("energy");
79-
expect(component.metadataForm.get("value").value).toEqual(3);
95+
expect(component.metadataForm.get("value").value).toEqual("3");
8096
expect(component.metadataForm.get("unit").value).toEqual("joule");
8197
});
8298
it("should set values in form control (number)", () => {

src/app/shared/modules/scientific-metadata-tree/tree-edit/tree-edit.component.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { ScientificMetadataTreeModule } from "../scientific-metadata-tree.module
1010

1111
import { FlatNodeEdit, TreeEditComponent } from "./tree-edit.component";
1212
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
13+
import { AppConfigService } from "app-config.service";
14+
import { provideHttpClient } from "@angular/common/http";
1315

1416
describe("TreeEditComponent", () => {
1517
let component: TreeEditComponent;
@@ -19,11 +21,26 @@ describe("TreeEditComponent", () => {
1921
TestBed.configureTestingModule({
2022
declarations: [TreeEditComponent],
2123
imports: [ScientificMetadataTreeModule, BrowserAnimationsModule],
22-
providers: [MatDialog, MatSnackBar, DatePipe],
24+
providers: [
25+
MatDialog,
26+
MatSnackBar,
27+
DatePipe,
28+
AppConfigService,
29+
provideHttpClient(),
30+
],
2331
}).compileComponents();
2432
}));
2533

2634
beforeEach(() => {
35+
const appConfigService = TestBed.inject(AppConfigService);
36+
(appConfigService as any).appConfig = {
37+
metadataFloatFormatEnabled: true,
38+
metadataFloatFormat: {
39+
significantDigits: 3,
40+
minCutoff: 0.001,
41+
maxCutoff: 1000,
42+
},
43+
};
2744
fixture = TestBed.createComponent(TreeEditComponent);
2845
component = fixture.componentInstance;
2946
component.metadata = {

src/app/shared/modules/scientific-metadata-tree/tree-edit/tree-edit.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { MatSnackBar } from "@angular/material/snack-bar";
2929
import { DatePipe } from "@angular/common";
3030
import { Type } from "../base-classes/metadata-input-base";
3131
import { DateTime } from "luxon";
32+
import { AppConfigService } from "app-config.service";
3233

3334
export class FlatNodeEdit implements FlatNode {
3435
key: string;
@@ -64,8 +65,9 @@ export class TreeEditComponent
6465
public dialog: MatDialog,
6566
private snackBar: MatSnackBar,
6667
datePipe: DatePipe,
68+
configService: AppConfigService,
6769
) {
68-
super();
70+
super(configService);
6971
this.datePipe = datePipe;
7072
this.treeFlattener = new MatTreeFlattener(
7173
this.transformer,

src/app/shared/modules/scientific-metadata-tree/tree-view/tree-view.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<div class="key-cell" [style.padding-left.px]="getPadding(node)">
3939
<label class="label-cell">{{ node.key }}</label>
4040
</div>
41-
<div class="value-cell">{{ getValueRepresentation(node) }}</div>
41+
<div class="value-cell">{{ getValueRepresentation(node) | formatNumber }}</div>
4242
</section>
4343
</mat-tree-node>
4444
<!-- Only Key -->

0 commit comments

Comments
 (0)