mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
refactoring relationship service code
This commit is contained in:
@@ -9,7 +9,7 @@ import { Observable } from 'rxjs/internal/Observable';
|
||||
import { RelationshipType } from '../shared/item-relationships/relationship-type.model';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { of as observableOf, combineLatest as observableCombineLatest } from 'rxjs';
|
||||
import { combineLatest as observableCombineLatest } from 'rxjs';
|
||||
import { ItemType } from '../shared/item-relationships/item-type.model';
|
||||
import { isNotUndefined } from '../../shared/empty.util';
|
||||
|
||||
|
@@ -10,7 +10,7 @@ import {
|
||||
getRemoteDataPayload, getResponseFromEntry,
|
||||
getSucceededRemoteData
|
||||
} from '../shared/operators';
|
||||
import { DeleteRequest, PostRequest, RestRequest } from './request.models';
|
||||
import { DeleteRequest, GetRequest, PostRequest, RestRequest } from './request.models';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { RestResponse } from '../cache/response.models';
|
||||
import { Item } from '../shared/item.model';
|
||||
@@ -27,6 +27,8 @@ import {
|
||||
} from '../../+item-page/simple/item-types/shared/item-relationships-utils';
|
||||
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
import { DeprecatedCurrencyPipe } from '@angular/common';
|
||||
import { deprecate } from 'util';
|
||||
|
||||
/**
|
||||
* The service handling all relationship requests
|
||||
@@ -134,6 +136,29 @@ export class RelationshipService {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an item their relationships in the form of an array
|
||||
* @param item
|
||||
*/
|
||||
getItemRelationships(item: Item): void {
|
||||
this.halService.getEndpoint(item.self + '/relationships')
|
||||
.pipe(
|
||||
map((endpointURL: string) => new GetRequest(this.requestService.generateRequestId(), endpointURL)),
|
||||
configureRequest(this.requestService),
|
||||
switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)),
|
||||
getResponseFromEntry()
|
||||
).subscribe(t => console.log(t));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get an item their relationships in the form of an array
|
||||
// * @param item
|
||||
// */
|
||||
// getItemRelationshipsByType(item: Item, relationshipTypeLabel: string): Observable<Relationship[]> {
|
||||
// this.getItemRelationshipsArray(item: Item)
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get an item their relationship types in the form of an array
|
||||
* @param item
|
||||
|
@@ -165,7 +165,6 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
} else {
|
||||
result = this.relationshipService.addRelationship(type.id, itemRD.payload, selectableObject.indexableObject);
|
||||
}
|
||||
console.log(result);
|
||||
return result;
|
||||
})
|
||||
)
|
||||
@@ -174,27 +173,12 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
|
||||
|
||||
deselect(selectableObject: SearchResult<Item>) {
|
||||
const relationshipType$: Observable<RelationshipType> = this.itemRD$.pipe(
|
||||
this.itemRD$.pipe(
|
||||
getSucceededRemoteData(),
|
||||
switchMap((itemRD: RemoteData<Item>) => {
|
||||
const type1: string = itemRD.payload.firstMetadataValue('relationship.type');
|
||||
const type2: string = selectableObject.indexableObject.firstMetadataValue('relationship.type');
|
||||
return this.relationshipTypeService.getRelationshipTypeByLabelAndTypes(this.relationship.relationshipType, type1, type2);
|
||||
}));
|
||||
|
||||
this.subscription = observableCombineLatest(relationshipType$, this.itemRD$)
|
||||
.pipe(
|
||||
take(1),
|
||||
switchMap(([type, itemRD]: [RelationshipType, RemoteData<Item>]) => {
|
||||
const isSwitched = type.rightLabel === this.relationship.relationshipType;
|
||||
if (isSwitched) {
|
||||
return this.relationshipService.addRelationship(type.id, selectableObject.indexableObject, itemRD.payload);
|
||||
} else {
|
||||
return this.relationshipService.addRelationship(type.id, itemRD.payload, selectableObject.indexableObject);
|
||||
}
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
tap((t) => console.log('succeeded')),
|
||||
map((itemRD: RemoteData<Item>) => this.relationshipService.getItemRelationships(itemRD.payload)),
|
||||
// map((items: Item[]) => items.find((item: Item) => ))
|
||||
).subscribe();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
|
Reference in New Issue
Block a user