mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +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
|
* 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
|
* @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();
|
@Output() submit: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Observable that emits the left and right item type of {@link relationshipType} simultaneously.
|
* 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)
|
this.getIsRelatedItem(relatedItem)
|
||||||
.subscribe((isRelated: boolean) => {
|
.subscribe((isRelated: boolean) => {
|
||||||
|
if (!isRelated ) {
|
||||||
if (!isRelated) {
|
modalComp.toAdd.push(searchResult);
|
||||||
modalComp.toAdd.push(relatedItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loading$.next(true);
|
this.loading$.next(true);
|
||||||
@@ -249,12 +247,12 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
selectableObjects.forEach((searchResult) => {
|
selectableObjects.forEach((searchResult) => {
|
||||||
const relatedItem: Item = searchResult.indexableObject;
|
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) {
|
if (foundIndex !== -1) {
|
||||||
modalComp.toAdd.splice(foundIndex,1);
|
modalComp.toAdd.splice(foundIndex,1);
|
||||||
} else {
|
} else {
|
||||||
modalComp.toRemove.push(relatedItem);
|
modalComp.toRemove.push(searchResult);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -265,11 +263,12 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
const subscriptions = [];
|
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(
|
subscriptions.push(this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe(
|
||||||
map((nameVariant) => {
|
map((nameVariant) => {
|
||||||
const update = {
|
const update = {
|
||||||
uuid: this.relationshipType.id + '-' + relatedItem.uuid,
|
uuid: this.relationshipType.id + '-' + searchResult.indexableObject.uuid,
|
||||||
nameVariant,
|
nameVariant,
|
||||||
type: this.relationshipType,
|
type: this.relationshipType,
|
||||||
relatedItem,
|
relatedItem,
|
||||||
@@ -280,10 +279,10 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
modalComp.toRemove.forEach( (relatedItem) => {
|
modalComp.toRemove.forEach( (searchResult) => {
|
||||||
subscriptions.push(this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe(
|
subscriptions.push(this.relationshipService.getNameVariant(this.listId, searchResult.indexableObjectuuid).pipe(
|
||||||
switchMap((nameVariant) => {
|
switchMap((nameVariant) => {
|
||||||
return this.getRelationFromId(relatedItem).pipe(
|
return this.getRelationFromId(searchResult.indexableObject).pipe(
|
||||||
map( (relationship: Relationship) => {
|
map( (relationship: Relationship) => {
|
||||||
const update = {
|
const update = {
|
||||||
uuid: relationship.id,
|
uuid: relationship.id,
|
||||||
@@ -297,7 +296,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
);
|
);
|
||||||
})
|
})
|
||||||
));
|
));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
observableCombineLatest(subscriptions).subscribe( (res) => {
|
observableCombineLatest(subscriptions).subscribe( (res) => {
|
||||||
@@ -312,6 +310,14 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
|
|
||||||
modalComp.discardEv = () => {
|
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.toAdd = [];
|
||||||
modalComp.toRemove = [];
|
modalComp.toRemove = [];
|
||||||
};
|
};
|
||||||
|
@@ -113,13 +113,12 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
|||||||
Object.assign(new Relationship(), relationship, { uuid: relationship.id })
|
Object.assign(new Relationship(), relationship, { uuid: relationship.id })
|
||||||
)),
|
)),
|
||||||
switchMap((relationships: Relationship[]) => {
|
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) => {
|
map((fieldUpdates: FieldUpdates) =>
|
||||||
return Object.values(fieldUpdates)
|
Object.values(fieldUpdates)
|
||||||
.filter((fieldUpdate: FieldUpdate) => fieldUpdate.changeType === FieldChangeType.REMOVE)
|
.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"
|
[isLeft]="isLeft"
|
||||||
[item]="item"
|
[item]="item"
|
||||||
[isEditRelationship]="isEditRelationship"
|
[isEditRelationship]="isEditRelationship"
|
||||||
|
[toRemove]="toRemove"
|
||||||
(selectObject)="select($event)"
|
(selectObject)="select($event)"
|
||||||
(deselectObject)="deselect($event)"
|
(deselectObject)="deselect($event)"
|
||||||
class="d-block pt-3">
|
class="d-block pt-3">
|
||||||
|
@@ -168,7 +168,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
console.log(this.toRemove);
|
||||||
if (!!this.currentItemIsLeftItem$) {
|
if (!!this.currentItemIsLeftItem$) {
|
||||||
this.currentItemIsLeftItem$.subscribe((isLeft) => {
|
this.currentItemIsLeftItem$.subscribe((isLeft) => {
|
||||||
this.isLeft = isLeft;
|
this.isLeft = isLeft;
|
||||||
|
@@ -83,6 +83,12 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
|||||||
*/
|
*/
|
||||||
@Input() isLeft: boolean;
|
@Input() isLeft: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if is left type or right type
|
||||||
|
*/
|
||||||
|
@Input() toRemove: SearchResult<Item>[];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if is being utilized by edit relationship component
|
* Check if is being utilized by edit relationship component
|
||||||
*/
|
*/
|
||||||
@@ -251,7 +257,7 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
|||||||
getRemoteDataPayload(),
|
getRemoteDataPayload(),
|
||||||
).subscribe( (res: PaginatedList<Relationship>) => {
|
).subscribe( (res: PaginatedList<Relationship>) => {
|
||||||
|
|
||||||
const selectableObject = res.page.map( (relationship: any) => {
|
let selectableObject = res.page.map( (relationship: any) => {
|
||||||
|
|
||||||
let arrUrl = [];
|
let arrUrl = [];
|
||||||
if ( this.isLeft ) {
|
if ( this.isLeft ) {
|
||||||
@@ -264,6 +270,10 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
|||||||
return this.getRelatedItem(uuid,resultListOfItems);
|
return this.getRelatedItem(uuid,resultListOfItems);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
selectableObject = selectableObject.filter((selObject)=>{
|
||||||
|
return !this.getIfInRemove(selObject.indexableObject.uuid);
|
||||||
|
})
|
||||||
|
|
||||||
if ( selectableObject.length > 0 ) {
|
if ( selectableObject.length > 0 ) {
|
||||||
this.selectableListService.select(this.listId, selectableObject);
|
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 {
|
ngOnDestroy(): void {
|
||||||
if (hasValue(this.subscription)) {
|
if (hasValue(this.subscription)) {
|
||||||
this.subscription.unsubscribe();
|
this.subscription.unsubscribe();
|
||||||
|
Reference in New Issue
Block a user