From 4e21bdaf1fc4d4b19ef9e6fa4e24328ab87dab22 Mon Sep 17 00:00:00 2001 From: Alessandro Martelli Date: Fri, 9 Apr 2021 10:16:56 +0200 Subject: [PATCH 1/3] [CST-3782] repeatable with lookup fixes --- .../ds-dynamic-form-control-container.component.html | 2 ++ .../ds-dynamic-form-control-container.component.ts | 8 +++++--- .../existing-metadata-list-element.component.html | 1 + .../existing-metadata-list-element.component.spec.ts | 3 +++ .../existing-metadata-list-element.component.ts | 6 +++++- .../existing-relation-list-element.component.html | 1 + .../existing-relation-list-element.component.spec.ts | 3 +++ .../existing-relation-list-element.component.ts | 4 ++++ 8 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html index bfa9c214e9e..7c0c08382a2 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html @@ -54,6 +54,7 @@ [metadataFields]="model.metadataFields" [submissionId]="model.submissionId" [relationshipOptions]="model.relationship" + [canRemove]="canRemove()" (remove)="onRemove()" > @@ -66,6 +67,7 @@ [metadataFields]="model.metadataFields" [submissionId]="model.submissionId" [relationshipOptions]="model.relationship" + [canRemove]="canRemove()" > 1; + } + /** * Initialize this.item$ based on this.model.submissionId */ diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.html index 07ea131a008..5275cef68ae 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.html @@ -9,6 +9,7 @@ diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.spec.ts index 3a5623cfddb..2a38a077594 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.spec.ts @@ -16,6 +16,8 @@ import { ItemSearchResult } from '../../../../object-collection/shared/item-sear import { of as observableOf } from 'rxjs'; import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; import { TranslateLoaderMock } from '../../../../testing/translate-loader.mock'; +import { SubmissionService } from '../../../../../submission/submission.service'; +import { SubmissionServiceStub } from '../../../../testing/submission-service.stub'; describe('ExistingMetadataListElementComponent', () => { let component: ExistingMetadataListElementComponent; @@ -79,6 +81,7 @@ describe('ExistingMetadataListElementComponent', () => { providers: [ { provide: SelectableListService, useValue: selectionService }, { provide: Store, useValue: store }, + { provide: SubmissionService, useClass: SubmissionServiceStub }, ], schemas: [NO_ERRORS_SCHEMA] }) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts index d0d4ad435bc..927d5e04d23 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts @@ -19,6 +19,7 @@ import { FormFieldMetadataValueObject } from '../../models/form-field-metadata-v import { RelationshipOptions } from '../../models/relationship-options.model'; import { DynamicConcatModel } from '../models/ds-dynamic-concat.model'; import { RemoveRelationshipAction } from '../relation-lookup-modal/relationship.actions'; +import { SubmissionService } from '../../../../../submission/submission.service'; // tslint:disable:max-classes-per-file /** @@ -145,6 +146,7 @@ export class ExistingMetadataListElementComponent implements OnInit, OnChanges, @Input() metadataFields: string[]; @Input() relationshipOptions: RelationshipOptions; @Input() submissionId: string; + @Input() canRemove = true; metadataRepresentation$: BehaviorSubject = new BehaviorSubject(undefined); relatedItem: Item; @Output() remove: EventEmitter = new EventEmitter(); @@ -155,7 +157,8 @@ export class ExistingMetadataListElementComponent implements OnInit, OnChanges, constructor( private selectableListService: SelectableListService, - private store: Store + private store: Store, + private submissionService: SubmissionService ) { } @@ -194,6 +197,7 @@ export class ExistingMetadataListElementComponent implements OnInit, OnChanges, * Removes the selected relationship from the list */ removeSelection() { + this.submissionService.dispatchSave(this.submissionId); this.selectableListService.deselectSingle(this.listId, Object.assign(new ItemSearchResult(), { indexableObject: this.relatedItem })); this.store.dispatch(new RemoveRelationshipAction(this.submissionItem, this.relatedItem, this.relationshipOptions.relationshipType, this.submissionId)); this.remove.emit(); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html index 15087d25531..ed29fd14e39 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html @@ -8,6 +8,7 @@ diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.spec.ts index fddb9605157..d733f503bba 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.spec.ts @@ -12,6 +12,8 @@ import { ItemSearchResult } from '../../../../object-collection/shared/item-sear import { of as observableOf } from 'rxjs'; import { ReorderableRelationship } from '../existing-metadata-list-element/existing-metadata-list-element.component'; import { createSuccessfulRemoteDataObject$ } from '../../../../remote-data.utils'; +import { SubmissionService } from '../../../../../submission/submission.service'; +import { SubmissionServiceStub } from '../../../../testing/submission-service.stub'; describe('ExistingRelationListElementComponent', () => { let component: ExistingRelationListElementComponent; @@ -67,6 +69,7 @@ describe('ExistingRelationListElementComponent', () => { providers: [ { provide: SelectableListService, useValue: selectionService }, { provide: Store, useValue: store }, + { provide: SubmissionService, useClass: SubmissionServiceStub }, ], schemas: [NO_ERRORS_SCHEMA] }) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts index 8a4a7120e89..6d7e846bcb7 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts @@ -12,6 +12,7 @@ import { RelationshipOptions } from '../../models/relationship-options.model'; import { RemoveRelationshipAction } from '../relation-lookup-modal/relationship.actions'; import { ViewMode } from '../../../../../core/shared/view-mode.model'; import { ReorderableRelationship } from '../existing-metadata-list-element/existing-metadata-list-element.component'; +import { SubmissionService } from '../../../../../submission/submission.service'; // tslint:disable:max-classes-per-file /** @@ -61,6 +62,7 @@ export class ExistingRelationListElementComponent implements OnInit, OnChanges, @Input() metadataFields: string[]; @Input() relationshipOptions: RelationshipOptions; @Input() submissionId: string; + @Input() canRemove = true; relatedItem$: BehaviorSubject = new BehaviorSubject(undefined); viewType = ViewMode.ListElement; @Output() remove: EventEmitter = new EventEmitter(); @@ -72,6 +74,7 @@ export class ExistingRelationListElementComponent implements OnInit, OnChanges, constructor( private selectableListService: SelectableListService, + private submissionService: SubmissionService, private store: Store ) { } @@ -102,6 +105,7 @@ export class ExistingRelationListElementComponent implements OnInit, OnChanges, * Removes the selected relationship from the list */ removeSelection() { + this.submissionService.dispatchSave(this.submissionId); this.selectableListService.deselectSingle(this.listId, Object.assign(new ItemSearchResult(), { indexableObject: this.relatedItem$.getValue() })); this.store.dispatch(new RemoveRelationshipAction(this.submissionItem, this.relatedItem$.getValue(), this.relationshipOptions.relationshipType, this.submissionId)); } From b537f70d7bc8186e78b206c22e0d0935131524ad Mon Sep 17 00:00:00 2001 From: Alessandro Martelli Date: Mon, 12 Apr 2021 10:04:34 +0200 Subject: [PATCH 2/3] [CST-3782] possibility to remove the only relationship --- .../ds-dynamic-form-control-container.component.html | 2 -- .../ds-dynamic-form-control-container.component.ts | 7 +++---- .../existing-metadata-list-element.component.html | 1 - .../existing-metadata-list-element.component.ts | 1 - .../existing-relation-list-element.component.html | 1 - .../existing-relation-list-element.component.ts | 1 - 6 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html index 7c0c08382a2..bfa9c214e9e 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html @@ -54,7 +54,6 @@ [metadataFields]="model.metadataFields" [submissionId]="model.submissionId" [relationshipOptions]="model.relationship" - [canRemove]="canRemove()" (remove)="onRemove()" > @@ -67,7 +66,6 @@ [metadataFields]="model.metadataFields" [submissionId]="model.submissionId" [relationshipOptions]="model.relationship" - [canRemove]="canRemove()" > 1; - } - /** * Initialize this.item$ based on this.model.submissionId */ diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.html index 5275cef68ae..07ea131a008 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.html @@ -9,7 +9,6 @@ diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts index 927d5e04d23..29097d13373 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts @@ -146,7 +146,6 @@ export class ExistingMetadataListElementComponent implements OnInit, OnChanges, @Input() metadataFields: string[]; @Input() relationshipOptions: RelationshipOptions; @Input() submissionId: string; - @Input() canRemove = true; metadataRepresentation$: BehaviorSubject = new BehaviorSubject(undefined); relatedItem: Item; @Output() remove: EventEmitter = new EventEmitter(); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html index ed29fd14e39..15087d25531 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.html @@ -8,7 +8,6 @@ diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts index 6d7e846bcb7..8e55f32ee6b 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component.ts @@ -62,7 +62,6 @@ export class ExistingRelationListElementComponent implements OnInit, OnChanges, @Input() metadataFields: string[]; @Input() relationshipOptions: RelationshipOptions; @Input() submissionId: string; - @Input() canRemove = true; relatedItem$: BehaviorSubject = new BehaviorSubject(undefined); viewType = ViewMode.ListElement; @Output() remove: EventEmitter = new EventEmitter(); From 31e4aa788ee484815c3588a7077e56d11af1068a Mon Sep 17 00:00:00 2001 From: Alessandro Martelli Date: Tue, 13 Apr 2021 09:51:05 +0200 Subject: [PATCH 3/3] [CST-3782] lookup click doesn't clear the plain value --- ...ynamic-form-control-container.component.ts | 19 +++++++++++++++++++ ...ng-metadata-list-element.component.spec.ts | 5 ++++- ...xisting-metadata-list-element.component.ts | 13 +++++++++---- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts index a2ed538ce64..b8024346f5f 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts @@ -37,6 +37,7 @@ import { DynamicFormControl, DynamicFormControlContainerComponent, DynamicFormControlEvent, + DynamicFormControlEventType, DynamicFormControlModel, DynamicFormLayout, DynamicFormLayoutService, @@ -394,6 +395,24 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo size: 'lg' }); + if (hasValue(this.model.value)) { + this.focus.emit({ + $event: new Event('focus'), + context: this.context, + control: this.control, + model: this.model, + type: DynamicFormControlEventType.Focus + } as DynamicFormControlEvent); + + this.change.emit({ + $event: new Event('change'), + context: this.context, + control: this.control, + model: this.model, + type: DynamicFormControlEventType.Change + } as DynamicFormControlEvent); + } + this.submissionService.dispatchSave(this.model.submissionId); const modalComp = this.modalRef.componentInstance; diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.spec.ts index 2a38a077594..b5af2a8843f 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.spec.ts @@ -38,6 +38,7 @@ describe('ExistingMetadataListElementComponent', () => { let relatedSearchResult; let submissionId; let relationshipService; + let submissionServiceStub; function init() { uuid1 = '91ce578d-2e63-4093-8c73-3faafd716000'; @@ -64,6 +65,8 @@ describe('ExistingMetadataListElementComponent', () => { relationship = Object.assign(new Relationship(), { leftItem: leftItemRD$, rightItem: rightItemRD$ }); submissionId = '1234'; reoRel = new ReorderableRelationship(relationship, true, {} as any, {} as any, submissionId); + submissionServiceStub = new SubmissionServiceStub(); + submissionServiceStub.getSubmissionObject.and.returnValue(observableOf({})); } beforeEach(waitForAsync(() => { @@ -81,7 +84,7 @@ describe('ExistingMetadataListElementComponent', () => { providers: [ { provide: SelectableListService, useValue: selectionService }, { provide: Store, useValue: store }, - { provide: SubmissionService, useClass: SubmissionServiceStub }, + { provide: SubmissionService, useValue: submissionServiceStub }, ], schemas: [NO_ERRORS_SCHEMA] }) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts index 29097d13373..899400eba04 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts @@ -3,7 +3,7 @@ import { FormControl } from '@angular/forms'; import { DynamicFormArrayGroupModel } from '@ng-dynamic-forms/core'; import { Store } from '@ngrx/store'; import { BehaviorSubject, Subscription } from 'rxjs'; -import { filter } from 'rxjs/operators'; +import { filter, take } from 'rxjs/operators'; import { AppState } from '../../../../../app.reducer'; import { RelationshipService } from '../../../../../core/data/relationship.service'; import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model'; @@ -20,6 +20,7 @@ import { RelationshipOptions } from '../../models/relationship-options.model'; import { DynamicConcatModel } from '../models/ds-dynamic-concat.model'; import { RemoveRelationshipAction } from '../relation-lookup-modal/relationship.actions'; import { SubmissionService } from '../../../../../submission/submission.service'; +import { SubmissionObjectEntry } from '../../../../../submission/objects/submission-objects.reducer'; // tslint:disable:max-classes-per-file /** @@ -197,9 +198,13 @@ export class ExistingMetadataListElementComponent implements OnInit, OnChanges, */ removeSelection() { this.submissionService.dispatchSave(this.submissionId); - this.selectableListService.deselectSingle(this.listId, Object.assign(new ItemSearchResult(), { indexableObject: this.relatedItem })); - this.store.dispatch(new RemoveRelationshipAction(this.submissionItem, this.relatedItem, this.relationshipOptions.relationshipType, this.submissionId)); - this.remove.emit(); + this.submissionService.getSubmissionObject(this.submissionId).pipe( + filter((state: SubmissionObjectEntry) => !state.savePending && !state.isLoading), + take(1)).subscribe(() => { + this.selectableListService.deselectSingle(this.listId, Object.assign(new ItemSearchResult(), { indexableObject: this.relatedItem })); + this.store.dispatch(new RemoveRelationshipAction(this.submissionItem, this.relatedItem, this.relationshipOptions.relationshipType, this.submissionId)); + this.remove.emit(); + }); } /**