mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +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) => {
|
map((objectEntry) => {
|
||||||
const fieldUpdates: FieldUpdates = {};
|
const fieldUpdates: FieldUpdates = {};
|
||||||
for (const object of initialFields) {
|
for (const object of initialFields) {
|
||||||
|
console.log(object.uuid,objectEntry.fieldUpdates);
|
||||||
let fieldUpdate = objectEntry.fieldUpdates[object.uuid];
|
let fieldUpdate = objectEntry.fieldUpdates[object.uuid];
|
||||||
if (isEmpty(fieldUpdate)) {
|
if (isEmpty(fieldUpdate)) {
|
||||||
fieldUpdate = { field: object, changeType: undefined };
|
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
|
* 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
|
||||||
|
@@ -249,7 +249,8 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
modalComp.submit = this.submit;
|
modalComp.submit = this.submit;
|
||||||
modalComp.reinstate = this.reinstate;
|
modalComp.reinstate = this.reinstate;
|
||||||
modalComp.discard = this.discard;
|
modalComp.discard = this.discard;
|
||||||
|
modalComp.toAdd = [];
|
||||||
|
modalComp.toRemove = [];
|
||||||
|
|
||||||
this.item.owningCollection.pipe(
|
this.item.owningCollection.pipe(
|
||||||
getFirstSucceededRemoteDataPayload()
|
getFirstSucceededRemoteDataPayload()
|
||||||
@@ -259,10 +260,74 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
modalComp.select = (...selectableObjects: SearchResult<Item>[]) => {
|
modalComp.select = (...selectableObjects: SearchResult<Item>[]) => {
|
||||||
selectableObjects.forEach((searchResult) => {
|
selectableObjects.forEach((searchResult) => {
|
||||||
const relatedItem: Item = searchResult.indexableObject;
|
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)
|
this.getIsRelatedItem(relatedItem)
|
||||||
.subscribe((isRelated: boolean) => {
|
.subscribe((isRelated: boolean) => {
|
||||||
|
|
||||||
|
|
||||||
if (!isRelated) {
|
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)
|
this.relationshipService.getNameVariant(this.listId, relatedItem.uuid)
|
||||||
.subscribe((nameVariant) => {
|
.subscribe((nameVariant) => {
|
||||||
const update = {
|
const update = {
|
||||||
@@ -273,30 +338,37 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
} as RelationshipIdentifiable;
|
} as RelationshipIdentifiable;
|
||||||
this.objectUpdatesService.saveAddFieldUpdate(this.url, update);
|
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$
|
this.relatedEntityType$
|
||||||
.pipe(take(1))
|
.pipe(take(1))
|
||||||
.subscribe((relatedEntityType) => {
|
.subscribe((relatedEntityType) => {
|
||||||
|
@@ -108,6 +108,10 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
|||||||
*/
|
*/
|
||||||
public submit(): void {
|
public submit(): void {
|
||||||
|
|
||||||
|
this.relationshipService.getItemRelationshipsArray(this.item).pipe(
|
||||||
|
take(1)
|
||||||
|
).subscribe(res=>console.log(res));
|
||||||
|
|
||||||
// Get all the relationships that should be removed
|
// Get all the relationships that should be removed
|
||||||
const removedRelationshipIDs$: Observable<DeleteRelationship[]> = this.relationshipService.getItemRelationshipsArray(this.item).pipe(
|
const removedRelationshipIDs$: Observable<DeleteRelationship[]> = this.relationshipService.getItemRelationshipsArray(this.item).pipe(
|
||||||
startWith([]),
|
startWith([]),
|
||||||
@@ -115,12 +119,14 @@ 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.getFieldUpdatesExclusive(this.url, relationships) as Observable<FieldUpdates>;
|
return this.objectUpdatesService.getFieldUpdatesAll(this.url, relationships) as Observable<FieldUpdates>;
|
||||||
}),
|
}),
|
||||||
map((fieldUpdates: FieldUpdates) =>
|
map((fieldUpdates: FieldUpdates) =>{
|
||||||
Object.values(fieldUpdates)
|
console.log(fieldUpdates);
|
||||||
|
return 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)
|
||||||
|
}
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -156,6 +162,7 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteRelationships(deleteRelationshipIDs: DeleteRelationship[]): Observable<RemoteData<NoContent>[]> {
|
deleteRelationships(deleteRelationshipIDs: DeleteRelationship[]): Observable<RemoteData<NoContent>[]> {
|
||||||
|
console.log(deleteRelationshipIDs);
|
||||||
return observableZip(...deleteRelationshipIDs.map((deleteRelationship) => {
|
return observableZip(...deleteRelationshipIDs.map((deleteRelationship) => {
|
||||||
let copyVirtualMetadata: string;
|
let copyVirtualMetadata: string;
|
||||||
if (deleteRelationship.keepLeftVirtualMetadata && deleteRelationship.keepRightVirtualMetadata) {
|
if (deleteRelationship.keepLeftVirtualMetadata && deleteRelationship.keepRightVirtualMetadata) {
|
||||||
|
@@ -79,7 +79,8 @@
|
|||||||
class="fas fa-undo-alt"></i>
|
class="fas fa-undo-alt"></i>
|
||||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.reinstate-button" | translate}}</span>
|
<span class="d-none d-sm-inline"> {{"item.edit.metadata.reinstate-button" | translate}}</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-primary submit" [disabled]="!(hasChanges | async)"
|
<!-- [disabled]="!(hasChanges | async)" -->
|
||||||
|
<button class="btn btn-primary submit"
|
||||||
(click)="submitEv()"><i
|
(click)="submitEv()"><i
|
||||||
class="fas fa-save"></i>
|
class="fas fa-save"></i>
|
||||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.save-button" | translate}}</span>
|
<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 { getAllSucceededRemoteDataPayload } from '../../../../../core/shared/operators';
|
||||||
import { RelationshipType } from '../../../../../core/shared/item-relationships/relationship-type.model';
|
import { RelationshipType } from '../../../../../core/shared/item-relationships/relationship-type.model';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dynamic-lookup-relation-modal',
|
selector: 'ds-dynamic-lookup-relation-modal',
|
||||||
styleUrls: ['./dynamic-lookup-relation-modal.component.scss'],
|
styleUrls: ['./dynamic-lookup-relation-modal.component.scss'],
|
||||||
@@ -161,6 +162,8 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
*/
|
*/
|
||||||
discard: EventEmitter<any>;
|
discard: EventEmitter<any>;
|
||||||
|
|
||||||
|
toAdd = [];
|
||||||
|
toRemove = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public modal: NgbActiveModal,
|
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
|
* Called when submit button is clicked, emit submit event to parent to conclude functionality
|
||||||
*/
|
*/
|
||||||
submitEv(): void {
|
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 ) {
|
if ( this.isLeft ) {
|
||||||
relationType = this.relationshipType.leftwardType;
|
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) => {
|
const selectableObject = res.page.map( (relationship: any) => {
|
||||||
|
|
||||||
@@ -261,6 +264,14 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
|||||||
|
|
||||||
return this.getRelatedItem(uuid,resultListOfItems);
|
return this.getRelatedItem(uuid,resultListOfItems);
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// uuid: relationship.id,
|
||||||
|
// type: this.relationshipType,
|
||||||
|
// relationship,
|
||||||
|
// nameVariant,
|
||||||
|
// } as RelationshipIdentifiable;
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if ( selectableObject.length > 0 ) {
|
if ( selectableObject.length > 0 ) {
|
||||||
|
Reference in New Issue
Block a user