mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +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 { RelationshipType } from '../shared/item-relationships/relationship-type.model';
|
||||||
import { RemoteData } from './remote-data';
|
import { RemoteData } from './remote-data';
|
||||||
import { PaginatedList } from './paginated-list';
|
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 { ItemType } from '../shared/item-relationships/item-type.model';
|
||||||
import { isNotUndefined } from '../../shared/empty.util';
|
import { isNotUndefined } from '../../shared/empty.util';
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@ import {
|
|||||||
getRemoteDataPayload, getResponseFromEntry,
|
getRemoteDataPayload, getResponseFromEntry,
|
||||||
getSucceededRemoteData
|
getSucceededRemoteData
|
||||||
} from '../shared/operators';
|
} 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 { Observable } from 'rxjs/internal/Observable';
|
||||||
import { RestResponse } from '../cache/response.models';
|
import { RestResponse } from '../cache/response.models';
|
||||||
import { Item } from '../shared/item.model';
|
import { Item } from '../shared/item.model';
|
||||||
@@ -27,6 +27,8 @@ import {
|
|||||||
} from '../../+item-page/simple/item-types/shared/item-relationships-utils';
|
} from '../../+item-page/simple/item-types/shared/item-relationships-utils';
|
||||||
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||||
import { HttpHeaders } from '@angular/common/http';
|
import { HttpHeaders } from '@angular/common/http';
|
||||||
|
import { DeprecatedCurrencyPipe } from '@angular/common';
|
||||||
|
import { deprecate } from 'util';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The service handling all relationship requests
|
* 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
|
* Get an item their relationship types in the form of an array
|
||||||
* @param item
|
* @param item
|
||||||
|
@@ -165,7 +165,6 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
} else {
|
} else {
|
||||||
result = this.relationshipService.addRelationship(type.id, itemRD.payload, selectableObject.indexableObject);
|
result = this.relationshipService.addRelationship(type.id, itemRD.payload, selectableObject.indexableObject);
|
||||||
}
|
}
|
||||||
console.log(result);
|
|
||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -174,27 +173,12 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
|
|
||||||
|
|
||||||
deselect(selectableObject: SearchResult<Item>) {
|
deselect(selectableObject: SearchResult<Item>) {
|
||||||
const relationshipType$: Observable<RelationshipType> = this.itemRD$.pipe(
|
this.itemRD$.pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
switchMap((itemRD: RemoteData<Item>) => {
|
tap((t) => console.log('succeeded')),
|
||||||
const type1: string = itemRD.payload.firstMetadataValue('relationship.type');
|
map((itemRD: RemoteData<Item>) => this.relationshipService.getItemRelationships(itemRD.payload)),
|
||||||
const type2: string = selectableObject.indexableObject.firstMetadataValue('relationship.type');
|
// map((items: Item[]) => items.find((item: Item) => ))
|
||||||
return this.relationshipTypeService.getRelationshipTypeByLabelAndTypes(this.relationship.relationshipType, type1, type2);
|
).subscribe();
|
||||||
}));
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
|
Reference in New Issue
Block a user