CST-11045 Dynamically creating dropdowns based on the coarconfig

This commit is contained in:
Mattia Vianelli
2023-10-25 23:03:24 +02:00
parent 7ed4d1457d
commit 0682b7b45f
2 changed files with 48 additions and 47 deletions

View File

@@ -1,31 +1,15 @@
<div class="container"> <div class="container">
<ds-alert [content]="'submission.sections.notify.info'" [dismissible]="true" [type]="AlertTypeEnum.Info"></ds-alert>
<ds-alert [content]="'submission.sections.notify.info'"
[dismissible]="true"
[type]="AlertTypeEnum.Info"></ds-alert>
<div class="dropdown-section"> <div class="dropdown-section">
<div class="dropdown"> <ng-container *ngIf="patternsLoaded">
<label>Request a Review at the following service</label> <div class="dropdown" *ngFor="let pattern of patterns">
<select [(ngModel)]="requestReview"> <label>Request a {{ pattern }} at the following service</label>
<option *ngFor="let reviewPatternService of (ldnServicesRD$ | async)?.payload?.page" <select [(ngModel)]="selectedServices[pattern]">
[value]="reviewPatternService">{{ reviewPatternService.name }}</option> <option *ngFor="let service of (ldnServicesRD$ | async)?.payload?.page" [value]="service">
</select> {{ service.name }}
</div> </option>
</select>
<div class="dropdown"> </div>
<label>Request an Endorsement at the following service</label> </ng-container>
<select [(ngModel)]="requestEndorsement">
<option *ngFor="let endorsementPatternService of (coarNotifyConfigRD$ | async)?.payload?.page"
[value]="endorsementPatternService">{{ endorsementPatternService.patterns }}</option>
</select>
</div>
<div class="dropdown">
<label>Dropdown 3</label>
<select [(ngModel)]="requestIngest">
<option *ngFor="let ingestPatternService of (ldnServicesRD$ | async)?.payload?.page"
[value]="ingestPatternService">{{ ingestPatternService.name }}</option>
</select>
</div>
</div> </div>
</div> </div>

View File

@@ -57,12 +57,11 @@ export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent
ldnServicesRD$: Observable<RemoteData<PaginatedList<LdnService>>>; ldnServicesRD$: Observable<RemoteData<PaginatedList<LdnService>>>;
selectedServiceValues: any[] = [];
/** patterns: string[] = [];
* The AlertType enumeration selectedServices: { [key: string]: LdnService } = {};
* @type {AlertType} patternsLoaded = false;
*/
public AlertTypeEnum = AlertType; public AlertTypeEnum = AlertType;
/** /**
* The form model * The form model
@@ -171,7 +170,15 @@ export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent
*/ */
setCoarNotifyConfig() { setCoarNotifyConfig() {
this.coarNotifyConfigRD$ = this.coarNotifyConfigDataService.findAll().pipe( this.coarNotifyConfigRD$ = this.coarNotifyConfigDataService.findAll().pipe(
getFirstCompletedRemoteData()); getFirstCompletedRemoteData()
);
this.coarNotifyConfigRD$.subscribe((data) => {
if (data.hasSucceeded) {
this.patterns = data.payload.page[0].patterns;
this.patternsLoaded = true;
}
});
} }
/** /**
@@ -181,10 +188,10 @@ export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent
*/ */
onCustomEvent(event: DynamicFormControlEvent) { onCustomEvent(event: DynamicFormControlEvent) {
this.formOperationsService.dispatchOperationsFromEvent( this.formOperationsService.dispatchOperationsFromEvent(
this.pathCombiner, this.pathCombiner,
event, event,
this.previousValue, this.previousValue,
null); null);
} }
/** /**
@@ -223,10 +230,10 @@ export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent
} }
this.formOperationsService.dispatchOperationsFromEvent( this.formOperationsService.dispatchOperationsFromEvent(
this.pathCombiner, this.pathCombiner,
event, event,
this.previousValue, this.previousValue,
this.hasStoredValue(fieldId, fieldIndex)); this.hasStoredValue(fieldId, fieldIndex));
} }
@@ -241,8 +248,8 @@ export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent
hasStoredValue(fieldId, index): boolean { hasStoredValue(fieldId, index): boolean {
if (isNotEmpty(this.sectionData.data)) { if (isNotEmpty(this.sectionData.data)) {
return this.sectionData.data.hasOwnProperty(fieldId) && return this.sectionData.data.hasOwnProperty(fieldId) &&
isNotEmpty(this.sectionData.data[fieldId][index]) && isNotEmpty(this.sectionData.data[fieldId][index]) &&
!this.isFieldToRemove(fieldId, index); !this.isFieldToRemove(fieldId, index);
} else { } else {
return false; return false;
} }
@@ -284,8 +291,8 @@ export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent
*/ */
onSectionDestroy() { onSectionDestroy() {
this.subs this.subs
.filter((subscription) => hasValue(subscription)) .filter((subscription) => hasValue(subscription))
.forEach((subscription) => subscription.unsubscribe()); .forEach((subscription) => subscription.unsubscribe());
} }
/** /**
@@ -293,9 +300,19 @@ export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent
* Retriev available NotifyConfigs * Retriev available NotifyConfigs
*/ */
fetchLdnServices() { fetchLdnServices() {
this.ldnServicesRD$ = this.ldnServicesService.findAll().pipe( this.ldnServicesRD$ = this.ldnServicesService.findAll().pipe(
getFirstCompletedRemoteData() getFirstCompletedRemoteData()
); );
this.ldnServicesRD$.subscribe((data) => {
if (this.patternsLoaded) {
this.patterns.forEach((pattern) => {
this.selectedServices[pattern] = data.payload.page.find((service) =>
this.hasInboundPattern(service, `Request ${pattern}`)
);
});
}
});
} }
protected getSectionStatus(): Observable<boolean> { protected getSectionStatus(): Observable<boolean> {