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
|
||||
*
|
||||
* @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(
|
||||
'byEntityType',
|
||||
@@ -139,12 +136,16 @@ export class RelationshipTypeService extends DataService<RelationshipType> {
|
||||
{
|
||||
fieldName: 'type',
|
||||
fieldValue: type
|
||||
}
|
||||
},
|
||||
{
|
||||
fieldName: 'size',
|
||||
fieldValue: 100
|
||||
},
|
||||
]
|
||||
}, true,true,followLink('leftType'),followLink('rightType')).pipe(
|
||||
getFirstSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
) as Observable<RelationshipType[]>;
|
||||
) as Observable<PaginatedList<RelationshipType>>;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -470,9 +470,17 @@ export class RelationshipService extends DataService<Relationship> {
|
||||
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[]> {
|
||||
|
||||
let searchParams = [
|
||||
const searchParams = [
|
||||
{
|
||||
fieldName: 'typeId',
|
||||
fieldValue: typeId
|
||||
@@ -485,10 +493,10 @@ export class RelationshipService extends DataService<Relationship> {
|
||||
fieldName: 'relationshipLabel',
|
||||
fieldValue: relationshipLabel
|
||||
},
|
||||
// {
|
||||
// fieldName: 'page',
|
||||
// fieldValue: 1
|
||||
// },
|
||||
{
|
||||
fieldName: 'size',
|
||||
fieldValue: arrayOfItemIds.length
|
||||
},
|
||||
];
|
||||
|
||||
arrayOfItemIds.forEach( (itemId) => {
|
||||
@@ -497,8 +505,8 @@ export class RelationshipService extends DataService<Relationship> {
|
||||
fieldName: 'relatedItem',
|
||||
fieldValue: itemId
|
||||
},
|
||||
)
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
return this.searchBy(
|
||||
'byItemsAndType',
|
||||
|
@@ -142,8 +142,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
|
||||
listOfRelatedItems = [];
|
||||
|
||||
relationshipTypeInfo: string;
|
||||
|
||||
constructor(
|
||||
protected objectUpdatesService: ObjectUpdatesService,
|
||||
protected linkService: LinkService,
|
||||
@@ -228,7 +226,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
modalComp.select = (...selectableObjects: SearchResult<Item>[]) => {
|
||||
selectableObjects.forEach((searchResult) => {
|
||||
const relatedItem: Item = searchResult.indexableObject;
|
||||
this.getFieldUpdatesForRelatedItemNew(relatedItem)
|
||||
this.getIsRelatedItem(relatedItem)
|
||||
.subscribe((isRelated: boolean) => {
|
||||
|
||||
|
||||
@@ -311,8 +309,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
// console.log(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
|
||||
*/
|
||||
private getFieldUpdatesForRelatedItem(relatedItem: Item): Observable<RelationshipIdentifiable[]> {
|
||||
console.log("getFieldUpdatesForRelatedItem",relatedItem);
|
||||
return this.updates$.pipe(
|
||||
take(1),
|
||||
map((updates) => Object.values(updates)
|
||||
@@ -333,40 +328,34 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
).pipe(
|
||||
defaultIfEmpty([]),
|
||||
map((relatedItems) => {
|
||||
console.log("identifiables",identifiables,relatedItems);
|
||||
return identifiables.filter((identifiable, index) =>
|
||||
{
|
||||
console.log(relatedItems[index].uuid,relatedItems,relatedItem.uuid);
|
||||
return relatedItems[index].uuid === relatedItem.uuid
|
||||
})
|
||||
return identifiables.filter( (identifiable, index) => {
|
||||
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(
|
||||
take(1),
|
||||
map( isLeft => {
|
||||
if (isLeft) {
|
||||
this.relationshipType.leftwardType;
|
||||
let listOfRelatedItems = this.item.allMetadataValues('relation.'+this.relationshipType.leftwardType);
|
||||
return !!listOfRelatedItems.find((uuid) => uuid == relatedItem.uuid);
|
||||
const listOfRelatedItems = this.item.allMetadataValues( 'relation.' + this.relationshipType.leftwardType );
|
||||
return !!listOfRelatedItems.find( (uuid) => uuid === relatedItem.uuid );
|
||||
} else {
|
||||
this.relationshipType.rightwardType;
|
||||
let listOfRelatedItems = this.item.allMetadataValues('relation.'+this.relationshipType.rightwardType);
|
||||
return !!listOfRelatedItems.find((uuid) => uuid == relatedItem.uuid);
|
||||
const 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([])
|
||||
)),
|
||||
switchMap((nextFields: RelationshipIdentifiable[]) => {
|
||||
console.log("nextFields",nextFields);
|
||||
// Get a list that contains the unsaved changes for the page, as well as the page of
|
||||
// RelationshipIdentifiables, as a single list of FieldUpdates
|
||||
return this.objectUpdatesService.getFieldUpdates(this.url, nextFields).pipe(
|
||||
map((fieldUpdates: FieldUpdates) => {
|
||||
console.log("fieldUpdates",fieldUpdates);
|
||||
const fieldUpdatesFiltered: FieldUpdates = {};
|
||||
this.nbAddedFields$.next(0);
|
||||
// iterate over the fieldupdates and filter out the ones that pertain to this
|
||||
@@ -535,7 +522,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
startWith({}),
|
||||
).subscribe((updates: FieldUpdates) => {
|
||||
this.loading$.next(false);
|
||||
console.log(updates);
|
||||
this.updates$.next(updates);
|
||||
}));
|
||||
}
|
||||
|
@@ -83,7 +83,7 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
|
||||
this.relationshipTypes$ = this.relationshipTypeService.searchByEntityType(label)
|
||||
.pipe(
|
||||
map((relationshipTypes:any) => relationshipTypes.page)
|
||||
map((relationshipTypes: PaginatedList<RelationshipType>) => relationshipTypes.page)
|
||||
);
|
||||
|
||||
this.entityType$ = this.entityTypeService.getEntityTypeByLabel(label).pipe(
|
||||
|
@@ -118,9 +118,9 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
|
||||
currentItemIsLeftItem$: Observable<boolean>;
|
||||
|
||||
isLeft: boolean = false;
|
||||
isLeft = false;
|
||||
|
||||
isEditRelationship: boolean = false;
|
||||
isEditRelationship = false;
|
||||
|
||||
|
||||
constructor(
|
||||
|
@@ -169,7 +169,7 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options).pipe(
|
||||
startWith(undefined),
|
||||
tap( res => {
|
||||
if(!!res && res.state == 'Success' && this.isEditRelationship){
|
||||
if ( !!res && res.state === 'Success' && this.isEditRelationship ) {
|
||||
const idOfItems = res.payload.page.map( itemSearchResult => {
|
||||
return itemSearchResult.indexableObject.uuid;
|
||||
});
|
||||
@@ -259,12 +259,12 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
} else {
|
||||
arrUrl = relationship._links.leftItem.href.split('/');
|
||||
}
|
||||
let uuid = arrUrl[arrUrl.length-1];
|
||||
const uuid = arrUrl[ arrUrl.length - 1 ];
|
||||
|
||||
return this.getRelatedItem(uuid,resultListOfItems);
|
||||
|
||||
});
|
||||
// console.log(selectableObject);
|
||||
|
||||
if ( selectableObject.length > 0 ) {
|
||||
this.selectableListService.select(this.listId, selectableObject);
|
||||
}
|
||||
@@ -282,9 +282,9 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
this.selectableListService.deselectAll(this.listId);
|
||||
}
|
||||
|
||||
getRelatedItem(uuid,resultList){
|
||||
getRelatedItem(uuid: string, resultList: SearchResult<Item>[]) {
|
||||
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)
|
||||
});
|
||||
return createSuccessfulRemoteDataObject(buildPaginatedList(pageInfo, selection));
|
||||
}),
|
||||
tap((res)=> console.log(res))
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
|
Reference in New Issue
Block a user