mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-4504] Fixed discard issue and submit issue
This commit is contained in:
@@ -151,25 +151,6 @@ export class ObjectUpdatesService {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that combines the state's updates (excluding updates that aren't part of the initialFields) with
|
||||
* the initial values (when there's no update) to create a FieldUpdates object
|
||||
* @param url The URL of the page for which the FieldUpdates should be requested
|
||||
* @param initialFields The initial values of the fields
|
||||
*/
|
||||
getFieldUpdatesAll(url: string, initialFields: Identifiable[]): Observable<FieldUpdates> {
|
||||
const objectUpdates = this.getObjectEntry(url);
|
||||
return objectUpdates.pipe(
|
||||
hasValueOperator(),
|
||||
map((objectEntry) => {
|
||||
console.log(objectEntry,initialFields);
|
||||
const fieldUpdates: FieldUpdates = {};
|
||||
for (const key of Object.keys(objectEntry.fieldUpdates)) {
|
||||
fieldUpdates[key] = objectEntry.fieldUpdates[key];
|
||||
}
|
||||
return fieldUpdates;
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Method to check if a specific field is currently editable in the store
|
||||
* @param url The URL of the page on which the field resides
|
||||
|
@@ -75,7 +75,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
*/
|
||||
@Output() submit: EventEmitter<any> = new EventEmitter();
|
||||
|
||||
|
||||
/**
|
||||
* Observable that emits the left and right item type of {@link relationshipType} simultaneously.
|
||||
*/
|
||||
@@ -233,9 +232,8 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.getIsRelatedItem(relatedItem)
|
||||
.subscribe((isRelated: boolean) => {
|
||||
|
||||
if (!isRelated) {
|
||||
modalComp.toAdd.push(relatedItem);
|
||||
if (!isRelated ) {
|
||||
modalComp.toAdd.push(searchResult);
|
||||
}
|
||||
|
||||
this.loading$.next(true);
|
||||
@@ -249,12 +247,12 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
selectableObjects.forEach((searchResult) => {
|
||||
const relatedItem: Item = searchResult.indexableObject;
|
||||
|
||||
const foundIndex = modalComp.toAdd.findIndex( el => el.uuid === relatedItem.uuid);
|
||||
const foundIndex = modalComp.toAdd.findIndex( el => el.indexableObject.uuid === relatedItem.uuid);
|
||||
|
||||
if (foundIndex !== -1) {
|
||||
modalComp.toAdd.splice(foundIndex,1);
|
||||
} else {
|
||||
modalComp.toRemove.push(relatedItem);
|
||||
modalComp.toRemove.push(searchResult);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -265,11 +263,12 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
|
||||
const subscriptions = [];
|
||||
|
||||
modalComp.toAdd.forEach((relatedItem) => {
|
||||
modalComp.toAdd.forEach((searchResult: SearchResult<Item>) => {
|
||||
const relatedItem = searchResult.indexableObject;
|
||||
subscriptions.push(this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe(
|
||||
map((nameVariant) => {
|
||||
const update = {
|
||||
uuid: this.relationshipType.id + '-' + relatedItem.uuid,
|
||||
uuid: this.relationshipType.id + '-' + searchResult.indexableObject.uuid,
|
||||
nameVariant,
|
||||
type: this.relationshipType,
|
||||
relatedItem,
|
||||
@@ -280,10 +279,10 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
));
|
||||
});
|
||||
|
||||
modalComp.toRemove.forEach( (relatedItem) => {
|
||||
subscriptions.push(this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe(
|
||||
modalComp.toRemove.forEach( (searchResult) => {
|
||||
subscriptions.push(this.relationshipService.getNameVariant(this.listId, searchResult.indexableObjectuuid).pipe(
|
||||
switchMap((nameVariant) => {
|
||||
return this.getRelationFromId(relatedItem).pipe(
|
||||
return this.getRelationFromId(searchResult.indexableObject).pipe(
|
||||
map( (relationship: Relationship) => {
|
||||
const update = {
|
||||
uuid: relationship.id,
|
||||
@@ -297,7 +296,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
);
|
||||
})
|
||||
));
|
||||
|
||||
});
|
||||
|
||||
observableCombineLatest(subscriptions).subscribe( (res) => {
|
||||
@@ -312,6 +310,14 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
|
||||
|
||||
modalComp.discardEv = () => {
|
||||
modalComp.toAdd.forEach((searchResult)=>{
|
||||
this.selectableListService.deselectSingle(this.listId,searchResult);
|
||||
})
|
||||
|
||||
modalComp.toRemove.forEach((searchResult)=>{
|
||||
this.selectableListService.selectSingle(this.listId,searchResult);
|
||||
})
|
||||
|
||||
modalComp.toAdd = [];
|
||||
modalComp.toRemove = [];
|
||||
};
|
||||
|
@@ -113,13 +113,12 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
Object.assign(new Relationship(), relationship, { uuid: relationship.id })
|
||||
)),
|
||||
switchMap((relationships: Relationship[]) => {
|
||||
return this.objectUpdatesService.getFieldUpdates(this.url, relationships) as Observable<FieldUpdates>;
|
||||
return this.objectUpdatesService.getFieldUpdatesExclusive(this.url, relationships) as Observable<FieldUpdates>;
|
||||
}),
|
||||
map((fieldUpdates: FieldUpdates) => {
|
||||
return Object.values(fieldUpdates)
|
||||
map((fieldUpdates: FieldUpdates) =>
|
||||
Object.values(fieldUpdates)
|
||||
.filter((fieldUpdate: FieldUpdate) => fieldUpdate.changeType === FieldChangeType.REMOVE)
|
||||
.map((fieldUpdate: FieldUpdate) => fieldUpdate.field as DeleteRelationship);
|
||||
}
|
||||
.map((fieldUpdate: FieldUpdate) => fieldUpdate.field as DeleteRelationship)
|
||||
),
|
||||
);
|
||||
|
||||
|
@@ -21,6 +21,7 @@
|
||||
[isLeft]="isLeft"
|
||||
[item]="item"
|
||||
[isEditRelationship]="isEditRelationship"
|
||||
[toRemove]="toRemove"
|
||||
(selectObject)="select($event)"
|
||||
(deselectObject)="deselect($event)"
|
||||
class="d-block pt-3">
|
||||
|
@@ -168,7 +168,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
console.log(this.toRemove);
|
||||
if (!!this.currentItemIsLeftItem$) {
|
||||
this.currentItemIsLeftItem$.subscribe((isLeft) => {
|
||||
this.isLeft = isLeft;
|
||||
|
@@ -83,6 +83,12 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
*/
|
||||
@Input() isLeft: boolean;
|
||||
|
||||
/**
|
||||
* Check if is left type or right type
|
||||
*/
|
||||
@Input() toRemove: SearchResult<Item>[];
|
||||
|
||||
|
||||
/**
|
||||
* Check if is being utilized by edit relationship component
|
||||
*/
|
||||
@@ -251,7 +257,7 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
getRemoteDataPayload(),
|
||||
).subscribe( (res: PaginatedList<Relationship>) => {
|
||||
|
||||
const selectableObject = res.page.map( (relationship: any) => {
|
||||
let selectableObject = res.page.map( (relationship: any) => {
|
||||
|
||||
let arrUrl = [];
|
||||
if ( this.isLeft ) {
|
||||
@@ -264,6 +270,10 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
return this.getRelatedItem(uuid,resultListOfItems);
|
||||
});
|
||||
|
||||
selectableObject = selectableObject.filter((selObject)=>{
|
||||
return !this.getIfInRemove(selObject.indexableObject.uuid);
|
||||
})
|
||||
|
||||
if ( selectableObject.length > 0 ) {
|
||||
this.selectableListService.select(this.listId, selectableObject);
|
||||
}
|
||||
@@ -287,6 +297,10 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
});
|
||||
}
|
||||
|
||||
getIfInRemove(uuid: string) {
|
||||
return !!this.toRemove.find((searchResult)=> searchResult.indexableObject.uuid == uuid);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (hasValue(this.subscription)) {
|
||||
this.subscription.unsubscribe();
|
||||
|
Reference in New Issue
Block a user