@@ -6,14 +6,9 @@ import { LayoutFacadeService, Sidebar } from 'app/entities/layout/layout.facade'
6
6
import { takeUntil } from 'rxjs/operators' ;
7
7
import { isNil } from 'lodash/fp' ;
8
8
9
- import { EntityStatus } from 'app/entities/entities' ;
10
9
import { GetEnvironments } from 'app/entities/environments/environment.action' ;
11
10
import { Environment } from 'app/entities/environments/environment.model' ;
12
- import {
13
- allEnvironments ,
14
- getAllStatus as getAllEnvironmentsForOrgStatus
15
- } from 'app/entities/environments/environment.selectors' ;
16
-
11
+ import { getAllStatus , environmentList } from 'app/entities/environments/environment.selectors' ;
17
12
18
13
@Component ( {
19
14
selector : 'app-environments' ,
@@ -29,7 +24,13 @@ export class EnvironmentsComponent implements OnInit, OnDestroy {
29
24
private isDestroyed = new Subject < boolean > ( ) ;
30
25
public environments : Environment [ ] = [ ] ;
31
26
public environmentsListLoading = true ;
27
+ public environmentListState : { items : Environment [ ] , total : number } ;
32
28
public authFailure = false ;
29
+ public per_page = 9 ;
30
+ public page = 1 ;
31
+ public searching = false ;
32
+ public searchValue = '' ;
33
+ public total : number ;
33
34
34
35
constructor (
35
36
private store : Store < NgrxStateAtom > ,
@@ -39,29 +40,61 @@ export class EnvironmentsComponent implements OnInit, OnDestroy {
39
40
ngOnInit ( ) {
40
41
this . layoutFacade . showSidebar ( Sidebar . Infrastructure ) ;
41
42
42
- this . store . dispatch ( new GetEnvironments ( {
43
- server_id : this . serverId , org_id : this . orgId
44
- } ) ) ;
43
+ const payload = {
44
+ environmentName : '' ,
45
+ page : this . page ,
46
+ per_page : this . per_page ,
47
+ server_id : this . serverId ,
48
+ org_id : this . orgId
49
+ } ;
50
+
51
+ this . store . dispatch ( new GetEnvironments ( payload ) ) ;
45
52
46
53
combineLatest ( [
47
- this . store . select ( getAllEnvironmentsForOrgStatus ) ,
48
- this . store . select ( allEnvironments )
49
- ] ) . pipe ( takeUntil ( this . isDestroyed ) )
50
- . subscribe ( ( [ getEnvironmentsSt , allEnvironmentsState ] ) => {
51
- if ( getEnvironmentsSt === EntityStatus . loadingSuccess && ! isNil ( allEnvironmentsState ) ) {
52
- this . environments = allEnvironmentsState ;
53
- this . environmentsListLoading = false ;
54
- } else if ( getEnvironmentsSt === EntityStatus . loadingFailure ) {
55
- this . environmentsListLoading = false ;
56
- this . authFailure = true ;
57
- }
58
- } ) ;
54
+ this . store . select ( getAllStatus ) ,
55
+ this . store . select ( environmentList )
56
+ ] ) . pipe (
57
+ takeUntil ( this . isDestroyed ) )
58
+ . subscribe ( ( [ _getEnvironmentsSt , EnvironmentsState ] ) => {
59
+ if ( ! isNil ( EnvironmentsState ) ) {
60
+ this . environmentListState = EnvironmentsState ;
61
+ this . environments = EnvironmentsState ?. items ;
62
+ this . total = EnvironmentsState ?. total ;
63
+ this . environmentsListLoading = false ;
64
+ this . searching = false ;
65
+ }
66
+ } ) ;
59
67
}
60
68
61
69
resetKeyTabRedirection ( resetLink : boolean ) {
62
70
this . resetKeyRedirection . emit ( resetLink ) ;
63
71
}
64
72
73
+ searchEnvironment ( currentText : string ) {
74
+ this . page = 1 ;
75
+ this . searching = true ;
76
+ this . searchValue = currentText ;
77
+ this . getEnvironmentData ( ) ;
78
+ }
79
+
80
+ onPageChange ( event : number ) : void {
81
+ this . page = event ;
82
+ this . searching = true ;
83
+ this . getEnvironmentData ( ) ;
84
+ }
85
+
86
+ getEnvironmentData ( ) {
87
+ const payload = {
88
+ environmentName : this . searchValue ,
89
+ page : this . page ,
90
+ per_page : this . per_page ,
91
+ server_id : this . serverId ,
92
+ org_id : this . orgId
93
+ } ;
94
+
95
+ this . store . dispatch ( new GetEnvironments ( payload ) ) ;
96
+ }
97
+
65
98
ngOnDestroy ( ) : void {
66
99
this . isDestroyed . next ( true ) ;
67
100
this . isDestroyed . complete ( ) ;
0 commit comments