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

Solve UI bugs of validation loading spinner #1357

Merged
merged 3 commits into from
Mar 15, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1146,21 +1146,44 @@ export class ExperimentController {
/**
* @swagger
* /experiments/{validation}:
* put:
* post:
* description: Validating Experiment
* consumes:
* - application/json
* parameters:
* - in: path
* - in: body
* name: experiments
* required: true
* schema:
* type: array
* items:
* type: object
* properties:
* fileName:
* type: string
* fileContent:
* type: string
* description: Experiment Files
* tags:
* - Experiments
* produces:
* - application/json
* responses:
* '200':
* description: Validations are done
* description: Validations are completed
* schema:
* type: array
* items:
* type: object
* properties:
* fileName:
* type: string
* error:
* type: string
* '401':
* description: AuthorizationRequiredError
* '500':
* description: Internal Server Error
*/
@Post('/validation')
public validateExperiment(
Expand All @@ -1173,21 +1196,44 @@ export class ExperimentController {
/**
* @swagger
* /experiments/{import}:
* put:
* post:
* description: Import New Experiment
* consumes:
* - application/json
* parameters:
* - in: path
* - in: body
* name: experiments
* required: true
* schema:
* type: array
* items:
* type: object
* properties:
* fileName:
* type: string
* fileContent:
* type: string
* description: Experiment Files
* tags:
* - Experiments
* produces:
* - application/json
* responses:
* '200':
* description: Experiment is imported
* schema:
* type: array
* items:
* type: object
* properties:
* fileName:
* type: string
* error:
* type: string
* '401':
* description: AuthorizationRequiredError
* '500':
* description: Internal Server Error
*/
@Post('/import')
public importExperiment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ export class ImportExperimentComponent implements OnInit {
}

async importExperiment() {
this.onCancelClick();
const importResult = (await this.dataService
.importExperiment(this.allExperiments)
.toPromise()) as ValidateExperimentError[];
//this.experimentService.importExperiment(this.allExperiments);
this.showNotification(importResult);
this.onCancelClick();

this.experimentService.loadExperiments(true);
}

Expand Down Expand Up @@ -86,8 +85,6 @@ export class ImportExperimentComponent implements OnInit {
}

async uploadFile(event) {
const index = 0;
const reader = new FileReader();
this.uploadedFileCount = event.target.files.length;
this.importFileErrors = [];
this.allExperiments = [];
Expand All @@ -97,25 +94,22 @@ export class ImportExperimentComponent implements OnInit {
// Set loading to true before processing the files
this.isLoadingExperiments$ = true;

const readFile = (fileIndex) => {
if (fileIndex >= event.target.files.length) {
// Check if this is the last file
if (fileIndex >= this.uploadedFileCount) {
this.checkValidation();
this.isLoadingExperiments$ = false;
}
return;
}
const file = event.target.files[fileIndex];
const fileName = file.name;
reader.onload = (e) => {
const fileContent = e.target.result;
this.allExperiments.push({ fileName: fileName, fileContent: fileContent });
readFile(fileIndex + 1);
};
reader.readAsText(file);
};

readFile(index);
const filesArray = Array.from(event.target.files) as any[];
await Promise.all(
filesArray.map((file) => {
return new Promise<void>((resolve) => {
const reader = new FileReader();
reader.onload = (e) => {
const fileContent = e.target.result;
this.allExperiments.push({ fileName: file.name, fileContent: fileContent });
resolve();
};
reader.readAsText(file);
});
})
);

await this.checkValidation();
this.isLoadingExperiments$ = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@
{{ 'segments.import-segmemt.message.text' | translate }}
</p>
<input accept=".json" type="file" multiple class="ft-14-400 file-input" (change)="uploadFile($event)" />
<ng-container *ngIf="importFileErrors.length">
<mat-table class="table" [dataSource]="importFileErrorsDataSource">
<!-- File Name -->
<ng-container matColumnDef="File Name">
<mat-header-cell class="ft-12-700" *matHeaderCellDef> File Name </mat-header-cell>
<mat-cell class="ft-12-600" *matCellDef="let element">
{{ element.fileName }}
</mat-cell>
</ng-container>
<ng-container *ngIf="!isLoadingSegments$; else loadingSegmentState">
<ng-container *ngIf="importFileErrors.length">
<mat-table class="table" [dataSource]="importFileErrorsDataSource">
<!-- File Name -->
<ng-container matColumnDef="File Name">
<mat-header-cell class="ft-12-700" *matHeaderCellDef> File Name </mat-header-cell>
<mat-cell class="ft-12-600" *matCellDef="let element">
{{ element.fileName }}
</mat-cell>
</ng-container>

<!-- Error -->
<ng-container matColumnDef="Error">
<mat-header-cell class="ft-12-700" *matHeaderCellDef> Error/Warning </mat-header-cell>
<mat-cell class="ft-12-600" *matCellDef="let element">
{{ element.error }}
</mat-cell>
</ng-container>
<!-- Error -->
<ng-container matColumnDef="Error">
<mat-header-cell class="ft-12-700" *matHeaderCellDef> Error/Warning </mat-header-cell>
<mat-cell class="ft-12-600" *matCellDef="let element">
{{ element.error }}
</mat-cell>
</ng-container>

<mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
</mat-table>
<mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
</mat-table>
</ng-container>
</ng-container>
</div>

Expand All @@ -50,3 +52,9 @@
</button>
</div>
</div>

<ng-template #loadingSegmentState>
<div class="loading-container">
<mat-spinner diameter="60"></mat-spinner>
</div>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@
justify-content: flex-end;
padding: 0 40px 40px;
}

.loading-container {
display: flex;
flex-grow: 1;
align-items: center;
justify-content: center;
margin-top: 60px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export class ImportSegmentComponent {
}

async importSegments() {
this.onCancelClick();
const importResult = (await this.segmentdataService
.importSegments(this.fileData)
.toPromise()) as SegmentImportError[];

this.showNotification(importResult);
this.onCancelClick();

this.segmentsService.fetchSegments(true);
}
Expand Down Expand Up @@ -75,12 +75,12 @@ export class ImportSegmentComponent {

fileList.forEach((file) => {
const reader = new FileReader();
reader.onload = (e) => {
reader.onload = async (e) => {
const fileContent = e.target?.result;
this.fileData.push({ fileName: file.name, fileContent: fileContent });
// Check if this is the last file and validate
if (this.fileData.length === this.uploadedFileCount) {
this.validateFiles();
await this.validateFiles();
this.isLoadingSegments$ = false;
}
};
Expand Down
Loading