mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
made sure added relationships are shown again, resolved issues with duplicate entries + other bug fixes
This commit is contained in:
@@ -30,6 +30,7 @@ import { ItemDataService } from './item-data.service';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { RemoteData, RemoteDataState } from './remote-data';
|
||||
import { RequestService } from './request.service';
|
||||
import { MetadataValue, VIRTUAL_METADATA_PREFIX } from '../shared/metadata.models';
|
||||
|
||||
const relationshipListsStateSelector = (state: AppState) => state.relationshipLists;
|
||||
|
||||
@@ -412,4 +413,15 @@ export class RelationshipService extends DataService<Relationship> {
|
||||
return update$;
|
||||
}
|
||||
|
||||
public toVirtualMetadata(relationship: Relationship, useLeft: boolean): MetadataValue {
|
||||
const metadataValue = new MetadataValue();
|
||||
metadataValue.authority = VIRTUAL_METADATA_PREFIX + relationship.id;
|
||||
// What if there's no name variant?
|
||||
if (useLeft) {
|
||||
metadataValue.value = relationship.leftwardValue
|
||||
} else {
|
||||
metadataValue.value = relationship.rightwardValue
|
||||
}
|
||||
return metadataValue;
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
<ng-container *ngTemplateOutlet="startTemplate?.templateRef; context: model"></ng-container>
|
||||
<!-- Should be *ngIf instead of class d-none, but that breaks the #componentViewContainer reference-->
|
||||
<div [ngClass]="{'form-row': model.hasLanguages || hasRelationLookup, 'd-none': relationshipValue$ | async}">
|
||||
<div [ngClass]="{'form-row': model.hasLanguages || isRelationship, 'd-none': relationshipValue$ | async}">
|
||||
<div [ngClass]="getClass('grid', 'control')">
|
||||
|
||||
<ng-container #componentViewContainer></ng-container>
|
||||
@@ -37,7 +37,7 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div *ngIf="hasRelationLookup && context?.index < 1" class="col-auto text-center">
|
||||
<div *ngIf="isRelationship && context?.index < 1" class="col-auto text-center">
|
||||
<button class="btn btn-secondary"
|
||||
type="submit"
|
||||
ngbTooltip="{{'form.lookup-help' | translate}}"
|
||||
@@ -55,6 +55,7 @@
|
||||
[submissionItem]="item"
|
||||
[listId]="listId"
|
||||
[metadataFields]="model.metadataFields"
|
||||
[submissionId]="model.submissionId"
|
||||
[relationshipOptions]="model.relationship">
|
||||
</ds-existing-metadata-list-element>
|
||||
</ng-container>
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
ChangeDetectionStrategy, ChangeDetectorRef,
|
||||
ChangeDetectionStrategy,
|
||||
ChangeDetectorRef,
|
||||
Component,
|
||||
ComponentFactoryResolver,
|
||||
ContentChildren,
|
||||
@@ -16,7 +17,7 @@ import {
|
||||
ViewChild,
|
||||
ViewContainerRef
|
||||
} from '@angular/core';
|
||||
import { FormArray, FormGroup } from '@angular/forms';
|
||||
import { FormGroup } from '@angular/forms';
|
||||
|
||||
import {
|
||||
DYNAMIC_FORM_CONTROL_TYPE_ARRAY,
|
||||
@@ -29,7 +30,7 @@ import {
|
||||
DYNAMIC_FORM_CONTROL_TYPE_SELECT,
|
||||
DYNAMIC_FORM_CONTROL_TYPE_TEXTAREA,
|
||||
DYNAMIC_FORM_CONTROL_TYPE_TIMEPICKER,
|
||||
DynamicDatePickerModel, DynamicFormArrayModel,
|
||||
DynamicDatePickerModel,
|
||||
DynamicFormControl,
|
||||
DynamicFormControlContainerComponent,
|
||||
DynamicFormControlEvent,
|
||||
@@ -50,10 +51,7 @@ import {
|
||||
DynamicNGBootstrapTimePickerComponent
|
||||
} from '@ng-dynamic-forms/ui-ng-bootstrap';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import {
|
||||
Reorderable,
|
||||
ReorderableRelationship
|
||||
} from './existing-metadata-list-element/existing-metadata-list-element.component';
|
||||
import { ReorderableRelationship } from './existing-metadata-list-element/existing-metadata-list-element.component';
|
||||
|
||||
import { DYNAMIC_FORM_CONTROL_TYPE_TYPEAHEAD } from './models/typeahead/dynamic-typeahead.model';
|
||||
import { DYNAMIC_FORM_CONTROL_TYPE_SCROLLABLE_DROPDOWN } from './models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
|
||||
@@ -75,8 +73,8 @@ import { DsDynamicFormArrayComponent } from './models/array-group/dynamic-form-a
|
||||
import { DsDynamicRelationGroupComponent } from './models/relation-group/dynamic-relation-group.components';
|
||||
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './models/relation-group/dynamic-relation-group.model';
|
||||
import { DsDatePickerInlineComponent } from './models/date-picker-inline/dynamic-date-picker-inline.component';
|
||||
import { map, startWith, switchMap, take } from 'rxjs/operators';
|
||||
import { combineLatest as observableCombineLatest, Observable, of as observableOf, Subscription } from 'rxjs';
|
||||
import { map, switchMap, take } from 'rxjs/operators';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { SearchResult } from '../../../search/search-result.model';
|
||||
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
|
||||
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
|
||||
@@ -95,10 +93,10 @@ import { SubmissionObjectDataService } from '../../../../core/submission/submiss
|
||||
import { SubmissionObject } from '../../../../core/submission/models/submission-object.model';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||
import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model';
|
||||
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
||||
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
|
||||
import { MetadataValue } from '../../../../core/shared/metadata.models';
|
||||
import { DynamicRowArrayModel } from './models/ds-dynamic-row-array-model';
|
||||
import { FormService } from '../../form.service';
|
||||
import { combineLatest as observableCombineLatest } from 'rxjs';
|
||||
|
||||
export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type<DynamicFormControl> | null {
|
||||
switch (model.type) {
|
||||
@@ -183,7 +181,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
@Input() layout = null as DynamicFormLayout;
|
||||
@Input() model: any;
|
||||
relationshipValue$: Observable<ReorderableRelationship>;
|
||||
hasRelationLookup: boolean;
|
||||
isRelationship: boolean;
|
||||
modalRef: NgbModalRef;
|
||||
item: Item;
|
||||
listId: string;
|
||||
@@ -221,7 +219,8 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
private zone: NgZone,
|
||||
private store: Store<AppState>,
|
||||
private submissionObjectService: SubmissionObjectDataService,
|
||||
private ref: ChangeDetectorRef
|
||||
private ref: ChangeDetectorRef,
|
||||
private formService: FormService
|
||||
) {
|
||||
super(componentFactoryResolver, layoutService, validationService);
|
||||
}
|
||||
@@ -230,29 +229,17 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
* Sets up the necessary variables for when this control can be used to add relationships to the submitted item
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.hasRelationLookup = hasValue(this.model.relationship);
|
||||
if (this.hasRelationLookup) {
|
||||
|
||||
this.isRelationship = hasValue(this.model.relationship);
|
||||
if (this.isRelationship) {
|
||||
this.listId = 'list-' + this.model.relationship.relationshipType;
|
||||
const item$ = this.submissionObjectService
|
||||
.findById(this.model.submissionId).pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
switchMap((submissionObject: SubmissionObject) => (submissionObject.item as Observable<RemoteData<Item>>)
|
||||
.pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
getRemoteDataPayload()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
this.subs.push(item$.subscribe((item) => this.item = item));
|
||||
this.setItem();
|
||||
const value = Object.assign(new MetadataValue(), this.model.value);
|
||||
if (hasValue(value) && value.isVirtual) {
|
||||
this.relationshipValue$ = this.relationshipService.findById(value.virtualValue)
|
||||
const relationship$ = this.relationshipService.findById(value.virtualValue)
|
||||
.pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
getRemoteDataPayload());
|
||||
this.relationshipValue$ = relationship$.pipe(
|
||||
switchMap((relationship: Relationship) =>
|
||||
relationship.leftItem.pipe(
|
||||
getSucceededRemoteData(),
|
||||
@@ -264,8 +251,10 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
this.relationService.getRelatedItemsByLabel(this.item, this.model.relationship.relationshipType).pipe(
|
||||
}
|
||||
if (this.model.relationshipConfig) {
|
||||
this.setItem();
|
||||
this.relationService.getRelatedItemsByLabel(this.item, this.model.relationshipConfig.relationshipType).pipe(
|
||||
map((items: RemoteData<PaginatedList<Item>>) => items.payload.page.map((item) => Object.assign(new ItemSearchResult(), { indexableObject: item }))),
|
||||
).subscribe((relatedItems: Array<SearchResult<Item>>) => this.selectableListService.select(this.listId, relatedItems));
|
||||
}
|
||||
@@ -316,6 +305,11 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
* Open a modal where the user can select relationships to be added to item being submitted
|
||||
*/
|
||||
openLookup() {
|
||||
// const event = this.createDynamicFormControlEvent(new CustomEvent('open'), 'change');
|
||||
// event.control = this.control;
|
||||
// event.model = this.model;
|
||||
// this.onChange(event);
|
||||
this.formService.removeForm(this.formId);
|
||||
this.modalRef = this.modalService.open(DsDynamicLookupRelationModalComponent, {
|
||||
size: 'lg'
|
||||
});
|
||||
@@ -328,6 +322,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
modalComp.relationshipOptions = this.model.relationship;
|
||||
modalComp.metadataFields = this.model.metadataFields;
|
||||
modalComp.item = this.item;
|
||||
modalComp.submissionId = this.model.submissionId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,4 +333,20 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
.filter((sub) => hasValue(sub))
|
||||
.forEach((sub) => sub.unsubscribe());
|
||||
}
|
||||
|
||||
private setItem() {
|
||||
const item$ = this.submissionObjectService
|
||||
.findById(this.model.submissionId).pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
switchMap((submissionObject: SubmissionObject) => (submissionObject.item as Observable<RemoteData<Item>>)
|
||||
.pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
getRemoteDataPayload()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
this.subs.push(item$.subscribe((item) => this.item = item));
|
||||
}
|
||||
}
|
||||
|
@@ -8,5 +8,5 @@
|
||||
[ngClass]="[getClass(model, 'element', 'host'), getClass(model, 'grid', 'host')]"
|
||||
[templates]="templates"
|
||||
(dfBlur)="onEvent($event, 'blur')"
|
||||
(dfChange)="onEvent($event, 'change')"
|
||||
(dfChange)="onEvent($event, 'change'); log('test')"
|
||||
(dfFocus)="onEvent($event, 'focus')"></ds-dynamic-form-control-container>
|
||||
|
@@ -37,4 +37,8 @@ export class DsDynamicFormComponent extends DynamicFormComponent {
|
||||
constructor(protected formService: FormBuilderService, protected layoutService: DynamicFormLayoutService) {
|
||||
super(formService, layoutService);
|
||||
}
|
||||
|
||||
log(t: string) {
|
||||
console.log(t);
|
||||
}
|
||||
}
|
||||
|
@@ -125,6 +125,7 @@ export class ExistingMetadataListElementComponent implements OnChanges, OnDestro
|
||||
@Input() reoRel: ReorderableRelationship;
|
||||
@Input() metadataFields: string[];
|
||||
@Input() relationshipOptions: RelationshipOptions;
|
||||
@Input() submissionId: string;
|
||||
metadataRepresentation: MetadataRepresentation;
|
||||
relatedItem: Item;
|
||||
|
||||
@@ -161,7 +162,7 @@ export class ExistingMetadataListElementComponent implements OnChanges, OnDestro
|
||||
|
||||
removeSelection() {
|
||||
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.store.dispatch(new RemoveRelationshipAction(this.submissionItem, this.relatedItem, this.relationshipOptions.relationshipType, this.submissionId))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -159,7 +159,6 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple
|
||||
if (reorderable.hasMoved) {
|
||||
const prevIndex = reorderable.oldIndex;
|
||||
reorderable.update().pipe(take(1)).subscribe((v) => {
|
||||
console.log(reorderable, index);
|
||||
if (reorderable instanceof ReorderableFormFieldMetadataValue) {
|
||||
const reoMD = reorderable as ReorderableFormFieldMetadataValue;
|
||||
const mdl = Object.assign({}, reoMD.model, { value: reoMD.metadataValue });
|
||||
@@ -189,9 +188,10 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple
|
||||
if (hasNoValue($event.context)) {
|
||||
const context = Object.assign({}, $event.context, { index: this.reorderables.length });
|
||||
event = Object.assign({}, $event, { context });
|
||||
super.onChange(event);
|
||||
} else {
|
||||
this.updateReorderables();
|
||||
}
|
||||
super.onChange(event);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { DynamicFormArrayModel, DynamicFormArrayModelConfig, DynamicFormControlLayout, serializable } from '@ng-dynamic-forms/core';
|
||||
import { RelationshipOptions } from '../../models/relationship-options.model';
|
||||
|
||||
export interface DynamicRowArrayModelConfig extends DynamicFormArrayModelConfig {
|
||||
notRepeatable: boolean;
|
||||
required: boolean;
|
||||
submissionId: string;
|
||||
hasRelationship: boolean;
|
||||
relationshipConfig: RelationshipOptions;
|
||||
metadataKey: string;
|
||||
}
|
||||
|
||||
@@ -12,7 +13,7 @@ export class DynamicRowArrayModel extends DynamicFormArrayModel {
|
||||
@serializable() notRepeatable = false;
|
||||
@serializable() required = false;
|
||||
@serializable() submissionId: string;
|
||||
@serializable() hasRelationship: boolean;
|
||||
@serializable() relationshipConfig: RelationshipOptions;
|
||||
@serializable() metadataKey: string;
|
||||
isRowArray = true;
|
||||
|
||||
@@ -21,7 +22,7 @@ export class DynamicRowArrayModel extends DynamicFormArrayModel {
|
||||
this.notRepeatable = config.notRepeatable;
|
||||
this.required = config.required;
|
||||
this.submissionId = config.submissionId;
|
||||
this.hasRelationship = config.hasRelationship;
|
||||
this.relationshipConfig = config.relationshipConfig;
|
||||
this.metadataKey = config.metadataKey;
|
||||
}
|
||||
}
|
||||
|
@@ -45,6 +45,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
subMap: {
|
||||
[uuid: string]: Subscription
|
||||
} = {};
|
||||
submissionId: string;
|
||||
|
||||
constructor(
|
||||
public modal: NgbActiveModal,
|
||||
@@ -92,7 +93,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
obs
|
||||
.subscribe((arr: any[]) => {
|
||||
return arr.forEach((object: any) => {
|
||||
this.store.dispatch(new AddRelationshipAction(this.item, object.item, this.relationshipOptions.relationshipType, object.nameVariant));
|
||||
this.store.dispatch(new AddRelationshipAction(this.item, object.item, this.relationshipOptions.relationshipType, this.submissionId, object.nameVariant));
|
||||
}
|
||||
);
|
||||
})
|
||||
@@ -103,14 +104,14 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
const nameVariant$ = this.relationshipService.getNameVariant(this.listId, sri.indexableObject.uuid);
|
||||
this.subMap[sri.indexableObject.uuid] = nameVariant$.pipe(
|
||||
skip(1),
|
||||
).subscribe((nameVariant: string) => this.store.dispatch(new UpdateRelationshipAction(this.item, sri.indexableObject, this.relationshipOptions.relationshipType, nameVariant)))
|
||||
).subscribe((nameVariant: string) => this.store.dispatch(new UpdateRelationshipAction(this.item, sri.indexableObject, this.relationshipOptions.relationshipType, this.submissionId, nameVariant)))
|
||||
}
|
||||
|
||||
deselect(...selectableObjects: Array<SearchResult<Item>>) {
|
||||
this.zone.runOutsideAngular(
|
||||
() => selectableObjects.forEach((object) => {
|
||||
this.subMap[object.indexableObject.uuid].unsubscribe();
|
||||
this.store.dispatch(new RemoveRelationshipAction(this.item, object.indexableObject, this.relationshipOptions.relationshipType));
|
||||
this.store.dispatch(new RemoveRelationshipAction(this.item, object.indexableObject, this.relationshipOptions.relationshipType, this.submissionId));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ export class AddRelationshipAction implements Action {
|
||||
item1: Item;
|
||||
item2: Item;
|
||||
relationshipType: string;
|
||||
submissionId: string;
|
||||
nameVariant: string;
|
||||
};
|
||||
|
||||
@@ -37,9 +38,10 @@ export class AddRelationshipAction implements Action {
|
||||
item1: Item,
|
||||
item2: Item,
|
||||
relationshipType: string,
|
||||
submissionId: string,
|
||||
nameVariant?: string
|
||||
) {
|
||||
this.payload = { item1, item2, relationshipType, nameVariant };
|
||||
this.payload = { item1, item2, relationshipType, submissionId, nameVariant };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +52,7 @@ export class UpdateRelationshipAction implements Action {
|
||||
item1: Item;
|
||||
item2: Item;
|
||||
relationshipType: string;
|
||||
submissionId: string;
|
||||
nameVariant: string;
|
||||
};
|
||||
|
||||
@@ -65,9 +68,10 @@ export class UpdateRelationshipAction implements Action {
|
||||
item1: Item,
|
||||
item2: Item,
|
||||
relationshipType: string,
|
||||
submissionId: string,
|
||||
nameVariant?: string
|
||||
) {
|
||||
this.payload = { item1, item2, relationshipType, nameVariant };
|
||||
this.payload = { item1, item2, relationshipType, submissionId, nameVariant };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +85,7 @@ export class RemoveRelationshipAction implements Action {
|
||||
item1: Item;
|
||||
item2: Item;
|
||||
relationshipType: string;
|
||||
submissionId: string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -93,8 +98,10 @@ export class RemoveRelationshipAction implements Action {
|
||||
constructor(
|
||||
item1: Item,
|
||||
item2: Item,
|
||||
relationshipType: string) {
|
||||
this.payload = { item1, item2, relationshipType };
|
||||
relationshipType: string,
|
||||
submissionId: string
|
||||
) {
|
||||
this.payload = { item1, item2, relationshipType, submissionId };
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,15 +1,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Actions, Effect, ofType } from '@ngrx/effects';
|
||||
import { debounceTime, map, mergeMap, take, tap } from 'rxjs/operators';
|
||||
import { debounceTime, map, mergeMap, switchMap, take } from 'rxjs/operators';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { RelationshipService } from '../../../../../core/data/relationship.service';
|
||||
import { getSucceededRemoteData } from '../../../../../core/shared/operators';
|
||||
import { AddRelationshipAction, RelationshipAction, RelationshipActionTypes, RemoveRelationshipAction, UpdateRelationshipAction } from './relationship.actions';
|
||||
import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../../core/shared/operators';
|
||||
import { AddRelationshipAction, RelationshipAction, RelationshipActionTypes, UpdateRelationshipAction } from './relationship.actions';
|
||||
import { Item } from '../../../../../core/shared/item.model';
|
||||
import { hasNoValue, hasValue, hasValueOperator } from '../../../../empty.util';
|
||||
import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model';
|
||||
import { RelationshipType } from '../../../../../core/shared/item-relationships/relationship-type.model';
|
||||
import { RelationshipTypeService } from '../../../../../core/data/relationship-type.service';
|
||||
import { SubmissionObjectDataService } from '../../../../../core/submission/submission-object-data.service';
|
||||
import { SaveSubmissionSectionFormSuccessAction } from '../../../../../submission/objects/submission-objects.actions';
|
||||
import { SubmissionObject } from '../../../../../core/submission/models/submission-object.model';
|
||||
import { SubmissionState } from '../../../../../submission/submission.reducers';
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
const DEBOUNCE_TIME = 5000;
|
||||
|
||||
@@ -40,7 +45,7 @@ export class RelationshipEffects {
|
||||
.pipe(
|
||||
ofType(RelationshipActionTypes.ADD_RELATIONSHIP, RelationshipActionTypes.REMOVE_RELATIONSHIP),
|
||||
map((action: RelationshipAction) => {
|
||||
const { item1, item2, relationshipType } = action.payload;
|
||||
const { item1, item2, submissionId, relationshipType } = action.payload;
|
||||
const identifier: string = this.createIdentifier(item1, item2, relationshipType);
|
||||
if (hasNoValue(this.debounceMap[identifier])) {
|
||||
this.initialActionMap[identifier] = action.type;
|
||||
@@ -57,13 +62,15 @@ export class RelationshipEffects {
|
||||
nameVariant = this.nameVariantUpdates[identifier];
|
||||
delete this.nameVariantUpdates[identifier];
|
||||
}
|
||||
this.addRelationship(item1, item2, relationshipType, nameVariant)
|
||||
this.addRelationship(item1, item2, relationshipType, submissionId, nameVariant);
|
||||
} else {
|
||||
this.removeRelationship(item1, item2, relationshipType);
|
||||
this.removeRelationship(item1, item2, relationshipType, submissionId);
|
||||
}
|
||||
|
||||
}
|
||||
delete this.debounceMap[identifier];
|
||||
delete this.initialActionMap[identifier];
|
||||
|
||||
}
|
||||
)
|
||||
} else {
|
||||
@@ -98,6 +105,8 @@ export class RelationshipEffects {
|
||||
constructor(private actions$: Actions,
|
||||
private relationshipService: RelationshipService,
|
||||
private relationshipTypeService: RelationshipTypeService,
|
||||
private submissionObjectService: SubmissionObjectDataService,
|
||||
private store: Store<SubmissionState>
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -105,7 +114,7 @@ export class RelationshipEffects {
|
||||
return `${item1.uuid}-${item2.uuid}-${relationshipType}`;
|
||||
}
|
||||
|
||||
private addRelationship(item1: Item, item2: Item, relationshipType: string, nameVariant?: string) {
|
||||
private addRelationship(item1: Item, item2: Item, relationshipType: string, submissionId: string, nameVariant?: string) {
|
||||
const type1: string = item1.firstMetadataValue('relationship.type');
|
||||
const type2: string = item2.firstMetadataValue('relationship.type');
|
||||
return this.relationshipTypeService.getRelationshipTypeByLabelAndTypes(relationshipType, type1, type2)
|
||||
@@ -119,16 +128,39 @@ export class RelationshipEffects {
|
||||
}
|
||||
}
|
||||
)
|
||||
).pipe(take(1))
|
||||
.subscribe();
|
||||
).pipe(take(1), switchMap(() => this.submissionObjectService.findById(submissionId).pipe(getSucceededRemoteData(), getRemoteDataPayload()))
|
||||
).subscribe((submissionObject: SubmissionObject) => this.store.dispatch(new SaveSubmissionSectionFormSuccessAction(submissionId, [submissionObject], false)));
|
||||
}
|
||||
|
||||
private removeRelationship(item1: Item, item2: Item, relationshipType: string) {
|
||||
private removeRelationship(item1: Item, item2: Item, relationshipType: string, submissionId: string) {
|
||||
this.relationshipService.getRelationshipByItemsAndLabel(item1, item2, relationshipType).pipe(
|
||||
take(1),
|
||||
hasValueOperator(),
|
||||
mergeMap((relationship: Relationship) => this.relationshipService.deleteRelationship(relationship.id)),
|
||||
take(1)
|
||||
).subscribe();
|
||||
take(1),
|
||||
switchMap(() => this.submissionObjectService.findById(submissionId).pipe(getSucceededRemoteData(), getRemoteDataPayload()))
|
||||
).subscribe((submissionObject: SubmissionObject) => this.store.dispatch(new SaveSubmissionSectionFormSuccessAction(submissionId, [submissionObject])));
|
||||
}
|
||||
|
||||
// private addAsMetadataInStore(submissionID: string, sectionID: string, metadataField: string, relationship: Relationship, repeatable: boolean, relationshipType: string) {
|
||||
// const sectionData$: Observable<WorkspaceitemSectionDataType> = this.sectionsService.getSectionData(submissionID, sectionID);
|
||||
// observableCombineLatest(
|
||||
// sectionData$.pipe(take(1)),
|
||||
// relationship.relationshipType.pipe(getSucceededRemoteData(), getRemoteDataPayload())
|
||||
// ).subscribe(
|
||||
// ([sectionData, relType]: [WorkspaceitemSectionDataType, RelationshipType]) => {
|
||||
// const useLeft = relType.rightwardType === relationshipType;
|
||||
// const value = this.relationshipService.toVirtualMetadata(relationship, useLeft);
|
||||
// let values;
|
||||
// if (repeatable) {
|
||||
// const existingValues: FormFieldMetadataValueObject[] = sectionData[metadataField];
|
||||
// values = [...existingValues, value];
|
||||
// } else {
|
||||
// values = [value];
|
||||
// }
|
||||
// sectionData[metadataField] = values;
|
||||
// this.sectionsService.updateSectionData(submissionID, sectionID, sectionData);
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
@@ -260,7 +260,7 @@ describe('FormBuilderService test suite', () => {
|
||||
id: 'testFormRowArray',
|
||||
initialCount: 5,
|
||||
notRepeatable: false,
|
||||
hasRelationship: false,
|
||||
relationshipConfig: undefined,
|
||||
submissionId: '1234',
|
||||
groupFactory: () => {
|
||||
return [
|
||||
|
@@ -51,7 +51,7 @@ export abstract class FieldParser {
|
||||
label: this.configData.label,
|
||||
initialCount: this.getInitArrayIndex(),
|
||||
notRepeatable: !this.configData.repeatable,
|
||||
hasRelationship: isNotEmpty(this.configData.selectableRelationship),
|
||||
relationshipConfig: this.configData.selectableRelationship,
|
||||
required: isNotEmpty(this.configData.mandatory),
|
||||
submissionId: this.submissionId,
|
||||
metadataKey,
|
||||
|
@@ -12,7 +12,7 @@
|
||||
(dfFocus)="onFocus($event)">
|
||||
<ng-template modelType="ARRAY" let-group let-index="index" let-context="context">
|
||||
<!--Array with repeatable items-->
|
||||
<div *ngIf="!context.notRepeatable && (!context.hasRelationship || (context.hasRelationship && index < 1))"
|
||||
<div *ngIf="!context.notRepeatable && (!context.relationshipConfig || (context.relationshipConfig && index < 1))"
|
||||
class="col-xs-2 d-flex flex-column justify-content-sm-start align-items-end">
|
||||
<div class="btn-group" role="group" aria-label="Add and remove button">
|
||||
<button type="button" class="btn btn-secondary"
|
||||
@@ -29,7 +29,7 @@
|
||||
</div>
|
||||
|
||||
<!--Array with non repeatable items - Only delete button-->
|
||||
<div *ngIf="context.notRepeatable && group.context.groups.length > 1 || (context.hasRelationship && index > 0 && !group.group[0]?.value?.isVirtual)"
|
||||
<div *ngIf="context.notRepeatable && group.context.groups.length > 1 || (context.relationshipConfig && index > 0 && !group.group[0]?.value?.isVirtual)"
|
||||
class="col-xs-2 d-flex flex-column justify-content-sm-start align-items-end">
|
||||
<div class="btn-group" role="group" aria-label="Remove button">
|
||||
<button type="button" class="btn btn-secondary"
|
||||
|
@@ -76,7 +76,7 @@ const rowArrayQualdropConfig = {
|
||||
id: 'row_QUALDROP_GROUP',
|
||||
initialCount: 1,
|
||||
notRepeatable: true,
|
||||
hasRelationship: false,
|
||||
relationshipConfig: undefined,
|
||||
groupFactory: () => {
|
||||
return [MockQualdropModel];
|
||||
},
|
||||
|
@@ -33,8 +33,8 @@ describe('ObjectCollectionComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(ObjectCollectionComponent);
|
||||
objectCollectionComponent = fixture.componentInstance;
|
||||
|
||||
}));
|
||||
|
||||
it('should only show the grid component when the viewmode is set to grid', () => {
|
||||
objectCollectionComponent.currentMode$ = observableOf(ViewMode.GridElement);
|
||||
|
||||
|
@@ -378,6 +378,7 @@ export class SaveSubmissionFormSuccessAction implements Action {
|
||||
payload: {
|
||||
submissionId: string;
|
||||
submissionObject: SubmissionObject[];
|
||||
notify?: boolean
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -388,8 +389,8 @@ export class SaveSubmissionFormSuccessAction implements Action {
|
||||
* @param submissionObject
|
||||
* the submission's Object
|
||||
*/
|
||||
constructor(submissionId: string, submissionObject: SubmissionObject[]) {
|
||||
this.payload = { submissionId, submissionObject };
|
||||
constructor(submissionId: string, submissionObject: SubmissionObject[], notify?: boolean) {
|
||||
this.payload = { submissionId, submissionObject, notify };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,6 +436,7 @@ export class SaveSubmissionSectionFormSuccessAction implements Action {
|
||||
payload: {
|
||||
submissionId: string;
|
||||
submissionObject: SubmissionObject[];
|
||||
notify?: boolean
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -445,8 +447,8 @@ export class SaveSubmissionSectionFormSuccessAction implements Action {
|
||||
* @param submissionObject
|
||||
* the submission's Object
|
||||
*/
|
||||
constructor(submissionId: string, submissionObject: SubmissionObject[]) {
|
||||
this.payload = { submissionId, submissionObject };
|
||||
constructor(submissionId: string, submissionObject: SubmissionObject[], notify?: boolean) {
|
||||
this.payload = { submissionId, submissionObject, notify };
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -136,7 +136,7 @@ export class SubmissionObjectEffects {
|
||||
ofType(SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM_SUCCESS, SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_SUCCESS),
|
||||
withLatestFrom(this.store$),
|
||||
map(([action, currentState]: [SaveSubmissionFormSuccessAction | SaveSubmissionSectionFormSuccessAction, any]) => {
|
||||
return this.parseSaveResponse((currentState.submission as SubmissionState).objects[action.payload.submissionId], action.payload.submissionObject, action.payload.submissionId);
|
||||
return this.parseSaveResponse((currentState.submission as SubmissionState).objects[action.payload.submissionId], action.payload.submissionObject, action.payload.submissionId, action.payload.notify);
|
||||
}),
|
||||
mergeMap((actions) => observableFrom(actions)));
|
||||
|
||||
|
Reference in New Issue
Block a user