forked from hazza/dspace-angular
Merge pull request #3143 from atmire/w2p-115284_add-support-for-non-repeatable-relationships_dspace-7-x
[Port dspace-7_x] Add support for non repeatable relationships
This commit is contained in:
@@ -80,7 +80,7 @@ describe('EditRelationshipListComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
};
|
};
|
||||||
|
|
||||||
function init(leftType: string, rightType: string): void {
|
function init(leftType: string, rightType: string, leftMaxCardinality?: number, rightMaxCardinality?: number): void {
|
||||||
entityTypeLeft = Object.assign(new ItemType(), {
|
entityTypeLeft = Object.assign(new ItemType(), {
|
||||||
id: leftType,
|
id: leftType,
|
||||||
uuid: leftType,
|
uuid: leftType,
|
||||||
@@ -100,6 +100,8 @@ describe('EditRelationshipListComponent', () => {
|
|||||||
rightType: createSuccessfulRemoteDataObject$(entityTypeRight),
|
rightType: createSuccessfulRemoteDataObject$(entityTypeRight),
|
||||||
leftwardType: `is${rightType}Of${leftType}`,
|
leftwardType: `is${rightType}Of${leftType}`,
|
||||||
rightwardType: `is${leftType}Of${rightType}`,
|
rightwardType: `is${leftType}Of${rightType}`,
|
||||||
|
leftMaxCardinality: leftMaxCardinality,
|
||||||
|
rightMaxCardinality: rightMaxCardinality,
|
||||||
});
|
});
|
||||||
|
|
||||||
paginationOptions = Object.assign(new PaginationComponentOptions(), {
|
paginationOptions = Object.assign(new PaginationComponentOptions(), {
|
||||||
@@ -370,4 +372,31 @@ describe('EditRelationshipListComponent', () => {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Is repeatable relationship', () => {
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
currentItemIsLeftItem$ = new BehaviorSubject<boolean>(true);
|
||||||
|
}));
|
||||||
|
describe('when max cardinality is 1', () => {
|
||||||
|
beforeEach(waitForAsync(() => init('Publication', 'OrgUnit', 1, undefined)));
|
||||||
|
it('should return false', () => {
|
||||||
|
const result = (comp as any).isRepeatable();
|
||||||
|
expect(result).toBeFalse();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('when max cardinality is 2', () => {
|
||||||
|
beforeEach(waitForAsync(() => init('Publication', 'OrgUnit', 2, undefined)));
|
||||||
|
it('should return true', () => {
|
||||||
|
const result = (comp as any).isRepeatable();
|
||||||
|
expect(result).toBeTrue();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('when max cardinality is undefined', () => {
|
||||||
|
beforeEach(waitForAsync(() => init('Publication', 'OrgUnit', undefined, undefined)));
|
||||||
|
it('should return true', () => {
|
||||||
|
const result = (comp as any).isRepeatable();
|
||||||
|
expect(result).toBeTrue();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -233,6 +233,22 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
return update && update.field ? update.field.uuid : undefined;
|
return update && update.field ? update.field.uuid : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the current entity can have multiple relationships of this type
|
||||||
|
* This is based on the max cardinality of the relationship
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private isRepeatable(): boolean {
|
||||||
|
const isLeft = this.currentItemIsLeftItem$.getValue();
|
||||||
|
if (isLeft) {
|
||||||
|
const leftMaxCardinality = this.relationshipType.leftMaxCardinality;
|
||||||
|
return hasNoValue(leftMaxCardinality) || leftMaxCardinality > 1;
|
||||||
|
} else {
|
||||||
|
const rightMaxCardinality = this.relationshipType.rightMaxCardinality;
|
||||||
|
return hasNoValue(rightMaxCardinality) || rightMaxCardinality > 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the dynamic lookup modal to search for items to add as relationships
|
* Open the dynamic lookup modal to search for items to add as relationships
|
||||||
*/
|
*/
|
||||||
@@ -250,6 +266,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
modalComp.toAdd = [];
|
modalComp.toAdd = [];
|
||||||
modalComp.toRemove = [];
|
modalComp.toRemove = [];
|
||||||
modalComp.isPending = false;
|
modalComp.isPending = false;
|
||||||
|
modalComp.repeatable = this.isRepeatable();
|
||||||
modalComp.hiddenQuery = '-search.resourceid:' + this.item.uuid;
|
modalComp.hiddenQuery = '-search.resourceid:' + this.item.uuid;
|
||||||
|
|
||||||
this.item.owningCollection.pipe(
|
this.item.owningCollection.pipe(
|
||||||
|
Reference in New Issue
Block a user