mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-16 22:43:03 +00:00
bug with deleting after adding
This commit is contained in:
3
src/app/core/cache/object-cache.service.ts
vendored
3
src/app/core/cache/object-cache.service.ts
vendored
@@ -195,8 +195,9 @@ export class ObjectCacheService {
|
|||||||
* false otherwise
|
* false otherwise
|
||||||
*/
|
*/
|
||||||
hasByUUID(uuid: string): boolean {
|
hasByUUID(uuid: string): boolean {
|
||||||
let result: boolean;
|
let result = false;
|
||||||
|
|
||||||
|
/* NB: that this is only a solution because the select method is synchronous, see: https://github.com/ngrx/store/issues/296#issuecomment-269032571*/
|
||||||
this.store.pipe(
|
this.store.pipe(
|
||||||
select(selfLinkFromUuidSelector(uuid)),
|
select(selfLinkFromUuidSelector(uuid)),
|
||||||
take(1)
|
take(1)
|
||||||
|
@@ -2,8 +2,8 @@ import { Injectable } from '@angular/core';
|
|||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
import { hasValue, hasValueOperator, isNotEmptyOperator } from '../../shared/empty.util';
|
import { hasNoValue, hasValue, hasValueOperator, isNotEmptyOperator } from '../../shared/empty.util';
|
||||||
import { distinctUntilChanged, filter, map, startWith, switchMap, take, tap } from 'rxjs/operators';
|
import { distinctUntilChanged, filter, map, mergeMap, skip, startWith, switchMap, take, tap } from 'rxjs/operators';
|
||||||
import { configureRequest, getRemoteDataPayload, getResponseFromEntry, getSucceededRemoteData } from '../shared/operators';
|
import { configureRequest, getRemoteDataPayload, getResponseFromEntry, getSucceededRemoteData } from '../shared/operators';
|
||||||
import { DeleteRequest, FindAllOptions, PostRequest, RestRequest } from './request.models';
|
import { DeleteRequest, FindAllOptions, PostRequest, RestRequest } from './request.models';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
@@ -91,7 +91,7 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)),
|
switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)),
|
||||||
getResponseFromEntry(),
|
getResponseFromEntry(),
|
||||||
tap(() => this.removeRelationshipItemsFromCache(item1)),
|
tap(() => this.removeRelationshipItemsFromCache(item1)),
|
||||||
tap(() => this.removeRelationshipItemsFromCache(item2)),
|
tap(() => this.removeRelationshipItemsFromCache(item2))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,6 +114,11 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
private removeRelationshipItemsFromCache(item) {
|
private removeRelationshipItemsFromCache(item) {
|
||||||
this.objectCache.remove(item.self);
|
this.objectCache.remove(item.self);
|
||||||
this.requestService.removeByHrefSubstring(item.self);
|
this.requestService.removeByHrefSubstring(item.self);
|
||||||
|
this.objectCache.hasBySelfLinkObservable(item.self).pipe(
|
||||||
|
filter((exists) => !exists),
|
||||||
|
take(1),
|
||||||
|
switchMap(() => this.itemService.findByHref(item.self).pipe(take(1)))
|
||||||
|
).subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,9 +251,14 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
|
|
||||||
|
|
||||||
getRelationshipByItemsAndLabel(item1: Item, item2: Item, label: string): Observable<Relationship> {
|
getRelationshipByItemsAndLabel(item1: Item, item2: Item, label: string): Observable<Relationship> {
|
||||||
|
console.log('item 1: ', this.objectCache.hasByUUID(item1.uuid));
|
||||||
|
console.log('item 1 uuid: ', item1.uuid);
|
||||||
|
console.log('item 2: ', this.objectCache.hasByUUID(item2.uuid));
|
||||||
|
console.log('item 2 uuid: ', item2.uuid);
|
||||||
|
|
||||||
return this.getItemRelationshipsByLabel(item1, label)
|
return this.getItemRelationshipsByLabel(item1, label)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap((relationships: Relationship[]) => {
|
mergeMap((relationships: Relationship[]) => {
|
||||||
return observableCombineLatest(...relationships.map((relationship: Relationship) => {
|
return observableCombineLatest(...relationships.map((relationship: Relationship) => {
|
||||||
console.log('relationship: ', relationship.uuid);
|
console.log('relationship: ', relationship.uuid);
|
||||||
return observableCombineLatest(
|
return observableCombineLatest(
|
||||||
@@ -261,6 +271,7 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
);
|
);
|
||||||
}))
|
}))
|
||||||
}),
|
}),
|
||||||
|
skip(1),
|
||||||
map((relationships: Relationship[]) => relationships.find((relationship => hasValue(relationship)))),
|
map((relationships: Relationship[]) => relationships.find((relationship => hasValue(relationship)))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -184,7 +184,6 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
modelValueMDRepresentation;
|
modelValueMDRepresentation;
|
||||||
listId: string;
|
listId: string;
|
||||||
searchConfig: string;
|
searchConfig: string;
|
||||||
uuid;
|
|
||||||
/* tslint:disable:no-output-rename */
|
/* tslint:disable:no-output-rename */
|
||||||
@Output('dfBlur') blur: EventEmitter<DynamicFormControlEvent> = new EventEmitter<DynamicFormControlEvent>();
|
@Output('dfBlur') blur: EventEmitter<DynamicFormControlEvent> = new EventEmitter<DynamicFormControlEvent>();
|
||||||
@Output('dfChange') change: EventEmitter<DynamicFormControlEvent> = new EventEmitter<DynamicFormControlEvent>();
|
@Output('dfChange') change: EventEmitter<DynamicFormControlEvent> = new EventEmitter<DynamicFormControlEvent>();
|
||||||
@@ -219,7 +218,6 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
this.listId = 'list-' + this.model.relationship.relationshipType;
|
this.listId = 'list-' + this.model.relationship.relationshipType;
|
||||||
this.model.workspaceItem.item.pipe(
|
this.model.workspaceItem.item.pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
tap((itemRD: RemoteData<Item>) => this.uuid = itemRD.payload.uuid),
|
|
||||||
switchMap((itemRD: RemoteData<Item>) => this.relationService.getRelatedItemsByLabel(itemRD.payload, this.model.relationship.relationshipType)),
|
switchMap((itemRD: RemoteData<Item>) => this.relationService.getRelatedItemsByLabel(itemRD.payload, this.model.relationship.relationshipType)),
|
||||||
map((items: Item[]) => items.map((item) => Object.assign(new SearchResult(), { indexableObject: item }))),
|
map((items: Item[]) => items.map((item) => Object.assign(new SearchResult(), { indexableObject: item }))),
|
||||||
).subscribe((relatedItems) => this.selectableListService.select(this.listId, relatedItems));
|
).subscribe((relatedItems) => this.selectableListService.select(this.listId, relatedItems));
|
||||||
@@ -280,12 +278,12 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
modalComp.listId = this.listId;
|
modalComp.listId = this.listId;
|
||||||
modalComp.relationship = this.model.relationship;
|
modalComp.relationship = this.model.relationship;
|
||||||
modalComp.label = this.model.label;
|
modalComp.label = this.model.label;
|
||||||
modalComp.uuid = this.uuid;
|
modalComp.itemRD$ = this.model.workspaceItem.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeSelection(object: SearchResult<Item>) {
|
removeSelection(object: SearchResult<Item>) {
|
||||||
this.selectableListService.deselectSingle(this.listId, object);
|
this.selectableListService.deselectSingle(this.listId, object);
|
||||||
setTimeout(() => this.itemService.findById(this.uuid).pipe(
|
setTimeout(() => this.model.workspaceItem.item.pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
switchMap((itemRD: RemoteData<Item>) => this.relationshipService.getRelationshipByItemsAndLabel(itemRD.payload, object.indexableObject, this.model.relationship.relationshipType)),
|
switchMap((itemRD: RemoteData<Item>) => this.relationshipService.getRelationshipByItemsAndLabel(itemRD.payload, object.indexableObject, this.model.relationship.relationshipType)),
|
||||||
tap(t => console.log(t)),
|
tap(t => console.log(t)),
|
||||||
|
@@ -55,7 +55,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
pageSize: 10
|
pageSize: 10
|
||||||
});
|
});
|
||||||
selection$: Observable<ListableObject[]>;
|
selection$: Observable<ListableObject[]>;
|
||||||
uuid;
|
itemRD$;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public modal: NgbActiveModal,
|
public modal: NgbActiveModal,
|
||||||
@@ -140,7 +140,9 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
map((resultsRD) => resultsRD.payload.page),
|
map((resultsRD) => resultsRD.payload.page),
|
||||||
tap(() => this.selectAllLoading = false),
|
tap(() => this.selectAllLoading = false),
|
||||||
).subscribe((results) => this.selectableListService.select(this.listId, results));
|
).subscribe((results) =>
|
||||||
|
this.selectableListService.select(this.listId, results)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
deselectAll() {
|
deselectAll() {
|
||||||
@@ -150,24 +152,24 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
|
|
||||||
|
|
||||||
select(selectableObject: SearchResult<Item>) {
|
select(selectableObject: SearchResult<Item>) {
|
||||||
this.itemService.findById(this.uuid)
|
this.itemRD$
|
||||||
.pipe(
|
.pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
mergeMap((itemRD: RemoteData<Item>) => {
|
mergeMap((itemRD: RemoteData<Item>) => {
|
||||||
const type1: string = itemRD.payload.firstMetadataValue('relationship.type');
|
const type1: string = itemRD.payload.firstMetadataValue('relationship.type');
|
||||||
const type2: string = selectableObject.indexableObject.firstMetadataValue('relationship.type');
|
const type2: string = selectableObject.indexableObject.firstMetadataValue('relationship.type');
|
||||||
return this.relationshipTypeService.getRelationshipTypeByLabelAndTypes(this.relationship.relationshipType, type1, type2).pipe(
|
return this.relationshipTypeService.getRelationshipTypeByLabelAndTypes(this.relationship.relationshipType, type1, type2)
|
||||||
mergeMap((type: RelationshipType) => {
|
.pipe(
|
||||||
const isSwitched = type.rightLabel === this.relationship.relationshipType;
|
mergeMap((type: RelationshipType) => {
|
||||||
if (isSwitched) {
|
const isSwitched = type.rightLabel === this.relationship.relationshipType;
|
||||||
return this.relationshipService.addRelationship(type.id, selectableObject.indexableObject, itemRD.payload);
|
if (isSwitched) {
|
||||||
} else {
|
return this.relationshipService.addRelationship(type.id, selectableObject.indexableObject, itemRD.payload);
|
||||||
return this.relationshipService.addRelationship(type.id, itemRD.payload, selectableObject.indexableObject);
|
} else {
|
||||||
|
return this.relationshipService.addRelationship(type.id, itemRD.payload, selectableObject.indexableObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
);
|
||||||
);
|
|
||||||
|
|
||||||
}),
|
}),
|
||||||
take(1)
|
take(1)
|
||||||
)
|
)
|
||||||
@@ -176,10 +178,9 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
|
|
||||||
|
|
||||||
deselect(selectableObject: SearchResult<Item>) {
|
deselect(selectableObject: SearchResult<Item>) {
|
||||||
this.itemService.findById(this.uuid).pipe(
|
this.itemRD$.pipe(
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
switchMap((itemRD: RemoteData<Item>) => this.relationshipService.getRelationshipByItemsAndLabel(itemRD.payload, selectableObject.indexableObject, this.relationship.relationshipType)),
|
switchMap((itemRD: RemoteData<Item>) => this.relationshipService.getRelationshipByItemsAndLabel(itemRD.payload, selectableObject.indexableObject, this.relationship.relationshipType)),
|
||||||
switchMap((relationship: Relationship) => this.relationshipService.deleteRelationship(relationship.id)),
|
|
||||||
take(1)
|
take(1)
|
||||||
).subscribe();
|
).subscribe();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user