Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/app/app-config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
thumbnailFetchLimitPerPage: 500,
maxFileUploadSizeInMb: "16mb",
maxDirectDownloadSize: 5000000000,
metadataFloatFormatEnabled: true,
metadataFloatFormat: {
significantDigits: 3,
minCutoff: 0.001,
maxCutoff: 1000,
},
metadataPreviewEnabled: true,
metadataStructure: "",
multipleDownloadAction: "http://localhost:3012/zip",
Expand Down Expand Up @@ -290,7 +296,7 @@
backendError = false,
) => {
spyOn(service["http"], "get").and.callFake(
(url: string): Observable<any> => {

Check warning on line 299 in src/app/app-config.service.spec.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
if (url === "/api/v3/admin/config") {
if (backendError) {
return new Observable((sub) =>
Expand Down
16 changes: 16 additions & 0 deletions src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
authenticatedUser: MainMenuOptions;
}

export class MetadataFloatFormat {
significantDigits: number;
minCutoff: number; // using scientific notation below this cutoff
maxCutoff: number; // using scientific notation above this cutoff
}

export interface AppConfigInterface {
allowConfigOverrides?: boolean;
skipSciCatLoginPageEnabled?: boolean;
Expand All @@ -76,13 +82,13 @@
datasetReduceEnabled: boolean;
datasetDetailsShowMissingProposalId: boolean;
datasetActionsEnabled: boolean;
datasetActions: any[];

Check warning on line 85 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
datafilesActionsEnabled: boolean;
datafilesActions: any[];

Check warning on line 87 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
datasetDetailsActionsEnabled: boolean;
datasetDetailsActions: any[];

Check warning on line 89 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
datasetSelectionActionsEnabled: boolean;
datasetSelectionActions: any[];

Check warning on line 91 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
editDatasetEnabled: boolean;
editDatasetSampleEnabled: boolean;
editMetadataEnabled: boolean;
Expand Down Expand Up @@ -111,6 +117,8 @@
maxDirectDownloadSize: number | null;
metadataPreviewEnabled: boolean;
metadataStructure: string;
metadataFloatFormat?: MetadataFloatFormat;
metadataFloatFormatEnabled?: boolean;
multipleDownloadAction: string | null;
multipleDownloadEnabled: boolean;
multipleDownloadUseAuthToken: boolean;
Expand Down Expand Up @@ -156,7 +164,7 @@
ingestorComponent?: IngestorComponentConfig;
}

function isMainPageConfiguration(obj: any): obj is MainPageConfiguration {

Check warning on line 167 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
const validKeys = Object.keys(MainPageOptions);
return (
obj &&
Expand Down Expand Up @@ -215,7 +223,7 @@
.pipe(timeout(2000))
.toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {

Check warning on line 226 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

'err' is defined but never used
console.log("No config available in backend, trying with local config.");
const config = await this.mergeConfig();
this.appConfig = Object.assign({}, this.appConfig, config);
Expand Down Expand Up @@ -247,6 +255,14 @@
config.dateFormat = "yyyy-MM-dd HH:mm";
}

if (!config.metadataFloatFormat) {
config.metadataFloatFormat = {
significantDigits: 3,
minCutoff: 0.001,
maxCutoff: 1000,
};
}

this.appConfig = config;
}

Expand Down
15 changes: 15 additions & 0 deletions src/app/datasets/dataset-table/dataset-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { FileSizePipe } from "shared/pipes/filesize.pipe";
import { actionMenu } from "shared/modules/dynamic-material-table/utilizes/default-table-settings";
import { TableConfigService } from "shared/services/table-config.service";
import { selectInstruments } from "state-management/selectors/instruments.selectors";
import { FormatNumberPipe } from "shared/pipes/format-number.pipe";

export interface SortChangeEvent {
active: string;
Expand Down Expand Up @@ -162,6 +163,7 @@ export class DatasetTableComponent implements OnInit, OnDestroy {
private datePipe: DatePipe,
private fileSize: FileSizePipe,
private tableConfigService: TableConfigService,
private formatNumberPipe: FormatNumberPipe,
) {}

private getInstrumentName(row: OutputDatasetObsoleteDto): string {
Expand Down Expand Up @@ -488,6 +490,19 @@ export class DatasetTableComponent implements OnInit, OnDestroy {
this.getInstrumentName(row);
}

if (column.name.startsWith("scientificMetadata.")) {
convertedColumn.customRender = (col, row) => {
return String(
this.formatNumberPipe.transform(lodashGet(row, col.name)),
);
};
convertedColumn.toExport = (row) => {
return String(
this.formatNumberPipe.transform(lodashGet(row, column.name)),
);
};
}

return convertedColumn;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { MetadataInputComponent } from "../metadata-input/metadata-input.compone
import { FormatNumberPipe } from "shared/pipes/format-number.pipe";
import { ScientificMetadataTreeModule } from "../scientific-metadata-tree.module";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppConfigService } from "app-config.service";
import { provideHttpClient } from "@angular/common/http";

describe("MetadataInputBase", () => {
let component: MetadataInputComponent;
Expand All @@ -15,11 +17,25 @@ describe("MetadataInputBase", () => {
TestBed.configureTestingModule({
declarations: [MetadataInputComponent],
imports: [ScientificMetadataTreeModule, BrowserAnimationsModule],
providers: [FormBuilder, FormatNumberPipe],
providers: [
FormBuilder,
FormatNumberPipe,
AppConfigService,
provideHttpClient(),
],
}).compileComponents();
}));

beforeEach(() => {
const appConfigService = TestBed.inject(AppConfigService);
(appConfigService as any).appConfig = {
metadataFloatFormatEnabled: true,
metadataFloatFormat: {
significantDigits: 3,
minCutoff: 0.001,
maxCutoff: 1000,
},
};
fixture = TestBed.createComponent(MetadataInputComponent);
component = fixture.componentInstance;
const data = new FlatNodeEdit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { FlatNode, TreeNode } from "../base-classes/tree-base";
import { TreeEditComponent } from "../tree-edit/tree-edit.component";
import { ScientificMetadataTreeModule } from "../scientific-metadata-tree.module";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppConfigService } from "app-config.service";
import { provideHttpClient } from "@angular/common/http";

describe("TreeBaseComponent", () => {
let component: TreeEditComponent;
Expand All @@ -16,11 +18,26 @@ describe("TreeBaseComponent", () => {
TestBed.configureTestingModule({
declarations: [TreeEditComponent],
imports: [ScientificMetadataTreeModule, BrowserAnimationsModule],
providers: [MatDialog, MatSnackBar, DatePipe],
providers: [
MatDialog,
MatSnackBar,
DatePipe,
AppConfigService,
provideHttpClient(),
],
}).compileComponents();
}));

beforeEach(() => {
const appConfigService = TestBed.inject(AppConfigService);
(appConfigService as any).appConfig = {
metadataFloatFormatEnabled: true,
metadataFloatFormat: {
significantDigits: 3,
minCutoff: 0.001,
maxCutoff: 1000,
},
};
fixture = TestBed.createComponent(TreeEditComponent);
component = fixture.componentInstance;
component.metadata = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FormatNumberPipe } from "shared/pipes/format-number.pipe";
import { PrettyUnitPipe } from "shared/pipes/pretty-unit.pipe";
import { DateTimeService } from "shared/services/date-time.service";
import { UnitsService } from "shared/services/units.service";
import { AppConfigService } from "app-config.service";

export class TreeNode {
children: TreeNode[];
Expand Down Expand Up @@ -43,10 +44,10 @@ export class TreeBaseComponent {
prettyUnitPipe: PrettyUnitPipe;
unitsService: UnitsService;
dateTimeService: DateTimeService;
constructor() {
constructor(protected configService: AppConfigService) {
this.unitsService = new UnitsService();
this.prettyUnitPipe = new PrettyUnitPipe(this.unitsService);
this.formatNumberPipe = new FormatNumberPipe();
this.formatNumberPipe = new FormatNumberPipe(this.configService);
this.dateTimeService = new DateTimeService();
}
buildDataTree(obj: { [key: string]: any }, level: number): TreeNode[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ScientificMetadataTreeModule } from "../scientific-metadata-tree.module
import { MetadataInputComponent } from "./metadata-input.component";

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

describe("MetadataInputComponent", () => {
let component: MetadataInputComponent;
Expand All @@ -18,11 +20,25 @@ describe("MetadataInputComponent", () => {
TestBed.configureTestingModule({
declarations: [MetadataInputComponent],
imports: [ScientificMetadataTreeModule, BrowserAnimationsModule],
providers: [FormBuilder, FormatNumberPipe],
providers: [
FormBuilder,
FormatNumberPipe,
AppConfigService,
provideHttpClient(),
],
}).compileComponents();
}));

beforeEach(() => {
const appConfigService = TestBed.inject(AppConfigService);
(appConfigService as any).appConfig = {
metadataFloatFormatEnabled: true,
metadataFloatFormat: {
significantDigits: 3,
minCutoff: 0.001,
maxCutoff: 1000,
},
};
fixture = TestBed.createComponent(MetadataInputComponent);
component = fixture.componentInstance;
const data = new FlatNodeEdit();
Expand Down Expand Up @@ -76,7 +92,7 @@ describe("MetadataInputComponent", () => {
component.addCurrentMetadata(component.data);
expect(component.metadataForm.get("type").value).toEqual("quantity");
expect(component.metadataForm.get("key").value).toEqual("energy");
expect(component.metadataForm.get("value").value).toEqual(3);
expect(component.metadataForm.get("value").value).toEqual("3");
expect(component.metadataForm.get("unit").value).toEqual("joule");
});
it("should set values in form control (number)", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { ScientificMetadataTreeModule } from "../scientific-metadata-tree.module

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

describe("TreeEditComponent", () => {
let component: TreeEditComponent;
Expand All @@ -19,11 +21,26 @@ describe("TreeEditComponent", () => {
TestBed.configureTestingModule({
declarations: [TreeEditComponent],
imports: [ScientificMetadataTreeModule, BrowserAnimationsModule],
providers: [MatDialog, MatSnackBar, DatePipe],
providers: [
MatDialog,
MatSnackBar,
DatePipe,
AppConfigService,
provideHttpClient(),
],
}).compileComponents();
}));

beforeEach(() => {
const appConfigService = TestBed.inject(AppConfigService);
(appConfigService as any).appConfig = {
metadataFloatFormatEnabled: true,
metadataFloatFormat: {
significantDigits: 3,
minCutoff: 0.001,
maxCutoff: 1000,
},
};
fixture = TestBed.createComponent(TreeEditComponent);
component = fixture.componentInstance;
component.metadata = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { MatSnackBar } from "@angular/material/snack-bar";
import { DatePipe } from "@angular/common";
import { Type } from "../base-classes/metadata-input-base";
import { DateTime } from "luxon";
import { AppConfigService } from "app-config.service";

export class FlatNodeEdit implements FlatNode {
key: string;
Expand Down Expand Up @@ -64,8 +65,9 @@ export class TreeEditComponent
public dialog: MatDialog,
private snackBar: MatSnackBar,
datePipe: DatePipe,
configService: AppConfigService,
) {
super();
super(configService);
this.datePipe = datePipe;
this.treeFlattener = new MatTreeFlattener(
this.transformer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<div class="key-cell" [style.padding-left.px]="getPadding(node)">
<label class="label-cell">{{ node.key }}</label>
</div>
<div class="value-cell">{{ getValueRepresentation(node) }}</div>
<div class="value-cell">{{ getValueRepresentation(node) | formatNumber }}</div>
</section>
</mat-tree-node>
<!-- Only Key -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,40 @@ import { waitForAsync, ComponentFixture, TestBed } from "@angular/core/testing";
import { FormatNumberPipe } from "shared/pipes/format-number.pipe";
import { PrettyUnitPipe } from "shared/pipes/pretty-unit.pipe";
import { ScientificMetadataTreeModule } from "../scientific-metadata-tree.module";

import { TreeViewComponent } from "./tree-view.component";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppConfigService } from "app-config.service";
import { provideHttpClient } from "@angular/common/http";

describe("TreeViewComponent", () => {
let component: TreeViewComponent;
let fixture: ComponentFixture<TreeViewComponent>;

beforeEach(waitForAsync(() => {
TestBed.resetTestingModule();
TestBed.configureTestingModule({
declarations: [TreeViewComponent],
imports: [ScientificMetadataTreeModule, BrowserAnimationsModule],
providers: [DatePipe, PrettyUnitPipe, FormatNumberPipe],
providers: [
DatePipe,
PrettyUnitPipe,
FormatNumberPipe,
AppConfigService,
provideHttpClient(),
],
}).compileComponents();
}));

beforeEach(() => {
const appConfigService = TestBed.inject(AppConfigService);
(appConfigService as any).appConfig = {
metadataFloatFormatEnabled: true,
metadataFloatFormat: {
significantDigits: 3,
minCutoff: 0.001,
maxCutoff: 1000,
},
};
fixture = TestBed.createComponent(TreeViewComponent);
component = fixture.componentInstance;
component.metadata = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
TreeNode,
} from "shared/modules/scientific-metadata-tree/base-classes/tree-base";
import { DatePipe } from "@angular/common";
import { AppConfigService } from "app-config.service";
@Component({
selector: "tree-view",
templateUrl: "./tree-view.component.html",
Expand All @@ -27,9 +28,11 @@ export class TreeViewComponent
implements OnInit, OnChanges
{
@Input() metadata: any;
constructor(datePipe: DatePipe) {
super();
this.datePipe = datePipe;
constructor(
public datePipe: DatePipe,
configService: AppConfigService,
) {
super(configService);
this.treeFlattener = new MatTreeFlattener(
this.transformer,
this.getLevel,
Expand Down
Loading
Loading