mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
[CST-4504] Fixed multiple delete & multiple add in modal and changed unit testing
This commit is contained in:
@@ -141,7 +141,6 @@ 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 };
|
||||||
|
@@ -497,6 +497,14 @@ export class RelationshipService extends DataService<Relationship> {
|
|||||||
fieldName: 'size',
|
fieldName: 'size',
|
||||||
fieldValue: arrayOfItemIds.length
|
fieldValue: arrayOfItemIds.length
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'embed',
|
||||||
|
fieldValue: 'leftItem'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'embed',
|
||||||
|
fieldValue: 'rightItem'
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
arrayOfItemIds.forEach( (itemId) => {
|
arrayOfItemIds.forEach( (itemId) => {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<h5>
|
<h5>
|
||||||
{{getRelationshipMessageKey() | async | translate}}
|
{{getRelationshipMessageKey() | async | translate}}
|
||||||
<button class="ml-2 btn btn-success" (click)="openLookup()">
|
<button class="ml-2 btn btn-success" [disabled]="(hasChanges | async)" (click)="openLookup()">
|
||||||
<i class="fas fa-plus"></i>
|
<i class="fas fa-plus"></i>
|
||||||
<span class="d-none d-sm-inline"> {{"item.edit.relationships.edit.buttons.add" | translate}}</span>
|
<span class="d-none d-sm-inline"> {{"item.edit.relationships.edit.buttons.add" | translate}}</span>
|
||||||
</button>
|
</button>
|
||||||
|
@@ -59,6 +59,7 @@ describe('EditRelationshipListComponent', () => {
|
|||||||
comp.itemType = entityType;
|
comp.itemType = entityType;
|
||||||
comp.url = url;
|
comp.url = url;
|
||||||
comp.relationshipType = relationshipType;
|
comp.relationshipType = relationshipType;
|
||||||
|
comp.hasChanges = observableOf(false);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -278,6 +279,24 @@ describe('EditRelationshipListComponent', () => {
|
|||||||
expect(label).toEqual('isAuthorOfPublication');
|
expect(label).toEqual('isAuthorOfPublication');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
describe('changes managment for add buttons', () => {
|
||||||
|
|
||||||
|
it('should show enabled add buttons', () => {
|
||||||
|
const element = de.query(By.css('.btn-success'));
|
||||||
|
expect(element.nativeElement?.disabled).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('after hash changes changed', () => {
|
||||||
|
comp.hasChanges = observableOf(true);
|
||||||
|
fixture.detectChanges();
|
||||||
|
const element = de.query(By.css('.btn-success'));
|
||||||
|
expect(element.nativeElement?.disabled).toBeTrue();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -81,32 +81,16 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
*/
|
*/
|
||||||
@Input() relationshipType: RelationshipType;
|
@Input() relationshipType: RelationshipType;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If updated information has changed
|
* If updated information has changed
|
||||||
*/
|
*/
|
||||||
@Input() hasChanges!: Observable<boolean>;
|
@Input() hasChanges!: Observable<boolean>;
|
||||||
|
|
||||||
/**
|
|
||||||
* If changes have been discarded and need reinstated
|
|
||||||
*/
|
|
||||||
@Input() isReinstatable!: Observable<boolean>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The event emmiter to submit the new information
|
* The event emmiter to submit the new information
|
||||||
*/
|
*/
|
||||||
@Output() submit: EventEmitter<any> = new EventEmitter();
|
@Output() submit: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
/**
|
|
||||||
* The event emmiter to reinstate the discarded information
|
|
||||||
*/
|
|
||||||
@Output() reinstate: EventEmitter<any> = new EventEmitter();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The event emmiter to discard the new information
|
|
||||||
*/
|
|
||||||
@Output() discard: 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.
|
||||||
@@ -168,7 +152,6 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
modalRef: NgbModalRef;
|
modalRef: NgbModalRef;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected objectUpdatesService: ObjectUpdatesService,
|
protected objectUpdatesService: ObjectUpdatesService,
|
||||||
protected linkService: LinkService,
|
protected linkService: LinkService,
|
||||||
@@ -244,92 +227,63 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
modalComp.item = this.item;
|
modalComp.item = this.item;
|
||||||
modalComp.relationshipType = this.relationshipType;
|
modalComp.relationshipType = this.relationshipType;
|
||||||
modalComp.currentItemIsLeftItem$ = this.currentItemIsLeftItem$;
|
modalComp.currentItemIsLeftItem$ = this.currentItemIsLeftItem$;
|
||||||
modalComp.hasChanges = this.hasChanges;
|
|
||||||
modalComp.isReinstatable = this.isReinstatable;
|
|
||||||
modalComp.submit = this.submit;
|
|
||||||
modalComp.reinstate = this.reinstate;
|
|
||||||
modalComp.discard = this.discard;
|
|
||||||
modalComp.toAdd = [];
|
modalComp.toAdd = [];
|
||||||
modalComp.toRemove = [];
|
modalComp.toRemove = [];
|
||||||
|
modalComp.isPending = false;
|
||||||
|
|
||||||
this.item.owningCollection.pipe(
|
this.item.owningCollection.pipe(
|
||||||
getFirstSucceededRemoteDataPayload()
|
getFirstSucceededRemoteDataPayload()
|
||||||
).subscribe((collection: Collection) => {
|
).subscribe((collection: Collection) => {
|
||||||
modalComp.collection = collection;
|
modalComp.collection = collection;
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
const foundIndex = modalComp.toRemove.findIndex( el => el.uuid === relatedItem.uuid);
|
||||||
console.log("select",foundIndex);
|
|
||||||
if(foundIndex !== -1) {
|
if (foundIndex !== -1) {
|
||||||
modalComp.toRemove.splice(foundIndex,1);
|
modalComp.toRemove.splice(foundIndex,1);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
this.getIsRelatedItem(relatedItem)
|
this.getIsRelatedItem(relatedItem)
|
||||||
.subscribe((isRelated: boolean) => {
|
.subscribe((isRelated: boolean) => {
|
||||||
|
|
||||||
|
if (!isRelated) {
|
||||||
|
modalComp.toAdd.push(relatedItem);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isRelated) {
|
this.loading$.next(true);
|
||||||
|
// emit the last page again to trigger a fieldupdates refresh
|
||||||
|
this.relationshipsRd$.next(this.relationshipsRd$.getValue());
|
||||||
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>[]) => {
|
modalComp.deselect = (...selectableObjects: SearchResult<Item>[]) => {
|
||||||
selectableObjects.forEach((searchResult) => {
|
selectableObjects.forEach((searchResult) => {
|
||||||
const relatedItem: Item = searchResult.indexableObject;
|
const relatedItem: Item = searchResult.indexableObject;
|
||||||
|
|
||||||
let foundIndex = modalComp.toAdd.findIndex( el => el.uuid == relatedItem.uuid);
|
const foundIndex = modalComp.toAdd.findIndex( el => el.uuid === relatedItem.uuid);
|
||||||
console.log("deselect",foundIndex);
|
|
||||||
|
|
||||||
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(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.submitEv = () => {
|
||||||
modalComp.toAdd.forEach((relatedItem)=>{
|
|
||||||
this.relationshipService.getNameVariant(this.listId, relatedItem.uuid)
|
const subscriptions = [];
|
||||||
.subscribe((nameVariant) => {
|
|
||||||
|
modalComp.toAdd.forEach((relatedItem) => {
|
||||||
|
subscriptions.push(this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe(
|
||||||
|
map((nameVariant) => {
|
||||||
const update = {
|
const update = {
|
||||||
uuid: this.relationshipType.id + '-' + relatedItem.uuid,
|
uuid: this.relationshipType.id + '-' + relatedItem.uuid,
|
||||||
nameVariant,
|
nameVariant,
|
||||||
@@ -337,37 +291,46 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
relatedItem,
|
relatedItem,
|
||||||
} as RelationshipIdentifiable;
|
} as RelationshipIdentifiable;
|
||||||
this.objectUpdatesService.saveAddFieldUpdate(this.url, update);
|
this.objectUpdatesService.saveAddFieldUpdate(this.url, update);
|
||||||
});
|
return update;
|
||||||
|
})
|
||||||
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
modalComp.toRemove.forEach((relatedItem)=>{
|
modalComp.toRemove.forEach( (relatedItem) => {
|
||||||
this.relationshipService.getNameVariant(this.listId, relatedItem.uuid)
|
subscriptions.push(this.relationshipService.getNameVariant(this.listId, relatedItem.uuid).pipe(
|
||||||
.subscribe((nameVariant) => {
|
switchMap((nameVariant) => {
|
||||||
const update = {
|
return this.getRelationFromId(relatedItem).pipe(
|
||||||
uuid: this.relationshipType.id + '-' + relatedItem.uuid,
|
map( (relationship: Relationship) => {
|
||||||
nameVariant,
|
const update = {
|
||||||
type: this.relationshipType,
|
uuid: relationship.id,
|
||||||
relatedItem,
|
nameVariant,
|
||||||
} as RelationshipIdentifiable;
|
type: this.relationshipType,
|
||||||
this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update);
|
relationship,
|
||||||
|
} as RelationshipIdentifiable;
|
||||||
|
this.objectUpdatesService.saveRemoveFieldUpdate(this.url,update);
|
||||||
|
return 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(()=>{
|
observableCombineLatest(subscriptions).subscribe( (res) => {
|
||||||
this.submit.emit();
|
// Wait until the states changes since there are multiple items
|
||||||
this.modalRef.close();
|
setTimeout( () => {
|
||||||
},3000);
|
this.submit.emit();
|
||||||
|
},1000);
|
||||||
|
|
||||||
}
|
modalComp.isPending = true;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
modalComp.discardEv = () => {
|
||||||
|
modalComp.toAdd = [];
|
||||||
|
modalComp.toRemove = [];
|
||||||
|
};
|
||||||
|
|
||||||
this.relatedEntityType$
|
this.relatedEntityType$
|
||||||
.pipe(take(1))
|
.pipe(take(1))
|
||||||
@@ -385,6 +348,26 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
|||||||
this.selectableListService.deselectAll(this.listId);
|
this.selectableListService.deselectAll(this.listId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRelationFromId(relatedItem) {
|
||||||
|
return this.currentItemIsLeftItem$.pipe(
|
||||||
|
take(1),
|
||||||
|
switchMap( isLeft => {
|
||||||
|
let apiCall;
|
||||||
|
if (isLeft) {
|
||||||
|
apiCall = this.relationshipService.searchByItemsAndType( this.relationshipType.id, this.item.uuid, this.relationshipType.leftwardType ,[relatedItem.id] );
|
||||||
|
} else {
|
||||||
|
apiCall = this.relationshipService.searchByItemsAndType( this.relationshipType.id, this.item.uuid, this.relationshipType.rightwardType ,[relatedItem.id] );
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiCall.pipe(
|
||||||
|
map( (res: PaginatedList<Relationship[]>) => res.page[0])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the existing field updates regarding a relationship with a given item
|
* Get the existing field updates regarding a relationship with a given item
|
||||||
* @param relatedItem The item for which to get the existing field updates
|
* @param relatedItem The item for which to get the existing field updates
|
||||||
|
@@ -79,7 +79,7 @@ export class EditRelationshipComponent implements OnChanges {
|
|||||||
* Sets the current relationship based on the fieldUpdate input field
|
* Sets the current relationship based on the fieldUpdate input field
|
||||||
*/
|
*/
|
||||||
ngOnChanges(): void {
|
ngOnChanges(): void {
|
||||||
if (this.relationship) {
|
if (this.relationship && (!!this.relationship.leftItem || !!this.relationship.rightItem)) {
|
||||||
this.leftItem$ = this.relationship.leftItem.pipe(
|
this.leftItem$ = this.relationship.leftItem.pipe(
|
||||||
getFirstSucceededRemoteData(),
|
getFirstSucceededRemoteData(),
|
||||||
getRemoteDataPayload(),
|
getRemoteDataPayload(),
|
||||||
|
@@ -28,9 +28,6 @@
|
|||||||
[itemType]="entityType$ | async"
|
[itemType]="entityType$ | async"
|
||||||
[relationshipType]="relationshipType"
|
[relationshipType]="relationshipType"
|
||||||
[hasChanges] = hasChanges()
|
[hasChanges] = hasChanges()
|
||||||
[isReinstatable] = isReinstatable()
|
|
||||||
(discard) = discard()
|
|
||||||
(reinstate) = reinstate()
|
|
||||||
(submit) = submit()
|
(submit) = submit()
|
||||||
></ds-edit-relationship-list>
|
></ds-edit-relationship-list>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -34,6 +34,7 @@ import { NoContent } from '../../../core/shared/NoContent.model';
|
|||||||
import { hasValue } from '../../../shared/empty.util';
|
import { hasValue } from '../../../shared/empty.util';
|
||||||
import { RelationshipTypeService } from '../../../core/data/relationship-type.service';
|
import { RelationshipTypeService } from '../../../core/data/relationship-type.service';
|
||||||
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||||
|
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-item-relationships',
|
selector: 'ds-item-relationships',
|
||||||
@@ -69,6 +70,7 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
|||||||
public entityTypeService: EntityTypeService,
|
public entityTypeService: EntityTypeService,
|
||||||
protected relationshipTypeService: RelationshipTypeService,
|
protected relationshipTypeService: RelationshipTypeService,
|
||||||
public cdr: ChangeDetectorRef,
|
public cdr: ChangeDetectorRef,
|
||||||
|
protected modalService: NgbModal,
|
||||||
) {
|
) {
|
||||||
super(itemService, objectUpdatesService, router, notificationsService, translateService, route);
|
super(itemService, objectUpdatesService, router, notificationsService, translateService, route);
|
||||||
}
|
}
|
||||||
@@ -108,10 +110,6 @@ 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([]),
|
||||||
@@ -119,13 +117,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.getFieldUpdatesAll(this.url, relationships) as Observable<FieldUpdates>;
|
return this.objectUpdatesService.getFieldUpdates(this.url, relationships) as Observable<FieldUpdates>;
|
||||||
}),
|
}),
|
||||||
map((fieldUpdates: FieldUpdates) =>{
|
map((fieldUpdates: FieldUpdates) => {
|
||||||
console.log(fieldUpdates);
|
|
||||||
return Object.values(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);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -155,6 +152,7 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
|||||||
this.initializeOriginalFields();
|
this.initializeOriginalFields();
|
||||||
this.cdr.detectChanges();
|
this.cdr.detectChanges();
|
||||||
this.displayNotifications(response);
|
this.displayNotifications(response);
|
||||||
|
this.modalService.dismissAll();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -162,7 +160,6 @@ 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) {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h4 class="modal-title" id="modal-title">{{ ('submission.sections.describe.relationship-lookup.title.' + relationshipOptions.relationshipType) | translate }}</h4>
|
<h4 class="modal-title" id="modal-title">{{ ('submission.sections.describe.relationship-lookup.title.' + relationshipOptions.relationshipType) | translate }}</h4>
|
||||||
<button type="button" class="close" aria-label="Close button" aria-describedby="modal-title"
|
<button type="button" [disabled]="isPending" class="close" aria-label="Close button" aria-describedby="modal-title"
|
||||||
(click)="modal.dismiss()">
|
(click)="close()">
|
||||||
<span aria-hidden="true">×</span>
|
<span aria-hidden="true">×</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -64,25 +64,27 @@
|
|||||||
<small>{{ ('submission.sections.describe.relationship-lookup.selected' | translate: {size: (selection$ | async)?.length || 0}) }}</small>
|
<small>{{ ('submission.sections.describe.relationship-lookup.selected' | translate: {size: (selection$ | async)?.length || 0}) }}</small>
|
||||||
<div class="buttons-container">
|
<div class="buttons-container">
|
||||||
<div class="close-button">
|
<div class="close-button">
|
||||||
<button type="button" class="btn btn-danger" (click)="close()">{{ ('submission.sections.describe.relationship-lookup.close' | translate) }}</button>
|
<button type="button" [disabled]="isPending" class="btn btn-outline-secondary" (click)="close()">
|
||||||
|
<span *ngIf="isPending" class="spinner-border spinner-border-sm" role="status"
|
||||||
|
aria-hidden="true"></span>
|
||||||
|
{{ ('submission.sections.describe.relationship-lookup.close' | translate) }}</button>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="isEditRelationship" class="button-row bottom">
|
<div *ngIf="isEditRelationship" class="button-row bottom">
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<button class="btn btn-danger discard" *ngIf="!(isReinstatable | async)"
|
<button class="btn btn-danger discard"
|
||||||
[disabled]="!(hasChanges | async)"
|
[disabled]="(toAdd.length == 0 && toRemove.length == 0) || isPending"
|
||||||
(click)="discardEv()"><i
|
(click)="discardEv()">
|
||||||
class="fas fa-times"></i>
|
<span *ngIf="isPending" class="spinner-border spinner-border-sm" role="status"
|
||||||
|
aria-hidden="true"></span>
|
||||||
|
<i class="fas fa-times"></i>
|
||||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.discard-button" | translate}}</span>
|
<span class="d-none d-sm-inline"> {{"item.edit.metadata.discard-button" | translate}}</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-warning reinstate" *ngIf="isReinstatable | async"
|
|
||||||
(click)="reinstateEv()"><i
|
|
||||||
class="fas fa-undo-alt"></i>
|
|
||||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.reinstate-button" | translate}}</span>
|
|
||||||
</button>
|
|
||||||
<!-- [disabled]="!(hasChanges | async)" -->
|
|
||||||
<button class="btn btn-primary submit"
|
<button class="btn btn-primary submit"
|
||||||
(click)="submitEv()"><i
|
[disabled]="(toAdd.length == 0 && toRemove.length == 0) || isPending"
|
||||||
class="fas fa-save"></i>
|
(click)="submitEv()">
|
||||||
|
<span *ngIf="isPending" class="spinner-border spinner-border-sm" role="status"
|
||||||
|
aria-hidden="true"></span>
|
||||||
|
<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>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -8,6 +8,10 @@
|
|||||||
width: 90%;
|
width: 90%;
|
||||||
margin: 5%;
|
margin: 5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.spinner-border{
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.buttons-container{
|
.buttons-container{
|
||||||
|
@@ -147,11 +147,8 @@ describe('DsDynamicLookupRelationModalComponent', () => {
|
|||||||
component.submissionId = submissionId;
|
component.submissionId = submissionId;
|
||||||
component.isEditRelationship = true;
|
component.isEditRelationship = true;
|
||||||
component.currentItemIsLeftItem$ = observableOf(true);
|
component.currentItemIsLeftItem$ = observableOf(true);
|
||||||
component.hasChanges = observableOf(false);
|
component.toAdd = [];
|
||||||
component.isReinstatable = observableOf(false);
|
component.toRemove = [];
|
||||||
component.submit = new EventEmitter();
|
|
||||||
component.reinstate = new EventEmitter();
|
|
||||||
component.discard = new EventEmitter();
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -213,14 +210,12 @@ describe('DsDynamicLookupRelationModalComponent', () => {
|
|||||||
it('discard button should be disabled', () => {
|
it('discard button should be disabled', () => {
|
||||||
expect(debugElement.query(By.css('.discard')).nativeElement?.disabled).toBeTrue();
|
expect(debugElement.query(By.css('.discard')).nativeElement?.disabled).toBeTrue();
|
||||||
});
|
});
|
||||||
it('should not show reinstate button', () => {
|
|
||||||
expect(debugElement.query(By.css('.reinstate'))).toBeNull();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when changes happen', () => {
|
describe('when changes happen', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
component.hasChanges = observableOf(true);
|
component.toAdd.push(searchResult1);
|
||||||
|
component.toRemove.push(searchResult2);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
it('submit button should be enabled', () => {
|
it('submit button should be enabled', () => {
|
||||||
@@ -241,25 +236,18 @@ describe('DsDynamicLookupRelationModalComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when changes happen & isReinstatable', () => {
|
|
||||||
|
describe('when request starts and isPending changes', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
component.hasChanges = observableOf(true);
|
component.isPending = true;
|
||||||
component.isReinstatable = observableOf(true);
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
it('should show reinstate button', () => {
|
|
||||||
expect(debugElement.query(By.css('.reinstate'))).toBeTruthy();
|
it('there should show 3 spinner for the 3 buttons', () => {
|
||||||
});
|
expect(debugElement.queryAll(By.css('.spinner-border')).length).toEqual(3);
|
||||||
it('should not show discard button', () => {
|
|
||||||
expect(debugElement.query(By.css('.discard'))).toBeNull();
|
|
||||||
});
|
|
||||||
it('reinstate button should be enabled', () => {
|
|
||||||
expect(debugElement.query(By.css('.reinstate')).nativeElement.disabled).toBeFalse();
|
|
||||||
});
|
|
||||||
it('should call reinstateEv when reinstate clicked', () => {
|
|
||||||
const reinstateFunct = spyOn((component as any), 'reinstateEv');
|
|
||||||
debugElement.query(By.css('.reinstate')).nativeElement.click();
|
|
||||||
expect(reinstateFunct).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -136,35 +136,11 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
*/
|
*/
|
||||||
isEditRelationship = false;
|
isEditRelationship = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Observable to check if any change has been made
|
|
||||||
*/
|
|
||||||
hasChanges: Observable<boolean>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Observable to check if any discard has been made
|
|
||||||
*/
|
|
||||||
isReinstatable: Observable<boolean>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Submit event emiter to emit to parent
|
|
||||||
*/
|
|
||||||
submit: EventEmitter<any>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reinstate event emiter to emit to parent
|
|
||||||
*/
|
|
||||||
reinstate: EventEmitter<any>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Discard event emiter to emit to parent
|
|
||||||
*/
|
|
||||||
discard: EventEmitter<any>;
|
|
||||||
|
|
||||||
toAdd = [];
|
toAdd = [];
|
||||||
toRemove = [];
|
toRemove = [];
|
||||||
|
|
||||||
|
isPending = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public modal: NgbActiveModal,
|
public modal: NgbActiveModal,
|
||||||
private selectableListService: SelectableListService,
|
private selectableListService: SelectableListService,
|
||||||
@@ -213,6 +189,8 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
|
this.toAdd = [];
|
||||||
|
this.toRemove = [];
|
||||||
this.modal.close();
|
this.modal.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,26 +283,18 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
Object.values(this.subMap).forEach((subscription) => subscription.unsubscribe());
|
Object.values(this.subMap).forEach((subscription) => subscription.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* tslint:disable:no-empty */
|
||||||
/**
|
/**
|
||||||
* Called when discard button is clicked, emit discard event to parent to conclude functionality
|
* Called when discard button is clicked, emit discard event to parent to conclude functionality
|
||||||
*/
|
*/
|
||||||
discardEv(): void {
|
discardEv(): void {
|
||||||
this.discard.emit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 {
|
||||||
console.log(this.toAdd, this.toRemove);
|
|
||||||
// this.submit.emit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when reinstate button is clicked, emit reinstate event to parent to conclude functionality
|
|
||||||
*/
|
|
||||||
reinstateEv(): void {
|
|
||||||
this.reinstate.emit();
|
|
||||||
}
|
}
|
||||||
|
/* tslint:enable:no-empty */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,12 @@ import { RelationshipType } from '../../../../../../core/shared/item-relationshi
|
|||||||
import { Relationship } from '../../../../../../core/shared/item-relationships/relationship.model';
|
import { Relationship } from '../../../../../../core/shared/item-relationships/relationship.model';
|
||||||
import { result } from 'lodash';
|
import { result } from 'lodash';
|
||||||
|
|
||||||
|
import {
|
||||||
|
FieldUpdate,
|
||||||
|
FieldUpdates,
|
||||||
|
RelationshipIdentifiable
|
||||||
|
} from '../../../../../../core/data/object-updates/object-updates.reducer';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dynamic-lookup-relation-search-tab',
|
selector: 'ds-dynamic-lookup-relation-search-tab',
|
||||||
@@ -263,15 +269,6 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
|||||||
const uuid = arrUrl[ arrUrl.length - 1 ];
|
const uuid = arrUrl[ arrUrl.length - 1 ];
|
||||||
|
|
||||||
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