mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-4504] Adding and removing in modal checkboxes, working on deleting paginated relationships
This commit is contained in:
@@ -141,6 +141,7 @@ export class ObjectUpdatesService {
|
||||
map((objectEntry) => {
|
||||
const fieldUpdates: FieldUpdates = {};
|
||||
for (const object of initialFields) {
|
||||
console.log(object.uuid,objectEntry.fieldUpdates);
|
||||
let fieldUpdate = objectEntry.fieldUpdates[object.uuid];
|
||||
if (isEmpty(fieldUpdate)) {
|
||||
fieldUpdate = { field: object, changeType: undefined };
|
||||
@@ -151,6 +152,25 @@ 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
|
||||
|
@@ -249,7 +249,8 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
modalComp.submit = this.submit;
|
||||
modalComp.reinstate = this.reinstate;
|
||||
modalComp.discard = this.discard;
|
||||
|
||||
modalComp.toAdd = [];
|
||||
modalComp.toRemove = [];
|
||||
|
||||
this.item.owningCollection.pipe(
|
||||
getFirstSucceededRemoteDataPayload()
|
||||
@@ -259,10 +260,74 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
modalComp.select = (...selectableObjects: SearchResult<Item>[]) => {
|
||||
selectableObjects.forEach((searchResult) => {
|
||||
const relatedItem: Item = searchResult.indexableObject;
|
||||
|
||||
|
||||
let foundIndex = modalComp.toRemove.findIndex( el => el.uuid == relatedItem.uuid);
|
||||
console.log("select",foundIndex);
|
||||
if(foundIndex !== -1) {
|
||||
modalComp.toRemove.splice(foundIndex,1);
|
||||
} else {
|
||||
|
||||
this.getIsRelatedItem(relatedItem)
|
||||
.subscribe((isRelated: boolean) => {
|
||||
|
||||
|
||||
if (!isRelated) {
|
||||
|
||||
|
||||
modalComp.toAdd.push(relatedItem);
|
||||
|
||||
// this.relationshipService.getNameVariant(this.listId, relatedItem.uuid)
|
||||
// .subscribe((nameVariant) => {
|
||||
// const update = {
|
||||
// uuid: this.relationshipType.id + '-' + relatedItem.uuid,
|
||||
// nameVariant,
|
||||
// type: this.relationshipType,
|
||||
// relatedItem,
|
||||
// } as RelationshipIdentifiable;
|
||||
// this.objectUpdatesService.saveAddFieldUpdate(this.url, update);
|
||||
// });
|
||||
}
|
||||
|
||||
this.loading$.next(true);
|
||||
// emit the last page again to trigger a fieldupdates refresh
|
||||
this.relationshipsRd$.next(this.relationshipsRd$.getValue());
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
modalComp.deselect = (...selectableObjects: SearchResult<Item>[]) => {
|
||||
selectableObjects.forEach((searchResult) => {
|
||||
const relatedItem: Item = searchResult.indexableObject;
|
||||
|
||||
let foundIndex = modalComp.toAdd.findIndex( el => el.uuid == relatedItem.uuid);
|
||||
console.log("deselect",foundIndex);
|
||||
|
||||
if(foundIndex !== -1) {
|
||||
modalComp.toAdd.splice(foundIndex,1);
|
||||
} else {
|
||||
modalComp.toRemove.push(relatedItem);
|
||||
}
|
||||
|
||||
|
||||
// this.objectUpdatesService.removeSingleFieldUpdate(this.url, this.relationshipType.id + '-' + relatedItem.uuid);
|
||||
// this.getFieldUpdatesForRelatedItem(relatedItem)
|
||||
// .subscribe((identifiables) =>
|
||||
// identifiables.forEach((identifiable) =>
|
||||
// this.objectUpdatesService.saveRemoveFieldUpdate(this.url, identifiable)
|
||||
// )
|
||||
// );
|
||||
});
|
||||
|
||||
// this.loading$.next(true);
|
||||
// emit the last page again to trigger a fieldupdates refresh
|
||||
// this.relationshipsRd$.next(this.relationshipsRd$.getValue());
|
||||
};
|
||||
|
||||
// TODO: JOIN SUBSCRIPTION BEFORE SUBMIT
|
||||
modalComp.submitEv = () => {
|
||||
modalComp.toAdd.forEach((relatedItem)=>{
|
||||
this.relationshipService.getNameVariant(this.listId, relatedItem.uuid)
|
||||
.subscribe((nameVariant) => {
|
||||
const update = {
|
||||
@@ -273,30 +338,37 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
} as RelationshipIdentifiable;
|
||||
this.objectUpdatesService.saveAddFieldUpdate(this.url, update);
|
||||
});
|
||||
});
|
||||
|
||||
modalComp.toRemove.forEach((relatedItem)=>{
|
||||
this.relationshipService.getNameVariant(this.listId, relatedItem.uuid)
|
||||
.subscribe((nameVariant) => {
|
||||
const update = {
|
||||
uuid: this.relationshipType.id + '-' + relatedItem.uuid,
|
||||
nameVariant,
|
||||
type: this.relationshipType,
|
||||
relatedItem,
|
||||
} as RelationshipIdentifiable;
|
||||
this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update);
|
||||
|
||||
});
|
||||
|
||||
// this.objectUpdatesService.removeSingleFieldUpdate(this.url, this.relationshipType.id + '-' + relatedItem.uuid);
|
||||
// this.getFieldUpdatesForRelatedItem(relatedItem)
|
||||
// .subscribe((identifiables) =>
|
||||
// identifiables.forEach((identifiable) =>
|
||||
// this.objectUpdatesService.saveRemoveFieldUpdate(this.url, identifiable)
|
||||
// )
|
||||
// );
|
||||
});
|
||||
|
||||
setTimeout(()=>{
|
||||
this.submit.emit();
|
||||
this.modalRef.close();
|
||||
},3000);
|
||||
|
||||
}
|
||||
|
||||
this.loading$.next(true);
|
||||
// emit the last page again to trigger a fieldupdates refresh
|
||||
this.relationshipsRd$.next(this.relationshipsRd$.getValue());
|
||||
});
|
||||
});
|
||||
};
|
||||
modalComp.deselect = (...selectableObjects: SearchResult<Item>[]) => {
|
||||
selectableObjects.forEach((searchResult) => {
|
||||
const relatedItem: Item = searchResult.indexableObject;
|
||||
this.objectUpdatesService.removeSingleFieldUpdate(this.url, this.relationshipType.id + '-' + relatedItem.uuid);
|
||||
this.getFieldUpdatesForRelatedItem(relatedItem)
|
||||
.subscribe((identifiables) =>
|
||||
identifiables.forEach((identifiable) =>
|
||||
this.objectUpdatesService.saveRemoveFieldUpdate(this.url, identifiable)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
this.loading$.next(true);
|
||||
// emit the last page again to trigger a fieldupdates refresh
|
||||
this.relationshipsRd$.next(this.relationshipsRd$.getValue());
|
||||
};
|
||||
this.relatedEntityType$
|
||||
.pipe(take(1))
|
||||
.subscribe((relatedEntityType) => {
|
||||
|
@@ -108,6 +108,10 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
*/
|
||||
public submit(): void {
|
||||
|
||||
this.relationshipService.getItemRelationshipsArray(this.item).pipe(
|
||||
take(1)
|
||||
).subscribe(res=>console.log(res));
|
||||
|
||||
// Get all the relationships that should be removed
|
||||
const removedRelationshipIDs$: Observable<DeleteRelationship[]> = this.relationshipService.getItemRelationshipsArray(this.item).pipe(
|
||||
startWith([]),
|
||||
@@ -115,12 +119,14 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
Object.assign(new Relationship(), relationship, { uuid: relationship.id })
|
||||
)),
|
||||
switchMap((relationships: Relationship[]) => {
|
||||
return this.objectUpdatesService.getFieldUpdatesExclusive(this.url, relationships) as Observable<FieldUpdates>;
|
||||
return this.objectUpdatesService.getFieldUpdatesAll(this.url, relationships) as Observable<FieldUpdates>;
|
||||
}),
|
||||
map((fieldUpdates: FieldUpdates) =>
|
||||
Object.values(fieldUpdates)
|
||||
map((fieldUpdates: FieldUpdates) =>{
|
||||
console.log(fieldUpdates);
|
||||
return Object.values(fieldUpdates)
|
||||
.filter((fieldUpdate: FieldUpdate) => fieldUpdate.changeType === FieldChangeType.REMOVE)
|
||||
.map((fieldUpdate: FieldUpdate) => fieldUpdate.field as DeleteRelationship)
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
@@ -156,6 +162,7 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
}
|
||||
|
||||
deleteRelationships(deleteRelationshipIDs: DeleteRelationship[]): Observable<RemoteData<NoContent>[]> {
|
||||
console.log(deleteRelationshipIDs);
|
||||
return observableZip(...deleteRelationshipIDs.map((deleteRelationship) => {
|
||||
let copyVirtualMetadata: string;
|
||||
if (deleteRelationship.keepLeftVirtualMetadata && deleteRelationship.keepRightVirtualMetadata) {
|
||||
|
@@ -79,7 +79,8 @@
|
||||
class="fas fa-undo-alt"></i>
|
||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.reinstate-button" | translate}}</span>
|
||||
</button>
|
||||
<button class="btn btn-primary submit" [disabled]="!(hasChanges | async)"
|
||||
<!-- [disabled]="!(hasChanges | async)" -->
|
||||
<button class="btn btn-primary submit"
|
||||
(click)="submitEv()"><i
|
||||
class="fas fa-save"></i>
|
||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.save-button" | translate}}</span>
|
||||
|
@@ -27,6 +27,7 @@ import { RemoteDataBuildService } from '../../../../../core/cache/builders/remot
|
||||
import { getAllSucceededRemoteDataPayload } from '../../../../../core/shared/operators';
|
||||
import { RelationshipType } from '../../../../../core/shared/item-relationships/relationship-type.model';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'ds-dynamic-lookup-relation-modal',
|
||||
styleUrls: ['./dynamic-lookup-relation-modal.component.scss'],
|
||||
@@ -161,6 +162,8 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
*/
|
||||
discard: EventEmitter<any>;
|
||||
|
||||
toAdd = [];
|
||||
toRemove = [];
|
||||
|
||||
constructor(
|
||||
public modal: NgbActiveModal,
|
||||
@@ -313,7 +316,8 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
* Called when submit button is clicked, emit submit event to parent to conclude functionality
|
||||
*/
|
||||
submitEv(): void {
|
||||
this.submit.emit();
|
||||
console.log(this.toAdd, this.toRemove);
|
||||
// this.submit.emit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -247,7 +247,10 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
if ( this.isLeft ) {
|
||||
relationType = this.relationshipType.leftwardType;
|
||||
}
|
||||
this.relationshipService.searchByItemsAndType( this.relationshipType.id, this.item.uuid, relationType ,idOfItems ).subscribe( (res: PaginatedList<Relationship[]>) => {
|
||||
this.relationshipService.searchByItemsAndType( this.relationshipType.id, this.item.uuid, relationType ,idOfItems ).pipe(
|
||||
|
||||
|
||||
).subscribe( (res: PaginatedList<Relationship[]>) => {
|
||||
|
||||
const selectableObject = res.page.map( (relationship: any) => {
|
||||
|
||||
@@ -261,6 +264,14 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
|
||||
return this.getRelatedItem(uuid,resultListOfItems);
|
||||
|
||||
// return {
|
||||
// uuid: relationship.id,
|
||||
// type: this.relationshipType,
|
||||
// relationship,
|
||||
// nameVariant,
|
||||
// } as RelationshipIdentifiable;
|
||||
|
||||
|
||||
});
|
||||
|
||||
if ( selectableObject.length > 0 ) {
|
||||
|
Reference in New Issue
Block a user