[ADF-2393] fixed reloading on delete with infinite scrolling (#3057)

* [ADF-2393] fixed reloading on delete with infinite scrolling

* [ADF-2393] refactored after PR
This commit is contained in:
Vito
2018-03-13 17:28:25 +00:00
committed by Eugenio Romano
parent 27de866193
commit 766bb082f5
3 changed files with 11 additions and 21 deletions

View File

@@ -295,7 +295,7 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
} }
emitReadyEvent(event: any) { emitReadyEvent(event: any) {
if (this.pageIsEmpty(event)) { if (this.standardPagination && this.pageIsEmpty(event)) {
this.standardPagination.goPrevious(); this.standardPagination.goPrevious();
} else { } else {
this.documentListReady.emit(event); this.documentListReady.emit(event);
@@ -328,11 +328,20 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
onContentActionSuccess(message) { onContentActionSuccess(message) {
const translatedMessage: any = this.translateService.get(message); const translatedMessage: any = this.translateService.get(message);
this.notificationService.openSnackMessage(translatedMessage.value, 4000); this.notificationService.openSnackMessage(translatedMessage.value, 4000);
this.reloadForInfiniteScrolling();
} }
onDeleteActionSuccess(message) { onDeleteActionSuccess(message) {
this.uploadService.fileDeleted.next(message); this.uploadService.fileDeleted.next(message);
this.deleteElementSuccess.emit(); this.deleteElementSuccess.emit();
this.reloadForInfiniteScrolling();
}
private reloadForInfiniteScrolling() {
if (this.infiniteScrolling) {
this.documentList.skipCount = 0;
this.documentList.reload();
}
} }
onManageVersions(event) { onManageVersions(event) {

View File

@@ -204,19 +204,6 @@ describe('DocumentActionsService', () => {
expect(documentListService.deleteNode).not.toHaveBeenCalled(); expect(documentListService.deleteNode).not.toHaveBeenCalled();
}); });
it('should reload target upon node deletion', () => {
spyOn(documentListService, 'deleteNode').and.returnValue(Observable.of(true));
let target = jasmine.createSpyObj('obj', ['reload']);
let permission = 'delete';
let file: any = new FileNode();
file.entry.allowableOperations = ['delete'];
service.getHandler('delete')(file, target, permission);
expect(documentListService.deleteNode).toHaveBeenCalled();
expect(target.reload).toHaveBeenCalled();
});
it('should emit success event upon node deletion', (done) => { it('should emit success event upon node deletion', (done) => {
service.success.subscribe((nodeId) => { service.success.subscribe((nodeId) => {
expect(nodeId).not.toBeNull(); expect(nodeId).not.toBeNull();

View File

@@ -101,10 +101,7 @@ export class DocumentActionsService {
private prepareHandlers(actionObservable, type: string, action: string, target?: any, permission?: string): void { private prepareHandlers(actionObservable, type: string, action: string, target?: any, permission?: string): void {
actionObservable.subscribe( actionObservable.subscribe(
(fileOperationMessage) => { (fileOperationMessage) => {
if (target && typeof target.reload === 'function') { this.success.next(fileOperationMessage);
target.reload();
}
this.success.next(fileOperationMessage);
}, },
this.error.next.bind(this.error) this.error.next.bind(this.error)
); );
@@ -117,9 +114,6 @@ export class DocumentActionsService {
if (this.contentService.hasPermission(node.entry, permission)) { if (this.contentService.hasPermission(node.entry, permission)) {
handlerObservable = this.documentListService.deleteNode(node.entry.id); handlerObservable = this.documentListService.deleteNode(node.entry.id);
handlerObservable.subscribe(() => { handlerObservable.subscribe(() => {
if (target && typeof target.reload === 'function') {
target.reload();
}
this.success.next(node.entry.id); this.success.next(node.entry.id);
}); });
return handlerObservable; return handlerObservable;