fa updates

This commit is contained in:
Timo 2021-04-09 09:36:50 +03:00
parent 7325e6117a
commit 2a2b25f2f6
2 changed files with 89 additions and 23 deletions

View File

@ -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<FileAttributeConfig | FileAttributesConfig>[] = [
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;
}
}
}

View File

@ -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<FileAttributesConfig>;
public addOrUpdateFileAttributesConfig(
body: FileAttributesConfig,
ruleSetId: string,
observe?: 'response',
reportProgress?: boolean
): Observable<HttpResponse<FileAttributesConfig>>;
public addOrUpdateFileAttributesConfig(
body: FileAttributesConfig,
ruleSetId: string,
observe?: 'events',
reportProgress?: boolean
): Observable<HttpEvent<FileAttributesConfig>>;
public addOrUpdateFileAttributesConfig(
body: FileAttributesConfig,
ruleSetId: string,
observe: any = 'body',
reportProgress: boolean = false
): Observable<any> {
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<FileAttributesConfig>(
'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