1- import { BehaviorSubject , Observable , of as observableOf , Subscription , timer } from 'rxjs' ;
21import {
32 ChangeDetectionStrategy ,
43 ChangeDetectorRef ,
54 Component ,
65 Input ,
7- NgZone ,
86 OnDestroy ,
97 OnInit ,
108 TemplateRef ,
119 ViewEncapsulation
1210} from '@angular/core' ;
1311import { trigger } from '@angular/animations' ;
1412import { DomSanitizer } from '@angular/platform-browser' ;
13+
14+ import { BehaviorSubject , Observable , of as observableOf , Subscription , timer } from 'rxjs' ;
15+ import { filter , map , switchMap , take , tap } from 'rxjs/operators' ;
16+
1517import { NotificationsService } from '../notifications.service' ;
1618import { scaleEnter , scaleInState , scaleLeave , scaleOutState } from '../../animations/scale' ;
1719import { rotateEnter , rotateInState , rotateLeave , rotateOutState } from '../../animations/rotate' ;
@@ -26,12 +28,9 @@ import { IProcessNotification } from '../models/process-notification.model';
2628import { ProcessDataService } from '../../../core/data/processes/process-data.service' ;
2729import { Process } from '../../../process-page/processes/process.model' ;
2830import { Bitstream } from '../../../core/shared/bitstream.model' ;
29- import {
30- getAllCompletedRemoteData , getFirstCompletedRemoteData
31- } from '../../../core/shared/operators' ;
31+ import { getAllCompletedRemoteData , getFirstCompletedRemoteData } from '../../../core/shared/operators' ;
3232import { DSONameService } from '../../../core/breadcrumbs/dso-name.service' ;
3333import { DSpaceObject } from '../../../core/shared/dspace-object.model' ;
34- import { filter , map , switchMap , take } from 'rxjs/operators' ;
3534import { RemoteData } from '../../../core/data/remote-data' ;
3635
3736@Component ( {
@@ -110,7 +109,7 @@ export class ProcessNotificationComponent implements OnInit, OnDestroy {
110109 protected processService : ProcessDataService ,
111110 protected nameService : DSONameService ,
112111 private cdr : ChangeDetectorRef ,
113- private zone : NgZone ) {
112+ ) {
114113 }
115114
116115 /**
@@ -127,45 +126,54 @@ export class ProcessNotificationComponent implements OnInit, OnDestroy {
127126 * Poll process endpoint until it's finished.
128127 */
129128 pollUntilProcessFinished ( ) {
130- timer ( 0 , 5000 ) . pipe (
129+ timer ( 0 , this . notification . checkTime ) . pipe (
131130 switchMap ( ( ) => this . processService . getProcess ( this . notification . processId ) ) ,
132131 getAllCompletedRemoteData ( ) ,
133- filter ( ( res : RemoteData < Process > ) => res ?. payload ?. processStatus . toString ( ) === 'COMPLETED' || res ?. payload ?. processStatus . toString ( ) === 'FAILED' ) ,
132+ filter ( ( res : RemoteData < Process > ) => res . hasFailed || res ?. payload ?. processStatus . toString ( ) === 'COMPLETED' || res ?. payload ?. processStatus . toString ( ) === 'FAILED' ) ,
134133 take ( 1 ) ,
135- ) . subscribe ( ( res : RemoteData < Process > ) => {
136- this . pollingFinishedFor ( res . payload ) ;
134+ tap ( ( res : RemoteData < Process > ) => this . pollingFinishedFor ( res ) ) ,
135+ switchMap ( ( res : RemoteData < Process > ) => this . getFiles ( res ) ) ,
136+ ) . subscribe ( ( files : Bitstream [ ] ) => {
137+ const logFiles = files . filter ( ( file ) => ! this . getFileName ( file ) . includes ( '.log' ) ) ;
138+ this . files$ . next ( logFiles ) ;
139+ this . finished . next ( true ) ;
137140 } ) ;
138141 }
139142
140143 /**
141144 * Handle process results
142145 *
143- * @param process The process finished
146+ * @param processRD The RemoteData object for finished process
144147 */
145- pollingFinishedFor ( process : Process ) {
146- const processStatus = process . processStatus . toString ( ) ;
147- if ( processStatus === 'COMPLETED' ) {
148+ pollingFinishedFor ( processRD : RemoteData < Process > ) {
149+ if ( processRD . hasSucceeded && processRD . payload . processStatus . toString ( ) === 'COMPLETED' ) {
148150 this . notificationType$ . next ( 'alert-success' ) ;
149151 this . processStatus$ . next ( 'process.new.notification.process.status.completed' ) ;
150- this . getFiles ( ) ;
151152 } else {
152153 this . processStatus$ . next ( 'process.new.notification.process.status.failed' ) ;
153154 this . notificationType$ . next ( 'alert-danger' ) ;
154155 }
155- this . finished . next ( true ) ;
156156 }
157157
158158 /**
159159 * When the process is completed get the files output.
160160 */
161- getFiles ( ) {
162- this . processService . getFiles ( this . notification . processId ) . pipe (
161+ getFiles ( processRD : RemoteData < Process > ) : Observable < Bitstream [ ] > {
162+ if ( processRD . hasSucceeded && processRD . payload . processStatus . toString ( ) === 'COMPLETED' ) {
163+ return this . processService . getFiles ( processRD . payload . processId ) . pipe (
164+ getFirstCompletedRemoteData ( ) ,
165+ map ( ( response ) => response . hasSucceeded ? response . payload . page : [ ] )
166+ ) ;
167+ } else {
168+ return observableOf ( [ ] ) ;
169+ }
170+ /* this.processService.getFiles(this.notification.processId).pipe(
163171 getFirstCompletedRemoteData(),
164172 map((response) => response.hasSucceeded ? response.payload.page : [])
165173 ).subscribe( (files: Bitstream[]) => {
166174 const logFiles = files.filter( (file) => !this.getFileName(file).includes('.log'));
167175 this.files$.next(logFiles);
168- } ) ;
176+ });*/
169177 }
170178
171179 /**
0 commit comments