diff --git a/apps/red-ui/src/app/modules/admin/screens/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.ts b/apps/red-ui/src/app/modules/admin/screens/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.ts index f0fefb272..3c9952da7 100644 --- a/apps/red-ui/src/app/modules/admin/screens/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.ts @@ -3,7 +3,7 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { AppStateService } from '../../../../state/app-state.service'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import * as Papa from 'papaparse'; -import { FileAttributeConfig, FileAttributesConfig, FileAttributesControllerService } from '@redaction/red-ui-http'; +import { FileAttributesControllerService } from '@redaction/red-ui-http'; import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling'; enum FieldType { @@ -175,32 +175,23 @@ export class FileAttributesCsvImportDialogComponent implements OnInit { } public async save() { - const promises: Promise[] = [ - this._fileAttributesControllerService.addOrUpdateFileAttributesBaseConfig(this.baseConfigForm.getRawValue(), this.ruleSetId).toPromise() - ]; - - for (const field of this.activeFields) { - promises.push( - this._fileAttributesControllerService - .setFileAttributesConfiguration( - { + await this._fileAttributesControllerService + .addOrUpdateFileAttributesConfig( + { + ...this.baseConfigForm.getRawValue(), + fileAttributeConfigs: this.activeFields.map((field) => { + return { csvColumnHeader: field.csvColumn, editable: !field.readonly, label: field.name, visible: field.display - }, - this.ruleSetId - ) - .toPromise() - ); - } - await this.resolveInSequence(promises); + }; + }) + }, + this.ruleSetId + ) + .toPromise(); + this.dialogRef.close(true); } - - async resolveInSequence(requests) { - for (const request of requests) { - await request; - } - } } diff --git a/libs/red-ui-http/src/lib/api/fileAttributesController.service.ts b/libs/red-ui-http/src/lib/api/fileAttributesController.service.ts index 7fba1da0e..598d80aeb 100644 --- a/libs/red-ui-http/src/lib/api/fileAttributesController.service.ts +++ b/libs/red-ui-http/src/lib/api/fileAttributesController.service.ts @@ -302,6 +302,81 @@ export class FileAttributesControllerService { ); } + /** + * Adds or updates file attributes base configuration and a list of file attributes, + * None + * @param body fileAttributesConfig + * @param ruleSetId ruleSetId + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public addOrUpdateFileAttributesConfig( + body: FileAttributesConfig, + ruleSetId: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public addOrUpdateFileAttributesConfig( + body: FileAttributesConfig, + ruleSetId: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public addOrUpdateFileAttributesConfig( + body: FileAttributesConfig, + ruleSetId: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public addOrUpdateFileAttributesConfig( + body: FileAttributesConfig, + ruleSetId: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling addOrUpdateFileAttributesConfig.'); + } + + if (ruleSetId === null || ruleSetId === undefined) { + throw new Error('Required parameter ruleSetId was null or undefined when calling addOrUpdateFileAttributesConfig.'); + } + + let headers = this.defaultHeaders; + + // authentication (RED-OAUTH) required + if (this.configuration.accessToken) { + const accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; + headers = headers.set('Authorization', 'Bearer ' + accessToken); + } + + // to determine the Accept header + const httpHeaderAccepts: string[] = ['application/json']; + const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); + if (httpHeaderAcceptSelected !== undefined) { + headers = headers.set('Accept', httpHeaderAcceptSelected); + } + + // to determine the Content-Type header + const consumes: string[] = ['application/json']; + const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); + if (httpContentTypeSelected !== undefined) { + headers = headers.set('Content-Type', httpContentTypeSelected); + } + + return this.httpClient.request( + 'put', + `${this.basePath}/fileAttributes/config/baseConfig/${encodeURIComponent(String(ruleSetId))}`, + { + body: body, + withCredentials: this.configuration.withCredentials, + headers: headers, + observe: observe, + reportProgress: reportProgress + } + ); + } + /** * Add or update a file attribute that can be used at importing csv. * None