mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[CST-5404] Code refactoring, fixing issues , lint fixes and started unit testing
This commit is contained in:
@@ -122,15 +122,12 @@ export class RelationshipTypeService extends DataService<RelationshipType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the given RelationshipType has the given itemTypes on its left and right sides.
|
* Search of the given RelationshipType if has the given itemTypes on its left and right sides.
|
||||||
* Returns an observable of the given RelationshipType if it matches, null if it doesn't
|
* Returns an observable of the given RelationshipType if it matches, null if it doesn't
|
||||||
*
|
*
|
||||||
* @param type The RelationshipType to check
|
* @param type The RelationshipType to check
|
||||||
* @param leftItemType The item type that should be on the left side
|
|
||||||
* @param rightItemType The item type that should be on the right side
|
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
searchByEntityType(type: string): Observable<RelationshipType[]> {
|
searchByEntityType(type: string): Observable<PaginatedList<RelationshipType>> {
|
||||||
|
|
||||||
return this.searchBy(
|
return this.searchBy(
|
||||||
'byEntityType',
|
'byEntityType',
|
||||||
@@ -139,12 +136,16 @@ export class RelationshipTypeService extends DataService<RelationshipType> {
|
|||||||
{
|
{
|
||||||
fieldName: 'type',
|
fieldName: 'type',
|
||||||
fieldValue: type
|
fieldValue: type
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'size',
|
||||||
|
fieldValue: 100
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}, true,true,followLink('leftType'),followLink('rightType')).pipe(
|
}, true,true,followLink('leftType'),followLink('rightType')).pipe(
|
||||||
getFirstSucceededRemoteData(),
|
getFirstSucceededRemoteData(),
|
||||||
getRemoteDataPayload(),
|
getRemoteDataPayload(),
|
||||||
) as Observable<RelationshipType[]>;
|
) as Observable<PaginatedList<RelationshipType>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -470,9 +470,17 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
return this.put(object);
|
return this.put(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Patch isn't supported on the relationship endpoint, so use put instead.
|
||||||
|
*
|
||||||
|
* @param typeId the relationship type id to apply as a filter to the returned relationships
|
||||||
|
* @param itemUuid The uuid of the item to be checked on the side defined by relationshipLabel
|
||||||
|
* @param relationshipLabel the name of the relation as defined from the side of the itemUuid
|
||||||
|
* @param arrayOfItemIds The uuid of the items to be found on the other side of returned relationships
|
||||||
|
*/
|
||||||
searchByItemsAndType(typeId: string,itemUuid: string,relationshipLabel: string, arrayOfItemIds: string[] ): Observable<Relationship[]> {
|
searchByItemsAndType(typeId: string,itemUuid: string,relationshipLabel: string, arrayOfItemIds: string[] ): Observable<Relationship[]> {
|
||||||
|
|
||||||
let searchParams = [
|
const searchParams = [
|
||||||
{
|
{
|
||||||
fieldName: 'typeId',
|
fieldName: 'typeId',
|
||||||
fieldValue: typeId
|
fieldValue: typeId
|
||||||
@@ -485,20 +493,20 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
fieldName: 'relationshipLabel',
|
fieldName: 'relationshipLabel',
|
||||||
fieldValue: relationshipLabel
|
fieldValue: relationshipLabel
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// fieldName: 'page',
|
fieldName: 'size',
|
||||||
// fieldValue: 1
|
fieldValue: arrayOfItemIds.length
|
||||||
// },
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
arrayOfItemIds.forEach((itemId)=>{
|
arrayOfItemIds.forEach( (itemId) => {
|
||||||
searchParams.push(
|
searchParams.push(
|
||||||
{
|
{
|
||||||
fieldName: 'relatedItem',
|
fieldName: 'relatedItem',
|
||||||
fieldValue: itemId
|
fieldValue: itemId
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
|
|
||||||
return this.searchBy(
|
return this.searchBy(
|
||||||
'byItemsAndType',
|
'byItemsAndType',
|
||||||
|
@@ -142,8 +142,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
listOfRelatedItems = [];
|
listOfRelatedItems = [];
|
||||||
|
|
||||||
relationshipTypeInfo: string;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected objectUpdatesService: ObjectUpdatesService,
|
protected objectUpdatesService: ObjectUpdatesService,
|
||||||
protected linkService: LinkService,
|
protected linkService: LinkService,
|
||||||
@@ -228,7 +226,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
modalComp.select = (...selectableObjects: SearchResult<Item>[]) => {
|
modalComp.select = (...selectableObjects: SearchResult<Item>[]) => {
|
||||||
selectableObjects.forEach((searchResult) => {
|
selectableObjects.forEach((searchResult) => {
|
||||||
const relatedItem: Item = searchResult.indexableObject;
|
const relatedItem: Item = searchResult.indexableObject;
|
||||||
this.getFieldUpdatesForRelatedItemNew(relatedItem)
|
this.getIsRelatedItem(relatedItem)
|
||||||
.subscribe((isRelated: boolean) => {
|
.subscribe((isRelated: boolean) => {
|
||||||
|
|
||||||
|
|
||||||
@@ -311,8 +309,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
// console.log(items);
|
// console.log(items);
|
||||||
// this.selectableListService.select(this.listId, items);
|
// this.selectableListService.select(this.listId, items);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(modalComp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -320,7 +316,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
* @param relatedItem The item for which to get the existing field updates
|
* @param relatedItem The item for which to get the existing field updates
|
||||||
*/
|
*/
|
||||||
private getFieldUpdatesForRelatedItem(relatedItem: Item): Observable<RelationshipIdentifiable[]> {
|
private getFieldUpdatesForRelatedItem(relatedItem: Item): Observable<RelationshipIdentifiable[]> {
|
||||||
console.log("getFieldUpdatesForRelatedItem",relatedItem);
|
|
||||||
return this.updates$.pipe(
|
return this.updates$.pipe(
|
||||||
take(1),
|
take(1),
|
||||||
map((updates) => Object.values(updates)
|
map((updates) => Object.values(updates)
|
||||||
@@ -333,40 +328,34 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
).pipe(
|
).pipe(
|
||||||
defaultIfEmpty([]),
|
defaultIfEmpty([]),
|
||||||
map((relatedItems) => {
|
map((relatedItems) => {
|
||||||
console.log("identifiables",identifiables,relatedItems);
|
return identifiables.filter( (identifiable, index) => {
|
||||||
return identifiables.filter((identifiable, index) =>
|
return relatedItems[index].uuid === relatedItem.uuid;
|
||||||
{
|
});
|
||||||
console.log(relatedItems[index].uuid,relatedItems,relatedItem.uuid);
|
|
||||||
return relatedItems[index].uuid === relatedItem.uuid
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
tap(res=> console.log("getFieldUpdatesForRelatedItem -> res",res))
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
private getFieldUpdatesForRelatedItemNew(relatedItem: Item): Observable<boolean> {
|
* Check if the given item is related with the item we are editing relationships
|
||||||
|
* @param relatedItem The item for which to get the existing field updates
|
||||||
|
*/
|
||||||
|
private getIsRelatedItem(relatedItem: Item): Observable<boolean> {
|
||||||
|
|
||||||
return this.currentItemIsLeftItem$.pipe(
|
return this.currentItemIsLeftItem$.pipe(
|
||||||
take(1),
|
take(1),
|
||||||
map(isLeft => {
|
map( isLeft => {
|
||||||
if(isLeft){
|
if (isLeft) {
|
||||||
this.relationshipType.leftwardType;
|
const listOfRelatedItems = this.item.allMetadataValues( 'relation.' + this.relationshipType.leftwardType );
|
||||||
let listOfRelatedItems = this.item.allMetadataValues('relation.'+this.relationshipType.leftwardType);
|
return !!listOfRelatedItems.find( (uuid) => uuid === relatedItem.uuid );
|
||||||
return !!listOfRelatedItems.find((uuid) => uuid == relatedItem.uuid);
|
} else {
|
||||||
}else{
|
const listOfRelatedItems = this.item.allMetadataValues( 'relation.' + this.relationshipType.rightwardType );
|
||||||
this.relationshipType.rightwardType;
|
return !!listOfRelatedItems.find( (uuid) => uuid === relatedItem.uuid );
|
||||||
let listOfRelatedItems = this.item.allMetadataValues('relation.'+this.relationshipType.rightwardType);
|
|
||||||
return !!listOfRelatedItems.find((uuid) => uuid == relatedItem.uuid);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// return this.relationshipService.searchByItemsAndType(this.relationshipType.id, this.item.uuid, this.relationshipTypeInfo ,[relatedItem.uuid])
|
|
||||||
// .pipe(map((res:any)=> res.page));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -497,12 +486,10 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
defaultIfEmpty([])
|
defaultIfEmpty([])
|
||||||
)),
|
)),
|
||||||
switchMap((nextFields: RelationshipIdentifiable[]) => {
|
switchMap((nextFields: RelationshipIdentifiable[]) => {
|
||||||
console.log("nextFields",nextFields);
|
|
||||||
// Get a list that contains the unsaved changes for the page, as well as the page of
|
// Get a list that contains the unsaved changes for the page, as well as the page of
|
||||||
// RelationshipIdentifiables, as a single list of FieldUpdates
|
// RelationshipIdentifiables, as a single list of FieldUpdates
|
||||||
return this.objectUpdatesService.getFieldUpdates(this.url, nextFields).pipe(
|
return this.objectUpdatesService.getFieldUpdates(this.url, nextFields).pipe(
|
||||||
map((fieldUpdates: FieldUpdates) => {
|
map((fieldUpdates: FieldUpdates) => {
|
||||||
console.log("fieldUpdates",fieldUpdates);
|
|
||||||
const fieldUpdatesFiltered: FieldUpdates = {};
|
const fieldUpdatesFiltered: FieldUpdates = {};
|
||||||
this.nbAddedFields$.next(0);
|
this.nbAddedFields$.next(0);
|
||||||
// iterate over the fieldupdates and filter out the ones that pertain to this
|
// iterate over the fieldupdates and filter out the ones that pertain to this
|
||||||
@@ -535,7 +522,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
startWith({}),
|
startWith({}),
|
||||||
).subscribe((updates: FieldUpdates) => {
|
).subscribe((updates: FieldUpdates) => {
|
||||||
this.loading$.next(false);
|
this.loading$.next(false);
|
||||||
console.log(updates);
|
|
||||||
this.updates$.next(updates);
|
this.updates$.next(updates);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@@ -83,7 +83,7 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
|||||||
|
|
||||||
this.relationshipTypes$ = this.relationshipTypeService.searchByEntityType(label)
|
this.relationshipTypes$ = this.relationshipTypeService.searchByEntityType(label)
|
||||||
.pipe(
|
.pipe(
|
||||||
map((relationshipTypes:any) => relationshipTypes.page)
|
map((relationshipTypes: PaginatedList<RelationshipType>) => relationshipTypes.page)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.entityType$ = this.entityTypeService.getEntityTypeByLabel(label).pipe(
|
this.entityType$ = this.entityTypeService.getEntityTypeByLabel(label).pipe(
|
||||||
|
@@ -116,11 +116,11 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
|
|
||||||
relationshipType;
|
relationshipType;
|
||||||
|
|
||||||
currentItemIsLeftItem$ : Observable<boolean>;
|
currentItemIsLeftItem$: Observable<boolean>;
|
||||||
|
|
||||||
isLeft: boolean = false;
|
isLeft = false;
|
||||||
|
|
||||||
isEditRelationship: boolean = false;
|
isEditRelationship = false;
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@@ -168,9 +168,9 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
|||||||
this.resultsRD$ = this.searchConfigService.paginatedSearchOptions.pipe(
|
this.resultsRD$ = this.searchConfigService.paginatedSearchOptions.pipe(
|
||||||
switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options).pipe(
|
switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options).pipe(
|
||||||
startWith(undefined),
|
startWith(undefined),
|
||||||
tap(res=> {
|
tap( res => {
|
||||||
if(!!res && res.state == 'Success' && this.isEditRelationship){
|
if ( !!res && res.state === 'Success' && this.isEditRelationship ) {
|
||||||
const idOfItems = res.payload.page.map(itemSearchResult => {
|
const idOfItems = res.payload.page.map( itemSearchResult => {
|
||||||
return itemSearchResult.indexableObject.uuid;
|
return itemSearchResult.indexableObject.uuid;
|
||||||
});
|
});
|
||||||
this.setSelectedIds(idOfItems,res.payload.page);
|
this.setSelectedIds(idOfItems,res.payload.page);
|
||||||
@@ -246,26 +246,26 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
|||||||
|
|
||||||
setSelectedIds(idOfItems, resultListOfItems) {
|
setSelectedIds(idOfItems, resultListOfItems) {
|
||||||
let relationType = this.relationshipType.rightwardType;
|
let relationType = this.relationshipType.rightwardType;
|
||||||
if(this.isLeft){
|
if ( this.isLeft ) {
|
||||||
relationType = this.relationshipType.leftwardType;
|
relationType = this.relationshipType.leftwardType;
|
||||||
}
|
}
|
||||||
this.relationshipService.searchByItemsAndType(this.relationshipType.id, this.item.uuid, relationType ,idOfItems).subscribe((res: any)=>{
|
this.relationshipService.searchByItemsAndType( this.relationshipType.id, this.item.uuid, relationType ,idOfItems ).subscribe( (res: any) => {
|
||||||
|
|
||||||
const selectableObject = res.page.map((relationship: Relationship) => {
|
const selectableObject = res.page.map( (relationship: Relationship) => {
|
||||||
|
|
||||||
let arrUrl = [];
|
let arrUrl = [];
|
||||||
if(this.isLeft){
|
if ( this.isLeft ) {
|
||||||
arrUrl = relationship._links.rightItem.href.split('/');
|
arrUrl = relationship._links.rightItem.href.split('/');
|
||||||
}else{
|
} else {
|
||||||
arrUrl = relationship._links.leftItem.href.split('/');
|
arrUrl = relationship._links.leftItem.href.split('/');
|
||||||
}
|
}
|
||||||
let uuid = arrUrl[arrUrl.length-1];
|
const uuid = arrUrl[ arrUrl.length - 1 ];
|
||||||
|
|
||||||
return this.getRelatedItem(uuid,resultListOfItems);
|
return this.getRelatedItem(uuid,resultListOfItems);
|
||||||
|
|
||||||
});
|
});
|
||||||
// console.log(selectableObject);
|
|
||||||
if(selectableObject.length > 0){
|
if ( selectableObject.length > 0 ) {
|
||||||
this.selectableListService.select(this.listId, selectableObject);
|
this.selectableListService.select(this.listId, selectableObject);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -282,9 +282,9 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
|||||||
this.selectableListService.deselectAll(this.listId);
|
this.selectableListService.deselectAll(this.listId);
|
||||||
}
|
}
|
||||||
|
|
||||||
getRelatedItem(uuid,resultList){
|
getRelatedItem(uuid: string, resultList: SearchResult<Item>[]) {
|
||||||
return resultList.find((resultItem) => {
|
return resultList.find( (resultItem) => {
|
||||||
return resultItem.indexableObject.uuid == uuid;
|
return resultItem.indexableObject.uuid === uuid;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -115,8 +115,7 @@ export class DsDynamicLookupRelationSelectionTabComponent {
|
|||||||
totalPages: Math.ceil(selected.length / pagination.pageSize)
|
totalPages: Math.ceil(selected.length / pagination.pageSize)
|
||||||
});
|
});
|
||||||
return createSuccessfulRemoteDataObject(buildPaginatedList(pageInfo, selection));
|
return createSuccessfulRemoteDataObject(buildPaginatedList(pageInfo, selection));
|
||||||
}),
|
})
|
||||||
tap((res)=> console.log(res))
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user