[ACA-1047] Personal Files - upload makes application unstable when view is destroyed (#121)

This commit is contained in:
Cilibiu Bogdan 2017-12-08 10:27:35 +02:00 committed by Denys Vuika
parent 17ae9af1fe
commit 2f33eafdc4

View File

@ -16,7 +16,7 @@
*/ */
import { Observable, Subscription } from 'rxjs/Rx'; import { Observable, Subscription } from 'rxjs/Rx';
import { Component, OnInit, OnDestroy, ChangeDetectorRef, ViewChild } from '@angular/core'; import { Component, OnInit, OnDestroy, ViewChild, NgZone } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router'; import { Router, ActivatedRoute, Params } from '@angular/router';
import { MinimalNodeEntity, MinimalNodeEntryEntity, PathElementEntity, NodePaging, PathElement } from 'alfresco-js-api'; import { MinimalNodeEntity, MinimalNodeEntryEntity, PathElementEntity, NodePaging, PathElement } from 'alfresco-js-api';
import { import {
@ -46,9 +46,9 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
constructor( constructor(
private router: Router, private router: Router,
private zone: NgZone,
private route: ActivatedRoute, private route: ActivatedRoute,
private nodesApi: NodesApiService, private nodesApi: NodesApiService,
private changeDetector: ChangeDetectorRef,
private nodeActionsService: NodeActionsService, private nodeActionsService: NodeActionsService,
private uploadService: UploadService, private uploadService: UploadService,
private contentManagementService: ContentManagementService, private contentManagementService: ContentManagementService,
@ -215,22 +215,18 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
this.isLoading = showIndicator; this.isLoading = showIndicator;
this.fetchNodes(this.getParentNodeId(), pagination) this.fetchNodes(this.getParentNodeId(), pagination)
.subscribe( .flatMap((page) => {
(page) => {
if (this.isCurrentPageEmpty(page) && this.isNotFirstPage(page)) { if (this.isCurrentPageEmpty(page) && this.isNotFirstPage(page)) {
const newSkipCount = pagination.skipCount - pagination.maxItems; const newSkipCount = pagination.skipCount - pagination.maxItems;
this.fetchNodes(this.getParentNodeId(), {skipCount: newSkipCount, maxItems: pagination.maxItems}) return this.fetchNodes(this.getParentNodeId(), {skipCount: newSkipCount, maxItems: pagination.maxItems});
.subscribe(
(previousPage) => this.onPageLoaded(previousPage),
error => this.onFetchError(error)
);
} else {
this.onPageLoaded(page);
} }
},
error => this.onFetchError(error), return Observable.of(page);
() => this.changeDetector.detectChanges() })
.subscribe(
(page) => this.zone.run(() => this.onPageLoaded(page)),
error => this.onFetchError(error)
); );
} }