Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement configurable localization for datasets detail view #1700

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@ngrx/effects": "^16",
"@ngrx/router-store": "^16",
"@ngrx/store": "^16",
"@ngx-translate/core": "^16.0.4",
"@scicatproject/scicat-sdk-ts": "^4.8.3",
"autolinker": "^4.0.0",
"deep-equal": "^2.0.5",
Expand Down
2 changes: 2 additions & 0 deletions src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Injectable } from "@angular/core";
import { timeout } from "rxjs/operators";
import {
DatasetDetailView,
DatasetsListSettings,
LabelMaps,
TableColumn,
Expand Down Expand Up @@ -42,7 +43,7 @@
datasetReduceEnabled: boolean;
datasetDetailsShowMissingProposalId: boolean;
datafilesActionsEnabled: boolean;
datafilesActions: any[];

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

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
editDatasetSampleEnabled: boolean;
editMetadataEnabled: boolean;
editPublishedData: boolean;
Expand Down Expand Up @@ -101,6 +102,7 @@
labelMaps: LabelMaps;
thumbnailFetchLimitPerPage: number;
maxFileUploadSizeInMb?: string;
datasetDetailView?: DatasetDetailView;
}

@Injectable()
Expand All @@ -116,12 +118,12 @@
.pipe(timeout(2000))
.toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {

Check warning on line 121 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.");
try {
const config = await this.http.get("/assets/config.json").toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {

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

View workflow job for this annotation

GitHub Actions / eslint

'err' is defined but never used
console.error("No config provided.");
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { SnackbarInterceptor } from "shared/interceptors/snackbar.interceptor";
import { AuthService } from "shared/services/auth/auth.service";
import { InternalStorage, SDKStorage } from "shared/services/auth/base.storage";
import { CookieService } from "ngx-cookie-service";
import { TranslateLoader, TranslateModule } from "@ngx-translate/core";
import { CustomTranslateLoader } from "shared/loaders/custom-translate.loader";

const appConfigInitializerFn = (appConfig: AppConfigService) => {
return () => appConfig.loadAppConfig();
Expand All @@ -51,6 +53,13 @@ const apiConfigurationFn = (
imports: [
AppConfigModule,
AppRoutingModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: CustomTranslateLoader,
deps: [AppConfigService],
},
}),
BrowserAnimationsModule,
BrowserModule,
HttpClientModule,
Expand Down
72 changes: 36 additions & 36 deletions src/app/datasets/dataset-detail/dataset-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@
<div mat-card-avatar class="section-icon">
<mat-icon> description </mat-icon>
</div>
General Information
{{ "General Information" | translate }}
</mat-card-header>
<mat-card-content>
<table>
<tr>
<th>Name</th>
<th>{{ "Dataset Name" | translate }}</th>
<td *ngIf="!editEnabled">{{ dataset.datasetName || "-" }}</td>
<td *ngIf="editEnabled && editingAllowed">
<mat-form-field class="full-width">
<mat-label>Name</mat-label>
<mat-label>dataset_name</mat-label>
<input matInput type="text" formControlName="datasetName" />
</mat-form-field>
</td>
</tr>
<tr>
<th>Description</th>
<th>{{ "Description" | translate }}</th>
<td *ngIf="!editEnabled">
<span [innerHTML]="dataset.description || '-' | linky"></span>
</td>
<td *ngIf="editEnabled && editingAllowed">
<mat-form-field class="full-width">
<mat-label>Description</mat-label>
<mat-label>description</mat-label>
<textarea
matInput
rows="5"
Expand All @@ -61,7 +61,7 @@
</td>
</tr>
<tr>
<th>PID</th>
<th>{{ "Pid" | translate }}</th>
<td>
{{ dataset.pid }}
<button
Expand All @@ -74,15 +74,15 @@
</td>
</tr>
<tr *ngIf="dataset.type as value">
<th>Type</th>
<th>{{ "Type" | translate }}</th>
<td>{{ value }}</td>
</tr>
<tr *ngIf="dataset.creationTime as value">
<th>Creation Time</th>
<th>{{ "Creation time" | translate }}</th>
<td>{{ value | date: "yyyy-MM-dd HH:mm" }}</td>
</tr>
<tr class="keywords-row">
<th>Keywords</th>
<th>{{ "Keywords" | translate }}</th>
<td *ngIf="!editEnabled">
<mat-chip-set role="list" #keywordChips>
<mat-chip
Expand Down Expand Up @@ -118,7 +118,7 @@
</td>
</tr>
<tr *ngIf="dataset.sharedWith && dataset.sharedWith.length > 0">
<th>Shared With</th>
<th>{{ "Shared With" | translate }}</th>
<td>
<mat-chip-listbox>
<mat-chip-option
Expand Down Expand Up @@ -171,37 +171,37 @@
<div mat-card-avatar class="section-icon">
<mat-icon> person </mat-icon>
</div>
Creator Information
{{ "Creator Information" | translate }}
</mat-card-header>

<mat-card-content>
<table>
<tr *ngIf="dataset.owner as value">
<th>Owner</th>
<th>{{ "Owner" | translate }}</th>
<td>{{ value }}</td>
</tr>
<tr *ngIf="dataset['principalInvestigator'] as value">
<th>Principal Investigator</th>
<th>{{ "Principal Investigator" | translate }}</th>
<td><span [innerHTML]="value | linky"></span></td>
</tr>
<tr *ngIf="dataset['investigator'] as value">
<th>Investigator</th>
<th>{{ "Investigator" | translate }}</th>
<td>{{ value }}</td>
</tr>
<tr *ngIf="dataset.orcidOfOwner as value">
<th>Orcid</th>
<th>{{ "Orcid" | translate }}</th>
<td><span [innerHTML]="value | linky"></span></td>
</tr>
<tr *ngIf="dataset.contactEmail as value">
<th>Contact Email</th>
<th>{{ "Contact Email" | translate }}</th>
<td><span [innerHTML]="value | linky"></span></td>
</tr>
<tr *ngIf="dataset.ownerGroup as value">
<th>Owner Group</th>
<th>{{ "Owner Group" | translate }}</th>
<td>{{ value }}</td>
</tr>
<tr *ngIf="dataset.accessGroups as value">
<th>Access Groups</th>
<th>{{ "Access Groups" | translate }}</th>
<td>{{ value }}</td>
</tr>
</table>
Expand All @@ -213,21 +213,21 @@
<div mat-card-avatar class="section-icon">
<mat-icon> folder </mat-icon>
</div>
File Information
{{ "File Information" | translate }}
</mat-card-header>

<mat-card-content>
<table>
<tr *ngIf="dataset.sourceFolder as value">
<th>Source Folder</th>
<th>{{ "Source Folder" | translate }}</th>
<td>{{ value }}</td>
</tr>
<tr *ngIf="dataset.size as value">
<th>Size</th>
<th>{{ "Size" | translate }}</th>
<td>{{ value | filesize }}</td>
</tr>
<tr *ngIf="dataset['dataFormat'] as value">
<th>Data Format</th>
<th>{{ "Data Format" | translate }}</th>
<td>{{ value }}</td>
</tr>
</table>
Expand All @@ -239,13 +239,13 @@
<div mat-card-avatar class="section-icon">
<mat-icon> library_books </mat-icon>
</div>
Related Documents
{{ "Related Documents" | translate }}
</mat-card-header>

<mat-card-content>
<table>
<tr *ngIf="dataset['proposalId'] && proposal">
<th>Proposal</th>
<th>{{ "Proposal" | translate }}</th>
<td>
<a (click)="onClickProposal(proposal.proposalId)">{{
proposal.title
Expand All @@ -259,31 +259,31 @@
appConfig.datasetDetailsShowMissingProposalId
"
>
<th>Proposal Id</th>
<th>{{ "Proposal Id" | translate }}</th>
<td>{{ dataset["proposalId"] }}</td>
</tr>
<tr *ngIf="dataset['sampleId'] && sample">
<th>Sample</th>
<th>{{ "Sample" | translate }}</th>
<td>
<a (click)="onClickSample(sample.sampleId)">
<span>{{ sample.description }}</span>
</a>
</td>
</tr>
<tr *ngIf="dataset['instrumentId'] && instrument">
<th>Instrument</th>
<th>{{ "Instrument" | translate }}</th>
<td>
<a (click)="onClickInstrument(instrument.pid)">
{{ instrument.name }}
</a>
</td>
</tr>
<tr *ngIf="dataset['creationLocation'] as value">
<th>Creation Location</th>
<th>{{ "Creation Location" | translate }}</th>
<td>{{ value }}</td>
</tr>
<tr *ngIf="dataset.techniques && dataset.techniques.length > 0">
<th>Techniques</th>
<th>{{ "Techniques" | translate }}</th>
<td>
<div *ngFor="let technique of dataset.techniques">
<span>
Expand All @@ -304,7 +304,7 @@
dataset['inputDatasets'] && dataset['inputDatasets'].length > 0
"
>
<th>Input Datasets</th>
<th>{{ "Input Datasets" | translate }}</th>
<td>
<div *ngFor="let datasetPid of dataset['inputDatasets']">
<span>
Expand All @@ -331,21 +331,21 @@
<div mat-card-avatar class="section-icon">
<mat-icon> analytics </mat-icon>
</div>
Derived Data
{{ "Derived Data" | translate }}
</mat-card-header>

<mat-card-content>
<table>
<tr *ngIf="dataset['usedSoftware'] as value">
<th>Software Used</th>
<th>{{ "Software Used" | translate }}</th>
<td>{{ value }}</td>
</tr>
<tr *ngIf="dataset['jobParameters'] as value">
<th>Job Parameters</th>
<th>{{ "Job Parameters" | translate }}</th>
<td>{{ value | json }}</td>
</tr>
<tr *ngIf="dataset['jobLogData'] as value">
<th>Job Log Data</th>
<th>{{ "Job Log Data" | translate }}</th>
<td>{{ value }}</td>
</tr>
</table>
Expand All @@ -357,7 +357,7 @@
<div mat-card-avatar class="section-icon">
<mat-icon> science </mat-icon>
</div>
Scientific Metadata
{{ "Scientific Metadata" | translate }}
</mat-card-header>
<mat-card-content>
<ng-template
Expand Down Expand Up @@ -425,7 +425,7 @@
<mat-card *ngIf="editingAllowed && appConfig.jsonMetadataEnabled">
<mat-card-content>
<button mat-stroked-button (click)="show = !show">
{{ show ? "Hide MetaData" : "Show Metadata" }}
{{ (show ? "Hide Metadata" : "Show Metadata") | translate }}
</button>

<br />
Expand Down
32 changes: 21 additions & 11 deletions src/app/datasets/dataset-detail/dataset-detail.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { SharedScicatFrontendModule } from "shared/shared.module";
import { MatTableModule } from "@angular/material/table";
import { MatChipInputEvent, MatChipsModule } from "@angular/material/chips";
import { of } from "rxjs";
import { Observable, of } from "rxjs";
import { MatDialogRef } from "@angular/material/dialog";
import { MatCardModule } from "@angular/material/card";
import { MatIconModule } from "@angular/material/icon";
Expand All @@ -33,19 +33,21 @@ import {
MatSlideToggleChange,
} from "@angular/material/slide-toggle";
import { ActivatedRoute, Router } from "@angular/router";
import {
createMock,
MockActivatedRoute,
mockDataset,
mockSample,
} from "shared/MockStubs";
import { MockActivatedRoute, mockDataset } from "shared/MockStubs";
import { DialogComponent } from "shared/modules/dialog/dialog.component";
import { AppConfigService } from "app-config.service";
import { AttachmentService } from "shared/services/attachment.service";
import { OutputDatasetObsoleteDto } from "@scicatproject/scicat-sdk-ts";
import {
OutputDatasetObsoleteDto,
ReturnedUserDto,
} from "@scicatproject/scicat-sdk-ts";
TranslateLoader,
TranslateModule,
TranslationObject,
} from "@ngx-translate/core";
class MockTranslateLoader implements TranslateLoader {
getTranslation(): Observable<TranslationObject> {
return of({});
}
}

describe("DatasetDetailComponent", () => {
let component: DatasetDetailComponent;
Expand All @@ -56,7 +58,9 @@ describe("DatasetDetailComponent", () => {
};

const getConfig = () => ({
editMetadataEnabled: true,
datasetDetailView: {
currentLabel: "test",
},
});

let store: MockStore;
Expand All @@ -76,6 +80,12 @@ describe("DatasetDetailComponent", () => {
MatTabsModule,
NgxJsonViewerModule,
SharedScicatFrontendModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: MockTranslateLoader,
},
}),
StoreModule.forRoot({}),
],
providers: [AttachmentService],
Expand Down
Loading
Loading