13
13
* limitations under the License.
14
14
*/
15
15
16
- import { Component , OnDestroy , OnInit , QueryList , ViewChildren } from '@angular/core' ;
16
+ import { AfterViewInit , Component , OnDestroy , OnInit , QueryList , ViewChildren } from '@angular/core' ;
17
17
import { Subject , Subscription } from 'rxjs' ;
18
18
import { AppState , selectWorkflowState } from '../../../stores/app.reducers' ;
19
19
import { WorkflowModel } from '../../../models/workflow.model' ;
@@ -24,9 +24,8 @@ import {
24
24
ImportWorkflows ,
25
25
LoadJobsForRun ,
26
26
RunWorkflows ,
27
+ SearchWorkflows ,
27
28
SetWorkflowFile ,
28
- SetWorkflowsFilters ,
29
- SetWorkflowsSort ,
30
29
UpdateWorkflowsIsActive ,
31
30
} from '../../../stores/workflows/workflows.actions' ;
32
31
import { ConfirmationDialogTypes } from '../../../constants/confirmationDialogTypes.constants' ;
@@ -38,24 +37,36 @@ import { ClrDatagridColumn, ClrDatagridStateInterface } from '@clr/angular';
38
37
import { SortAttributesModel } from '../../../models/search/sortAttributes.model' ;
39
38
import { filter } from 'rxjs/operators' ;
40
39
import { workflowsHomeColumns } from 'src/app/constants/workflow.constants' ;
40
+ import { TableSearchRequestModel } from '../../../models/search/tableSearchRequest.model' ;
41
+ import { ContainsFilterAttributes } from '../../../models/search/containsFilterAttributes.model' ;
42
+ import { BooleanFilterAttributes } from '../../../models/search/booleanFilterAttributes.model' ;
41
43
42
44
@Component ( {
43
45
selector : 'app-workflows-home' ,
44
46
templateUrl : './workflows-home.component.html' ,
45
47
styleUrls : [ './workflows-home.component.scss' ] ,
46
48
} )
47
- export class WorkflowsHomeComponent implements OnInit , OnDestroy {
49
+ export class WorkflowsHomeComponent implements OnInit , AfterViewInit , OnDestroy {
48
50
@ViewChildren ( ClrDatagridColumn ) columns : QueryList < ClrDatagridColumn > ;
49
51
50
52
confirmationDialogServiceSubscription : Subscription = null ;
51
53
runWorkflowDialogSubscription : Subscription = null ;
52
54
workflowsSubscription : Subscription = null ;
55
+ loadingSubscription : Subscription = null ;
53
56
routerSubscription : Subscription = null ;
54
57
workflows : WorkflowModel [ ] = [ ] ;
55
58
absoluteRoutes = absoluteRoutes ;
56
59
workflowsHomeColumns = workflowsHomeColumns ;
57
60
selected : WorkflowModel [ ] = [ ] ;
58
61
62
+ loading = true ;
63
+ loadingAction = false ;
64
+
65
+ page = 1 ;
66
+ total = 0 ;
67
+ pageFrom = 0 ;
68
+ pageSize = 0 ;
69
+
59
70
removeWorkflowFilterSubject : Subject < any > = new Subject ( ) ;
60
71
sort : SortAttributesModel = undefined ;
61
72
filters : any [ ] = undefined ;
@@ -74,9 +85,29 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
74
85
75
86
ngOnInit ( ) : void {
76
87
this . workflowsSubscription = this . store . select ( selectWorkflowState ) . subscribe ( ( state ) => {
77
- this . workflows = state . workflows ;
78
- this . sort = state . workflowsSort ;
79
- this . filters = state . workflowsFilters ;
88
+ this . workflows = state . workflowsSearch . workflows ;
89
+ this . total = state . workflowsSearch . total ;
90
+ this . sort = state . workflowsSearch . searchRequest ?. sort ;
91
+ this . filters = [
92
+ ...( state . workflowsSearch . searchRequest ?. containsFilterAttributes || [ ] ) ,
93
+ ...( state . workflowsSearch . searchRequest ?. booleanFilterAttributes || [ ] ) ,
94
+ ] ;
95
+ this . pageFrom = state . workflowsSearch . searchRequest ?. from ? state . workflowsSearch . searchRequest ?. from : 0 ;
96
+ this . pageSize = state . workflowsSearch . searchRequest ?. size ? state . workflowsSearch . searchRequest ?. size : 100 ;
97
+ this . page = this . pageFrom / this . pageSize + 1 ;
98
+
99
+ if ( this . loadingAction == true && state . workflowAction . loading == false ) {
100
+ this . loadingAction = false ;
101
+ this . refresh ( ) ;
102
+ } else {
103
+ this . loadingAction = state . workflowAction . loading ;
104
+ }
105
+ } ) ;
106
+ }
107
+
108
+ ngAfterViewInit ( ) : void {
109
+ this . loadingSubscription = this . store . select ( selectWorkflowState ) . subscribe ( ( state ) => {
110
+ this . loading = state . workflowsSearch . loading ;
80
111
} ) ;
81
112
}
82
113
@@ -95,7 +126,6 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
95
126
this . confirmationDialogServiceSubscription = this . confirmationDialogService
96
127
. confirm ( ConfirmationDialogTypes . YesOrNo , texts . BULK_RUN_WORKFLOWS_TITLE , texts . BULK_RUN_WORKFLOWS_CONTENT ( selected . length ) )
97
128
. subscribe ( ( confirmed ) => {
98
- this . ignoreRefresh = true ;
99
129
if ( confirmed ) this . store . dispatch ( new RunWorkflows ( selected . map ( ( workflow ) => workflow . id ) ) ) ;
100
130
} ) ;
101
131
}
@@ -146,7 +176,6 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
146
176
this . confirmationDialogServiceSubscription = this . confirmationDialogService
147
177
. confirm ( ConfirmationDialogTypes . Delete , texts . DELETE_WORKFLOW_CONFIRMATION_TITLE , texts . DELETE_WORKFLOW_CONFIRMATION_CONTENT )
148
178
. subscribe ( ( confirmed ) => {
149
- this . ignoreRefresh = true ;
150
179
if ( confirmed ) this . store . dispatch ( new DeleteWorkflow ( id ) ) ;
151
180
} ) ;
152
181
}
@@ -160,7 +189,6 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
160
189
)
161
190
. subscribe ( ( confirmed ) => {
162
191
if ( confirmed ) {
163
- this . ignoreRefresh = true ;
164
192
this . store . dispatch ( new SwitchWorkflowActiveState ( { id : id , currentActiveState : currentActiveState } ) ) ;
165
193
}
166
194
} ) ;
@@ -177,16 +205,28 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
177
205
onClarityDgRefresh ( state : ClrDatagridStateInterface ) {
178
206
if ( ! this . ignoreRefresh ) {
179
207
this . sort = state . sort ? new SortAttributesModel ( state . sort . by as string , state . sort . reverse ? - 1 : 1 ) : undefined ;
180
- this . store . dispatch ( new SetWorkflowsSort ( this . sort ) ) ;
208
+ this . pageFrom = state . page . from < 0 ? 0 : state . page . from ;
209
+ this . pageSize = state . page . size ;
181
210
this . filters = state . filters ? state . filters : [ ] ;
182
- this . store . dispatch ( new SetWorkflowsFilters ( this . filters ) ) ;
211
+ this . refresh ( ) ;
183
212
}
184
213
}
185
214
215
+ refresh ( ) {
216
+ const searchRequestModel : TableSearchRequestModel = {
217
+ from : this . pageFrom ,
218
+ size : this . pageSize ,
219
+ sort : this . sort ,
220
+ containsFilterAttributes : this . filters . filter ( ( f ) => f instanceof ContainsFilterAttributes ) . map ( ( f ) => f as ContainsFilterAttributes ) ,
221
+ booleanFilterAttributes : this . filters . filter ( ( f ) => f instanceof BooleanFilterAttributes ) . map ( ( f ) => f as BooleanFilterAttributes ) ,
222
+ } ;
223
+ this . store . dispatch ( new SearchWorkflows ( searchRequestModel ) ) ;
224
+ }
225
+
186
226
getFilter ( name : string ) : any | undefined {
187
227
let filter = undefined ;
188
228
if ( this . filters ) {
189
- filter = this . filters . find ( ( filter ) => filter . field == name ) ;
229
+ filter = this . filters . find ( ( filter ) => filter ? .field == name ) ;
190
230
}
191
231
192
232
return filter && filter . value ? filter . value : undefined ;
@@ -197,7 +237,8 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
197
237
}
198
238
199
239
clearFilters ( ) {
200
- this . removeWorkflowFilterSubject . next ( ) ;
240
+ this . filters = [ ] ;
241
+ this . refresh ( ) ;
201
242
}
202
243
203
244
clearSort ( ) {
@@ -236,7 +277,6 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
236
277
)
237
278
. subscribe ( ( confirmed ) => {
238
279
if ( confirmed ) {
239
- this . ignoreRefresh = true ;
240
280
this . store . dispatch ( new UpdateWorkflowsIsActive ( { ids : ids , isActiveNewValue : isActiveNewValue } ) ) ;
241
281
}
242
282
} ) ;
@@ -247,5 +287,6 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
247
287
! ! this . confirmationDialogServiceSubscription && this . confirmationDialogServiceSubscription . unsubscribe ( ) ;
248
288
! ! this . runWorkflowDialogSubscription && this . runWorkflowDialogSubscription . unsubscribe ( ) ;
249
289
! ! this . routerSubscription && this . routerSubscription . unsubscribe ( ) ;
290
+ ! ! this . loadingSubscription && this . loadingSubscription . unsubscribe ( ) ;
250
291
}
251
292
}
0 commit comments