1
1
import { Component , Input , OnDestroy } from '@angular/core' ;
2
2
import { AbstractViewWithHeadersComponent } from '../abstract/view-with-headers' ;
3
- import { Observable , Subject , Subscription } from 'rxjs' ;
3
+ import { Observable , ReplaySubject , Subscription } from 'rxjs' ;
4
4
import { TaskPanelData } from '../../panel/task-panel-list/task-panel-data/task-panel-data' ;
5
5
import { TaskViewService } from './service/task-view.service' ;
6
- import { map , takeUntil } from 'rxjs/operators' ;
7
6
import { ActivatedRoute } from '@angular/router' ;
8
7
9
8
export class TaskConst {
@@ -18,22 +17,25 @@ export abstract class AbstractSingleTaskViewComponent extends AbstractViewWithHe
18
17
19
18
@Input ( ) initiallyExpanded : boolean = true ;
20
19
@Input ( ) preventCollapse : boolean = true ;
21
- public task$ : Observable < TaskPanelData > ;
20
+ public taskPanelData : ReplaySubject < TaskPanelData > ;
22
21
public loading$ : Observable < boolean > ;
23
22
private transitionId : string ;
24
- private subRoute : Subscription ;
25
- protected unsubscribe$ : Subject < void > ;
23
+ private subRoute : Subscription | undefined ;
24
+ protected subPanelData : Subscription ;
26
25
27
26
protected constructor ( protected taskViewService : TaskViewService ,
28
27
activatedRoute : ActivatedRoute ) {
29
28
super ( taskViewService , activatedRoute ) ;
30
- this . unsubscribe$ = new Subject < void > ( ) ;
29
+ this . taskPanelData = new ReplaySubject < TaskPanelData > ( 1 ) ;
31
30
this . subRoute = this . _activatedRoute . paramMap . subscribe ( paramMap => {
32
31
if ( ! ! ( paramMap ?. [ 'params' ] ?. [ TaskConst . TRANSITION_ID ] ) ) {
33
32
this . transitionId = paramMap [ 'params' ] [ TaskConst . TRANSITION_ID ] ;
34
- this . task$ = this . taskViewService . tasks$ . pipe ( map < Array < TaskPanelData > , TaskPanelData > ( tasks => {
35
- return this . resolveTransitionTask ( tasks ) ;
36
- } ) , takeUntil ( this . unsubscribe$ ) ) ;
33
+ this . subPanelData . unsubscribe ( ) ;
34
+ this . subPanelData = this . taskViewService . tasks$ . subscribe ( tasks => {
35
+ if ( ! ! tasks && tasks . length > 0 ) {
36
+ this . taskPanelData . next ( this . resolveTransitionTask ( tasks ) ) ;
37
+ }
38
+ } ) ;
37
39
}
38
40
} ) ;
39
41
this . loading$ = this . taskViewService . loading$ ;
@@ -42,8 +44,13 @@ export abstract class AbstractSingleTaskViewComponent extends AbstractViewWithHe
42
44
ngOnDestroy ( ) {
43
45
super . ngOnDestroy ( ) ;
44
46
this . subRoute . unsubscribe ( ) ;
45
- this . unsubscribe$ . next ( ) ;
46
- this . unsubscribe$ . complete ( ) ;
47
+ if ( ! ! this . subPanelData ) {
48
+ this . subPanelData . unsubscribe ( ) ;
49
+ }
50
+ }
51
+
52
+ get task$ ( ) : Observable < TaskPanelData > {
53
+ return this . taskPanelData . asObservable ( ) ;
47
54
}
48
55
49
56
private resolveTransitionTask ( tasks : Array < TaskPanelData > ) : TaskPanelData {
0 commit comments