1313 * limitations under the License.
1414 */
1515
16- import { Component , OnDestroy , OnInit , QueryList , ViewChildren } from '@angular/core' ;
16+ import { AfterViewInit , Component , OnDestroy , OnInit , QueryList , ViewChildren } from '@angular/core' ;
1717import { Subject , Subscription } from 'rxjs' ;
1818import { AppState , selectWorkflowState } from '../../../stores/app.reducers' ;
1919import { WorkflowModel } from '../../../models/workflow.model' ;
@@ -24,9 +24,8 @@ import {
2424 ImportWorkflows ,
2525 LoadJobsForRun ,
2626 RunWorkflows ,
27+ SearchWorkflows ,
2728 SetWorkflowFile ,
28- SetWorkflowsFilters ,
29- SetWorkflowsSort ,
3029 UpdateWorkflowsIsActive ,
3130} from '../../../stores/workflows/workflows.actions' ;
3231import { ConfirmationDialogTypes } from '../../../constants/confirmationDialogTypes.constants' ;
@@ -38,24 +37,36 @@ import { ClrDatagridColumn, ClrDatagridStateInterface } from '@clr/angular';
3837import { SortAttributesModel } from '../../../models/search/sortAttributes.model' ;
3938import { filter } from 'rxjs/operators' ;
4039import { 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' ;
4143
4244@Component ( {
4345 selector : 'app-workflows-home' ,
4446 templateUrl : './workflows-home.component.html' ,
4547 styleUrls : [ './workflows-home.component.scss' ] ,
4648} )
47- export class WorkflowsHomeComponent implements OnInit , OnDestroy {
49+ export class WorkflowsHomeComponent implements OnInit , AfterViewInit , OnDestroy {
4850 @ViewChildren ( ClrDatagridColumn ) columns : QueryList < ClrDatagridColumn > ;
4951
5052 confirmationDialogServiceSubscription : Subscription = null ;
5153 runWorkflowDialogSubscription : Subscription = null ;
5254 workflowsSubscription : Subscription = null ;
55+ loadingSubscription : Subscription = null ;
5356 routerSubscription : Subscription = null ;
5457 workflows : WorkflowModel [ ] = [ ] ;
5558 absoluteRoutes = absoluteRoutes ;
5659 workflowsHomeColumns = workflowsHomeColumns ;
5760 selected : WorkflowModel [ ] = [ ] ;
5861
62+ loading = true ;
63+ loadingAction = false ;
64+
65+ page = 1 ;
66+ total = 0 ;
67+ pageFrom = 0 ;
68+ pageSize = 0 ;
69+
5970 removeWorkflowFilterSubject : Subject < any > = new Subject ( ) ;
6071 sort : SortAttributesModel = undefined ;
6172 filters : any [ ] = undefined ;
@@ -74,9 +85,29 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
7485
7586 ngOnInit ( ) : void {
7687 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 ;
80111 } ) ;
81112 }
82113
@@ -95,7 +126,6 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
95126 this . confirmationDialogServiceSubscription = this . confirmationDialogService
96127 . confirm ( ConfirmationDialogTypes . YesOrNo , texts . BULK_RUN_WORKFLOWS_TITLE , texts . BULK_RUN_WORKFLOWS_CONTENT ( selected . length ) )
97128 . subscribe ( ( confirmed ) => {
98- this . ignoreRefresh = true ;
99129 if ( confirmed ) this . store . dispatch ( new RunWorkflows ( selected . map ( ( workflow ) => workflow . id ) ) ) ;
100130 } ) ;
101131 }
@@ -146,7 +176,6 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
146176 this . confirmationDialogServiceSubscription = this . confirmationDialogService
147177 . confirm ( ConfirmationDialogTypes . Delete , texts . DELETE_WORKFLOW_CONFIRMATION_TITLE , texts . DELETE_WORKFLOW_CONFIRMATION_CONTENT )
148178 . subscribe ( ( confirmed ) => {
149- this . ignoreRefresh = true ;
150179 if ( confirmed ) this . store . dispatch ( new DeleteWorkflow ( id ) ) ;
151180 } ) ;
152181 }
@@ -160,7 +189,6 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
160189 )
161190 . subscribe ( ( confirmed ) => {
162191 if ( confirmed ) {
163- this . ignoreRefresh = true ;
164192 this . store . dispatch ( new SwitchWorkflowActiveState ( { id : id , currentActiveState : currentActiveState } ) ) ;
165193 }
166194 } ) ;
@@ -177,16 +205,28 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
177205 onClarityDgRefresh ( state : ClrDatagridStateInterface ) {
178206 if ( ! this . ignoreRefresh ) {
179207 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 ;
181210 this . filters = state . filters ? state . filters : [ ] ;
182- this . store . dispatch ( new SetWorkflowsFilters ( this . filters ) ) ;
211+ this . refresh ( ) ;
183212 }
184213 }
185214
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+
186226 getFilter ( name : string ) : any | undefined {
187227 let filter = undefined ;
188228 if ( this . filters ) {
189- filter = this . filters . find ( ( filter ) => filter . field == name ) ;
229+ filter = this . filters . find ( ( filter ) => filter ? .field == name ) ;
190230 }
191231
192232 return filter && filter . value ? filter . value : undefined ;
@@ -197,7 +237,8 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
197237 }
198238
199239 clearFilters ( ) {
200- this . removeWorkflowFilterSubject . next ( ) ;
240+ this . filters = [ ] ;
241+ this . refresh ( ) ;
201242 }
202243
203244 clearSort ( ) {
@@ -236,7 +277,6 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
236277 )
237278 . subscribe ( ( confirmed ) => {
238279 if ( confirmed ) {
239- this . ignoreRefresh = true ;
240280 this . store . dispatch ( new UpdateWorkflowsIsActive ( { ids : ids , isActiveNewValue : isActiveNewValue } ) ) ;
241281 }
242282 } ) ;
@@ -247,5 +287,6 @@ export class WorkflowsHomeComponent implements OnInit, OnDestroy {
247287 ! ! this . confirmationDialogServiceSubscription && this . confirmationDialogServiceSubscription . unsubscribe ( ) ;
248288 ! ! this . runWorkflowDialogSubscription && this . runWorkflowDialogSubscription . unsubscribe ( ) ;
249289 ! ! this . routerSubscription && this . routerSubscription . unsubscribe ( ) ;
290+ ! ! this . loadingSubscription && this . loadingSubscription . unsubscribe ( ) ;
250291 }
251292}
0 commit comments